瀏覽代碼

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 年之前
父節點
當前提交
809b730fb0
共有 2 個文件被更改,包括 25 次插入17 次删除
  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;