mirror of
https://github.com/rgleichman/glance.git
synced 2024-08-16 18:30:36 +03:00
Use an Enum for the mouse buttons.
This commit is contained in:
parent
276d445f97
commit
0dbbab316a
20
gui/Main.hs
20
gui/Main.hs
@ -33,11 +33,17 @@ import qualified Graphics.Rendering.Cairo as Cairo
|
|||||||
import Graphics.Rendering.Cairo.Internal (Render (runRender))
|
import Graphics.Rendering.Cairo.Internal (Render (runRender))
|
||||||
import Graphics.Rendering.Cairo.Types (Cairo (Cairo))
|
import Graphics.Rendering.Cairo.Types (Cairo (Cairo))
|
||||||
|
|
||||||
leftMouseButton :: Word32
|
-- | An Enum of mouse buttons, so order is important!
|
||||||
leftMouseButton = 1
|
data MouseButtons
|
||||||
|
= LeftMouseButton
|
||||||
|
| MiddleMouseButton
|
||||||
|
| RightMouseButton
|
||||||
|
deriving (Eq, Ord, Enum)
|
||||||
|
|
||||||
rightMouseButton :: Word32
|
-- | A mapping between mouse button names and the GTK
|
||||||
rightMouseButton = 3
|
-- mouse button numbers via Enum, so order is important!
|
||||||
|
mouseButtonNum :: MouseButtons -> Word32
|
||||||
|
mouseButtonNum = fromIntegral . (+ 1) . fromEnum
|
||||||
|
|
||||||
nodeSize :: (Double, Double)
|
nodeSize :: (Double, Double)
|
||||||
nodeSize = (100, 40)
|
nodeSize = (100, 40)
|
||||||
@ -97,7 +103,7 @@ emptyInputs =
|
|||||||
_inEvents = mempty
|
_inEvents = mempty
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCairo :: Coercible a (GI.Cairo.Context) => a -> Render c -> IO c
|
renderCairo :: Coercible a GI.Cairo.Context => a -> Render c -> IO c
|
||||||
renderCairo c r = withManagedPtr c $ \pointer ->
|
renderCairo c r = withManagedPtr c $ \pointer ->
|
||||||
runReaderT (runRender r) (Cairo (castPtr pointer))
|
runReaderT (runRender r) (Cairo (castPtr pointer))
|
||||||
|
|
||||||
@ -324,7 +330,7 @@ startApp app = do
|
|||||||
let backgroundPress eventButton = do
|
let backgroundPress eventButton = do
|
||||||
mouseBtn <- get eventButton #button
|
mouseBtn <- get eventButton #button
|
||||||
when
|
when
|
||||||
(mouseBtn == rightMouseButton)
|
(mouseBtn == mouseButtonNum RightMouseButton)
|
||||||
( do
|
( do
|
||||||
(x, y) <- getXandY eventButton
|
(x, y) <- getXandY eventButton
|
||||||
|
|
||||||
@ -345,7 +351,7 @@ startApp app = do
|
|||||||
pure ()
|
pure ()
|
||||||
)
|
)
|
||||||
when
|
when
|
||||||
(mouseBtn == leftMouseButton)
|
(mouseBtn == mouseButtonNum LeftMouseButton)
|
||||||
( do
|
( do
|
||||||
putStrLn "Left click"
|
putStrLn "Left click"
|
||||||
mousePosition <- getXandY eventButton
|
mousePosition <- getXandY eventButton
|
||||||
|
Loading…
Reference in New Issue
Block a user