rebuild example02

This commit is contained in:
nek0 2017-03-16 23:24:34 +01:00
parent a32c8957bd
commit 7c51fbf3ac

View file

@ -3,14 +3,9 @@
import Affection
import qualified SDL
import qualified GEGL as G
import qualified GEGL.FFI.Buffer as G
import qualified BABL as B
import qualified Data.Map.Strict as M
import Foreign.C.Types
import Foreign.Marshal.Utils (new)
import Foreign.Ptr (castPtr)
import Debug.Trace
main :: IO ()
@ -31,7 +26,6 @@ main = do
data UserData = UserData
{ nodeGraph :: M.Map String G.GeglNode
, foreground :: G.GeglBuffer
, coordinates :: Maybe (Int, Int)
, lastTick :: Double
}
@ -53,48 +47,46 @@ load _ = do
[ G.Property "buffer" $ G.PropertyBuffer buffer
]
traceM "buffer-sink"
nop <- G.gegl_node_new_child root $ G.Operation "gegl:nop" []
traceM "nop"
rect <- G.gegl_node_new_child root $ G.Operation "gegl:rectangle"
[ G.Property "x" $ G.PropertyDouble 0
, G.Property "y" $ G.PropertyDouble 0
, G.Property "width" $ G.PropertyDouble 20
, G.Property "height" $ G.PropertyDouble 20
, G.Property "color" $ G.PropertyColor $ G.RGBA 1 0 0 0.5
]
traceM "rect"
crop <- G.gegl_node_new_child root $ G.Operation "gegl:crop"
[ G.Property "width" $ G.PropertyDouble 800
, G.Property "height" $ G.PropertyDouble 600
]
G.gegl_node_link_many [checkerboard, over, crop, sink]
G.gegl_node_connect_to nop "output" over "aux"
_ <- G.gegl_node_connect_to rect "output" over "aux"
traceM "connections made"
myMap <- return $ M.fromList
[ ("root" , root)
, ("over" , over)
, ("background" , checkerboard)
, ("sink" , sink)
, ("nop" , nop)
, ("rect" , rect)
, ("crop" , crop)
]
traceM "loading complete"
return $ UserData
{ nodeGraph = myMap
, foreground = buffer
, coordinates = Nothing
, lastTick = 0
}
-- drawInit :: Affection UserData ()
-- drawInit = do
-- UserData{..} <- getAffection
-- present (nodeGraph M.! "over") foreground (GeglRectangle 0 0 800 600) True
-- present (GeglRectangle 0 0 800 600) foreground True
draw :: Affection UserData ()
draw = do
UserData{..} <- getAffection
maybe (return ()) (\(x, y) ->
drawRect
(nodeGraph M.! "nop")
(G.RGBA 1 0 0 0.5)
(Fill)
(G.GeglRectangle (x - 10) (y - 10) 20 20)
foreground
) coordinates
process (nodeGraph M.! "sink")
present (GeglRectangle 0 0 800 600) foreground True
update :: Affection UserData ()
update = do
@ -105,14 +97,17 @@ update = do
putAffection $ ud { lastTick = tick }
let dt = tick - lastTick ud
traceM $ (show $ 1 / dt) ++ " FPS"
return ()
-- traceM $ (show $ 1 / dt) ++ " FPS"
handle (SDL.MouseMotionEvent dat) = do
let (SDL.P (SDL.V2 x y)) = SDL.mouseMotionEventPos dat
ud <- getAffection
putAffection $ ud
{ coordinates = Just (fromIntegral x, fromIntegral y)
}
liftIO $ G.gegl_node_set (nodeGraph ud M.! "rect") $ G.Operation ""
[ G.Property "x" $ G.PropertyDouble $ fromIntegral (x - 10)
, G.Property "y" $ G.PropertyDouble $ fromIntegral (y - 10)
]
liftIO $ traceIO $ show x ++ " " ++ show y
handle (SDL.WindowClosedEvent _) = do
traceM "seeya!"