Copyright | (c) Sebastiaan la Fleur, 2014 |
---|---|
License | BSD3 |
Maintainer | sebastiaan.la.fleur@gmail.com |
Stability | experimental |
Portability | All |
Safe Haskell | None |
Language | Haskell98 |
Complete import of all the exposed features of this library.
The Eventloop package is used to express the communication between a Haskell server and a program modelling an 'IO Device'.
This package contains an example implementation of how such a server would like when a browser is used as a graphical IO device also containing a mouse and keyboard.
The InputEvent
models the possible mouse and keyboard events. The OutputEvent
models the possible graphical
output events. There are also input and output systemmessages to communicate metadata between the Haskell server and the graphical IO browser.
The starting point for this example implementation is start
.
- start :: (a -> InputEvent -> ([OutputEvent], a)) -> a -> IO ()
- type Pos = (Float, Float)
- type Dimension = (Float, Float)
- type Element = [Char]
- data InputEvent
- data Keyboard = KeyPress KeyboardButton
- type KeyboardButton = [Char]
- data Mouse
- data MouseButton
- data SystemMessageIn
- = Setup
- | Background
- | Time
- data OutputEvent
- data SystemMessageOut
- data Graphical
- data GObject
- data Primitive
- type Name = [Char]
- type Groupname = [Char]
- type Color = (Float, Float, Float)
- type Font = [Char]
- type Relative = Bool
- outSingle :: OutputEvent -> IO ()
Documentation
:: (a -> InputEvent -> ([OutputEvent], a)) | Eventhandler from |
-> a | The begin state of variable a. |
-> IO () |
High-level function to start an eventloop. The eventloop takes an InputEvent
and outputs an OutputEvent
.
Starting place for the example implementation of the eventloop. It takes a variable of type a to hold information in between handler calls.
type Pos = (Float, Float) Source
Type to express a position on the screen. It uses the format (x,y). As Canvas is used in the example implementation, remember that the lefttop corner is (0,0) and the leftbottom corner is (0, height of screen).
type Dimension = (Float, Float) Source
Type to express the dimension of an element. It uses the format (w,h).
The name of a graphical element. It is used for Mouse
to express the name of which element is clicked on.
data InputEvent Source
The central InputEvent
type.
InMouse Mouse | A |
InKeyboard Keyboard | A |
InSysMessage SystemMessageIn | A |
type KeyboardButton = [Char] Source
Type to express how a KeyboardButton
is modelled.
Datatype to express the different Mouse
events.
The Pos
expresses where on the screen the event happened.
The Element
expresses on which top element on screen the event happened. The Element
value is the name of the GObject
.
MouseClick MouseButton Pos Element | Expresses a complete |
MouseUp MouseButton Pos Element | Expresses when a |
MouseDown MouseButton Pos Element | Expresses when a |
data SystemMessageIn Source
The different possible SystemMessageIn
s.
Setup | A request for the |
Background | A request for the |
Time | When a timer has been spawn, each 'tick' a |
data OutputEvent Source
The central OutputEvent
type.
data SystemMessageOut Source
The different possible SystemMessageOut
s.
Graphical Responses Out
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 |
RemoveElement Name | Remove an element. |
A general graphical object containing the common attributes of each Primitive
.
Primitive graphical structures
Text | The text graphical primitive |
| |
Line | The line graphical primitive |
Rect | The rectangle graphical primitive |
Arc | The arc graphical primitive. This is the part of a circle. When startAng=0 and endAng=360 you get a full circle. |
|
The name of a graphical object. Another synonym in the package used for this is Element
.
type Color = (Float, Float, Float) Source
The color expressed in (red, green, blue) code where each value is between 0 <= 255.
outSingle :: OutputEvent -> IO () Source
Outputs a single OutputEvent
. Right now only Draw
events are implemented.
The server automatically determines the maximum Dimension
s of the picture and sends a Setup
containing those Dimension
s.