rebuild example02
This commit is contained in:
parent
a32c8957bd
commit
7c51fbf3ac
1 changed files with 19 additions and 24 deletions
|
@ -3,14 +3,9 @@
|
||||||
import Affection
|
import Affection
|
||||||
import qualified SDL
|
import qualified SDL
|
||||||
import qualified GEGL as G
|
import qualified GEGL as G
|
||||||
import qualified GEGL.FFI.Buffer as G
|
|
||||||
import qualified BABL as B
|
import qualified BABL as B
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
|
|
||||||
import Foreign.C.Types
|
|
||||||
import Foreign.Marshal.Utils (new)
|
|
||||||
import Foreign.Ptr (castPtr)
|
|
||||||
|
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
@ -31,7 +26,6 @@ main = do
|
||||||
data UserData = UserData
|
data UserData = UserData
|
||||||
{ nodeGraph :: M.Map String G.GeglNode
|
{ nodeGraph :: M.Map String G.GeglNode
|
||||||
, foreground :: G.GeglBuffer
|
, foreground :: G.GeglBuffer
|
||||||
, coordinates :: Maybe (Int, Int)
|
|
||||||
, lastTick :: Double
|
, lastTick :: Double
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,48 +47,46 @@ load _ = do
|
||||||
[ G.Property "buffer" $ G.PropertyBuffer buffer
|
[ G.Property "buffer" $ G.PropertyBuffer buffer
|
||||||
]
|
]
|
||||||
traceM "buffer-sink"
|
traceM "buffer-sink"
|
||||||
nop <- G.gegl_node_new_child root $ G.Operation "gegl:nop" []
|
rect <- G.gegl_node_new_child root $ G.Operation "gegl:rectangle"
|
||||||
traceM "nop"
|
[ 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"
|
crop <- G.gegl_node_new_child root $ G.Operation "gegl:crop"
|
||||||
[ G.Property "width" $ G.PropertyDouble 800
|
[ G.Property "width" $ G.PropertyDouble 800
|
||||||
, G.Property "height" $ G.PropertyDouble 600
|
, G.Property "height" $ G.PropertyDouble 600
|
||||||
]
|
]
|
||||||
G.gegl_node_link_many [checkerboard, over, crop, sink]
|
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"
|
traceM "connections made"
|
||||||
myMap <- return $ M.fromList
|
myMap <- return $ M.fromList
|
||||||
[ ("root" , root)
|
[ ("root" , root)
|
||||||
, ("over" , over)
|
, ("over" , over)
|
||||||
, ("background" , checkerboard)
|
, ("background" , checkerboard)
|
||||||
, ("sink" , sink)
|
, ("sink" , sink)
|
||||||
, ("nop" , nop)
|
, ("rect" , rect)
|
||||||
, ("crop" , crop)
|
, ("crop" , crop)
|
||||||
]
|
]
|
||||||
traceM "loading complete"
|
traceM "loading complete"
|
||||||
return $ UserData
|
return $ UserData
|
||||||
{ nodeGraph = myMap
|
{ nodeGraph = myMap
|
||||||
, foreground = buffer
|
, foreground = buffer
|
||||||
, coordinates = Nothing
|
|
||||||
, lastTick = 0
|
, lastTick = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
-- drawInit :: Affection UserData ()
|
-- drawInit :: Affection UserData ()
|
||||||
-- drawInit = do
|
-- drawInit = do
|
||||||
-- UserData{..} <- getAffection
|
-- 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 :: Affection UserData ()
|
||||||
draw = do
|
draw = do
|
||||||
UserData{..} <- getAffection
|
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")
|
process (nodeGraph M.! "sink")
|
||||||
|
present (GeglRectangle 0 0 800 600) foreground True
|
||||||
|
|
||||||
update :: Affection UserData ()
|
update :: Affection UserData ()
|
||||||
update = do
|
update = do
|
||||||
|
@ -105,14 +97,17 @@ update = do
|
||||||
putAffection $ ud { lastTick = tick }
|
putAffection $ ud { lastTick = tick }
|
||||||
|
|
||||||
let dt = tick - lastTick ud
|
let dt = tick - lastTick ud
|
||||||
traceM $ (show $ 1 / dt) ++ " FPS"
|
return ()
|
||||||
|
-- traceM $ (show $ 1 / dt) ++ " FPS"
|
||||||
|
|
||||||
handle (SDL.MouseMotionEvent dat) = do
|
handle (SDL.MouseMotionEvent dat) = do
|
||||||
let (SDL.P (SDL.V2 x y)) = SDL.mouseMotionEventPos dat
|
let (SDL.P (SDL.V2 x y)) = SDL.mouseMotionEventPos dat
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
putAffection $ ud
|
liftIO $ G.gegl_node_set (nodeGraph ud M.! "rect") $ G.Operation ""
|
||||||
{ coordinates = Just (fromIntegral x, fromIntegral y)
|
[ 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
|
handle (SDL.WindowClosedEvent _) = do
|
||||||
traceM "seeya!"
|
traceM "seeya!"
|
||||||
|
|
Loading…
Reference in a new issue