Skip to content

Instantly share code, notes, and snippets.

@jonashaag
Created March 5, 2014 13:32
Show Gist options
  • Save jonashaag/9367215 to your computer and use it in GitHub Desktop.
Save jonashaag/9367215 to your computer and use it in GitHub Desktop.
diagrams-gtk plane vs. text
module Demo where
import Diagrams.Prelude
import Diagrams.Backend.Cairo
import Diagrams.Backend.Gtk
import Graphics.UI.Gtk
import Graphics.Rendering.Cairo (liftIO)
main = do
initGUI
window <- windowNew
set window [windowTitle := "CairoGraphics"
]
frame <- frameNew
containerAdd window frame
canvas <- drawingAreaNew
containerAdd frame canvas
canvas `set` [widgetCanFocus := True]
widgetModifyBg canvas StateNormal (Color 65535 65535 65535)
widgetAddEvents canvas [PointerMotionMask, PointerMotionHintMask]
widgetShowAll window
-- Drawing happens here:
canvas `on` motionNotifyEvent $ do coord <- eventCoordinates
liftIO $ do drawable <- widgetGetDrawWindow canvas
putStrLn (show coord)
renderToGtk drawable (dia coord)
eventRequestMotions
return True
onDestroy window mainQuit
mainGUI
dia :: (Double,Double) -> Diagram B R2
dia (x,y) = text "Hello World" # scale 10 # bg yellow # moveTo (p2 (x,y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment