Copyright | (c) Pavel Krajcevski 2018 |
---|---|

License | MIT |

Maintainer | Krajcevski@gmail.com |

Stability | experimental |

Portability | POSIX |

Safe Haskell | None |

Language | Haskell2010 |

This module contains data types with instances needed to create wires
that can be used with the netwire-input combinators. In particular, this
package implements `GLFWInputT`

which has instances of `MonadKeyboard`

and
`MonadMouse`

- type GLFWInput = GLFWInputT Identity
- runGLFWInput :: GLFWInput a -> GLFWInputState -> (a, GLFWInputState)
- data GLFWInputT m a
- runGLFWInputT :: GLFWInputT m a -> GLFWInputState -> m (a, GLFWInputState)
- class Monad m => MonadGLFWInput m where
- data GLFWInputControl
- data GLFWInputState
- getInput :: GLFWInputControl -> IO GLFWInputState
- mkInputControl :: Window -> IO GLFWInputControl
- pollGLFW :: GLFWInputState -> GLFWInputControl -> IO GLFWInputState

# GLFW Input

## Basic Input Monad

type GLFWInput = GLFWInputT Identity Source #

The `GLFWInput`

monad is simply the `GLFWInputT`

transformer around the
identity monad.

runGLFWInput :: GLFWInput a -> GLFWInputState -> (a, GLFWInputState) Source #

Runs the `GLFWInput`

computation with a current input snapshot and returns
the potentially modified input.

## Monad Transformer

data GLFWInputT m a Source #

The `GLFWInputT`

monad transformer is simply a state monad transformer using
`GLFWInputState`

MonadTrans GLFWInputT Source # | |

MonadWriter w m => MonadWriter w (GLFWInputT m) Source # | |

MonadState s m => MonadState s (GLFWInputT m) Source # | |

MonadReader r m => MonadReader r (GLFWInputT m) Source # | |

MonadError e m => MonadError e (GLFWInputT m) Source # | |

Monad m => Monad (GLFWInputT m) Source # | |

Functor m => Functor (GLFWInputT m) Source # | |

MonadFix m => MonadFix (GLFWInputT m) Source # | |

Monad m => Applicative (GLFWInputT m) Source # | |

MonadIO m => MonadIO (GLFWInputT m) Source # | |

MonadPlus m => Alternative (GLFWInputT m) Source # | |

MonadPlus m => MonadPlus (GLFWInputT m) Source # | |

MonadCont m => MonadCont (GLFWInputT m) Source # | |

Monad m => MonadGLFWInput (GLFWInputT m) Source # | |

runGLFWInputT :: GLFWInputT m a -> GLFWInputState -> m (a, GLFWInputState) Source #

To execute a computation with the current input snapshot, we need to give
supply the current `GLFWInputState`

. This comes from the `GLFWInputControl`

associated with the given window.

# Typeclass

class Monad m => MonadGLFWInput m where Source #

Describes a monad that provides stateful access to a `GLFWInputState`

. By
being able to modify the state, the context that satisfies this typeclass
can decide to debounce or "take ownership" of the button presses at a
specific point of the computation. This should be done via the `MonadKey`

and
`MonadMouse`

instances.

getGLFWInput :: m GLFWInputState Source #

Retrieves the current input state

putGLFWInput :: GLFWInputState -> m () Source #

Places a modified input state back into the context. This should probably not be called directly.

Monad m => MonadGLFWInput (GLFWInputT m) Source # | |

# State Types

data GLFWInputControl Source #

data GLFWInputState Source #

The GLFW input state is a record that keeps track of which buttons and keys are currently pressed. Because GLFW works with callbacks, a call to pollEvents must be made in order to process any of the events. At this time, all of the appropriate callbacks are fired in order of the events received, and this record is updated to reflect the most recent input state.

getInput :: GLFWInputControl -> IO GLFWInputState Source #

Returns a current snapshot of the input

mkInputControl :: Window -> IO GLFWInputControl Source #

Creates and returns an `STM`

variable for the window that holds all of the
most recent input state information

pollGLFW :: GLFWInputState -> GLFWInputControl -> IO GLFWInputState Source #

Allows GLFW to interact with the windowing system to update the current
state. The old state must be passed in order to properly reset certain
properties such as the scroll wheel. The returned input state is identical
to a subsequent call to `getInput`

right after a call to `pollEvents`

# Orphan instances

MouseButton MouseButton Source # | |

Key Key Source # | |

MonadGLFWInput m => MonadMouse MouseButton m Source # | |

MonadGLFWInput m => MonadKeyboard Key m Source # | |