-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A SDL2-based graphics library, batteries-included.
--
-- This package provides the wheel for a graphical application or a game.
--
-- Basic concepts and features:
--
--
-- - Figure: convenient SDL texture, once created, it can be translated
-- or rotated during rendering.
-- - Component: a reusable widget with event handlers, its figures can
-- also be cached.
-- - dynamic component loading: view components can be constructed by
-- an external yaml file.
-- - built-in components: some common components are predefined. You
-- can define a new component by yourself.
--
@package minilight
@version 0.2.0
module MiniLight.Event
-- | Event type representation
data Event
Never :: Event
Signal :: Text -> Dynamic -> Event
RawEvent :: Event -> Event
-- | EventType says some type can be used as an event type.
class Typeable e => EventType e
signal :: EventType a => Text -> a -> Event
asSignal :: EventType a => Event -> Text -> Maybe a
module MiniLight.Light
class HasLightEnv env
rendererL :: HasLightEnv env => Lens' env Renderer
fontCacheL :: HasLightEnv env => Lens' env FontMap
newtype LightT env m a
LightT :: ReaderT env m a -> LightT env m a
[runLightT'] :: LightT env m a -> ReaderT env m a
data LightEnv
LightEnv :: Renderer -> FontMap -> LightEnv
[renderer] :: LightEnv -> Renderer
[fontCache] :: LightEnv -> FontMap
type MiniLight = LightT LightEnv IO
liftMiniLight :: (HasLightEnv env, MonadIO m) => MiniLight a -> LightT env m a
envLightT :: (env' -> env) -> LightT env m a -> LightT env' m a
mapLightT :: (m a -> n a) -> LightT env m a -> LightT env n a
class HasLoopEnv env
-- | Contains the number of frames that a specific keys are continuously
-- pressing.
keyStatesL :: HasLoopEnv env => Lens' env (HashMap Scancode Int)
-- | Occurred events since the last frame.
eventsL :: HasLoopEnv env => Lens' env (IORef [Event])
-- | A queue storing the events occurred in this frame.
signalQueueL :: HasLoopEnv env => Lens' env (IORef [Event])
data FontDescriptor
FontDescriptor :: !Text -> !FontStyle -> FontDescriptor
[_descriptorFamilyName] :: FontDescriptor -> !Text
[_descriptorStyle] :: FontDescriptor -> !FontStyle
data FontStyle
FontStyle :: !Bool -> !Bool -> FontStyle
[_fontStyleBold] :: FontStyle -> !Bool
[_fontStyleItalic] :: FontStyle -> !Bool
loadFontCache :: MonadIO m => m FontMap
loadFont :: (HasLightEnv env, MonadIO m) => FontDescriptor -> Int -> LightT env m Font
withFont :: (HasLightEnv env, MonadIO m, MonadMask m) => FontDescriptor -> Int -> (Font -> LightT env m a) -> LightT env m a
-- | Monads in which IO computations may be embedded. Any monad
-- built by applying a sequence of monad transformers to the IO
-- monad will be an instance of this class.
--
-- Instances should satisfy the following laws, which state that
-- liftIO is a transformer of monads:
--
--
class Monad m => MonadIO (m :: Type -> Type)
-- | Lift a computation from the IO monad.
liftIO :: MonadIO m => IO a -> m a
instance Control.Monad.Catch.MonadCatch m => Control.Monad.Catch.MonadCatch (MiniLight.Light.LightT env m)
instance Control.Monad.Catch.MonadMask m => Control.Monad.Catch.MonadMask (MiniLight.Light.LightT env m)
instance Control.Monad.Catch.MonadThrow m => Control.Monad.Catch.MonadThrow (MiniLight.Light.LightT env m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (MiniLight.Light.LightT env m)
instance GHC.Base.Monad m => GHC.Base.Monad (MiniLight.Light.LightT env m)
instance GHC.Base.Applicative m => GHC.Base.Applicative (MiniLight.Light.LightT env m)
instance GHC.Base.Functor m => GHC.Base.Functor (MiniLight.Light.LightT env m)
instance MiniLight.Light.HasLightEnv MiniLight.Light.LightEnv
instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader env (MiniLight.Light.LightT env m)
instance Data.Hashable.Class.Hashable Graphics.Text.TrueType.FontFolders.FontDescriptor
-- | This module provides many convenient operations for textures.
module MiniLight.Figure
-- | Lens for the center of a rectangle.
centerL :: Lens' (Rectangle a) (V2 a)
-- | Lens for the size of a rectangle.
sizeL :: Lens' (Rectangle a) (V2 a)
-- | Figure type carries a texture, sizing information and rotation
-- information.
data Figure
Figure :: Texture -> Rectangle Int -> Rectangle Int -> Double -> Figure
[texture] :: Figure -> Texture
[sourceArea] :: Figure -> Rectangle Int
[targetArea] :: Figure -> Rectangle Int
[rotation] :: Figure -> Double
getFigureSize :: Figure -> V2 Int
freeFigure :: MonadIO m => Figure -> m ()
union :: Rectangle Int -> Rectangle Int -> Rectangle Int
-- | Render a figure.
render :: (HasLightEnv env, MonadIO m, MonadMask m) => Figure -> LightT env m ()
-- | Render figures.
renders :: (HasLightEnv env, MonadIO m, MonadMask m) => [Figure] -> LightT env m ()
withBlendedText :: (MonadIO m, MonadMask m) => Font -> Text -> Color -> (Surface -> m a) -> m a
-- | Rendering typeclass provides basic operations for figures.
class Rendering r m | r -> m
-- | Change the place to be rendered.
translate :: Rendering r m => V2 Int -> r -> r
-- | Specify some area and clip the figure into the region.
clip :: Rendering r m => Rectangle Int -> r -> r
-- | Rotate a figure.
rotate :: Rendering r m => Double -> r -> r
-- | Create a text texture. Be careful: this is a slow operation,
-- use cache as long as you can.
text :: Rendering r m => Font -> V4 Word8 -> Text -> m r
-- | Create a texture from a png file. Be careful: this is a slow
-- operation, use cache as long as you can.
picture :: Rendering r m => FilePath -> m r
-- | Create a texture from a raw SDL texture.
fromTexture :: Rendering r m => Texture -> m r
-- | Create an outlined rectangle. Be careful: this is a slow
-- operation, use cache as long as you can.
rectangleOutline :: Rendering r m => V4 Word8 -> V2 Int -> m r
-- | Create a filled texture. Be careful: this is a slow operation,
-- use cache as long as you can.
rectangleFilled :: Rendering r m => V4 Word8 -> V2 Int -> m r
-- | Create an outlined triangle. Be careful: this is a slow
-- operation, use cache as long as you can.
triangleOutline :: Rendering r m => V4 Word8 -> V2 Int -> m r
instance MiniLight.Figure.Rendering MiniLight.Figure.Figure MiniLight.Light.MiniLight
module MiniLight.Component.Types
class HasComponentEnv env
-- | Lens to the unique id, which is provided for each component.
uidL :: HasComponentEnv env => Lens' env Text
-- | Emit a signal, which will be catched at the next frame.
emit :: (HasLoopEnv env, HasComponentEnv env, MonadIO m, EventType et) => et -> LightT env m ()
-- | CompoonentUnit typeclass provides a way to define a new component. Any
-- ComponentUnit instance can be embedded into Component
-- type.
class ComponentUnit c
-- | Updating a model.
update :: (ComponentUnit c, HasLightEnv env, HasLoopEnv env, HasComponentEnv env, MonadIO m, MonadMask m) => c -> LightT env m c
-- | Descirbes a view. The figures here would be cached. See also
-- useCache for the cache configuration.
figures :: (ComponentUnit c, HasLightEnv env, MonadIO m, MonadMask m) => c -> LightT env m [Figure]
-- | Drawing a figures.
draw :: (ComponentUnit c, HasLightEnv env, MonadIO m, MonadMask m) => c -> LightT env m ()
-- | Event handlers
onSignal :: (ComponentUnit c, HasLightEnv env, HasLoopEnv env, HasComponentEnv env, MonadIO m, MonadMask m) => Event -> c -> LightT env m c
-- | Return True if a cache stored in the previous frame should be
-- used.
useCache :: ComponentUnit c => c -> c -> Bool
-- | To be called just before clearing caches. If you want to destroy
-- cached textures for memory efficiency, override this method.
--
-- NB: Freeing SDL textures and figures are not performed
-- automatically. You must call freeFigure at your own risk.
beforeClearCache :: (ComponentUnit c, HasLightEnv env, MonadIO m, MonadMask m) => c -> [Figure] -> LightT env m ()
-- | A wrapper for ComponentUnit instances.
data Component
-- | Create a new component.
newComponent :: (ComponentUnit c, HasLightEnv env, MonadIO m, MonadMask m) => c -> LightT env m Component
-- | Get the size of a component.
getComponentSize :: (ComponentUnit c, HasLightEnv env, MonadIO m, MonadMask m) => c -> LightT env m (Rectangle Int)
-- | Get its unique id.
getUID :: Component -> Text
-- | Clear the previous model cache and reflect the current model.
propagate :: Component -> Component
instance MiniLight.Component.Types.ComponentUnit MiniLight.Component.Types.Component
module MiniLight.Component.Loader
data ComponentConfig
ComponentConfig :: Text -> Value -> ComponentConfig
[name] :: ComponentConfig -> Text
[properties] :: ComponentConfig -> Value
data AppConfig
AppConfig :: [ComponentConfig] -> AppConfig
[app] :: AppConfig -> [ComponentConfig]
-- | Load an config file and construct components.
loadAppConfig :: (HasLightEnv env, MonadIO m) => FilePath -> (Text -> Value -> LightT env m Component) -> LightT env m [Component]
data Expr
None :: Expr
-- | reference syntax: ${ref:...}
Ref :: Text -> Expr
-- | variable syntax: ${var:...}
Var :: Text -> Expr
-- | expr operator: +, -, *, /
Op :: Text -> Expr -> Expr -> Expr
-- | constants (string or number or null)
Constant :: Value -> Expr
parser :: Parser Expr
data Context
Context :: Vector (Either Int Text) -> Object -> Value -> Context
[path] :: Context -> Vector (Either Int Text)
[variables] :: Context -> Object
[target] :: Context -> Value
getAt :: Value -> [Either Int Text] -> Value
normalize :: Vector (Either Int Text) -> [Either Int Text] -> [Either Int Text]
pattern Arithmetic :: Text -> Scientific -> Scientific -> Expr
eval :: Context -> Expr -> Value
convertPath :: Text -> [Either Int Text]
convert :: Context -> Text -> Value
parseText :: Parser a -> Text -> Result a
resolve :: Value -> Value
instance GHC.Show.Show MiniLight.Component.Loader.Expr
instance GHC.Classes.Eq MiniLight.Component.Loader.Expr
instance GHC.Generics.Generic MiniLight.Component.Loader.AppConfig
instance GHC.Generics.Generic MiniLight.Component.Loader.ComponentConfig
instance Data.Aeson.Types.FromJSON.FromJSON MiniLight.Component.Loader.AppConfig
instance Data.Aeson.Types.FromJSON.FromJSON MiniLight.Component.Loader.ComponentConfig
-- | The package provides the configuration loader.
--
-- An configuration example:
--
--
-- _vars:
-- window:
-- width: 800
-- height: 600
-- app:
-- - name: message-layer
-- properties:
-- window:
-- image: resources/window-base.png
-- position:
-- x: 0
-- y: ${${var:window.height} - ${ref:..size.height}}
-- size:
-- width: ${var:window.width}
-- height: 150
--
--
-- Syntax
--
-- _vars
--
-- You can define a new variable. Use object syntax under the
-- _vars field.
--
-- The variables can be referenced in all siblings and under their
-- siblings to the _vars, in the variable syntax
-- ${var:_path_}.
--
-- Expr
--
-- In each field, you can specify an expression defined in the loader.
--
--
-- - ${}: enclose the expr by ${}, to tell the
-- parsers that the field is an expr not a plain string.
-- - ${ref:_path_}: specify any path to refer any other value.
-- The path resolution is performed once, not recursively resolved.
-- _path_ consists of field names splitted by a period. Use
-- double dots .. for a parent.
-- - ${var:_path_}: specify any path to value defined at the
-- field. _path_ consists of field names splitted by a
-- period.
-- - arithmetic operator: addition, subtraction, multiplication and
-- division (+,-,*,/) can also be used in ${}.
--
module MiniLight.Component
-- | Load an config file and construct components.
loadAppConfig :: (HasLightEnv env, MonadIO m) => FilePath -> (Text -> Value -> LightT env m Component) -> LightT env m [Component]
type Resolver = Text -> Value -> MiniLight Component
-- | MiniLight module exports all basic concepts and oprations except for
-- concrete components.
module MiniLight
-- | Run a Light monad.
runLightT :: (MonadIO m, MonadMask m) => LightT LightEnv m a -> m a
-- | Use defConfig for a default setting.
data LoopConfig
LoopConfig :: Maybe [Scancode] -> Maybe FilePath -> (Text -> Value -> MiniLight Component) -> [Component] -> LoopConfig
-- | Set Nothing if all keys should be watched. See also
-- LoopState.
[watchKeys] :: LoopConfig -> Maybe [Scancode]
-- | Specify a yaml file which describes component settings. See
-- Component for the yaml syntax.
[appConfigFile] :: LoopConfig -> Maybe FilePath
-- | Your custom mappings between a component name and its type.
[componentResolver] :: LoopConfig -> Text -> Value -> MiniLight Component
-- | The components here would be added during the initialization.
[additionalComponents] :: LoopConfig -> [Component]
-- | Default configurations for the mainloop. You need to set
-- componentResolver if you use a component.
defConfig :: LoopConfig
-- | LoopEnv value would be passed to user side in a mainloop.
data LoopEnv env
LoopState :: env -> HashMap Scancode Int -> IORef [Event] -> IORef [Event] -> IOVector Component -> LoopEnv env
[env] :: LoopEnv env -> env
[keyStates] :: LoopEnv env -> HashMap Scancode Int
[events] :: LoopEnv env -> IORef [Event]
[signalQueue] :: LoopEnv env -> IORef [Event]
[components] :: LoopEnv env -> IOVector Component
-- | Type synonym to the minimal type of the mainloop
type MiniLoop = LightT (LoopEnv LightEnv) IO
-- | Run a mainloop. In a mainloop, components and events are managed.
--
-- Components in a mainloop: draw ~ update ~ (user-defined function) ~
-- event handling
runMainloop :: (HasLightEnv env, HasLightEnv loop, HasLoopEnv loop, MonadIO m, MonadMask m) => (LoopEnv env -> loop) -> LoopConfig -> s -> (s -> LightT loop m s) -> LightT env m ()
instance MiniLight.Light.HasLightEnv env => MiniLight.Light.HasLightEnv (MiniLight.LoopEnv env)
instance MiniLight.Light.HasLoopEnv (MiniLight.LoopEnv env)
instance Data.Hashable.Class.Hashable SDL.Input.Keyboard.Codes.Scancode
instance MiniLight.Light.HasLightEnv env => MiniLight.Light.HasLightEnv (Data.Text.Internal.Text, env)
instance MiniLight.Light.HasLoopEnv env => MiniLight.Light.HasLoopEnv (Data.Text.Internal.Text, env)
instance MiniLight.Component.Types.HasComponentEnv (Data.Text.Internal.Text, env)
module Data.Component.MessageEngine
data MessageEngine
MessageEngine :: Font -> Int -> Int -> Figure -> Bool -> Config -> MessageEngine
[font] :: MessageEngine -> Font
[counter] :: MessageEngine -> Int
[rendered] :: MessageEngine -> Int
[textTexture] :: MessageEngine -> Figure
[finished] :: MessageEngine -> Bool
[config] :: MessageEngine -> Config
data Config
Config :: Text -> Bool -> V4 Word8 -> FontDescriptor -> Int -> Config
[messages] :: Config -> Text
[static] :: Config -> Bool
[color] :: Config -> V4 Word8
[fontConf] :: Config -> FontDescriptor
[fontSize] :: Config -> Int
new :: Config -> MiniLight MessageEngine
instance MiniLight.Component.Types.ComponentUnit Data.Component.MessageEngine.MessageEngine
instance Data.Aeson.Types.FromJSON.FromJSON Data.Component.MessageEngine.Config
module Data.Component.Layer
data Layer
Layer :: Figure -> Layer
[layer] :: Layer -> Figure
data Config
Config :: FilePath -> V2 Int -> V2 Int -> Config
[image] :: Config -> FilePath
[size] :: Config -> V2 Int
[position] :: Config -> V2 Int
new :: Config -> MiniLight Layer
newNineTile :: Config -> MiniLight Layer
instance Data.Aeson.Types.FromJSON.FromJSON Data.Component.Layer.Config
instance MiniLight.Component.Types.ComponentUnit Data.Component.Layer.Layer
module Data.Component.Button
data Button
Button :: Font -> Config -> Button
[font] :: Button -> Font
[config] :: Button -> Config
data ButtonEvent
Click :: ButtonEvent
data Config
Config :: V2 Int -> Text -> V4 Word8 -> FontDescriptor -> Int -> Config
[size] :: Config -> V2 Int
[label] :: Config -> Text
[color] :: Config -> V4 Word8
[fontConf] :: Config -> FontDescriptor
[fontSize] :: Config -> Int
new :: Config -> MiniLight Button
instance MiniLight.Component.Types.ComponentUnit Data.Component.Button.Button
instance Data.Aeson.Types.FromJSON.FromJSON Data.Component.Button.Config
instance MiniLight.Event.EventType Data.Component.Button.ButtonEvent
-- | The package provides the basics for all components in the library.
--
-- A component should have the followings (those can be omitted):
--
--
-- - position: {x: int, y: int}
-- - size: {width: int, height: int}
-- - color: int[4]
-- - font: {family: string, bold: bool, italic: bool, size:
-- int}
--
module Data.Component.Basic
-- | Basic config type
data Config
Config :: V2 Int -> V2 Int -> V4 Word8 -> FontDescriptor -> Int -> Config
[size] :: Config -> V2 Int
[position] :: Config -> V2 Int
[color] :: Config -> V4 Word8
[fontDesc] :: Config -> FontDescriptor
[fontSize] :: Config -> Int
-- | Load a system font from Config type.
loadFontFrom :: Config -> MiniLight Font
-- | This wrapper function is useful when you write your component config
-- parser.
wrapConfig :: (Config -> a -> Parser r) -> (Object -> Parser a) -> Value -> Parser r
-- | The rectangle region of the component.
areaRectangle :: Config -> Rectangle Int
-- | Basic signal type.
data Signal
[MousePressed] :: V2 Int -> Signal
[MouseReleased] :: V2 Int -> Signal
[MouseOver] :: V2 Int -> Signal
-- | This wrapper function is useful when you write your own
-- onSignal component.
wrapSignal :: (HasLightEnv env, HasLoopEnv env, HasComponentEnv env, MonadIO m, ComponentUnit c) => (c -> Config) -> (Event -> c -> LightT env m c) -> Event -> c -> LightT env m c
-- | Basic signaling function.
emitBasicSignal :: (HasLightEnv env, HasLoopEnv env, HasComponentEnv env, MonadIO m) => Event -> Config -> LightT env m ()
contains :: (Ord a, Num a) => Rectangle a -> V2 a -> Bool
instance MiniLight.Event.EventType Data.Component.Basic.Signal
instance Data.Aeson.Types.FromJSON.FromJSON Data.Component.Basic.Config
module Data.Component.AnimationLayer
data AnimationLayer
AnimationLayer :: Layer -> Int -> V2 Int -> Int -> Config -> AnimationLayer
[layer] :: AnimationLayer -> Layer
[counter] :: AnimationLayer -> Int
[tileSize] :: AnimationLayer -> V2 Int
[scaler] :: AnimationLayer -> Int
[config] :: AnimationLayer -> Config
data Config
Config :: Config -> V2 Int -> Config
[layerConf] :: Config -> Config
[division] :: Config -> V2 Int
new :: Config -> MiniLight AnimationLayer
instance MiniLight.Component.Types.ComponentUnit Data.Component.AnimationLayer.AnimationLayer
instance Data.Aeson.Types.FromJSON.FromJSON Data.Component.AnimationLayer.Config
module Data.Component.MessageLayer
data MessageLayer
MessageLayer :: MessageEngine -> Layer -> AnimationLayer -> Config -> MessageLayer
[messageEngine] :: MessageLayer -> MessageEngine
[layer] :: MessageLayer -> Layer
[cursor] :: MessageLayer -> AnimationLayer
[config] :: MessageLayer -> Config
engineL :: Lens' MessageLayer MessageEngine
cursorL :: Lens' MessageLayer AnimationLayer
data Config
Config :: Config -> Config -> Config -> Config
[engine] :: Config -> Config
[window] :: Config -> Config
[next] :: Config -> Config
new :: Config -> MiniLight MessageLayer
instance MiniLight.Component.Types.ComponentUnit Data.Component.MessageLayer.MessageLayer
instance Data.Aeson.Types.FromJSON.FromJSON Data.Component.MessageLayer.Config
-- | This module provides the default resolver for pre-defined components.
module Data.Component.Resolver
-- | Pre-defined resolver supports all components in this library.
resolver :: Resolver
foldResult :: (String -> b) -> (a -> b) -> Result a -> b