{-| Module : EventLoop.Input.InputEvent Description : Library of all the possible 'InputEvent's in the example implementation. Copyright : (c) Sebastiaan la Fleur, 2014 License : BSD3 Maintainer : sebastiaan.la.fleur@gmail.com Stability : experimental Portability : All All different 'InputEvent's are combined to a single 'InputEvent' type. In this example implementation, the 'EventLoop.Input.Keyboard', 'EventLoop.Input.Mouse' and 'EventLoop.Input.SystemMessage' are modeled. -} module EventLoop.Input.InputEvent where import EventLoop.Config import EventLoop.Json import EventLoop.Input.Keyboard import EventLoop.Input.Mouse import EventLoop.Input.SystemMessage {-| The central 'InputEvent' type. -} data InputEvent = InMouse Mouse -- ^ A 'EventLoop.Input.Mouse' event. | InKeyboard Keyboard -- ^ A 'EventLoop.Input.Keyboard' event. | InSysMessage SystemMessageIn -- ^ A 'EventLoop.Input.SystemMessage' event. {-| Instance to express how a JSON formatted message can be parsed into an 'InputEvent'. -} instance FromJSON InputEvent where fromJsonMessage obj@(JSONObject ms) | keyboardS == type' = InKeyboard (fromJsonMessage obj) | mouseS == type' = InMouse (fromJsonMessage obj) | systemmessageS == type' = InSysMessage (fromJsonMessage obj) where JSONString type' = retrieveError typeS ms