Created
March 5, 2014 13:32
-
-
Save jonashaag/9367215 to your computer and use it in GitHub Desktop.
diagrams-gtk plane vs. text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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