-
-
Save MichaelXavier/d331d9817f120daf5a65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
data GUIEvent = KeyDownEvent { key_down__ctrl :: !Bool | |
, key_down__shift :: !Bool | |
, key_down__code :: !Int } | |
| MouseEvent { mouse__x :: !Int | |
, mouse__y ::!Int } | |
deriving (Show) | |
instance FromJSON GUIEvent where | |
parseJSON = withObject "GUIObject" parseGUIEvent | |
parseGUIEvent v = parseKeyDownEvent v <|> parseMouseEvent | |
parseKeyDownEvent = do | |
tag <- v .: "tag" | |
guard (tag == String "KeyDownEvent") | |
KeyDownEvent <$> v .: "ctrlKey" | |
<*> v .: "shiftKey" | |
<*> v .: "keyCode" | |
parseMouseEvent = do | |
tag <- v .: "tag" | |
guard (tag == String "MouseEvent") | |
MouseEvent <$> v .: "x" | |
<*> v .: "y" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment