summaryrefslogtreecommitdiff
path: root/Draw.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-13 05:42:04 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-17 18:41:18 -0400
commit990f88d3678f98998433c9439592a32bbda56ffe (patch)
treec18b4c13dc20ba7888495370d873bac0bfadd33f /Draw.hs
parenta79ad8c55f8e8368218a0e1f0b81bcc8fa554d9a (diff)
Bare-bones drawing widget.
Diffstat (limited to 'Draw.hs')
-rw-r--r--Draw.hs58
1 files changed, 58 insertions, 0 deletions
diff --git a/Draw.hs b/Draw.hs
new file mode 100644
index 0000000..3377548
--- /dev/null
+++ b/Draw.hs
@@ -0,0 +1,58 @@
1{-# LANGUAGE LambdaCase #-}
2module Draw where
3
4import Control.Concurrent
5import Data.Int
6import Data.IORef
7import Foreign.ForeignPtr
8import Foreign.Ptr
9import GI.Gdk.Objects
10import GI.Gtk
11import System.IO
12
13data Realized = Realized
14 {
15 }
16
17data State = State
18 { stRealized :: MVar Realized
19 }
20
21initState :: IO State
22initState = do
23 r <- newEmptyMVar
24 return State
25 { stRealized = r
26 }
27
28realize :: State -> GLArea -> IO ()
29realize st glarea = gLAreaMakeCurrent glarea >> gLAreaGetError glarea >>= \me ->
30 maybe id (\e _ -> print e) me $ do
31 _ <- tryTakeMVar (stRealized st)
32 putMVar (stRealized st) $ Realized
33
34unrealize :: State -> GLArea -> IO ()
35unrealize st glarea = do
36 _ <- tryTakeMVar (stRealized st)
37 return ()
38
39onResize :: State -> GLArea -> Int32 -> Int32 -> IO ()
40onResize st glarea w h = do
41 return ()
42
43render :: State -> GLArea -> GLContext -> IO Bool
44render st glarea gl = do
45 return True
46
47createContext :: State -> GLArea -> IO GLContext
48createContext st glarea = do
49 widgetGetWindow glarea >>= \case
50 Just win -> windowCreateGlContext win
51 Nothing -> do
52 oops "createContext: GLArea has no window."
53 fp <- newForeignPtr_ nullPtr
54 disown <- newIORef Nothing
55 return $ GLContext $ ManagedPtr fp disown
56
57oops :: String -> IO ()
58oops s = hPutStrLn stderr s