Skip to content

Commit

Permalink
Change GObject.visible behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 28, 2017
1 parent 0e757ac commit 8a73a14
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion libfairygui/Classes/GComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ cocos2d::Vec2 GComponent::getSnappingPosition(const cocos2d::Vec2 & pt)

GObject* GComponent::hitTest(const Vec2 &worldPoint, const Camera* camera)
{
if (!_touchable || !_visible || !internalVisible())
if (_touchDisabled || !_touchable || !_displayObject->isVisible() || !_displayObject->getParent())
return nullptr;

GObject * target = nullptr;
Expand Down
14 changes: 5 additions & 9 deletions libfairygui/Classes/GGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,9 @@ void GGroup::handleAlphaChanged()
return;

int cnt = _parent->numChildren();
int i;
GObject* child;
for (i = 0; i < cnt; i++)
for (int i = 0; i < cnt; i++)
{
child = _parent->getChildAt(i);
GObject* child = _parent->getChildAt(i);
if (child->_group == this)
child->setAlpha(_alpha);
}
Expand All @@ -426,13 +424,11 @@ void GGroup::handleVisibleChanged()
return;

int cnt = _parent->numChildren();
int i;
GObject* child;
for (i = 0; i < cnt; i++)
for (int i = 0; i < cnt; i++)
{
child = _parent->getChildAt(i);
GObject* child = _parent->getChildAt(i);
if (child->_group == this)
child->setVisible(_visible);
child->handleVisibleChanged();
}
}

Expand Down
14 changes: 11 additions & 3 deletions libfairygui/Classes/GObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,16 @@ void GObject::setVisible(bool value)
}
}

bool GObject::internalVisible()
bool GObject::internalVisible() const
{
return _internalVisible && (_group == nullptr || _group->internalVisible());
}

bool GObject::internalVisible2() const
{
return _visible && (_group == nullptr || _group->internalVisible2());
}

void GObject::setTouchable(bool value)
{
_touchable = value;
Expand Down Expand Up @@ -331,6 +336,9 @@ void GObject::setGroup(GGroup * value)
_group = value;
if (_group != nullptr)
_group->setBoundsChangedFlag(true);
handleVisibleChanged();
if (_parent)
_parent->childStateChanged(this);
}
}

Expand Down Expand Up @@ -631,7 +639,7 @@ void GObject::constructFromResource()

GObject* GObject::hitTest(const Vec2 &worldPoint, const Camera* camera)
{
if (_touchDisabled || !_touchable || !_visible || !internalVisible())
if (_touchDisabled || !_touchable || !_displayObject->isVisible() || !_displayObject->getParent())
return nullptr;

Rect rect;
Expand Down Expand Up @@ -717,7 +725,7 @@ void GObject::handleGrayedChanged()

void GObject::handleVisibleChanged()
{
_displayObject->setVisible(_visible);
_displayObject->setVisible(internalVisible2());
}

void GObject::handleControllerChanged(GController * c)
Expand Down
3 changes: 2 additions & 1 deletion libfairygui/Classes/GObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ class GObject : public UIEventDispatcher
bool _finalGrayed;

private:
bool internalVisible();
bool internalVisible() const;
bool internalVisible2() const;
void updateGearFromRelations(int index, float dx, float dy);
void transformRectPoint(const cocos2d::Vec2& pt, float rect[], GObject* targetSpace);

Expand Down
16 changes: 15 additions & 1 deletion libfairygui/Classes/event/InputProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ NS_FGUI_BEGIN
USING_NS_CC;

InputProcessor* InputProcessor::_activeProcessor = nullptr;
bool InputProcessor::_touchOnUI = false;
unsigned int InputProcessor::_touchOnUIFlagFrameId = 0;

class TouchInfo
{
Expand Down Expand Up @@ -127,6 +129,14 @@ void InputProcessor::updateRecentInput(TouchInfo* ti, GObject* target)
_recentInput._mouseWheelDelta = ti->mouseWheelDelta;
_recentInput._touch = ti->touch;
_recentInput._touchId = ti->touch ? ti->touchId : -1;

int curFrame = Director::getInstance()->getTotalFrames();
bool flag = target != _owner;
if (curFrame != _touchOnUIFlagFrameId)
_touchOnUI = flag;
else if (flag)
_touchOnUI = true;
_touchOnUIFlagFrameId = curFrame;
}

void InputProcessor::handleRollOver(TouchInfo* touch, GObject* target)
Expand Down Expand Up @@ -263,6 +273,11 @@ GObject* InputProcessor::clickTest(TouchInfo* touch, GObject* target)
return obj;
}

bool InputProcessor::isTouchOnUI()
{
return isTouchOnUI;
}

bool InputProcessor::onTouchBegan(Touch *touch, Event* /*unusedEvent*/)
{
auto camera = Camera::getVisitingCamera();
Expand Down Expand Up @@ -423,7 +438,6 @@ void InputProcessor::onTouchCancelled(Touch* touch, Event* /*unusedEvent*/)
return;

ti->touch = touch;

updateRecentInput(ti, _owner);
_activeProcessor = this;

Expand Down
3 changes: 3 additions & 0 deletions libfairygui/Classes/event/InputProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class InputProcessor
typedef std::function<void(int eventType)> CaptureEventCallback;

InputEvent* getRecentInput() { return &_recentInput; }
static bool isTouchOnUI();

InputProcessor(GComponent* owner);
~InputProcessor();
Expand Down Expand Up @@ -60,6 +61,8 @@ class InputProcessor
InputEvent _recentInput;
uint16_t _keyModifiers;

static bool _touchOnUI;
static unsigned int _touchOnUIFlagFrameId;
static InputProcessor* _activeProcessor;

friend class UIEventDispatcher;
Expand Down

0 comments on commit 8a73a14

Please sign in to comment.