diff options
author | Joe Crayne <joe@jerkface.net> | 2019-04-13 05:42:04 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-04-17 18:41:18 -0400 |
commit | 990f88d3678f98998433c9439592a32bbda56ffe (patch) | |
tree | c18b4c13dc20ba7888495370d873bac0bfadd33f /Draw.hs | |
parent | a79ad8c55f8e8368218a0e1f0b81bcc8fa554d9a (diff) |
Bare-bones drawing widget.
Diffstat (limited to 'Draw.hs')
-rw-r--r-- | Draw.hs | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -0,0 +1,58 @@ | |||
1 | {-# LANGUAGE LambdaCase #-} | ||
2 | module Draw where | ||
3 | |||
4 | import Control.Concurrent | ||
5 | import Data.Int | ||
6 | import Data.IORef | ||
7 | import Foreign.ForeignPtr | ||
8 | import Foreign.Ptr | ||
9 | import GI.Gdk.Objects | ||
10 | import GI.Gtk | ||
11 | import System.IO | ||
12 | |||
13 | data Realized = Realized | ||
14 | { | ||
15 | } | ||
16 | |||
17 | data State = State | ||
18 | { stRealized :: MVar Realized | ||
19 | } | ||
20 | |||
21 | initState :: IO State | ||
22 | initState = do | ||
23 | r <- newEmptyMVar | ||
24 | return State | ||
25 | { stRealized = r | ||
26 | } | ||
27 | |||
28 | realize :: State -> GLArea -> IO () | ||
29 | realize 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 | |||
34 | unrealize :: State -> GLArea -> IO () | ||
35 | unrealize st glarea = do | ||
36 | _ <- tryTakeMVar (stRealized st) | ||
37 | return () | ||
38 | |||
39 | onResize :: State -> GLArea -> Int32 -> Int32 -> IO () | ||
40 | onResize st glarea w h = do | ||
41 | return () | ||
42 | |||
43 | render :: State -> GLArea -> GLContext -> IO Bool | ||
44 | render st glarea gl = do | ||
45 | return True | ||
46 | |||
47 | createContext :: State -> GLArea -> IO GLContext | ||
48 | createContext 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 | |||
57 | oops :: String -> IO () | ||
58 | oops s = hPutStrLn stderr s | ||