module EventLoop.Input.Mouse(
Mouse(..),
MouseButton(..)
) where
import EventLoop.Json
import EventLoop.Config
import EventLoop.CommonTypes
data Mouse = MouseClick MouseButton Pos Element
| MouseUp MouseButton Pos Element
| MouseDown MouseButton Pos Element
deriving Show
data MouseButton = MLeft | MRight | MMiddle
deriving Show
instance FromJSON Mouse where
fromJsonMessage (JSONObject ms) | mouseType == mouseclickS = MouseClick button pos element
| mouseType == mouseupS = MouseUp button pos element
| mouseType == mousedownS = MouseDown button pos element
where
JSONString mouseType = retrieveError mousetypeS ms
JSONFloat x = retrieveError xS ms
JSONFloat y = retrieveError yS ms
pos = (x, y)
JSONString element = retrieveError elementS ms
jsonButton = retrieveError buttonS ms
button = fromJsonMessage jsonButton
instance FromJSON MouseButton where
fromJsonMessage (JSONString but) | leftS == but = MLeft
| middleS == but = MMiddle
| rightS == but = MRight
| otherwise = error ("Could not create a mouse button from value: " ++ but)