mirror of https://github.com/axmolengine/axmol.git
issue #5057. add UIDeprecated.h and refactor FocusDirection to inner class of
Widget and also simplify the enum value
This commit is contained in:
parent
9f0e25d808
commit
0c2fd977ea
|
@ -2287,6 +2287,7 @@
|
|||
2905FA1218CF08D100240AA3 /* UITextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITextField.h; sourceTree = "<group>"; };
|
||||
2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = "<group>"; };
|
||||
2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = "<group>"; };
|
||||
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
|
||||
296CAD201915EC8000C64FBF /* CCEventFocus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventFocus.cpp; path = ../base/CCEventFocus.cpp; sourceTree = "<group>"; };
|
||||
296CAD211915EC8000C64FBF /* CCEventFocus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCEventFocus.h; path = ../base/CCEventFocus.h; sourceTree = "<group>"; };
|
||||
296CAD261915EC9900C64FBF /* CCEventListenerFocus.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCEventListenerFocus.cpp; path = ../base/CCEventListenerFocus.cpp; sourceTree = "<group>"; };
|
||||
|
@ -4021,6 +4022,7 @@
|
|||
50E6D33118E174130051CA34 /* UIRelativeBox.h */,
|
||||
50E6D33218E174130051CA34 /* UIVBox.cpp */,
|
||||
50E6D33318E174130051CA34 /* UIVBox.h */,
|
||||
29080DEB191B82CE0066F8DF /* UIDeprecated.h */,
|
||||
);
|
||||
name = ui;
|
||||
path = ../cocos/ui;
|
||||
|
|
|
@ -45,6 +45,7 @@ THE SOFTWARE.
|
|||
#include "ui/UIHBox.h"
|
||||
#include "ui/UIVBox.h"
|
||||
#include "ui/UIRelativeBox.h"
|
||||
#include "ui/UIDeprecated.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
namespace ui {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// UIDeprecated.h
|
||||
// cocos2d_libs
|
||||
//
|
||||
// Created by guanghui on 5/8/14.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef cocos2d_libs_UIDeprecated_h
|
||||
#define cocos2d_libs_UIDeprecated_h
|
||||
|
||||
#include "base/CCPlatformMacros.h"
|
||||
#include "UIWidget.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
namespace ui {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif
|
|
@ -1675,7 +1675,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
|
|||
|
||||
float distance = FLT_MAX;
|
||||
int found = 0;
|
||||
if (direction == FocusDirection::FocusDirection_Left || direction == FocusDirection::FocusDirection_Right)
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
|
||||
{
|
||||
Vector2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
|
@ -1709,7 +1709,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
|
|||
index = 0;
|
||||
found = 0;
|
||||
distance = FLT_MAX;
|
||||
if (direction == FocusDirection::FocusDirection_Down || direction == FocusDirection::FocusDirection_Up) {
|
||||
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
|
||||
Vector2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
{
|
||||
|
@ -1743,7 +1743,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Layout::findFarestChildWidgetIndex(cocos2d::ui::FocusDirection direction, cocos2d::ui::Widget *baseWidget)
|
||||
int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Widget *baseWidget)
|
||||
{
|
||||
if (baseWidget == nullptr || baseWidget == this)
|
||||
{
|
||||
|
@ -1754,7 +1754,7 @@ int Layout::findFarestChildWidgetIndex(cocos2d::ui::FocusDirection direction, co
|
|||
|
||||
float distance = -FLT_MAX;
|
||||
int found = 0;
|
||||
if (direction == FocusDirection::FocusDirection_Left || direction == FocusDirection::FocusDirection_Right)
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
|
||||
{
|
||||
Vector2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
|
@ -1788,7 +1788,7 @@ int Layout::findFarestChildWidgetIndex(cocos2d::ui::FocusDirection direction, co
|
|||
index = 0;
|
||||
found = 0;
|
||||
distance = -FLT_MAX;
|
||||
if (direction == FocusDirection::FocusDirection_Down || direction == FocusDirection::FocusDirection_Up) {
|
||||
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
|
||||
Vector2 widgetPosition = this->getWorldCenterPoint(baseWidget);
|
||||
while (index < count)
|
||||
{
|
||||
|
@ -1873,27 +1873,27 @@ void Layout::findProperSearchingFunctor(FocusDirection dir, Widget* baseWidget)
|
|||
|
||||
Vector2 layoutPosition = this->getWorldCenterPoint(this->findFirstNonLayoutWidget());
|
||||
|
||||
if (dir == FocusDirection::FocusDirection_Left) {
|
||||
if (dir == FocusDirection::LEFT) {
|
||||
if (previousWidgetPosition.x > layoutPosition.x) {
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this);
|
||||
}
|
||||
else{
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findFarestChildWidgetIndex, this);
|
||||
}
|
||||
}else if(dir == FocusDirection::FocusDirection_Right){
|
||||
}else if(dir == FocusDirection::RIGHT){
|
||||
if (previousWidgetPosition.x > layoutPosition.x) {
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findFarestChildWidgetIndex, this);
|
||||
}
|
||||
else{
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this);
|
||||
}
|
||||
}else if(dir == FocusDirection::FocusDirection_Down){
|
||||
}else if(dir == FocusDirection::DOWN){
|
||||
if (previousWidgetPosition.y > layoutPosition.y) {
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this);
|
||||
}else{
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findFarestChildWidgetIndex, this);
|
||||
}
|
||||
}else if(dir == FocusDirection::FocusDirection_Up){
|
||||
}else if(dir == FocusDirection::UP){
|
||||
if (previousWidgetPosition.y < layoutPosition.y) {
|
||||
onPassFocusToChild = CC_CALLBACK_2(Layout::findNearestChildWidgetIndex, this);
|
||||
}else{
|
||||
|
@ -1906,7 +1906,7 @@ void Layout::findProperSearchingFunctor(FocusDirection dir, Widget* baseWidget)
|
|||
}
|
||||
|
||||
|
||||
Widget* Layout::passFocusToChild(cocos2d::ui::FocusDirection dir, cocos2d::ui::Widget *current)
|
||||
Widget* Layout::passFocusToChild(FocusDirection dir, cocos2d::ui::Widget *current)
|
||||
{
|
||||
if (checkFocusEnabledChild())
|
||||
{
|
||||
|
@ -2188,7 +2188,7 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
|
|||
ssize_t index = container.getIndex(widget);
|
||||
if (parent->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL)
|
||||
{
|
||||
if (direction == FocusDirection::FocusDirection_Left) {
|
||||
if (direction == FocusDirection::LEFT) {
|
||||
if (index == 0)
|
||||
{
|
||||
return true * isLastWidgetInContainer(parent, direction);
|
||||
|
@ -2198,7 +2198,7 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (direction == FocusDirection::FocusDirection_Right) {
|
||||
if (direction == FocusDirection::RIGHT) {
|
||||
if (index == container.size()-1)
|
||||
{
|
||||
return true * isLastWidgetInContainer(parent, direction);
|
||||
|
@ -2208,19 +2208,19 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (direction == FocusDirection::FocusDirection_Down)
|
||||
if (direction == FocusDirection::DOWN)
|
||||
{
|
||||
return isLastWidgetInContainer(parent, direction);
|
||||
}
|
||||
|
||||
if (direction == FocusDirection::FocusDirection_Up)
|
||||
if (direction == FocusDirection::UP)
|
||||
{
|
||||
return isLastWidgetInContainer(parent, direction);
|
||||
}
|
||||
}
|
||||
else if(parent->getLayoutType() == LAYOUT_LINEAR_VERTICAL)
|
||||
{
|
||||
if (direction == FocusDirection::FocusDirection_Up)
|
||||
if (direction == FocusDirection::UP)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
|
@ -2232,7 +2232,7 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (direction == FocusDirection::FocusDirection_Down)
|
||||
if (direction == FocusDirection::DOWN)
|
||||
{
|
||||
if (index == container.size() - 1)
|
||||
{
|
||||
|
@ -2243,12 +2243,12 @@ bool Layout::isLastWidgetInContainer(Widget* widget, FocusDirection direction)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (direction == FocusDirection::FocusDirection_Left)
|
||||
if (direction == FocusDirection::LEFT)
|
||||
{
|
||||
return isLastWidgetInContainer(parent, direction);
|
||||
}
|
||||
|
||||
if (direction == FocusDirection::FocusDirection_Right)
|
||||
if (direction == FocusDirection::RIGHT)
|
||||
{
|
||||
return isLastWidgetInContainer(parent, direction);
|
||||
}
|
||||
|
@ -2274,7 +2274,7 @@ bool Layout::isWidgetAncestorSupportLoopFocus(Widget* widget, FocusDirection di
|
|||
auto layoutType = parent->getLayoutType();
|
||||
if (layoutType == LAYOUT_LINEAR_HORIZONTAL)
|
||||
{
|
||||
if (direction == FocusDirection::FocusDirection_Left || direction == FocusDirection::FocusDirection_Right)
|
||||
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -2285,7 +2285,7 @@ bool Layout::isWidgetAncestorSupportLoopFocus(Widget* widget, FocusDirection di
|
|||
}
|
||||
if (layoutType == LAYOUT_LINEAR_VERTICAL)
|
||||
{
|
||||
if (direction == FocusDirection::FocusDirection_Down || direction == FocusDirection::FocusDirection_Up)
|
||||
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -2338,16 +2338,16 @@ Widget* Layout::findNextFocusedWidget(FocusDirection direction, Widget* current)
|
|||
{
|
||||
switch (direction)
|
||||
{
|
||||
case FocusDirection::FocusDirection_Left:
|
||||
case FocusDirection::LEFT:
|
||||
{
|
||||
return this->getPreviousFocusedWidget(direction, current);
|
||||
}break;
|
||||
case FocusDirection::FocusDirection_Right:
|
||||
case FocusDirection::RIGHT:
|
||||
{
|
||||
return this->getNextFocusedWidget(direction, current);
|
||||
}break;
|
||||
case FocusDirection::FocusDirection_Down:
|
||||
case FocusDirection::FocusDirection_Up:
|
||||
case FocusDirection::DOWN:
|
||||
case FocusDirection::UP:
|
||||
{
|
||||
if (isLastWidgetInContainer(this, direction))
|
||||
{
|
||||
|
@ -2375,8 +2375,8 @@ Widget* Layout::findNextFocusedWidget(FocusDirection direction, Widget* current)
|
|||
{
|
||||
switch (direction)
|
||||
{
|
||||
case FocusDirection::FocusDirection_Left:
|
||||
case FocusDirection::FocusDirection_Right:
|
||||
case FocusDirection::LEFT:
|
||||
case FocusDirection::RIGHT:
|
||||
{
|
||||
if (isLastWidgetInContainer(this, direction))
|
||||
{
|
||||
|
@ -2393,12 +2393,12 @@ Widget* Layout::findNextFocusedWidget(FocusDirection direction, Widget* current)
|
|||
return Widget::findNextFocusedWidget(direction, this);
|
||||
}
|
||||
} break;
|
||||
case FocusDirection::FocusDirection_Down:
|
||||
case FocusDirection::DOWN:
|
||||
{
|
||||
return getNextFocusedWidget(direction, current);
|
||||
}
|
||||
break;
|
||||
case FocusDirection::FocusDirection_Up:
|
||||
case FocusDirection::UP:
|
||||
{
|
||||
return getPreviousFocusedWidget(direction, current);
|
||||
}
|
||||
|
|
|
@ -984,12 +984,13 @@ bool Widget::isFocusEnabled()
|
|||
return _focusEnabled;
|
||||
}
|
||||
|
||||
Widget* Widget::findNextFocusedWidget(cocos2d::ui::FocusDirection direction, Widget* current)
|
||||
Widget* Widget::findNextFocusedWidget(FocusDirection direction, Widget* current)
|
||||
{
|
||||
if (nullptr == onNextFocusedWidget || nullptr == onNextFocusedWidget(direction) ) {
|
||||
if (this->isFocused() || !current->isFocusEnabled())
|
||||
{
|
||||
Node* parent = this->getParent();
|
||||
|
||||
Layout* layout = dynamic_cast<Layout*>(parent);
|
||||
if (nullptr == layout)
|
||||
{
|
||||
|
|
|
@ -73,13 +73,7 @@ typedef enum
|
|||
POSITION_PERCENT
|
||||
}PositionType;
|
||||
|
||||
enum class FocusDirection
|
||||
{
|
||||
FocusDirection_Left,
|
||||
FocusDirection_Right,
|
||||
FocusDirection_Up,
|
||||
FocusDirection_Down
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef void (Ref::*SEL_TouchEvent)(Ref*,TouchEventType);
|
||||
|
@ -91,6 +85,14 @@ typedef void (Ref::*SEL_TouchEvent)(Ref*,TouchEventType);
|
|||
class Widget : public ProtectedNode
|
||||
{
|
||||
public:
|
||||
enum class FocusDirection
|
||||
{
|
||||
LEFT,
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN
|
||||
};
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
|
|
|
@ -80,7 +80,7 @@ void UIFocusTestBase::onLeftKeyPressed()
|
|||
if (!_firstFocusedWidget->isFocused()) {
|
||||
_firstFocusedWidget = _firstFocusedWidget->getCurrentFocusedWidget(false);
|
||||
}
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(FocusDirection::FocusDirection_Left, _firstFocusedWidget);
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::LEFT, _firstFocusedWidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ void UIFocusTestBase::onRightKeyPressed()
|
|||
if (!_firstFocusedWidget->isFocused()) {
|
||||
_firstFocusedWidget = _firstFocusedWidget->getCurrentFocusedWidget(false);
|
||||
}
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(FocusDirection::FocusDirection_Right, _firstFocusedWidget);
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::RIGHT, _firstFocusedWidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ void UIFocusTestBase::onUpKeyPressed()
|
|||
if (!_firstFocusedWidget->isFocused()) {
|
||||
_firstFocusedWidget = _firstFocusedWidget->getCurrentFocusedWidget(false);
|
||||
}
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(FocusDirection::FocusDirection_Up, _firstFocusedWidget);
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::UP, _firstFocusedWidget);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ void UIFocusTestBase::onDownKeyPressed()
|
|||
if (!_firstFocusedWidget->isFocused()) {
|
||||
_firstFocusedWidget = _firstFocusedWidget->getCurrentFocusedWidget(false);
|
||||
}
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(FocusDirection::FocusDirection_Down, _firstFocusedWidget);
|
||||
_firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::DOWN, _firstFocusedWidget);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue