twentefp-eventloop-graphics 0.1.0.3 → 0.1.0.4
raw patch · 5 files changed
+24/−7 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ EventLoop: ClearAll :: Graphical
+ EventLoop.Output: ClearAll :: Graphical
+ EventLoop.Output: Off :: TimeData
+ EventLoop.Output: On :: Int -> TimeData
+ EventLoop.Output: data TimeData
+ EventLoop.Output.Graphical: ClearAll :: Graphical
- EventLoop: Timer :: Bool -> SystemMessageOut
+ EventLoop: Timer :: TimeData -> SystemMessageOut
- EventLoop.Output: Timer :: Bool -> SystemMessageOut
+ EventLoop.Output: Timer :: TimeData -> SystemMessageOut
Files
- src/EventLoop/Config.hs +3/−0
- src/EventLoop/Output.hs +1/−0
- src/EventLoop/Output/Graphical/Graphical.hs +4/−1
- src/EventLoop/Output/SystemMessage.hs +15/−5
- twentefp-eventloop-graphics.cabal +1/−1
src/EventLoop/Config.hs view
@@ -29,6 +29,7 @@ moveelementS = "moveelement" removegroupS = "removegroup" removeelementS = "removeelement" +clearallS = "clearall" gobjectS = "gobject" nameS = "name" @@ -105,7 +106,9 @@ canvassetupS = "canvassetup" dimensionS = "dimension" timerS = "timer" +timedataS = "timedata" useS = "use" +iS = "i" closeS = "close"
src/EventLoop/Output.hs view
@@ -1,6 +1,7 @@ module EventLoop.Output( OutputEvent(..), SystemMessageOut(..), + TimeData(..), Graphical(..), GObject(..), Primitive(..),
src/EventLoop/Output/Graphical/Graphical.hs view
@@ -49,8 +49,9 @@ data Graphical = Draw GObject Groupname -- ^ Draw the graphical object with the given groupname. | MoveGroup Groupname Pos Relative -- ^ Move an entire group to a new position possibly relative to the old position. | MoveElement Name Pos Relative -- ^ Move a single element to a new position possibly relative to the old position. - | RemoveGroup Groupname -- ^ Remove a group + | RemoveGroup Groupname -- ^ Remove a group. | RemoveElement Name -- ^ Remove an element. + | ClearAll -- ^ Clears all from the canvas. -- | Instance to express how a 'Graphical' event can be parsed to a JSON formatted 'String'. instance JSONAble Graphical where @@ -73,6 +74,8 @@ toJsonMessage (RemoveElement name) = JSONObject [(JSONMember modeS (JSONString removeelementS)), (JSONMember nameS (JSONString name))] + + toJsonMessage (ClearAll) = JSONObject [JSONMember modeS (JSONString clearallS)]
src/EventLoop/Output/SystemMessage.hs view
@@ -9,7 +9,7 @@ This module expresses how the outgoing 'SystemMessage's are modelled in the example implementation. -} -module EventLoop.Output.SystemMessage(SystemMessageOut(..)) where +module EventLoop.Output.SystemMessage(SystemMessageOut(..), TimeData(..)) where import EventLoop.Json import EventLoop.Config @@ -19,17 +19,27 @@ The different possible 'SystemMessageOut's. -} data SystemMessageOut = CanvasSetup Dimension -- ^ Answer to the 'EventLoop.Input.SystemMessage.Setup' containing the dimensions of the canvas that will be used. - | Timer Bool -- ^ Request to create a timer at the clientside that will generate a 'EventLoop.Input.SystemMessage.Time' message each \'tick\'. + | Timer TimeData -- ^ Request to create a timer at the clientside that will generate a 'EventLoop.Input.SystemMessage.Time' message each \'tick\'. | Close -- ^ A request for the client to completely close the connection to the server. + +data TimeData = On Int -- ^ Tells that the timer should be on with the time in ms + | Off -- ^ Tells that the timer should be off {-| - Instance to express how to parse a 'SystemMessageIn' from a JSON formatted 'String'. + Instance to express how to parse a 'SystemMessageIn' to a JSON formatted 'String'. -} instance JSONAble SystemMessageOut where toJsonMessage (CanvasSetup dim) = JSONObject [(JSONMember sysmessageanswerS (JSONString canvassetupS)), (JSONMember dimensionS (dimensionToJsonMessage dim))] - toJsonMessage (Timer bool) = JSONObject [(JSONMember sysmessageanswerS (JSONString timerS)), (JSONMember useS (JSONBool bool))] + toJsonMessage (Timer timedata) = JSONObject [(JSONMember sysmessageanswerS (JSONString timerS)), (JSONMember timedataS (toJsonMessage timedata))] toJsonMessage (Close) = JSONObject [(JSONMember sysmessageanswerS (JSONString closeS))] -- | Private dimensionToJsonMessage :: Dimension -> JSONMessage -dimensionToJsonMessage (w, h) = JSONObject [(JSONMember hS (JSONFloat h)), (JSONMember wS (JSONFloat w))]+dimensionToJsonMessage (w, h) = JSONObject [(JSONMember hS (JSONFloat h)), (JSONMember wS (JSONFloat w))] + +{-| + Instance to express how to parse a 'TimeData' to a JSON formatted 'String'. +-} +instance JSONAble TimeData where + toJsonMessage Off = JSONObject [(JSONMember useS (JSONBool False))] + toJsonMessage (On i) = JSONObject [(JSONMember useS (JSONBool True)), (JSONMember iS (JSONFloat $ fromIntegral i))]
twentefp-eventloop-graphics.cabal view
@@ -1,5 +1,5 @@ name: twentefp-eventloop-graphics -version: 0.1.0.3 +version: 0.1.0.4 synopsis: Used as Lab Assignments Environment at Univeriteit Twente description: An eventloop based graphical IO system. It uses websockets as a way to communicate with IO devices; a browser in this case. This system is used in the Graphical submodule to be able to express graphical output using the eventloop system for a browser. license: BSD3