Skip to content

Instantly share code, notes, and snippets.

@wavewave
Created January 21, 2012 00:10
Show Gist options
  • Select an option

  • Save wavewave/1650370 to your computer and use it in GitHub Desktop.

Select an option

Save wavewave/1650370 to your computer and use it in GitHub Desktop.
gtk2hs drawingArea
import Graphics.UI.Gtk
import Graphics.Rendering.Cairo
import Control.Monad.Trans
main :: IO ()
main = do
initGUI
window <- windowNew
vbox <- vBoxNew False 0
canvas <- drawingAreaNew
set canvas [ widgetWidthRequest := 400
, widgetHeightRequest := 400 ]
boxPackStart vbox canvas PackNatural 0
containerAdd window vbox
canvas `on` exposeEvent $ tryEvent $ do
win <- liftIO $ widgetGetDrawWindow canvas
liftIO . renderWithDrawable win $ do
setSourceRGBA 0 0 0 1
setLineWidth 1.0
moveTo 100 100
lineTo 200 200
stroke
window `on` deleteEvent $ tryEvent $ do
liftIO $ mainQuit
widgetShowAll window
mainGUI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment