Copyright | (c) Anton Gushcha, 2015-2016 |
---|---|
License | BSD3 |
Maintainer | ncrashed@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
The core module contains API for SDL2 library integration. The module doesn't depends on others core modules and could be place in any place in game monad stack.
The module is NOT pure within first phase (see ModuleStack
docs), therefore currently only IO
end monad can handler the module.
Example of embedding:
-- | Application monad is monad stack build from given list of modules over base monad (IO) type AppStack = ModuleStack [SDLT, ... other modules ... ] IO newtype AppState = AppState (ModuleState AppStack) deriving (Generic) instance NFData AppState -- | Wrapper around type family newtype AppMonad a = AppMonad (AppStack a) deriving (Functor, Applicative, Monad, MonadFix, MonadIO, MonadThrow, MonadCatch, MonadSDL, ... other modules monads ... ) instance GameModule AppMonad AppState where type ModuleState AppMonad = AppState runModule (AppMonad m) (AppState s) = do (a, s') <- runModule m s return (a, AppState s') newModuleState = AppState $ newModuleState withModule _ = withModule (Proxy :: Proxy AppStack) cleanupModule (AppState s) = cleanupModule s -- | Arrow that is build over the monad stack type AppWire a b = GameWire AppMonad a b -- | Action that makes indexed app wire type AppActor i a b = GameActor AppMonad i a b
- data SDLState s
- data SDLT s m a
- class (MonadIO m, MonadThrow m) => MonadSDL m where
- data WindowConfig :: * = WindowConfig {
- windowBorder :: Bool
- windowHighDPI :: Bool
- windowInputGrabbed :: Bool
- windowMode :: WindowMode
- windowOpenGL :: Maybe OpenGLConfig
- windowPosition :: WindowPosition
- windowResizable :: Bool
- windowInitialSize :: V2 CInt
- data RendererConfig :: * = RendererConfig {}
- data RendererType :: *
- keyScancode :: MonadSDL m => Scancode -> InputMotion -> GameWire m a (Event (Seq KeyboardEventData))
- keyPress :: MonadSDL m => Scancode -> GameWire m a (Event (Seq KeyboardEventData))
- keyRelease :: MonadSDL m => Scancode -> GameWire m a (Event (Seq KeyboardEventData))
- keyPressing :: MonadSDL m => Scancode -> GameWire m a (Event KeyboardEventData)
- mouseScroll :: MonadSDL m => GameWire m a (Event (V2 Int32))
- mouseScrollX :: MonadSDL m => GameWire m a (Event Int32)
- mouseScrollY :: MonadSDL m => GameWire m a (Event Int32)
- mouseClick :: MonadSDL m => MouseButton -> GameWire m a (Event (V2 Double))
- windowClosed :: MonadSDL m => Text -> GameWire m a (Event ())
Low level API
Inner state of SDL module.
s
- - State of next module, the states are chained via nesting.
Monad transformer of SDL core module.
s
- - State of next core module in modules chain;
m
- - Next monad in modules monad stack;
a
- - Type of result value;
How to embed module:
type AppStack = ModuleStack [SDLT, ... other modules ... ] IO newtype AppMonad a = AppMonad (AppStack a) deriving (Functor, Applicative, Monad, MonadFix, MonadIO, MonadThrow, MonadCatch, MonadSDL)
The module is NOT pure within first phase (see ModuleStack
docs), therefore currently only IO
end monad can handler the module.
MonadBase IO m => MonadBase IO (SDLT s m) Source # | |
MonadError e m => MonadError e (SDLT s m) Source # | |
MonadTrans (SDLT s) Source # | |
Monad m => MonadState (SDLState s) (SDLT s m) Source # | |
Monad m => Monad (SDLT s m) Source # | |
Functor m => Functor (SDLT s m) Source # | |
MonadFix m => MonadFix (SDLT s m) Source # | |
Monad m => Applicative (SDLT s m) Source # | |
MonadIO m => MonadIO (SDLT s m) Source # | |
MonadThrow m => MonadThrow (SDLT s m) Source # | |
MonadMask m => MonadMask (SDLT s m) Source # | |
MonadCatch m => MonadCatch (SDLT s m) Source # | |
MonadResource m => MonadResource (SDLT s m) Source # | |
(MonadIO m, MonadThrow m) => MonadSDL (SDLT s m) Source # | |
type ModuleState (SDLT s m) Source # | |
class (MonadIO m, MonadThrow m) => MonadSDL m where Source #
Low level API for module
sdlCreateWindowM, sdlGetWindowM, sdlDestroyWindowM, sdlSetBackColor, sdlCreateContext, sdlMakeCurrent, sdlWindowShownEventsM, sdlWindowHiddenEventsM, sdlWindowExposedEventsM, sdlWindowMovedEventsM, sdlWindowResizedEventsM, sdlWindowSizeChangedEventsM, sdlWindowMinimizedEventsM, sdlWindowMaximizedEventsM, sdlWindowRestoredEventsM, sdlWindowGainedMouseFocusEventsM, sdlWindowLostMouseFocusEventsM, sdlWindowGainedKeyboardFocusEventsM, sdlWindowLostKeyboardFocusEventsM, sdlWindowClosedEventsM, sdlKeyboardEventsM, sdlTextEditingEventsM, sdlTextInputEventsM, sdlMouseMotionEventsM, sdlMouseButtonEventsM, sdlMouseWheelEventsM, sdlJoyAxisEventsM, sdlJoyBallEventsM, sdlJoyHatEventsM, sdlJoyButtonEventsM, sdlJoyDeviceEventsM, sdlControllerAxisEventsM, sdlControllerButtonEventsM, sdlControllerDeviceEventsM, sdlQuitEventM, sdlUserEventsM, sdlSysWMEventsM, sdlTouchFingerEventsM, sdlMultiGestureEventsM, sdlDollarGestureEventsM, sdlDropEventsM, sdlClipboardUpdateEventsM
sdlCreateWindowM :: WindowName -> Text -> WindowConfig -> RendererConfig -> m (Window, Renderer) Source #
Creates window and stores in module context
Throws SDL'ConflictingWindows
on name conflict
sdlGetWindowM :: WindowName -> m (Maybe (Window, Renderer)) Source #
Getting window and renderer by name
sdlDestroyWindowM :: WindowName -> m () Source #
Destroying window and renderer by name
sdlSetBackColor :: WindowName -> Maybe (V4 Word8) -> m () Source #
Setup background color for window
sdlCreateContext :: WindowName -> m () Source #
Creates context for given window
Note: destroys previous context if existed
sdlMakeCurrent :: WindowName -> m () Source #
Makes GL context of given window current
Does nothing if sdlCreateContext
wasn't called.
sdlWindowShownEventsM :: m (Seq WindowShownEventData) Source #
Getting window shown events that occurs scince last frame
sdlWindowHiddenEventsM :: m (Seq WindowHiddenEventData) Source #
Getting window hidden events that occurs scince last frame
sdlWindowExposedEventsM :: m (Seq WindowExposedEventData) Source #
Getting window exposed events that occurs scince last frame
sdlWindowMovedEventsM :: m (Seq WindowMovedEventData) Source #
Getting window move events that occurs scince last frame
sdlWindowResizedEventsM :: m (Seq WindowResizedEventData) Source #
Getting window resize events that occurs scince last frame
This is event is always preceded by WindowSizeChangedEvent.
sdlWindowSizeChangedEventsM :: m (Seq WindowSizeChangedEventData) Source #
Getting window resize events that occurs scince last frame
The window size has changed, either as a result of an API call or through the system or user changing the window size; this event is followed by WindowResizedEvent if the size was changed by an external event, i.e. the user or the window manager.
sdlWindowMinimizedEventsM :: m (Seq WindowMinimizedEventData) Source #
Getting window minimization events that occurs scince last frame
sdlWindowMaximizedEventsM :: m (Seq WindowMaximizedEventData) Source #
Getting window maximization events that occurs scince last frame
sdlWindowRestoredEventsM :: m (Seq WindowRestoredEventData) Source #
Getting window restore events that occurs scince last frame
sdlWindowGainedMouseFocusEventsM :: m (Seq WindowGainedMouseFocusEventData) Source #
Getting window focus events that occurs scince last frame
sdlWindowLostMouseFocusEventsM :: m (Seq WindowLostMouseFocusEventData) Source #
Getting window focus events that occurs scince last frame
sdlWindowGainedKeyboardFocusEventsM :: m (Seq WindowGainedKeyboardFocusEventData) Source #
Getting window focus events that occurs scince last frame
sdlWindowLostKeyboardFocusEventsM :: m (Seq WindowLostKeyboardFocusEventData) Source #
Getting window focus events that occurs scince last frame
sdlWindowClosedEventsM :: m (Seq WindowClosedEventData) Source #
Getting window close events that occurs scince last frame
sdlKeyboardEventsM :: m (Seq KeyboardEventData) Source #
Getting keyboard events that occurs scince last frame
sdlTextEditingEventsM :: m (Seq TextEditingEventData) Source #
Getting input API events that occurs scince last frame
sdlTextInputEventsM :: m (Seq TextInputEventData) Source #
Getting input API events that occurs scince last frame
sdlMouseMotionEventsM :: m (Seq MouseMotionEventData) Source #
Getting mouse events that occurs scince last frame
sdlMouseButtonEventsM :: m (Seq MouseButtonEventData) Source #
Getting mouse events that occurs scince last frame
sdlMouseWheelEventsM :: m (Seq MouseWheelEventData) Source #
Getting mouse events that occurs scince last frame
sdlJoyAxisEventsM :: m (Seq JoyAxisEventData) Source #
Getting joystick events that occurs scince last frame
sdlJoyBallEventsM :: m (Seq JoyBallEventData) Source #
Getting joystick events that occurs scince last frame
sdlJoyHatEventsM :: m (Seq JoyHatEventData) Source #
Getting joystick events that occurs scince last frame
sdlJoyButtonEventsM :: m (Seq JoyButtonEventData) Source #
Getting joystick events that occurs scince last frame
sdlJoyDeviceEventsM :: m (Seq JoyDeviceEventData) Source #
Getting joystick events that occurs scince last frame
sdlControllerAxisEventsM :: m (Seq ControllerAxisEventData) Source #
Getting controller events that occurs scince last frame
sdlControllerButtonEventsM :: m (Seq ControllerButtonEventData) Source #
Getting controller events that occurs scince last frame
sdlControllerDeviceEventsM :: m (Seq ControllerDeviceEventData) Source #
Getting controller events that occurs scince last frame
sdlQuitEventM :: m Bool Source #
Getting quit request event
sdlUserEventsM :: m (Seq UserEventData) Source #
Getting user events that occurs scince last frame
sdlSysWMEventsM :: m (Seq SysWMEventData) Source #
Getting video driver specific events that occurs scince last frame
sdlTouchFingerEventsM :: m (Seq TouchFingerEventData) Source #
Getting touch events that occurs scince last frame
sdlMultiGestureEventsM :: m (Seq MultiGestureEventData) Source #
Getting touch events that occurs scince last frame
sdlDollarGestureEventsM :: m (Seq DollarGestureEventData) Source #
Getting touch events that occurs scince last frame
sdlDropEventsM :: m (Seq DropEventData) Source #
Getting file opened events that occurs scince last frame
sdlClipboardUpdateEventsM :: m (Seq ClipboardUpdateEventData) Source #
Getting clipboard changed events that occurs scince last frame
Arrow API
data WindowConfig :: * #
WindowConfig | |
|
data RendererConfig :: * #
Eq RendererConfig | |
Data RendererConfig | |
Ord RendererConfig | |
Read RendererConfig | |
Show RendererConfig | |
Generic RendererConfig | |
ToNumber RendererConfig Word32 | |
FromNumber RendererConfig Word32 | |
type Rep RendererConfig | |
data RendererType :: * #
Keyboard arrow API
keyScancode :: MonadSDL m => Scancode -> InputMotion -> GameWire m a (Event (Seq KeyboardEventData)) Source #
Fires when specific scancode key is pressed/unpressed
keyPress :: MonadSDL m => Scancode -> GameWire m a (Event (Seq KeyboardEventData)) Source #
Fires when specific scancode key is pressed
keyRelease :: MonadSDL m => Scancode -> GameWire m a (Event (Seq KeyboardEventData)) Source #
Fires when specific scancode key is released
keyPressing :: MonadSDL m => Scancode -> GameWire m a (Event KeyboardEventData) Source #
Fires event from moment of press until release of given key
Mouse arrow API
mouseScroll :: MonadSDL m => GameWire m a (Event (V2 Int32)) Source #
Returns accumulated mouse scroll scince last frame
mouseScrollX :: MonadSDL m => GameWire m a (Event Int32) Source #
Returns accumulated mouse scroll scince last frame
mouseScrollY :: MonadSDL m => GameWire m a (Event Int32) Source #
Returns accumulated mouse scroll scince last frame
mouseClick :: MonadSDL m => MouseButton -> GameWire m a (Event (V2 Double)) Source #
Fires when user clicks within window. Click coordinates are in [-1 .. 1] range
Window arrow API
windowClosed :: MonadSDL m => Text -> GameWire m a (Event ()) Source #
Fires when window with specific name is closed