Browse Source

Changed Control::getState to give the FOCUS state priority over all other states but ACTIVE. This fixes an issue where focus colors and styles do not properly show up for UI themes.

Made Container::moveFocus(Direction) public to allow easy extension of input mechanisms for UI.
sgrenier 11 years ago
parent
commit
809b730fb0
2 changed files with 25 additions and 17 deletions
  1. 22 14
      gameplay/src/Container.h
  2. 3 3
      gameplay/src/Control.cpp

+ 22 - 14
gameplay/src/Container.h

@@ -37,6 +37,19 @@ public:
         SCROLL_BOTH = SCROLL_HORIZONTAL | SCROLL_VERTICAL
     };
 
+    /**
+     * Defines supported focus chagne directions.
+     */
+    enum Direction
+    {
+        UP = 0x01,
+        DOWN = 0x02,
+        LEFT = 0x04,
+        RIGHT = 0x08,
+        NEXT = 0x10,
+        PREVIOUS = 0x20
+    };
+
     /**
      * Creates a new container.
      *
@@ -245,6 +258,15 @@ public:
      */
     bool setFocus();
 
+    /**
+     * Attempts to switch focus to a child of this container in the specified direction.
+     *
+     * @param direction The direction for focus change.
+     *
+     * @return True on success, false if there are no controls to focus on.
+     */
+    bool moveFocus(Direction direction);
+
     /**
      * Returns the currently active control for this container.
      *
@@ -546,22 +568,8 @@ private:
      */
     Container(const Container& copy);
 
-    enum Direction
-    {
-        UP = 0x01,
-        DOWN = 0x02,
-        LEFT = 0x04,
-        RIGHT = 0x08,
-        NEXT = 0x10,
-        PREVIOUS = 0x20
-    };
-
     static const int MAX_CONTACT_INDICES = 10;
 
-    // Returns true on success; false if there are no controls to focus on,
-    // in which case scrolling can be initiated.
-    bool moveFocus(Direction direction);
-
 	bool moveFocusNextPrevious(Direction direction);
 	bool moveFocusDirectional(Direction direction);
 

+ 3 - 3
gameplay/src/Control.cpp

@@ -909,10 +909,10 @@ Theme* Control::getTheme() const
 
 Control::State Control::getState() const
 {
-    if (_state == HOVER)
+    if (Form::getFocusControl() == this)
     {
-        // Focus state takes priority over hover
-        return (Form::getFocusControl() == this ? FOCUS : HOVER);
+        // Active is the only state that overrides focus state
+        return _state == ACTIVE ? ACTIVE : FOCUS;
     }
 
     return _state;