diagrams-gtk-1.4/0000755000000000000000000000000013004306111012103 5ustar0000000000000000diagrams-gtk-1.4/Setup.hs0000644000000000000000000000005613004306111013540 0ustar0000000000000000import Distribution.Simple main = defaultMain diagrams-gtk-1.4/diagrams-gtk.cabal0000644000000000000000000000225213004306111015442 0ustar0000000000000000name: diagrams-gtk version: 1.4 synopsis: Backend for rendering diagrams directly to GTK windows description: An optional add-on to the diagrams-cairo package which allows rendering diagrams directly to GTK windows. homepage: http://projects.haskell.org/diagrams/ license: BSD3 license-file: LICENSE author: John Lato maintainer: diagrams-discuss@googlegroups.com copyright: John Lato category: Graphics build-type: Simple cabal-version: >=1.10 tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC == 8.0.1 extra-source-files: CHANGES.markdown, README.markdown source-repository head type: git location: http://github.com/diagrams/diagrams-gtk.git library exposed-modules: Diagrams.Backend.Gtk build-depends: base >= 4.2 && < 4.10, diagrams-lib >= 1.3 && < 1.5, diagrams-cairo >= 1.3 && < 1.5, gtk >= 0.12.0 && < 0.15, cairo >= 0.12.4 && < 0.14 hs-source-dirs: src default-language: Haskell2010 diagrams-gtk-1.4/LICENSE0000644000000000000000000000327713004306111013121 0ustar0000000000000000Copyright (c) 2012-2015 the diagrams-gtk team: Daniel Bergey Jonas Haag John Lato Jeffrey Rosenbluth Brent Yorgey All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of John Lato nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diagrams-gtk-1.4/README.markdown0000644000000000000000000000041513004306111014604 0ustar0000000000000000[![Build Status](https://secure.travis-ci.org/diagrams/diagrams-gtk.png)](http://travis-ci.org/diagrams/diagrams-gtk) A rendering backend for drawing [diagrams](http://projects.haskell.org/diagrams) directly to GTK windows, built on top of the diagrams-cairo backend. diagrams-gtk-1.4/CHANGES.markdown0000644000000000000000000000215413004306111014721 0ustar00000000000000001.4 (2016-10-26) ---------------- * Updates for diagrams 1.4: - allow diagrams-lib-1.4 - allow diagrams-cairo-1.4 1.3.0.2 (16 June 2016) ---------------------- - allow `base-4.9` - test on GHC 8.0.1 1.3.0.1 (24 January 2016) ------------------------- - allow gtk-0.14 1.3 (19 April 2015) ------------------- * Updates for diagrams 1.3: - allow base-4.8 - require diagrams-lib-1.3 - require diagrams-cairo-1.3 1.0.1.3 (8 Sept 2014) --------------------- * Allow `gtk-0.13` and `cairo-0.13` 1.0.1.2 (3 June 2014) --------------------- * Require `diagrams-lib-1.2` and `diagrams-cairo-1.2` 1.0.1.1: 2 June 2014 ------------------- * Allow `diagrams-lib-1.2` * Allow `diagrams-cairo-1.2` 1.0.1: 8 March 2014 ------------------- * Use double buffering. Thanks to Jonas Haag for the patch. 1.0: 25 November 2013 --------------------- * Updated to work with diagrams-cairo-1.0. 0.6.0.1: 1 August 2013 ---------------------- * Allow `base-4.7`, `diagrams-lib-0.7`, and `diagrams-cairo-0.7` 0.6: 11 December 2012 --------------------- Initial release. Split out into a separate package from `diagrams-cairo`. diagrams-gtk-1.4/src/0000755000000000000000000000000013004306111012672 5ustar0000000000000000diagrams-gtk-1.4/src/Diagrams/0000755000000000000000000000000013004306111014421 5ustar0000000000000000diagrams-gtk-1.4/src/Diagrams/Backend/0000755000000000000000000000000013004306111015750 5ustar0000000000000000diagrams-gtk-1.4/src/Diagrams/Backend/Gtk.hs0000644000000000000000000000774013004306111017041 0ustar0000000000000000{-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | -- Module : Diagrams.Backend.Gtk -- Copyright : (c) 2011 Diagrams-cairo team (see LICENSE) -- License : BSD-style (see LICENSE) -- Maintainer : diagrams-discuss@googlegroups.com -- -- Convenient interface to rendering diagrams directly -- on Gtk widgets using the Cairo backend. -- ----------------------------------------------------------------------------- module Diagrams.Backend.Gtk ( defaultRender , toGtkCoords , renderToGtk ) where import Diagrams.Backend.Cairo as Cairo import Diagrams.Prelude hiding (height, width) -- Below hack is needed because GHC 7.0.x has a bug regarding export -- of data family constructors; see comments in Diagrams.Backend.Cairo #if __GLASGOW_HASKELL__ < 702 || __GLASGOW_HASKELL__ >= 704 import Diagrams.Backend.Cairo.Internal #endif import qualified Graphics.Rendering.Cairo as CG import Graphics.UI.Gtk -- | Convert a Diagram to the backend coordinates. -- -- Provided to Query the diagram with coordinates from a mouse click -- event. -- -- > widget `on` buttonPressEvent $ tryEvent $ do -- > click <- eventClick -- > (x,y) <- eventCoordinates -- > let result = runQuery (query $ toGtkCoords myDiagram) (x ^& y) -- > do_something_with result -- -- `toGtkCoords` does no rescaling of the diagram, however it is centered in -- the window. toGtkCoords :: Monoid' m => QDiagram Cairo V2 Double m -> QDiagram Cairo V2 Double m toGtkCoords d = (\(_,_,d') -> d') $ adjustDia Cairo (CairoOptions "" absolute RenderOnly False) d -- | Render a diagram to a DrawingArea with double buffering, -- rescaling to fit the full area. defaultRender :: Monoid' m => DrawingArea -> QDiagram Cairo V2 Double m -> IO () defaultRender drawingarea diagram = do drawWindow <- (widgetGetDrawWindow drawingarea) renderDoubleBuffered drawWindow opts diagram where opts w h = (CairoOptions { _cairoFileName = "" , _cairoSizeSpec = dims (V2 (fromIntegral w) (fromIntegral h)) , _cairoOutputType = RenderOnly , _cairoBypassAdjust = False } ) -- | Render a diagram to a 'DrawableClass' with double buffering. No -- rescaling or transformations will be performed. -- -- Typically the diagram will already have been transformed by -- 'toGtkCoords'. renderToGtk :: (DrawableClass dc, Monoid' m) => dc -- ^ widget to render onto -> QDiagram Cairo V2 Double m -- ^ Diagram -> IO () renderToGtk drawable = do renderDoubleBuffered drawable opts where opts _ _ = (CairoOptions { _cairoFileName = "" , _cairoSizeSpec = absolute , _cairoOutputType = RenderOnly , _cairoBypassAdjust = True } ) -- | Render a diagram onto a 'DrawableClass' using the given CairoOptions. -- -- This uses cairo double-buffering. renderDoubleBuffered :: (Monoid' m, DrawableClass dc) => dc -- ^ drawable to render onto -> (Int -> Int -> Options Cairo V2 Double) -- ^ options, depending on drawable width and height -> QDiagram Cairo V2 Double m -- ^ Diagram -> IO () renderDoubleBuffered drawable renderOpts diagram = do (w,h) <- drawableGetSize drawable let opts = renderOpts w h renderAction = delete w h >> snd (renderDia Cairo opts diagram) renderWithDrawable drawable (doubleBuffer renderAction) -- | White rectangle of size (w,h). -- -- Used to clear canvas when using double buffering. delete :: Int -> Int -> CG.Render () delete w h = do CG.setSourceRGB 1 1 1 CG.rectangle 0 0 (fromIntegral w) (fromIntegral h) CG.fill -- | Wrap the given render action in double buffering. doubleBuffer :: CG.Render () -> CG.Render () doubleBuffer renderAction = do CG.pushGroup renderAction CG.popGroupToSource CG.paint