view mde/input/config.d @ 2:78eb491bd642

mergetag: partially redesigned dataset and text reader classes. Changed text format. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 03 Nov 2007 15:15:43 +0000
parents d547009c104c
children 9a990644948c
line wrap: on
line source

/// This module contains a class for holding configs and handles saving, loading and editing.
module mde.input.config;

// package imports
import mde.input.core;

/** Struct to hold the configuration for the input system. Thus loading and switching between
 *  multiple configurations should be easy.
 *
 *  Note: documentation should be generated for the codes (enum : uint ...), but it's not.
 */
struct Config
{
    /** Button event type bit-codes
     *
     *  These bitcodes are OR'd to the identifier code for the input device, to indicate which type
     *  of input they are for. E.g. when a key event is recieved with code x, look up
     *  B.SDLKEY | x in b. Keyboard events are SDL-specific since the codes may differ for other
     *  libraries.
     *
     *  For joystick hat events, a motion should be converted into up and down events on separate
     *  U,L,D,R positions and up and down events sent to the appropriate outputs.
     */
    enum B : uint {
        KEY		= 0x8000_0000u,		/// 0x8000_0000u
        SDLKEY		= 0x8800_0000u,		/// 0x8800_0000u
        MOUSE		= 0x4000_0000u,		/// 0x4000_0000u
        JOYBUTTON	= 0x2000_0000u,		/// 0x2000_0000u
        JOYHAT		= 0x1000_0000u,		/// 0x1000_0000u
        JOYHAT_U	= 0x1800_0000u,		/// 0x1800_0000u
        JOYHAT_D	= 0x1400_0000u,		/// 0x1400_0000u
        JOYHAT_L	= 0x1200_0000u,		/// 0x1200_0000u
        JOYHAT_R	= 0x1100_0000u,		/// 0x1100_0000u
    }
    
    /** Axis event type bit-codes
     *
     *  Well, SDL only supports one type of axis now, but this could be extended in the future.
    */
    enum A : uint {
        JOYAXIS		= 0x8000_0000u,		/// 0x8000_0000u
    }
    
    /** Mouse & Joystick ball event type bit-codes
     *
     *  Currently, mouse input only comes from the window manager: the code is exactly M.WMMOUSE.
     */
    enum M : uint {
        MOUSE		= 0x8000_0000u,		/// 0x8000_0000u
        WMMOUSE		= 0x8800_0000u,		/// 0x8800_0000u
        JOYBALL		= 0x4000_0000u,		/// 0x4000_0000u
    }
    
    /** Output queues --- the core of the input configuration.
    *
    *  b, axis and mouse each have their own index specifications. This is split into two parts:
    *  the first byte specifies the type of input (given by the above enums), and the last three
    *  bytes define where the input comes from.
    *
    *  For B.SDLKEY, the last three bytes are for the SDL keysym.
    *  For B.MOUSE, B.JOY*, A.JOY* & M.JOY*, the last three bytes are split into two sets of 12
    *  bits (with masks 0x00FF_F000 and 0x0000_0FFF), the higher of which specifies the device
    *  (which mouse or joystick), and the lower of which specifies the button/axis/ball.
    *
    *  The code for mouse motion is currently only M.WMMOUSE. If/when multiple mice are supported
    *  new codes will be defined.
    */
    outQueue[uint] b;
    outQueue[uint] axis;    /// ditto
    outQueue[uint] mouse;    /// ditto
}