diagrams-gtk (empty) → 0.6
raw patch · 6 files changed
+158/−0 lines, 6 filesdep +basedep +diagrams-cairodep +diagrams-libsetup-changed
Dependencies added: base, diagrams-cairo, diagrams-lib, gtk
Files
- CHANGES.markdown +5/−0
- LICENSE +30/−0
- README.markdown +5/−0
- Setup.hs +2/−0
- diagrams-gtk.cabal +29/−0
- src/Diagrams/Backend/Gtk.hs +87/−0
+ CHANGES.markdown view
@@ -0,0 +1,5 @@+0.6: 11 December 2012+---------------------++Initial release. Split out into a separate package from+`diagrams-cairo`.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, John Lato++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.
+ README.markdown view
@@ -0,0 +1,5 @@+[](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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ diagrams-gtk.cabal view
@@ -0,0 +1,29 @@+name: diagrams-gtk+version: 0.6+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.2.1, GHC == 7.4.2+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.7, + diagrams-lib ==0.6.*,+ diagrams-cairo ==0.6.*, + gtk >= 0.12.0 && < 0.13+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Diagrams/Backend/Gtk.hs view
@@ -0,0 +1,87 @@+{-# 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.Prelude hiding (width, height)+import Diagrams.Backend.Cairo as Cairo++-- 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 Graphics.UI.Gtk+import qualified Graphics.UI.Gtk.Cairo as CG++-- | 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) (P (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 R2 m -> QDiagram Cairo R2 m+toGtkCoords d = snd $+ adjustDia Cairo+ (CairoOptions "" Absolute RenderOnly False)+ d++-- | Render a diagram to a DrawingArea, rescaling to fit the full area.+defaultRender :: Monoid' m => DrawingArea -> QDiagram Cairo R2 m -> IO ()+defaultRender da d = do+ (w,h) <- widgetGetSize da+ dw <- widgetGetDrawWindow da+ let r = snd $ renderDia Cairo+ (CairoOptions+ { cairoFileName = ""+ , cairoSizeSpec = Dims (fromIntegral w) (fromIntegral h)+ , cairoOutputType = RenderOnly+ , cairoBypassAdjust = False+ }+ )+ d+ CG.renderWithDrawable dw r++-- | Render a diagram to a 'DrawableClass'. 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 R2 m -- ^ Diagram+ -> IO ()+renderToGtk dc d = do+ let r = snd $ renderDia Cairo+ (CairoOptions+ { cairoFileName = ""+ , cairoSizeSpec = Absolute+ , cairoOutputType = RenderOnly+ , cairoBypassAdjust = True+ }+ )+ d+ CG.renderWithDrawable dc r