twentefp-0.4.2: Lab Assignments Environment at Univeriteit Twente

Safe HaskellNone

FPPrac.Events

Description

The event mode lets you manage your own input. Pressing ESC will still closes the window, but you don't get automatic pan and zoom controls like with graphicsout. Should only be called once during the execution of a program!

Synopsis

Documentation

data FileType Source

Possible filetypes

Constructors

TXTFile String

Text file

BMPFile Picture

Bitmap file

Instances

data Input Source

Possible input events

Constructors

NoInput

No input

Generated every refresh of the eventhandler

KeyIn Char

Keyboard key x is pressed down; ' ' for space, \t for tab, \n for enter

MouseDown (Float, Float)

Left mouse button is pressed at location (x,y)

MouseUp (Float, Float)

Left mouse button is released at location (x,y)

MouseMotion (Float, Float)

Mouse pointer is moved to location (x,y)

MouseDoubleClick (Float, Float)

Mouse is double-clicked at location (x,y)

Prompt PromptInfo

Prompt (windowname,textbox content)

Content returned from textbox in promptwindow with windowname

Panel Int [(Int, String)]

Panel buttonId [(controlId, value)]

Event indicating that in the panel, the button with buttonId is pressed and that at the time the controls had the given value

Note: the list is ordered by controlId

  • For checkboxes a value "Y" indicates that they are checked and a value of "N" indicates they are unchecked
  • Buttons have no controlstate
File FilePath FileType

File name content

The found file with given name, and found content

Save FilePath Bool

Indicates if saving of file at filepath succeeded

Time Float

Response to GetTime

The time from midnight, 0 <= t < 86401s (because of leap-seconds) It has a precision of 10^-12 s. Leap second is only added if day has leap seconds

Invalid

Invalid / Unknown input

Instances

data Output Source

Constructors

DrawOnBuffer Bool

Command to change the drawing mode

Pictures returned from the eventhandler will normally be drawn on the screen and in a buffer, so that the window can be quickly redrawn.

A DrawOnBuffer command can change this default behavior, If the parameter is False, pictures are only drawn on the screen. If the parameter is True, drawing will be down on both the buffer and the screen. This can be useful in response to MouseMotion Events.

Example of rubber banding in line drawing program:

 handler (p1:ps) (MouseDown p2)
   = (p1:ps, [DrawOnBuffer False, DrawPicture (Color black $ Line [p1,p2])])
 handler (p1:ps) (MouseMotion p2)
   = (p1:ps, [DrawOnBuffer False, DrawPicture (Color black $ Line [p1,p2])])
 handler (p1:ps) (MouseUp p2)
   = (p2:p1:ps, [DrawOnBuffer True, DrawPicture (Color black $ Line [p1,p2])])
DrawPicture Picture

Draw the picture

GraphPrompt PromptInfo

GraphPrompt (windowName,info)

Create a graphical prompt window which asks the user to enter a string in a textbox. The user can be informed about valid entries through the info field.

Note: the entered string is recorded as the following input event: 'Prompt (windowName,enteredText)'

PanelCreate PanelContent

Command to create a panel with the given panel content, must be actived with the PanelUpdate command

PanelUpdate Bool [(Int, String)]

PanelUpdate visible [(identifier, value)]

Command to change visibility and the content of a panel.

Note: not all controls need to be listed, the order can be arbitrary

  • For checkboxes, a value "Y" checks them, a value "N" unchecks them
  • Buttons can not be altered
ScreenClear

Clear the screen and buffer

ReadFile FilePath FileType

ReadFile fileName default

Read the file of the given filetype at the filename, if it fails The default content is returned

Note: the read file command generates following input event: 'File fileName content'

SaveFile FilePath FileType

SaveFile fileName content

Save the file of the given filetype at the filename location

Note: the save file command generates following input event: Save fileName success (True/False)

GetTime

Request the current time of day in seconds

Note: the gettime command generates the following input event: 'Time timeOfDay'

Instances

type PanelContent = (String, Float, Float, [(String, [(String, Int)])], [PanelItem])Source

(Title, width, height, menuItems, commandItems)

Note: - panels are drawn in the center of the screen

  • menu items are currently not supported

type PanelItem = (Int, String, PanelItemType, Float, Float, Float, Float)Source

(Id, Title, Type, x-coord, y-coord, width, height)

installEventHandlerSource

Arguments

:: forall userState .  
=> String

Name of the window

-> (userState -> Input -> (userState, [Output]))

Event handler that takes current state, input, and returns new state and maybe an updated picture

-> userState

Initial state of the program

-> Picture

Initial Picture

-> Int

doubleclick speed

-> IO () 

The event mode lets you manage your own input. Pressing ESC will still abort the program, but you don't get automatic pan and zoom controls like with graphicsout. Should only be called once during the execution of a program!