canvashs-0.1

Safe HaskellSafe-Inferred

CanvasHs.Data

Description

The CanvasHs.Data module exposes all data types needed for the Event handler function. It exposes Events, Shapes, Actions and Output and all their needed sub-types

Synopsis

Documentation

type Point = (Int, Int)

Represents a Point on the canvas as a tuple of two Ints: (x, y)

type Path = [Point]

Represents a path as a list of Points

type Color = (Int, Int, Int, Float)

Represents a RGBA color as tuple of 3 Ints for RGB (value should range from 0 to 255) and a float for A (value should range from 0 to 1.0), (r, g, b, a) these value ranges are not enforced by the encoding and values outside of the range will be send to the canvas unchanged and could result in unexpected behaviour.

class Defaults a where

A class that defines a function defaults that returns a default value for a given record

Methods

defaults :: a

Instances

Defaults TextData

The Defaults for TextData, has Arial 12, is left Aligned and is not bold, italic, or underlined.

Defaults EventData 

data EventData

Used in conjunction with the Event Shape to decribe which events a Shape is interested in.

Constructors

EventData 

Fields

eventId :: String

The ID of the event, should be unique. Duplicate id's could result in unexpected behaviour

mouseDown :: Bool

Toggles whether to react on mouseDown.

mouseClick :: Bool

Toggles whether to react on mouseClick.

mouseUp :: Bool

Toggles whether to react on mouseUp.

mouseDoubleClick :: Bool

Toggles whether to react on mouseDoubleClick.

mouseDrag :: Bool

Toggles whether to react on mouseDrag.

mouseOver :: Bool

Toggles whether to react on mouseOver

mouseOut :: Bool

Toggles whether to react on mouseOut.

scroll :: Bool

Toggles whether to react on scrollevents.

type FontSize = Int

Defines fontsize as an Int

data Alignment

Defines text alignment, used in conjunction with TextData

Constructors

AlignLeft

Aligns the start of the text to the specified point.

AlignRight

Aligns the end of the text to the specified point.

AlignCenter

Aligns the center of the text to the specified point.

data TextData

Used in conjunction with the Text shape to describe how to draw text

Constructors

TextData 

Fields

font :: String

The font for this text, no guarantees are made about availability

size :: FontSize

The fontsize in Points or Pixels

bold :: Bool

Toggles bold.

italic :: Bool

Toggles italic.

alignment :: Alignment

Specifies how to align this text.

Instances

Eq TextData 
Show TextData 
Defaults TextData

The Defaults for TextData, has Arial 12, is left Aligned and is not bold, italic, or underlined.

data Shape

All drawable Shapes and the transformations that can be applied to them. In practice these will be combined in one big shape tree. By default shapes are filled in black (0,0,0,1.0)

Constructors

Rect Point Int Int

A rectangle. Has a startpoint (left upper corner) and width, height

Circle Point Int

A circle. Has a centerpoint and a radius

Arc Point Int Int

An arch. Has a centerpoint, radius and angle, rotation is done by Rotate.

Line Path

A line. Has a path containing its points, doesn't connect start and end.

Polygon Path

A polygon. Has a path containing its points, does connect start to end to form a closed shape

Text Point String TextData

Text. Has a point (how to align to that point is set using the alignment field in TextData) a string containing the text to draw and TextData containing extra data on how to draw the text

Fill Color Shape

Applies fill. Has a Color and a shape that the fill will be applied to.

Stroke Color Int Shape

Applies stroke. Has a Color, a strokewidth and a shape that the stroke will be applied to.

Rotate Int Shape

Applies rotation. Has a rotation (counterclockwise) in degrees and a shape that needs to be rotated.

Translate Int Int Shape

Applies translation. Has an xdiff and ydiff (how much the Shape should be moved in x an y direction) and a shape that needs to be translated.

Scale Float Float Shape

Applies scale. Has xscale, yscale (how much the shape should be scaled in width and height) and a shape that needs to be scaled.

Event EventData Shape

Indicates that the given shape is interested in Events. EventData describes this interest

Offset Point Shape

Overrides the normal rotationpoint or scalepoint with the one specified

Container Int Int [Shape]

A container. Has width and height and a list of shapes in this container. Note that by default a container is drawn at point (0, 0) and it can be moved using Translate

data BlockingAction

A BlockingAction can not be combined with other Shapes or Actions in Output. Like an Action it will instruct CanvasHs to do something. It will execute and then trigger an Event with the result of the BlockingAction

Constructors

LoadFileString String

Loads a file as string. Has a filepath to load from

LoadFileBinary String

Loads a file in binary mode. Has a filepath to load from

data Action

An Action will instruct CanvasHs to do something on either the haskell side, such as saving a file or starting a timer, or on the canvas side such as prompting for input or downloading a file. These Actions may or may not result in an Event and could be done either by Haskell or the Canvas (javascript)\

__Note:__ In case your application performs poorly using multiple timers, consider producing output in one of the timers.

Constructors

SaveFileString String String

Saves a file as string. Has a filepath to save to, and a String of the file contents. If the file already has contents it will be overwritten

SaveFileBinary String ByteString

Saves a file in binary mode. Has a filepath to save to, and a ByteString of the file contents. When the file already has contents it will be overwritten

Timer Int String

Starts a repeating Timer. Has a timeout in ms and a String identifying the Timer.

StopTimer String

Stops a started timer, idintief by it's id.

Debug Bool

Turns the debug console on or off. Has a Bool, True means show, False means hide is send to javascript

DragNDrop Bool Bool

Turns file dragndrop acceptance on or off. Has a Bool (True means accept, False means don't accept) and a Bool (True means accept multiple files, false means don't accept multiple files) Could result in one or multiple UploadComplete events is send to javascript

DisplayType WindowDisplayType

Changes the window display type to the specified WindowDisplayType is send to javascript

Download String String

Sends a file to the javascript so the user can download it. Has the filename and filecontents as String is send to javacript

RequestUpload Bool

Asks the user to select a file to upload, the Bool indicates if multiple files can be selected or not. could result in one or multiple UploadComplete events. is send to javascript

Prompt String String

Prompts the user a message and asks for a certain value, with a default for that value. Has a String of the message to show and a String of the default value.

data WindowDisplayType

The window display type for use in conjunction with the DisplayType Event. FixedSize has a Width and Height

type RegularOutput = (Maybe Shape, [Action])

RegularOutput is output consisting of Maybe a Shape to draw and a list of Actions, Nothing implies nothing should be changed on the canvas and an empty list implies no actions have to be taken

data Output

Output is the return type of the handler. It is either a BlockingAction or RemoteOutput It can't have both a BlockingAction and a Shape to draw, because the BlockingAction will trigger handler, which could then return also return a Shape, we then would not know which Shape to draw.

data Modifier

Modifier keys that could be held when pressing another key, for use in conjunction with the KeyUp and KeyDown Events.

Constructors

Shift 
Ctrl 
Alt 

Instances

data Event

The events that can be triggered by CanvasHs. These could either be the result of user input (such as i.e. MouseDown or KeyUp) or could be triggered by an Action such as FileLoaded or Tick, or could be triggered by CanvasHs itself (StartEvent)

Constructors

MouseDown Point String

A mousedown event consisting of a point and ID string of the interested object

MouseClick Point String

A mouseclick event consisting of a point and ID string of the interested object

MouseUp Point String

A mouseup event consisting of a point and ID string of the interested object

MouseDoubleClick Point String

A mousedoubleclick event consisting of a point and ID string of the interested object

MouseDrag Point String Point

A mousedrag event with start and end, both consisting of a Point an ID string

MouseOver Point String

A mouseover event, consisting of a point and ID string of the interested object

MouseOut Point String

A mouseout event, consisting of a point and ID string of the interested object

KeyDown String [Modifier]

A keydown event, consist of a key that was pressed and a list of modifiers that were active

KeyUp String [Modifier]

A keyup event, consist of a key that was pressed and a list of modifiers that were active

Scroll String Int Int

A scroll event consisting of an ID string of the interested object, a xdiff and an ydiff (how much was scrolled in the x and y direction)

StartEvent

Start event is triggered when the server is started to notify user

FileLoadedString String String

When a file requested using the LoadFileString Action has been loaded. Has a filepath and file contents as String

FileLoadedBinary String ByteString

When a file requested using the LoadFileString Action has been loaded. Has a filepath and file contents as ByteString

Tick String

Tick event from a Timer. Has a string identifying the Timer

UploadComplete (String, ByteString)

An upload has been completed. Has contents

WindowResize Int Int

A reseizewindoweventm has a new width and height

PromptResponse String

A response of the user to the prompt. Has a String of the response.

Instances

Eq Event 
Show Event 
FromJSON Event

The FromJSON instance of Event allows incoming JSON strings describing an event to be decoded by Aeson, incoming strings hold an event field identyfing the type of event and a datafield which describes the event both of these are read by Aeson and read by the makeEvent function