Portability | GHC only |
---|---|
Stability | experimental |
Maintainer | Michael Sloan <mgsloan@gmail.com> |
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.
- type KeyInfo = (Bool, Int, [Modifier])
- type KeyTable = Map String KeyInfo
- data InputState = InputState {}
- class Interactive a where
- tick :: InputState -> a -> IO (a, Bool)
- display :: DrawWindow -> InputState -> a -> IO a
- mouse :: MouseEvent -> InputState -> a -> IO a
- keyboard :: KeyEvent -> InputState -> a -> IO a
- runToy :: Interactive a => a -> IO ()
- quitToy :: IO ()
- keyInfo :: String -> InputState -> Maybe KeyInfo
- keyHeld :: String -> InputState -> Bool
- mouseHeld :: Int -> InputState -> Bool
- simpleTick :: (a -> a) -> InputState -> a -> IO (a, Bool)
- simpleDisplay :: (DrawWindow -> a -> a) -> DrawWindow -> InputState -> a -> IO a
- simpleMouse :: (MouseEvent -> (Double, Double) -> a -> a) -> MouseEvent -> InputState -> a -> IO a
- simpleKeyboard :: (KeyEvent -> a -> a) -> KeyEvent -> InputState -> a -> IO a
- quitKeyboard :: KeyEvent -> InputState -> a -> IO a
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
class Interactive a whereSource
A class for things which can be drawn and change within an interactive context. The default method implementations do nothing.
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.
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.