Forráskód Böngészése

Added Theme.cpp and Theme.h for supporting loading of a theme from a Theme file.

Ramprasad Madhavan 14 éve
szülő
commit
68e29ad2c7

+ 2 - 0
gameplay/gameplay.vcxproj

@@ -72,6 +72,7 @@
     <ClCompile Include="src\SpriteBatch.cpp" />
     <ClCompile Include="src\Technique.cpp" />
     <ClCompile Include="src\Texture.cpp" />
+    <ClCompile Include="src\Theme.cpp" />
     <ClCompile Include="src\Transform.cpp" />
     <ClCompile Include="src\Vector2.cpp" />
     <ClCompile Include="src\Vector3.cpp" />
@@ -137,6 +138,7 @@
     <ClInclude Include="src\SpriteBatch.h" />
     <ClInclude Include="src\Technique.h" />
     <ClInclude Include="src\Texture.h" />
+    <ClInclude Include="src\Theme.h" />
     <ClInclude Include="src\Transform.h" />
     <ClInclude Include="src\Vector2.h" />
     <ClInclude Include="src\Vector3.h" />

+ 9 - 1
gameplay/gameplay.vcxproj.filters

@@ -204,6 +204,10 @@
     <ClCompile Include="src\PhysicsMotionState.cpp">
       <Filter>src</Filter>
     </ClCompile>
+    <ClCompile Include="src\Gamepad.cpp" />
+    <ClCompile Include="src\Theme.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">
@@ -395,6 +399,10 @@
     <ClInclude Include="src\PhysicsSocketConstraint.h">
       <Filter>src</Filter>
     </ClInclude>
+    <ClInclude Include="src\Gamepad.h" />
+    <ClInclude Include="src\Theme.h">
+      <Filter>src</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="res\shaders\bumped-specular.vsh">
@@ -508,4 +516,4 @@
       <Filter>src</Filter>
     </None>
   </ItemGroup>
-</Project>
+</Project>

+ 1 - 12
gameplay/src/Game.cpp

@@ -2,7 +2,6 @@
 #include "Game.h"
 #include "Platform.h"
 #include "RenderState.h"
-#include "Gamepad.h"
 
 // Extern global variables
 GLenum __gl_error_code = GL_NO_ERROR;
@@ -271,20 +270,10 @@ void Game::keyChar(char key)
 
 void Game::keyPress(int key, int keyEvent)
 {
-    Gamepad* gamepad = Gamepad::getCurrentGamepad();
-    if (gamepad)
-    {
-        gamepad->keyPress(key, keyEvent);
-    }
 }
 
 void Game::touch(int x, int y, int touchEvent)
 {
-    Gamepad* gamepad = Gamepad::getCurrentGamepad();
-    if (gamepad)
-    {
-        gamepad->touch(x, y, touchEvent);
-    }
 }
 
-}
+}

+ 0 - 602
gameplay/src/Gamepad.cpp

@@ -1,602 +0,0 @@
-/*
- * Gamepad.cpp
- */
-
-#include "Base.h"
-#include "Gamepad.h"
-#include "Texture.h"
-
-namespace gameplay
-{
-
-static Gamepad* __gamepad = NULL;
-
-Gamepad::Gamepad()
-    : _buttonCount(0), _joystickCount(0), _texture(NULL), _spriteBatch(NULL)
-{
-}
-
-Gamepad::Gamepad(const Gamepad* g)
-{
-}
-
-Gamepad::~Gamepad()
-{
-}
-
-Gamepad::Button::Button()
-    : _pressed(BUTTON_RELEASED), _key(Input::KEY_NONE), _position(Vector2::zero()),
-    _defaultTexCoord(Vector4::zero()), _defaultTexture(false), 
-    _focusTexCoord(Vector4::zero()), _focusTexture(false)
-{
-
-}
-
-Gamepad::Button::Button(const Button& button)
-{
-}
-
-Gamepad::Button::~Button()
-{
-}
-
-Gamepad::Joystick::Joystick()
-    : _direction(Vector2::zero()), _deltaX(0.0f), _deltaY(0.0f),
-    _north(Input::KEY_NONE), _south(Input::KEY_NONE), _east(Input::KEY_NONE), _west(Input::KEY_NONE), _radius(0.0f), _enabledMovement(false),
-    _boundsInner(Vector4::zero()),
-    _defaultTextureInner(false), _defaultTexCoordInner(Vector4::zero()),
-    _focusTextureInner(false), _focusTexCoordInner(Vector4::zero()),
-    _boundsOuter(Vector4::zero()),
-    _defaultTextureOuter(false), _defaultTexCoordOuter(Vector4::zero()), 
-    _focusTextureOuter(false), _focusTexCoordOuter(Vector4::zero())
-{
-
-}
-
-Gamepad::Joystick::Joystick(const Joystick& joystick)
-{
-}
-
-Gamepad::Joystick::~Joystick()
-{
-}
-
-Gamepad::ButtonState Gamepad::getButtonState(unsigned int index) const
-{
-    assert(index < MAX_BUTTONS);
-
-    return _buttons[index]._pressed;
-}
-
-Input::Key Gamepad::getButtonKeyModifier(unsigned int index) const
-{
-    assert(index < MAX_BUTTONS);
-
-    return _buttons[index]._key;
-}
-
-void Gamepad::setButtonKeyModifier(unsigned int index, Input::Key key)
-{
-    assert(index < MAX_BUTTONS);
-
-    _buttons[index]._key = key;
-}
-
-const Vector2& Gamepad::getJoystickState(unsigned int index) const
-{
-    assert(index < MAX_JOYSTICKS);
-
-    return _joysticks[index]._direction;
-}
-
-Input::Key Gamepad::getJoystickKeyModifier(unsigned int index, JoystickOrientation orientation) const
-{
-    assert(index < MAX_JOYSTICKS);
-    
-    Input::Key key;
-    
-    switch(orientation)
-    {
-    case NORTH:
-        key = _joysticks[index]._north;
-        break;
-    case SOUTH:
-        key = _joysticks[index]._south;
-        break;
-    case EAST:
-        key = _joysticks[index]._east;
-        break;
-    case WEST:
-        key = _joysticks[index]._west;
-        break;
-    }
-    
-    return key;
-}
-
-void Gamepad::setJoystickKeyModifier(unsigned int index, JoystickOrientation orientation, Input::Key key)
-{
-    assert(index < MAX_JOYSTICKS);
-
-    switch(orientation)
-    {
-    case NORTH:
-        _joysticks[index]._north = key;
-        break;
-    case SOUTH:
-        _joysticks[index]._south  = key;
-        break;
-    case EAST:
-        _joysticks[index]._east = key;
-        break;
-    case WEST:
-        _joysticks[index]._west = key;
-        break;
-    }
-}
-
-bool Gamepad::loadButtons(Gamepad* gamepad, Properties* properties)
-{
-    properties->rewind();
-
-    Properties* buttons = NULL;
-    while ((buttons = properties->getNextNamespace()))
-    {
-        buttons->rewind();
-
-        // Create and load a button.
-        if (strcmp(buttons->getNamespace(), "button") == 0)
-        {
-            Button* button = new Button();
-            
-            const char* name = NULL;
-            while (name = buttons->getNextProperty())
-            {
-                float u1 = 0.0f, v1 = 0.0f , u2 = 0.0f, v2 = 0.0f;
-
-                if (strcmp(name, "x") == 0)
-                {
-                    button->_position.x = buttons->getFloat();
-                }
-                else if (strcmp(name, "y") == 0)
-                {
-                    button->_position.y = buttons->getFloat();
-                }
-                if (strcmp(name, "width") == 0)
-                {
-                    button->_width = buttons->getFloat();
-                }
-                else if (strcmp(name, "height") == 0)
-                {
-                    button->_height = buttons->getFloat();
-                }
-                else if (strcmp(name, "default") == 0)
-                {
-                    Vector2 out = Vector2(0.0, 0.0);
-                    buttons->getVector2(NULL, &out);
-                    button->_defaultTexCoord.x = out.x; // u1
-                    button->_defaultTexCoord.y = out.y; // v1
-                    button->_defaultTexture = true;
-                }
-                else if (strcmp(name, "focus") == 0)
-                {
-                    Vector2 out = Vector2(0.0, 0.0);
-                    buttons->getVector2(NULL, &out); 
-                    button->_focusTexCoord.x = out.x; // u1
-                    button->_focusTexCoord.y = out.y; // v1
-                    button->_focusTexture = true;
-                }
-                else if (strcmp(name, "key-modifier") == 0)
-                {
-                    button->_key = (Input::Key)buttons->getInt();
-                }
-            }
-
-            // if (u1, v1) of default and focus button texture is specified in the gamepad file then
-            // calculate the respective (u2, v2).
-            if (button->_defaultTexture)
-            {
-                button->_defaultTexCoord.x = (button->_defaultTexCoord.x / gamepad->_texture->getWidth() );
-                button->_defaultTexCoord.y = 1.0f - (button->_defaultTexCoord.y / gamepad->_texture->getHeight());
-                button->_defaultTexCoord.z = button->_defaultTexCoord.x + (button->_width / gamepad->_texture->getWidth()); // u2
-                button->_defaultTexCoord.w = button->_defaultTexCoord.y - (button->_width / gamepad->_texture->getHeight()); // v2
-            }
-
-            if (button->_focusTexture)
-            {
-                button->_focusTexCoord.x = (button->_focusTexCoord.x / gamepad->_texture->getWidth() );
-                button->_focusTexCoord.y = 1.0f - (button->_focusTexCoord.y / gamepad->_texture->getHeight());
-                button->_focusTexCoord.z = button->_focusTexCoord.x + (button->_width / gamepad->_texture->getWidth()); // u2
-                button->_focusTexCoord.w = button->_focusTexCoord.y - (button->_width / gamepad->_texture->getWidth()); // v2
-            }
-
-            gamepad->addButton(button);
-        }
-    }
-
-    return true;
-}
-
-bool Gamepad::loadJoysticks(Gamepad* gamepad, Properties* properties)
-{
-    properties->rewind();
-
-    Properties* joysticks = NULL;
-    while ((joysticks = properties->getNextNamespace()))
-    {
-        joysticks->rewind();
-        Vector4 defaultTexCoordInner = Vector4::zero();
-        Vector4 defaultTexCoordOuter = Vector4::zero();
-
-        // Create and load a button.
-        if (strcmp(joysticks->getNamespace(), "joystick") == 0)
-        {
-            Joystick* joystick = new Joystick();
-            
-            const char* name = NULL;
-            while (name = joysticks->getNextProperty())
-            {
-                float u1 = 0.0f, v1 = 0.0f , u2 = 0.0f, v2 = 0.0f;
-
-                if (strcmp(name, "bounds-outer") == 0)
-                {
-                    joysticks->getVector4(NULL, &joystick->_boundsOuter);
-                }
-                else if (strcmp(name, "bounds-inner") == 0)
-                {
-                    joysticks->getVector4(NULL, &joystick->_boundsInner);
-                }
-                else if (strcmp(name, "default-inner") == 0)
-                {
-                    joysticks->getVector4(NULL, &defaultTexCoordInner);
-                    joystick->_defaultTextureInner = true;
-                }
-                else if (strcmp(name, "focus-inner") == 0)
-                {
-                    // TODO.
-                }
-                else if (strcmp(name, "default-outer") == 0)
-                {
-                    joysticks->getVector4(NULL, &defaultTexCoordOuter);
-                    joystick->_defaultTextureOuter = true;
-                }
-                else if (strcmp(name, "focus-outer") == 0)
-                {
-                    // TODO.
-                }
-                else if (strcmp(name, "key-modifier") == 0)
-                {
-                    // TODO.
-                }
-                else if (strcmp(name, "radius") == 0)
-                {
-                    joystick->_radius = joysticks->getFloat(NULL);
-                }
-            }
-
-            // if (u1, v1) of default and focus button texture is specified in the gamepad file then
-            // calculate the respective (u2, v2).
-            if (joystick->_defaultTextureInner)
-            {
-                joystick->_defaultTexCoordInner.x = (defaultTexCoordInner.x / gamepad->_texture->getWidth());
-                joystick->_defaultTexCoordInner.y = 1.0f - (defaultTexCoordInner.y / gamepad->_texture->getHeight());
-                joystick->_defaultTexCoordInner.z = joystick->_defaultTexCoordInner.x + (defaultTexCoordInner.z / gamepad->_texture->getWidth()); // u2
-                joystick->_defaultTexCoordInner.w = joystick->_defaultTexCoordInner.y - (defaultTexCoordInner.w / gamepad->_texture->getHeight()); // v2
-            }
-
-            if (joystick->_defaultTextureOuter)
-            {
-                joystick->_defaultTexCoordOuter.x = (defaultTexCoordOuter.x / gamepad->_texture->getWidth());
-                joystick->_defaultTexCoordOuter.y = 1.0f - (defaultTexCoordOuter.y / gamepad->_texture->getHeight());
-                joystick->_defaultTexCoordOuter.z = joystick->_defaultTexCoordOuter.x + (defaultTexCoordOuter.z / gamepad->_texture->getWidth()); // u2
-                joystick->_defaultTexCoordOuter.w = joystick->_defaultTexCoordOuter.y - (defaultTexCoordOuter.w / gamepad->_texture->getHeight()); // v2
-            }
-
-            gamepad->addJoystick(joystick);
-        }
-    }
-
-    return true;
-}
-
-void Gamepad::setSpriteBatch(SpriteBatch* spriteBatch)
-{
-    _spriteBatch = spriteBatch;
-}
-
-Gamepad* Gamepad::create(const char* gamepadPath)
-{
-    assert (gamepadPath);
-
-    // Load the gamepad properties from file
-    Properties* properties = Properties::create(gamepadPath);
-    assert(properties);
-    if (properties == NULL)
-    {
-        return NULL;
-    }
-
-    Properties* gamepadProperties = properties->getNextNamespace();
-    assert (gamepadProperties);
-    if (!gamepadProperties || !(strcmp(gamepadProperties->getNamespace(), "gamepad") == 0))
-    {
-        SAFE_DELETE(properties);
-        return NULL;
-    }
-
-    // Load the gamepad texture.
-    const char* texturePath = gamepadProperties->getString("texture");
-    if (strlen(texturePath) == 0)
-    {
-        LOG_ERROR_VARG("Error loading Gamepad: No valid texture path specified, in %s", gamepadPath);
-        return NULL;
-    }
-
-    Gamepad* gamepad = new Gamepad();
-
-    gamepad->_texture = Texture::create(texturePath, true);
-    assert(gamepad->_texture);
-
-    // Load gamepad components.
-    Properties* componentProperties = NULL;
-    while ((componentProperties = gamepadProperties->getNextNamespace()))
-    {
-        if (strcmp(componentProperties->getNamespace(), "buttons") == 0)
-        {
-            if (!loadButtons(gamepad, componentProperties))
-            {
-                SAFE_RELEASE(gamepad);
-                SAFE_DELETE(properties);
-                return NULL;
-            }
-            
-        }
-
-        else if (strcmp(componentProperties->getNamespace(), "joysticks") == 0)
-        {
-            if(!loadJoysticks(gamepad, componentProperties))
-            {
-                SAFE_RELEASE(gamepad);
-                SAFE_DELETE(properties);
-                return NULL;
-            }
-        }
-    }
-    
-    // Create a sprite batch.
-    // TODO: determine the "actual" number of sprites required when parsing the .gamepad file.
-    SpriteBatch* spriteBatch = SpriteBatch::create(gamepad->_texture, 0, MAX_BUTTONS + MAX_JOYSTICKS);
-    gamepad->_spriteBatch = spriteBatch;
-
-    return gamepad;
-}
-
-void Gamepad::update(long elapsedTime)
-{
-
-
-}
-
-void Gamepad::draw()
-{
-    _spriteBatch->begin();
-    
-    // Draw buttons.
-    for (int i = 0; i < _buttonCount; ++i)
-    {
-        if ((_buttons[i]._pressed == BUTTON_PRESSED) && (_buttons[i]._focusTexture))
-        {
-            _spriteBatch->draw(_buttons[i]._position.x, _buttons[i]._position.y,  _buttons[i]._width,  _buttons[i]._height, 
-                           _buttons[i]._focusTexCoord.x, _buttons[i]._focusTexCoord.y, _buttons[i]._focusTexCoord.z, _buttons[i]._focusTexCoord.w, 
-                           Vector4::one());
-            continue;
-        }
-        else
-        {
-            _spriteBatch->draw(_buttons[i]._position.x, _buttons[i]._position.y,  _buttons[i]._width,  _buttons[i]._height, 
-                           _buttons[i]._defaultTexCoord.x, _buttons[i]._defaultTexCoord.y, _buttons[i]._defaultTexCoord.z, _buttons[i]._defaultTexCoord.w, 
-                           Vector4::one());
-        }
-    }
-
-    // Draw joysticks.
-    for (int i = 0; i < _joystickCount; ++i)
-    {
-        // Draw Outer joggle.
-        float x = _joysticks[i]._boundsOuter.x;
-        float y = _joysticks[i]._boundsOuter.y;
-        float width = _joysticks[i]._boundsOuter.z;
-        float height = _joysticks[i]._boundsOuter.w;
-        float radius = _joysticks[i]._radius;
-        float outerJoggleRadius = _joysticks[i]._boundsOuter.z / 2.0f;
-
-        x = x - (width / 2.0f);
-        y = y - (height / 2.0f);
-        
-        float u1 = _joysticks[i]._defaultTexCoordOuter.x;
-        float v1 = _joysticks[i]._defaultTexCoordOuter.y;
-        float u2 = _joysticks[i]._defaultTexCoordOuter.z;
-        float v2 = _joysticks[i]._defaultTexCoordOuter.w;
-
-        _spriteBatch->draw(x, y, width,  height, u1, v1, u2, v2, Vector4::one());
-
-        // Draw Inner joggle.
-        x = _joysticks[i]._boundsInner.x;
-        y = _joysticks[i]._boundsInner.y;
-        width = _joysticks[i]._boundsInner.z;
-        height = _joysticks[i]._boundsInner.w;
-
-        // Move position to reflect displacement.
-        if (((_joysticks[i]._deltaX * _joysticks[i]._deltaX) + 
-             (_joysticks[i]._deltaY * _joysticks[i]._deltaY)) <= 
-            (outerJoggleRadius * outerJoggleRadius))
-        {
-            x += _joysticks[i]._deltaX;
-            y += _joysticks[i]._deltaY;
-        }
-        else
-        {
-            Vector2 dir = Vector2(_joysticks[i]._deltaX, _joysticks[i]._deltaY);
-            dir.normalize();
-            dir.scale(outerJoggleRadius);
-            x += dir.x;
-            y += dir.y;
-        }
-        
-        // Adjust inner joggle (x, y) position to point to top right.
-        x = x - (width / 2.0f);
-        y = y - (height / 2.0f);
-
-        u1 = _joysticks[i]._defaultTexCoordInner.x;
-        v1 = _joysticks[i]._defaultTexCoordInner.y;
-        u2 = _joysticks[i]._defaultTexCoordInner.z;
-        v2 = _joysticks[i]._defaultTexCoordInner.w;
-        
-        _spriteBatch->draw(x, y, width, height, u1, v1, u2, v2, Vector4::one());
-    }
-
-    _spriteBatch->end();
-}
-
-void Gamepad::keyPress(int key, int keyEvent)
-{
-
-}
-
-void Gamepad::touch(int x, int y, int touchEvent)
-{
-    for (int i = 0; i < _buttonCount; ++i)
-    {
-        if ((x >= _buttons[i]._position.x) && (x <= (_buttons[i]._position.x + _buttons[i]._width)) &&
-            (y >= _buttons[i]._position.y) && (y <= (_buttons[i]._position.y + _buttons[i]._height)))
-        {
-            switch(touchEvent)
-            {
-            case Input::TOUCHEVENT_PRESS:
-            {
-                _buttons[i]._pressed = BUTTON_PRESSED;
-            }
-            break;
-            case Input::TOUCHEVENT_RELEASE:
-            {
-                _buttons[i]._pressed = BUTTON_RELEASED;
-            }
-            break;
-            }
-        }
-    }
-
-    for (int i = 0; i < _joystickCount; ++i)
-    {
-        switch(touchEvent)
-        {
-        case Input::TOUCHEVENT_PRESS:
-        {
-            float bx = _joysticks[i]._boundsOuter.x;
-            float by = _joysticks[i]._boundsOuter.y;
-            float bwidth = _joysticks[i]._boundsOuter.z;
-            float bheight = _joysticks[i]._boundsOuter.w;
-
-            if ((x >= (bx - (bwidth / 2.0f))) && (x <= (bx + (bwidth / 2.0f))) &&
-                (y >= (by - (bheight / 2.0f))) && (y <= (by + (bheight / 2.0f))))
-            {
-                _joysticks[i]._enabledMovement = true;
-                _joysticks[i]._deltaX = 0.0f;
-                _joysticks[i]._deltaY = 0.0f;
-                _joysticks[i]._direction.zero();
-            }
-        }
-        case Input::TOUCHEVENT_MOVE:
-        {
-            if (_joysticks[i]._enabledMovement)
-            {
-                _joysticks[i]._deltaX = x - _joysticks[i]._boundsOuter.x;
-                _joysticks[i]._deltaY = y - _joysticks[i]._boundsOuter.y;
-                
-                if (((_joysticks[i]._deltaX * _joysticks[i]._deltaX) +
-                     (_joysticks[i]._deltaY * _joysticks[i]._deltaY)) <=
-                    ((_joysticks[i]._radius * _joysticks[i]._radius)))
-                {
-                    _joysticks[i]._direction.x = _joysticks[i]._deltaX;
-                    _joysticks[i]._direction.y = _joysticks[i]._deltaY;
-                    //_joysticks[i]._direction.normalize();
-                    _joysticks[i]._direction.scale(1.0f /  _joysticks[i]._radius);
-                }
-                else
-                {
-                    if (_joysticks[i]._deltaX > _joysticks[i]._radius)
-                    {
-                        _joysticks[i]._direction.x = _joysticks[i]._radius;
-                    }
-                    if (_joysticks[i]._deltaX < -_joysticks[i]._radius)
-                    {
-                        _joysticks[i]._direction.x = -_joysticks[i]._radius;
-                    }
-                    if (_joysticks[i]._deltaY > _joysticks[i]._radius)
-                    {
-                        _joysticks[i]._direction.y = _joysticks[i]._radius;
-                    }
-                    if (_joysticks[i]._deltaY < -_joysticks[i]._radius)
-                    {
-                        _joysticks[i]._direction.y = -_joysticks[i]._radius;
-                    }
-
-                    _joysticks[i]._direction.scale(1.0f /  _joysticks[i]._radius);
-                    //_joysticks[i]._direction.scale(_joysticks[i]._radius);
-                    //_joysticks[i]._direction.normalize();
-                }
-                
-                // _joysticks[i]._direction.normalize();
-                // _joysticks[i]._direction.scale(1.0f / _joysticks[i]._radius);
-            }
-        }
-        break;
-        case Input::TOUCHEVENT_RELEASE:
-        {
-            if (_joysticks[i]._enabledMovement)
-            {
-                _joysticks[i]._deltaX = 0.0f;
-                _joysticks[i]._deltaY = 0.0f;
-                _joysticks[i]._direction.x = 0.0f;
-                _joysticks[i]._direction.y = 0.0f;
-                _joysticks[i]._enabledMovement = false;
-            }
-        }
-        break;
-        }
-    }
-}
-
-void Gamepad::setCurrentGamepad(Gamepad* gamepad)
-{
-    __gamepad = gamepad;
-}
-
-Gamepad* Gamepad::getCurrentGamepad()
-{
-    return __gamepad;
-}
-
-void Gamepad::addButton(Button* button)
-{
-    if (_buttonCount == MAX_BUTTONS)
-    {
-        return;
-    }
-    
-    _buttons[_buttonCount] = *button;
-    _buttonCount++;
-}
-
-void Gamepad::addJoystick(Joystick* joystick)
-{
-    if (_joystickCount == MAX_JOYSTICKS)
-    {
-        return;    
-    }
-
-    _joysticks[_joystickCount] = *joystick;
-    _joystickCount++;
-}
-
-}

+ 0 - 17
gameplay/src/Input.h

@@ -4,8 +4,6 @@
 namespace gameplay
 {
 
-class Gamepad;
-
 /**
  * Defines an input class for requesting input.
  */
@@ -209,21 +207,6 @@ public:
      */
     static void getAccelerometerPitchAndRoll(float* pitch, float* roll);
 
-    /**
-     * Indicates if the game device supports a gamepad.
-     * 
-     * @return true if the gamepad is supported; false otherwise.
-     */
-    static bool isGamepadSupported();
-
-    /**
-     * Gets the gamepad
-     *
-     * @ returns an instance of gamepad if Id is valid; NULL otherwise.
-     */
-    static Gamepad* getGamepad();
-
-
 private:
 
     /**

+ 153 - 0
gameplay/src/Theme.cpp

@@ -0,0 +1,153 @@
+/*
+ * Theme.cpp
+ */
+
+#include "Theme.h"
+
+namespace gameplay
+{
+    Theme::Theme()
+        //: _texture(NULL)
+    {
+    }
+
+    Theme::Theme(const Theme* theme)
+    {
+    }
+
+    Theme::~Theme()
+    {
+        // Destroy all the cursors, styles and , fonts.
+        for (unsigned int i = 0, count = _cursors.size(); i < count; ++i)
+        {
+            Cursor* cursor = _cursors[i];
+            if (cursor)
+            {
+                delete cursor;
+            }
+        }
+
+        for (unsigned int i = 0, count = _styles.size(); i < count; ++i)
+        {
+            Style* style = _styles[i];
+            if (style)
+            {
+                delete style;
+            }
+        }
+
+        for (unsigned int i = 0, count = _fonts.size(); i < count; ++i)
+        {
+            Font* font = _fonts[i];
+            if (font)
+            {
+                SAFE_RELEASE(font);
+            }
+        }
+    }
+
+    Theme::Style::Overlay::~Overlay()
+    {
+        SAFE_RELEASE(_font);
+    }
+
+    Theme* Theme::create(const char* path)
+    {
+        assert(path);
+
+        // Load theme properties from file path.
+        Properties* properties = Properties::create(path);
+        assert(properties);
+        if (properties == NULL)
+        {
+            return NULL;
+        }
+
+        // Check if the Properties is valid and has a valid namespace.
+        Properties* themeProperties = properties->getNextNamespace();
+        assert(themeProperties);
+        if (!themeProperties || !(strcmp(themeProperties->getNamespace(), "theme") == 0))
+        {
+            SAFE_DELETE(properties);
+            return NULL;
+        }
+
+        // Create a new theme.
+        Theme* theme = new Theme();
+        return theme;
+    }   
+
+    const Theme::Style* Theme::getStyle(const char* name) const
+    {
+        for (unsigned int i = 0, count = _styles.size(); i < count; ++i)
+        {
+            if (strcmp(name, _styles[i]->getId()) == 0)
+            {
+                return _styles[i];
+            }
+        }
+
+        return NULL;
+    }
+
+    const char* Theme::Cursor::getId() const
+    {
+        return _id.data();
+    }
+
+    const Rectangle& Theme::Cursor::getRegion() const
+    {
+        return _region;
+    }
+
+    const Theme::UVs& Theme::Cursor::getUVs() const
+    {
+        return _uvs;
+    }
+    
+    const char* Theme::Style::getId() const
+    {
+        return _id.data();
+    }
+
+    const Theme::Style::Overlay& Theme::Style::getOverlay(OverlayType overlayType) const
+    {
+        return _overlays[overlayType];
+    }
+
+    const Theme::Border& Theme::Style::getBorder() const
+    {
+        return _border;
+    }
+
+    const Theme::Padding& Theme::Style::getPadding() const
+    {
+        return _padding;
+    }
+
+    Theme::Style::OverlayType Theme::Style::Overlay::getId()
+    {
+        return _id;
+    }
+    
+    const Rectangle& Theme::Style::Overlay::getRegion() const
+    {
+        return _region;
+    }
+
+    const Theme::UVs& Theme::Style::Overlay::getUVs() const
+    {
+        return _uvs;   
+    }
+
+    const Font* Theme::Style::Overlay::getFont() const
+    {
+        return _font;
+    }
+
+    const Theme::Cursor& Theme::Style::Overlay::getCursor() const
+    {
+        return _cursor;
+    }
+
+}

+ 205 - 0
gameplay/src/Theme.h

@@ -0,0 +1,205 @@
+/*
+ * Theme.h
+ */
+
+# ifndef THEME_H_
+# define THEME_H_
+
+#include "Base.h"
+#include "Ref.h"
+#include "Font.h"
+#include "Rectangle.h"
+#include "Texture.h"
+#include "Properties.h"
+
+namespace gameplay
+{
+
+#define MAX_OVERLAYS 3
+/**
+ * This class represents the apperance of an UI form described in a 
+ * theme file. A theme file, at its simplest, contains a source texture atlas,
+ * the texture coordinates of each control in its different mode. Once loaded,
+ * the appearance properties can be retrieved using a style id and set on a UI control.
+ */
+class Theme: public Ref
+{
+public:
+    class Style;
+    class Cursor;
+
+    typedef struct UVs
+    {
+        float u1;
+        float v1;
+        float u2;
+        float v2;
+    } UVs;
+
+    typedef struct padding
+    {
+        float top;
+        float bottom;
+        float left;
+        float right;
+    } Border, Padding;
+
+    /**
+     * Creates an instance of a Theme from a theme file.
+     *
+     * @param path path to a theme file.
+     *
+     * @return A new Theme.
+     */
+    static Theme* create(const char* path);
+
+    /**
+     * Returns style with the given name.
+     *
+     * @param name Name of the style (as specified in the Theme file).
+     *
+     * @return instance of the Style.
+     */
+    const Theme::Style* getStyle(const char* styleName) const;
+
+    /**
+     * This class represents the apperance of a cursor.
+     */
+    class Cursor
+    {
+    public:
+       /**
+        * Returns the Id of this Cursor.
+        */
+        const char* getId() const;
+
+       /**
+        * Gets a texture region in the texture atlas for a cursor.
+        */
+        const Rectangle& getRegion() const;
+
+       /**
+        * Gets a UV coordinates computed from the texture region.
+        */
+        const Theme::UVs& getUVs() const;
+    
+    private:
+
+        std::string _id;
+        Rectangle _region;
+        UVs _uvs;
+    };
+    
+    /**
+     * This class represents the apperance of a control's style.
+     */
+    class Style
+    {
+    public:
+        class Overlay;
+
+        enum OverlayType
+        {
+            OVERLAY_NORMAL,
+            OVERLAY_FOCUS,
+            OVERLAY_ACTIVE
+        };
+
+        /**
+         * Returns the Id of this Style.
+         */
+        const char* getId() const;
+
+        /**
+         * Gets an overlay from the overlay type.
+         */
+        const Theme::Style::Overlay& getOverlay(OverlayType overlayType) const;
+
+       /**
+        * Gets a Border region of this overlay.
+        */
+        const Theme::Border& getBorder() const;
+
+        /**
+        * Gets a Padding region of this overlay.
+        */
+        const Theme::Padding& getPadding() const;
+       
+        /**
+         * This class represents a control's overlay for one of the 3 modes: normal, focussed or active.
+         */
+        class Overlay
+        {
+        public:
+           /**
+            * Destructor.
+            */
+            ~Overlay();
+
+           /**
+            * Returns the Overlay type.
+            */
+            OverlayType getId();
+            
+            /**
+            * Gets a texture region in the texture atlas that the overlay uses.
+            */
+            const Rectangle& getRegion() const;
+
+           /**
+            * Gets a UV coordinates computed from the texture region.
+            */
+            const Theme::UVs& getUVs() const;
+
+           /**
+            * Gets a font associated with this overlay.
+            */
+            const Font* getFont() const;
+
+           /**
+            * Gets a cursor associated with this overlay.
+            */
+            const Cursor& getCursor() const;
+        
+        private:
+           
+            OverlayType _id;
+            Rectangle _region;
+            UVs _uvs;
+            Font* _font;
+            Cursor _cursor;
+        };
+
+    private:
+        
+        std::string _id;
+        Border _border;
+        Padding _padding;
+        Overlay _overlays[MAX_OVERLAYS];
+    };
+
+private:
+    /**
+     * Constructor.
+     */
+    Theme();
+
+    /**
+     * Copy Constructor.
+     */
+    Theme(const Theme* theme);
+
+    /**
+     * Destructor.
+     */
+    ~Theme();
+
+    Texture* _texture;
+    std::vector<Cursor *> _cursors;
+    std::vector<Style *> _styles;
+    std::vector<Font *> _fonts;
+};
+
+}
+
+#endif

+ 0 - 284
gameplay/src/gamepad.h

@@ -1,284 +0,0 @@
-/*
- * Gamepad.h
- */
-
-#ifndef GAMEPAD_H_
-#define GAMEPAD_H_
-
-#include "Vector3.h"
-#include "Input.h"
-#include "Properties.h"
-#include "Ref.h"
-#include "SpriteBatch.h"
-
-namespace gameplay
-{
-
-/**
- * Defines a class for accessing gamepad controls: Buttons and Joysticks.
- */
-class Gamepad: public Ref
-{
-public:
-
-    enum ButtonState
-    {
-        BUTTON_PRESSED,
-        BUTTON_RELEASED
-    };
-
-    enum JoystickOrientation
-    {
-        NORTH,
-        SOUTH,
-        EAST,
-        WEST
-    };
-
-    /**
-     * Represents the maximum number of buttons supported on a gamepad.
-     */
-    static const int MAX_BUTTONS = 32;
-
-    /**
-     * Represents the maximum number of joysticks supported on a gamepad.
-     */
-    static const int MAX_JOYSTICKS = 2;
-
-    /**
-     * Returns a button state.
-     *
-     * @param index Index of the button in the list of buttons specified in the gamepad file.
-     * @return BUTTON_PRESSED if the button is pressed; BUTTON_RELEASED otherwise.
-     */
-    ButtonState getButtonState(unsigned int index) const;
-
-    /**
-     * Returns an input key mapped to this button.
-     *
-     * @param index Index of a button in the list of buttons specified in the gamepad file.
-     * @return input key mapped to this button.
-     */
-    Input::Key getButtonKeyModifier(unsigned int index) const;
-
-    /**
-     * Sets an input key mapping for this button.
-     *
-     * @param index Index of a button in the list of buttons specified in the gamepad file.
-     * @return input key mapped to this button.
-     */
-    void setButtonKeyModifier(unsigned int index, Input::Key key);
-
-    /**
-     * Returns a joystick state in the specified direction vector.
-     *
-     * @param index index of the joystick in the list of joysticks specified in the gamepad file.
-     * @return direction of the joystick movement as Vector3.
-     */
-    const Vector2& getJoystickState(unsigned int index) const;
-
-    /**
-     * Returns the key mapped to a joystick orientation.
-     *
-     * @param index Index of the joystick in the list of joysticks specified in the gamepad file.
-     * @param orientation One of the 4 supported Joystick orientations.
-     * @return Key associated with a specified joystick orientation.
-     */
-    Input::Key getJoystickKeyModifier(unsigned int index, JoystickOrientation orientation) const;
-
-    /**
-     * Sets a key mapping for a joystick orientation.
-     *
-     * @param index Index of the joystick in the list of joysticks specified in the gamepad file.
-     * @param orientation One of the 4 supported Joystick orientations.
-     * @param key associated with a specified joystick orientation.
-     */
-    void setJoystickKeyModifier(unsigned int index, JoystickOrientation orientation, Input::Key key);
-
-    /**
-     * Creates an gamepad from an input gamepad file. 
-     * 
-     * @param gamepadPath Path of the gamepad file.
-     * @return instance of a Gamepad.
-     */
-    static Gamepad* create(const char* gamepadPath);
-
-    /**
-     * Sets a gamepad current.
-     *
-     * @param gamepad Instance of a Gamepad.
-     */
-    static void setCurrentGamepad(Gamepad* gamepad);
-
-    /**
-     * Returns the current Gamepad.
-     *
-     * @return currently set gamepad.
-     */
-    static Gamepad* getCurrentGamepad();
-    
-    /**
-     * Updates the gamepad.
-     *
-     * @param elapsedTime The amount of time that has passed since the last call to update(), in milliseconds.
-     */
-    void update(long elapsedTime);
-
-    /**
-     * Draws the gamepad.
-     */
-    void draw();
-
-    /**
-     * Input callback on keyPress events.
-     *
-     * @param key The key code pressed.
-     * @param keyEvent The key event that occured.
-     * 
-     * @see Input::Key
-     * @see Input::KeyEvent
-     */
-    void keyPress(int key, int keyEvent);
-
-    /**
-     * Input callback on touch events.
-     *
-     * @param x The x position of the touch.
-     * @param y The y position of the touch.
-     * @param touchEvent The touch event that occurred.
-     * 
-     * @see Input::TouchEvent
-     */
-    void touch(int x, int y, int touchEvent);
-
-
-private:
-
-    /**
-     * Constructor.
-     */
-    Gamepad();
-
-    /**
-     * Hidden copy constructor.
-     */
-    Gamepad(const Gamepad* gamepad);
-
-    /**
-     * Destructor.
-     */
-    ~Gamepad();
-
-    /**
-     * Sets a spritebatch to this gamepad.
-     */
-    void setSpriteBatch(SpriteBatch* spriteBatch);
-
-    /**
-     * Load the gamepad buttons specified in the properties.
-     */
-    static bool loadButtons(Gamepad* gamepad, Properties* properties);
-
-    /**
-     * Load the gamepad joysticks specified in the properties.
-     */
-    static bool loadJoysticks(Gamepad* gamepad, Properties* properties);
-
-    /** 
-     * Defines a gamepad button.
-     */
-    class Button
-    {
-    public:
-       /**
-        * Constructor.
-        */
-        Button();
-
-       /**
-        * Copy constructor.
-        */
-        Button(const Button& button);
-
-        /**
-         * Destructor.
-         */
-        ~Button();
-        
-        Gamepad::ButtonState _pressed;
-        Input::Key _key;
-        Vector2 _position;
-        Vector4 _defaultTexCoord;
-        bool _defaultTexture;
-        Vector4 _focusTexCoord;
-        bool _focusTexture;
-        float _height;
-        float _width;
-    };
-
-    /**
-     * Defines a gamepad joystick.
-     */
-    class Joystick
-    {
-    public:
-       /**
-        * Constructor.
-        */
-        Joystick();
-
-       /**
-        * Copy constructor.
-        */
-        Joystick(const Joystick& joystick);
-
-        /**
-         * Destructor.
-         */
-        ~Joystick();
-        
-        bool _enabledMovement;
-        float _deltaX;
-        float _deltaY;
-        Vector2 _direction;
-        float _radius;
-        
-        Vector4 _boundsInner;
-        bool _defaultTextureInner;
-        bool _focusTextureInner;
-        Vector4 _defaultTexCoordInner;
-        Vector4 _focusTexCoordInner;
-
-        Vector4 _boundsOuter;
-        bool _defaultTextureOuter;
-        bool _focusTextureOuter;
-        Vector4 _defaultTexCoordOuter;
-        Vector4 _focusTexCoordOuter;
-        
-        Input::Key _north;
-        Input::Key _south;
-        Input::Key _east;
-        Input::Key _west;
-    };
-
-    /**
-     * Adds a button to the Gamepad.
-     */
-    void addButton(Button* button);
-
-    /**
-     * Adds a joystick to the Gamepad.
-     */
-    void addJoystick(Joystick* joystick);
-
-    Button _buttons[MAX_BUTTONS];
-    int _buttonCount;
-    Joystick _joysticks[MAX_JOYSTICKS];
-    int _joystickCount;
-    Texture* _texture;
-    SpriteBatch* _spriteBatch;
-};
-
-}
-
-#endif

+ 1 - 1
gameplay/src/gameplay.h

@@ -5,7 +5,7 @@
 #include "Input.h"
 #include "FileSystem.h"
 #include "Package.h"
-#include "Gamepad.h"
+#include "Theme.h"
 
 // Math
 #include "Rectangle.h"