gtk-toy-0.2.0: Convenient Gtk canvas with mouse and keyboard input.

PortabilityGHC only
Stabilityexperimental
MaintainerMichael Sloan <mgsloan@gmail.com>

Graphics.UI.Gtk.Toy

Contents

Description

The Gtk Toy Framework is a wrapper over Gtk for conveniently creating applications which draw things and use the mouse or keyboard.

It handles the minutiae of setting up the Gtk window and canvas, and processes mouse and keyboard inputs into more palatable data structures.

Synopsis

Documentation

type KeyInfo = (Bool, Int, [Modifier])Source

Information about the most recent key-state transition. The tuple contains whether the button was pressed, at what time in msec, and with which GTK modifiers.

type KeyTable = Map String KeyInfoSource

A map of GTK keynames to last-received event regarding each respective key. This can be interpreted as the current keyboard state - a key is down if it was last seen being pressed.

type MouseEvent = Maybe (Bool, Int)Source

A MouseEvent is Nothing if it's a mouse motion event, and otherwise provides mouse press information.

type KeyEvent = (Bool, Either String Char)Source

A KeyEvent tuple specifies whether the key was pressed or not, and which key was pressed. Right Char is yielded for keys which would normally correspond to character insertions, while Left String provides GTK-convention names for the rest.

data InputState Source

Constructors

InputState 

Fields

mousePos :: (Double, Double)

The most recent mouse position

keyTable :: KeyTable

Map from key-name to most recent event

class Interactive a whereSource

A class for things which change within an interactive context. The default method implementations do nothing.

Methods

tick :: InputState -> a -> IO (a, Bool)Source

tick is (ideally) called every 30ms. The bool result indicates if the graphics need to be refreshed.

mouse :: MouseEvent -> InputState -> a -> IO aSource

mouse is called when the mouse moves or presses occur.

keyboard :: KeyEvent -> InputState -> a -> IO aSource

keyboard is called on key-presses.

class Interactive a => GtkInteractive a whereSource

Methods

display :: DrawWindow -> InputState -> a -> IO aSource

display is called when the rendering needs to be refreshed.

runToy :: GtkInteractive a => a -> IO ()Source

Main program entrypoint. This is how you turn an instance of Interactive into an application.

quitToy :: IO ()Source

Like it says on the can. This is a synonym for Graphics.UI.Gtk.mainQuit

InputState Accessors

keyInfo :: String -> InputState -> Maybe KeyInfoSource

the information for the most recent key event of the named key.

keyHeld :: String -> InputState -> BoolSource

Gets whether the named key is held down.

mouseHeld :: Int -> InputState -> BoolSource

Whether the indicated mouse button is considered pressed in the InputState.

Utilities

Functions to allow for writing simpler, pure implementations of the different members of Interactive.

simpleTick :: (a -> a) -> InputState -> a -> IO (a, Bool)Source

Converts a pure state transform to a function for Interactive tick.

simpleDisplay :: (DrawWindow -> a -> a) -> DrawWindow -> InputState -> a -> IO aSource

Converts a diagram projection to a function for Interactive display.

simpleMouse :: (MouseEvent -> (Double, Double) -> a -> a) -> MouseEvent -> InputState -> a -> IO aSource

Converts a function which responds to mouse-presses, and transforms state accordingly to a function for Interactive mouse.

simpleKeyboard :: (KeyEvent -> a -> a) -> KeyEvent -> InputState -> a -> IO aSource

Converts a function which responds to key-presses, and transforms state accordingly to a function for Interactive keyboard.

quitKeyboard :: KeyEvent -> InputState -> a -> IO aSource

A definition for the keyboard handler that just calls quitToy when Escape is pressed.