mirror of
https://github.com/rgleichman/glance.git
synced 2024-08-16 18:30:36 +03:00
Split node in half. Add struct for input events.
This commit is contained in:
parent
e809724dad
commit
fe31307995
14
gui/Main.hs
14
gui/Main.hs
@ -40,6 +40,8 @@ rightMouseButton = 3
|
|||||||
nodeSize :: (Double, Double)
|
nodeSize :: (Double, Double)
|
||||||
nodeSize = (100, 40)
|
nodeSize = (100, 40)
|
||||||
|
|
||||||
|
-- TODO USE newtype for element ID.
|
||||||
|
|
||||||
-- | A graphical element that can be clicked
|
-- | A graphical element that can be clicked
|
||||||
data Element = Element
|
data Element = Element
|
||||||
{ _elPosition :: !(Double, Double) -- ^ (x, y) of top left corner
|
{ _elPosition :: !(Double, Double) -- ^ (x, y) of top left corner
|
||||||
@ -52,6 +54,7 @@ data Inputs = Inputs
|
|||||||
{ _inMouseXandY :: !(Double, Double)
|
{ _inMouseXandY :: !(Double, Double)
|
||||||
, _inTime :: SystemTime
|
, _inTime :: SystemTime
|
||||||
, _inPrevTime :: SystemTime
|
, _inPrevTime :: SystemTime
|
||||||
|
, _inEvents :: [InputEvents]
|
||||||
}
|
}
|
||||||
|
|
||||||
data AppState = AppState
|
data AppState = AppState
|
||||||
@ -61,6 +64,10 @@ data AppState = AppState
|
|||||||
, _asFPSr :: Double -- ^ FPS rouned down to nearest hundred if over 200 fps.
|
, _asFPSr :: Double -- ^ FPS rouned down to nearest hundred if over 200 fps.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data InputEvents =
|
||||||
|
-- Which node was clicked and the relative click position within a node.
|
||||||
|
LeftClickOnNode Int (Double, Double)
|
||||||
|
|
||||||
emptyAppState :: AppState
|
emptyAppState :: AppState
|
||||||
emptyAppState = AppState
|
emptyAppState = AppState
|
||||||
{ _asMovingNode = Nothing
|
{ _asMovingNode = Nothing
|
||||||
@ -74,6 +81,7 @@ emptyInputs = Inputs
|
|||||||
{ _inMouseXandY = (0, 0)
|
{ _inMouseXandY = (0, 0)
|
||||||
, _inTime = MkSystemTime 0 0
|
, _inTime = MkSystemTime 0 0
|
||||||
, _inPrevTime = MkSystemTime 0 0
|
, _inPrevTime = MkSystemTime 0 0
|
||||||
|
, _inEvents = mempty
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCairo :: Coercible a (ManagedPtr ()) => a -> Render c -> IO c
|
renderCairo :: Coercible a (ManagedPtr ()) => a -> Render c -> IO c
|
||||||
@ -110,12 +118,16 @@ drawNode (elemId, Element{..}) = do
|
|||||||
let
|
let
|
||||||
(x, y) = _elPosition
|
(x, y) = _elPosition
|
||||||
(width, height) = _elSize
|
(width, height) = _elSize
|
||||||
|
halfWidth = width / 2
|
||||||
|
|
||||||
setSourceRGB 1 0 0
|
setSourceRGB 1 0 0
|
||||||
setLineWidth 1
|
setLineWidth 1
|
||||||
rectangle x y width height
|
rectangle x y halfWidth height
|
||||||
showText (show elemId)
|
showText (show elemId)
|
||||||
stroke
|
stroke
|
||||||
|
setSourceRGB 0 1 0
|
||||||
|
rectangle (x + halfWidth) y halfWidth height
|
||||||
|
stroke
|
||||||
|
|
||||||
updateBackground :: p -> IORef AppState -> Render (())
|
updateBackground :: p -> IORef AppState -> Render (())
|
||||||
updateBackground _canvas stateRef = do
|
updateBackground _canvas stateRef = do
|
||||||
|
Loading…
Reference in New Issue
Block a user