issue #4861, improve UIFocusTest, add click event to ImageView

This commit is contained in:
andyque 2014-05-06 14:14:22 +08:00
parent a15dd55baa
commit ad4e1f1e2c
2 changed files with 33 additions and 4 deletions

View File

@ -60,6 +60,21 @@ bool UIFocusTestBase::init()
return false;
}
void UIFocusTestBase::onImageViewClicked(cocos2d::Ref *ref, TouchEventType touchType)
{
if (touchType == TouchEventType::TOUCH_EVENT_ENDED) {
Widget *w = (Widget*)ref;
if (w->isFocusEnabled()) {
w->setFocusEnabled(false);
w->setColor(Color3B::WHITE);
w->setScale(0.8);
}else{
w->setFocusEnabled(true);
w->setScale(1.0);
}
}
}
//UIFocusTestHorizontal
UIFocusTestHorizontal::UIFocusTestHorizontal()
@ -89,6 +104,8 @@ bool UIFocusTestHorizontal::init()
int count = 3;
for (int i=0; i<count; ++i) {
ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
w->setTouchEnabled(true);
w->addTouchEventListener(this, toucheventselector(UIFocusTestHorizontal::onImageViewClicked));
_horizontalLayout->addChild(w);
}
@ -110,6 +127,9 @@ bool UIFocusTestHorizontal::init()
return false;
}
void UIFocusTestHorizontal::toggleFocusLoop(cocos2d::Ref * pObjc, TouchEventType type)
{
if (type == TouchEventType::TOUCH_EVENT_ENDED) {
@ -126,13 +146,13 @@ void UIFocusTestHorizontal::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus,
{
//only change the widgets' state
Layout *getLayout = dynamic_cast<Layout*>(widgetGetFocus);
if (!getLayout && widgetGetFocus) {
if (!getLayout && widgetGetFocus && widgetGetFocus->isFocusEnabled()) {
widgetGetFocus->setScale(1.2);
widgetGetFocus->setColor(Color3B::RED);
}
Layout *loseLayout = dynamic_cast<Layout*>(widgetLostFocus);
if (!loseLayout && widgetLostFocus) {
if (!loseLayout && widgetLostFocus && widgetLostFocus->isFocusEnabled()) {
widgetLostFocus->setScale(1.0);
widgetLostFocus->setColor(Color3B::WHITE);
}
@ -197,6 +217,8 @@ bool UIFocusTestVertical::init()
int count = 3;
for (int i=0; i<count; ++i) {
ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
w->setTouchEnabled(true);
w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked));
_verticalLayout->addChild(w);
}
@ -218,6 +240,7 @@ bool UIFocusTestVertical::init()
return false;
}
void UIFocusTestVertical::toggleFocusLoop(cocos2d::Ref * pObjc, TouchEventType type)
{
if (type == TouchEventType::TOUCH_EVENT_ENDED) {
@ -234,13 +257,13 @@ void UIFocusTestVertical::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus, c
{
//only change the widgets' state
Layout *getLayout = dynamic_cast<Layout*>(widgetGetFocus);
if (!getLayout && widgetGetFocus) {
if (!getLayout && widgetGetFocus && widgetGetFocus->isFocusEnabled()) {
widgetGetFocus->setScale(1.2);
widgetGetFocus->setColor(Color3B::RED);
}
Layout *loseLayout = dynamic_cast<Layout*>(widgetLostFocus);
if (!loseLayout && widgetLostFocus) {
if (!loseLayout && widgetLostFocus && widgetLostFocus->isFocusEnabled()) {
widgetLostFocus->setScale(1.0);
widgetLostFocus->setColor(Color3B::WHITE);
}

View File

@ -11,6 +11,8 @@
#include "../UIScene.h"
class UIFocusTestBase : public UIScene
{
public:
@ -23,6 +25,9 @@ public:
virtual void onUpKeyPressed() = 0;
virtual void onDownKeyPressed() = 0;
virtual void onFocusChanged(Widget* widgetLostFocus, Widget* widgetGetFocus) = 0;
void onImageViewClicked(Ref* ref, TouchEventType touchType);
protected:
Menu *_dpadMenu;
Widget *_firstFocusedWidget;
@ -42,6 +47,7 @@ public:
virtual void onFocusChanged(Widget* widgetLostFocus, Widget* widgetGetFocus);
void toggleFocusLoop(Ref*,TouchEventType);
protected:
UI_SCENE_CREATE_FUNC(UIFocusTestHorizontal);
Layout *_horizontalLayout;