gtk-toy-0.1.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 an interface over Gtk for 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 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.

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 can be drawn and 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.

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

display is called when the rendering needs 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.

runToy :: Interactive 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

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

keyHeld :: String -> InputState -> BoolSource

Gets whether the named key is currently thought to be held down.

mouseHeld :: Int -> InputState -> BoolSource

Yields whether the mouse button (1st parameter) is considered pressed in the passed 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.