quickest way to get started with cairo

前端 未结 2 1829
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 22:32

I have taken passing shots at learning Cairo in the past, but always moved on in favor of some other graphics library. My problem is that I can\'t find a good tutorial that

2条回答
  •  迷失自我
    2021-01-02 22:59

    An answer to a related question demonstrates a very simple setup in Gtk2HS to draw on a drawingArea with Cairo.

    import Graphics.UI.Gtk
    import Graphics.Rendering.Cairo
    
    main :: IO ()
    main = do
        initGUI
        window      <- windowNew
        drawingArea <- drawingAreaNew
        containerAdd window drawingArea
    
        drawingArea `onExpose` (\_ -> renderScene drawingArea)
        window `onDestroy` mainQuit
    
        windowSetDefaultSize window 640 480
        widgetShowAll window
        mainGUI
    
    renderScene :: DrawingArea -> IO Bool
    renderScene da = do
        dw <- widgetGetDrawWindow da
        renderWithDrawable dw $ do setSourceRGBA 0.5 0.5 0.5 1.0
                                   moveTo 100.0 100.0
                                   showText "HelloWorld"
    
        return True
    

    Simply pass your Cairo animation routine to renderWithDrawable dw in renderScene.

提交回复
热议问题