Remove useless samples

This commit is contained in:
CaiWenzhi 2014-01-07 09:47:46 +08:00
parent 9d58951d56
commit 8cfc6fcafb
11 changed files with 3 additions and 1500 deletions

View File

@ -267,6 +267,9 @@ void Text::copySpecialProperties(Widget *widget)
setFontSize(label->_labelRenderer->getFontSize());
setText(label->getStringValue());
setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled);
setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment());
setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment());
setTextAreaSize(label->_labelRenderer->getDimensions());
}
}

View File

@ -1,215 +0,0 @@
#include "UIGridViewTest.h"
// UIGridViewTest_Mode_Column
UIGridViewTest_Mode_Column::UIGridViewTest_Mode_Column()
{
}
UIGridViewTest_Mode_Column::~UIGridViewTest_Mode_Column()
{
}
bool UIGridViewTest_Mode_Column::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = gui::Label::create();
_displayValueLabel->setText("Move by vertical direction");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Layout is in use with GridView bases on column mode");
alert->setFontName("Marker Felt");
alert->setFontSize(20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
// Create the grid view with grid layout mode column
GridView* gridView = GridView::create();
gridView->setLayoutType(LAYOUT_GRID_MODE_COLUMN);
gridView->setScrollEnabled(true);
gridView->setDirection(SCROLLVIEW_DIR_VERTICAL);
gridView->setBounceEnabled(true);
gridView->setTouchEnabled(true);
gridView->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
gridView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f +
(backgroundSize.width - gridView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - gridView->getSize().height) / 2.0f));
gridView->addEventListenerScrollView(this, scrollvieweventselector(UIGridViewTest_Mode_Column::selectedChildEvent));
_uiLayer->addChild(gridView);
// create items
int count = 19;
for (int i = 0; i < count; ++i)
{
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
button->setScale9Enabled(true);
AffineTransform transform = AffineTransformMakeIdentity();
transform = AffineTransformScale(transform, 3.0f, 1.3f);
button->setSize(SizeApplyAffineTransform(button->getContentSize(), transform));
button->setTitleText(String::createWithFormat("grid_%d", i)->getCString());
Layout* item = Layout::create();
item->setTouchEnabled(true);
item->setSize(button->getSize());
button->setPosition(Point(item->getSize().width / 2.0f, item->getSize().height / 2.0f));
item->addChild(button);
gridView->addChild(item);
}
// set grid view row and column
Widget* item = static_cast<Widget*>(gridView->getChildren().at(0));
int rowCount = gridView->getSize().height / item->getSize().height;
int columnCount = gridView->getSize().width / item->getSize().width;
gridView->setGridLayoutRowAndColumnCount(rowCount, columnCount);
return true;
}
return false;
}
void UIGridViewTest_Mode_Column::selectedChildEvent(Object *pSender, ScrollviewEventType type)
{
switch (type)
{
case SCROLLVIEW_EVENT_SELECT_CHILD:
{
GridView* gridView = static_cast<GridView*>(pSender);
CCLOG("select child index = %d", gridView->getSelectedChildIndex());
}
break;
default:
break;
}
}
// UIGridViewTest_Mode_Row
UIGridViewTest_Mode_Row::UIGridViewTest_Mode_Row()
{
}
UIGridViewTest_Mode_Row::~UIGridViewTest_Mode_Row()
{
}
bool UIGridViewTest_Mode_Row::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = gui::Label::create();
_displayValueLabel->setText("Move by horizontal direction");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Layout is in use with GridView bases on row mode");
alert->setFontName("Marker Felt");
alert->setFontSize(20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
// Create the scroll grid with grid layout mode row
GridView* gridView = GridView::create();
gridView->setLayoutType(LAYOUT_GRID_MODE_ROW);
gridView->setScrollEnabled(true);
gridView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
gridView->setBounceEnabled(true);
gridView->setTouchEnabled(true);
gridView->setSize(Size(280, 150));
Size backgroundSize = background->getSize();
gridView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f +
(backgroundSize.width - gridView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - gridView->getSize().height) / 2.0f));
gridView->addEventListenerScrollView(this, scrollvieweventselector(UIGridViewTest_Mode_Row::selectedChildEvent));
_uiLayer->addChild(gridView);
// create items
int count = 19;
for (int i = 0; i < count; ++i)
{
Button* button = Button::create();
button->setTouchEnabled(true);
button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
button->setScale9Enabled(true);
AffineTransform transform = AffineTransformMakeIdentity();
transform = AffineTransformScale(transform, 3.0f, 1.3f);
button->setSize(SizeApplyAffineTransform(button->getContentSize(), transform));
button->setTitleText(String::createWithFormat("grid_%d", i)->getCString());
Layout* item = Layout::create();
item->setTouchEnabled(true);
item->setSize(button->getSize());
button->setPosition(Point(item->getSize().width / 2.0f, item->getSize().height / 2.0f));
item->addChild(button);
gridView->addChild(item);
}
// set grid view row and column
Widget* item = static_cast<Widget*>(gridView->getChildren().at(0));
int rowCount = gridView->getSize().height / item->getSize().height;
int columnCount = gridView->getSize().width / item->getSize().width;
gridView->setGridLayoutRowAndColumnCount(rowCount, columnCount);
return true;
}
return false;
}
void UIGridViewTest_Mode_Row::selectedChildEvent(Object *pSender, ScrollviewEventType type)
{
switch (type)
{
case SCROLLVIEW_EVENT_SELECT_CHILD:
{
GridView* gridView = static_cast<GridView*>(pSender);
CCLOG("select child index = %d", gridView->getSelectedChildIndex());
}
break;
default:
break;
}
}

View File

@ -1,56 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __TestCpp__UIGridViewTest__
#define __TestCpp__UIGridViewTest__
#include "../UIScene.h"
class UIGridViewTest_Mode_Column : public UIScene
{
public:
UIGridViewTest_Mode_Column();
~UIGridViewTest_Mode_Column();
bool init();
void selectedChildEvent(Object* pSender, ScrollviewEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIGridViewTest_Mode_Column)
gui::Label* _displayValueLabel;
};
class UIGridViewTest_Mode_Row : public UIScene
{
public:
UIGridViewTest_Mode_Row();
~UIGridViewTest_Mode_Row();
bool init();
void selectedChildEvent(Object* pSender, ScrollviewEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIGridViewTest_Mode_Row)
gui::Label* _displayValueLabel;
};
#endif /* defined(__TestCpp__UIGridViewTest__) */

View File

@ -1,264 +0,0 @@
#include "UIPickerViewTest.h"
// UIPickerViewTest_Vertical
UIPickerViewTest_Vertical::UIPickerViewTest_Vertical()
{
}
UIPickerViewTest_Vertical::~UIPickerViewTest_Vertical()
{
CC_SAFE_RELEASE(m_array);
}
bool UIPickerViewTest_Vertical::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
m_pDisplayValueLabel = gui::Label::create();
m_pDisplayValueLabel->setText("Move by vertical direction");
m_pDisplayValueLabel->setFontName("Marker Felt");
m_pDisplayValueLabel->setFontSize(32);
m_pDisplayValueLabel->setAnchorPoint(Point(0.5f, -1));
m_pDisplayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
_uiLayer->addChild(m_pDisplayValueLabel);
gui::Label* alert = gui::Label::create();
alert->setText("PickerView vertical");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
Size backgroundSize = background->getContentSize();
// create picker view data
m_array = __Array::create();
CC_SAFE_RETAIN(m_array);
for (int i = 0; i < 20; ++i)
{
String* ccstr = String::createWithFormat("pickerview_%d", i);
m_array->addObject(ccstr);
}
// Create the picker view
PickerView* pickerView = PickerView::create();
// set picker view direction
pickerView->setDirection(SCROLLVIEW_DIR_VERTICAL);
pickerView->setTouchEnabled(true);
pickerView->setBounceEnabled(true);
pickerView->setBackGroundImage("cocosgui/yellow_edit.png");
pickerView->setBackGroundImageScale9Enabled(true);
pickerView->setSize(Size(240, 150));
pickerView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
(backgroundSize.width - pickerView->getSize().width) / 2,
(widgetSize.height - backgroundSize.height) / 2 +
(backgroundSize.height - pickerView->getSize().height) / 2));
pickerView->addEventListenerScrollView(this, scrollvieweventselector(UIPickerViewTest_Vertical::selectedItemEvent));
pickerView->addEventListenerPickerView(this, pickervieweventselector(UIPickerViewTest_Vertical::pickItemEvent));
_uiLayer->addChild(pickerView);
int count = m_array->count();
pickerView->setItemCountInContainerWithOddNumber(count / 5);
for (int i = 0; i < count; ++i)
{
Button* button = Button::create();
button->loadTextures("cocosgui/orange_edit.png", "cocosgui/orange_edit.png", "");
button->setScale9Enabled(true);
button->setSize(Size(100,
pickerView->getSize().height / pickerView->getItemCountInContainerWithOddNumber()));
button->setTitleText(static_cast<String*>(m_array->getObjectAtIndex(i))->getCString());
pickerView->addChild(button);
}
// create picker render of picker view
Button* button_0 = static_cast<Button*>(pickerView->getChildren().at(0));
pickerView->loadPickerTexture("cocosgui/green_edit.png");
Scale9Sprite* pickerRender = pickerView->getPickerRender();
pickerRender->setOpacity(pickerView->getOpacity() / 3);
pickerRender->setPreferredSize(Size(pickerView->getSize().width, button_0->getSize().height));
return true;
}
return false;
}
void UIPickerViewTest_Vertical::selectedItemEvent(Object *pSender, ScrollviewEventType type)
{
switch (type)
{
case SCROLLVIEW_EVENT_SELECT_CHILD:
{
PickerView* pickerView = static_cast<PickerView*>(pSender);
CCLOG("select child index = %d", pickerView->getSelectedChildIndex());
}
break;
default:
break;
}
}
void UIPickerViewTest_Vertical::pickItemEvent(Object *pSender, PickerViewEventType type)
{
switch (type)
{
case PICKERVIEW_EVENT_PICK_ITEM:
{
PickerView* pickerView = static_cast<PickerView*>(pSender);
CCLOG("picker view pick index = %d", pickerView->getPickIndex());
}
break;
default:
break;
}
}
// UIPickerViewTest_Horizontal
UIPickerViewTest_Horizontal::UIPickerViewTest_Horizontal()
{
}
UIPickerViewTest_Horizontal::~UIPickerViewTest_Horizontal()
{
CC_SAFE_RELEASE(m_array);
}
bool UIPickerViewTest_Horizontal::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
m_pDisplayValueLabel = gui::Label::create();
m_pDisplayValueLabel->setText("Move by horizontal direction");
m_pDisplayValueLabel->setFontName("Marker Felt");
m_pDisplayValueLabel->setFontSize(32);
m_pDisplayValueLabel->setAnchorPoint(Point(0.5f, -1));
m_pDisplayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
_uiLayer->addChild(m_pDisplayValueLabel);
gui::Label* alert = gui::Label::create();
alert->setText("PickerView horizontal");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
Size backgroundSize = background->getContentSize();
// create picker view data
m_array = __Array::create();
CC_SAFE_RETAIN(m_array);
for (int i = 0; i < 20; ++i)
{
String* ccstr = String::createWithFormat("PCKER%d", i);
m_array->addObject(ccstr);
}
const char* title_0 = static_cast<String*>(m_array->getObjectAtIndex(0))->getCString();
// Create the picker view
PickerView* pickerView = PickerView::create();
// set picker view direction
pickerView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
pickerView->setTouchEnabled(true);
pickerView->setBounceEnabled(true);
pickerView->setBackGroundImage("cocosgui/yellow_edit.png");
pickerView->setBackGroundImageScale9Enabled(true);
pickerView->setSize(Size(240, 150));
pickerView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
(backgroundSize.width - pickerView->getSize().width) / 2,
(widgetSize.height - backgroundSize.height) / 2 +
(backgroundSize.height - pickerView->getSize().height) / 2));
pickerView->addEventListenerScrollView(this, scrollvieweventselector(UIPickerViewTest_Horizontal::selectedItemEvent));
pickerView->addEventListenerPickerView(this, pickervieweventselector(UIPickerViewTest_Horizontal::pickItemEvent));
_uiLayer->addChild(pickerView);
int count = m_array->count();
pickerView->setItemCountInContainerWithOddNumber(count / 4);
for (int i = 0; i < count; ++i)
{
Button* button = Button::create();
button->loadTextures("cocosgui/orange_edit.png", "cocosgui/orange_edit.png", "");
button->setScale9Enabled(true);
button->setSize(Size(pickerView->getSize().width / pickerView->getItemCountInContainerWithOddNumber(),
120));
button->setTitleText(static_cast<String*>(m_array->getObjectAtIndex(i))->getCString());
button->setTitleDimension(Size(button->getTitleFontSize(),
button->getTitleFontSize() * (strlen(title_0) * 2)));
button->setTitleHorizontalAlignment(TextHAlignment::CENTER);
button->setTitleVerticalAlignment(TextVAlignment::CENTER);
pickerView->addChild(button);
}
// create picker render of picker view
Button* button_0 = static_cast<Button*>(pickerView->getChildren().at(0));
pickerView->loadPickerTexture("cocosgui/green_edit.png");
Scale9Sprite* pickerRender = pickerView->getPickerRender();
pickerRender->setOpacity(pickerView->getOpacity() / 3);
pickerRender->setPreferredSize(Size(button_0->getSize().width, pickerView->getSize().height));
return true;
}
return false;
}
void UIPickerViewTest_Horizontal::selectedItemEvent(Object *pSender, ScrollviewEventType type)
{
switch (type)
{
case SCROLLVIEW_EVENT_SELECT_CHILD:
{
PickerView* pickerView = static_cast<PickerView*>(pSender);
CCLOG("select child index = %d", pickerView->getSelectedChildIndex());
}
break;
default:
break;
}
}
void UIPickerViewTest_Horizontal::pickItemEvent(Object *pSender, PickerViewEventType type)
{
switch (type)
{
case PICKERVIEW_EVENT_PICK_ITEM:
{
PickerView* pickerView = static_cast<PickerView*>(pSender);
CCLOG("picker view pick index = %d", pickerView->getPickIndex());
}
break;
default:
break;
}
}

View File

@ -1,62 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __TestCpp__UIPickViewTest__
#define __TestCpp__UIPickViewTest__
#include "../UIScene.h"
class UIPickerViewTest_Vertical : public UIScene
{
public:
UIPickerViewTest_Vertical();
~UIPickerViewTest_Vertical();
bool init();
void selectedItemEvent(Object* pSender, ScrollviewEventType type);
void pickItemEvent(Object* pSender, PickerViewEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIPickerViewTest_Vertical)
gui::Label* m_pDisplayValueLabel;
__Array* m_array;
};
class UIPickerViewTest_Horizontal : public UIScene
{
public:
UIPickerViewTest_Horizontal();
~UIPickerViewTest_Horizontal();
bool init();
void selectedItemEvent(Object* pSender, ScrollviewEventType type);
void pickItemEvent(Object* pSender, PickerViewEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIPickerViewTest_Horizontal)
gui::Label* m_pDisplayValueLabel;
__Array* m_array;
};
#endif /* defined(__TestCpp__UIPickViewTest__) */

View File

@ -1,80 +0,0 @@
#include "UIPotentiometerTest.h"
// UIPotentiometerTest
UIPotentiometerTest::UIPotentiometerTest()
: _displayValueLabel(NULL)
{
}
UIPotentiometerTest::~UIPotentiometerTest()
{
}
bool UIPotentiometerTest::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the button events will be displayed
_displayValueLabel = gui::Label::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height / 3));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Potentiometer");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2));
_uiLayer->addChild(alert);
// Create the potentiometer
Potentiometer *potentiometer = Potentiometer::create();
potentiometer->setTouchEnabled(true);
potentiometer->loadTexture("cocosgui/potentiometerTrack.png", "cocosgui/potentiometerProgress.png", "cocosgui/potentiometerButton.png");
potentiometer->setPosition(Point(widgetSize.width / 2 - potentiometer->getSize().width, widgetSize.height / 2));
potentiometer->addEventListenerPotentiometer(this, potentiometervaluechangedselector(UIPotentiometerTest::valueChangedEvent));
_uiLayer->addChild(potentiometer);
// Create the potentiometer with allow min and max value
Potentiometer *potentiometerAllow = Potentiometer::create();
potentiometerAllow->setTouchEnabled(true);
potentiometerAllow->loadTexture("cocosgui/potentiometerTrack.png", "cocosgui/potentiometerProgress.png", "cocosgui/potentiometerButton.png");
potentiometerAllow->setPosition(Point(widgetSize.width / 2 + potentiometerAllow->getSize().width, widgetSize.height / 2));
potentiometerAllow->addEventListenerPotentiometer(this, potentiometervaluechangedselector(UIPotentiometerTest::valueChangedEvent));
potentiometerAllow->setMinimumAllowValue(0.3);
potentiometerAllow->setMaximumAllowValue(0.7);
potentiometerAllow->setValue(0.3);
_uiLayer->addChild(potentiometerAllow);
return true;
}
return false;
}
void UIPotentiometerTest::valueChangedEvent(Object *pSender, PotentiometerEventType type)
{
Potentiometer* potentiometer = static_cast<Potentiometer*>(pSender);
switch (type)
{
case POTENTIOMETER_EVENT_VALUECHANGED:
_displayValueLabel->setText(CCString::createWithFormat("%.02f", potentiometer->getValue())->getCString());
break;
default:
break;
}
}

View File

@ -1,45 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __TestCpp__UIPotentiometerTest__
#define __TestCpp__UIPotentiometerTest__
#include "../UIScene.h"
class UIPotentiometerTest : public UIScene
{
public:
UIPotentiometerTest();
~UIPotentiometerTest();
bool init();
void valueChangedEvent(Object* pSender, PotentiometerEventType type);
protected:
UI_SCENE_CREATE_FUNC(UIPotentiometerTest)
gui::Label* _displayValueLabel;
};
#endif /* defined(__TestCpp__UIPotentiometerTest__) */

View File

@ -1,362 +0,0 @@
#include "UIProgressTimerTest.h"
// UIProgressTimerTest_Radial
bool UIProgressTimerTest_Radial::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer Radial");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* to1 = ProgressTo::create(2.0f, 100.0f);
ProgressTo* to2 = ProgressTo::create(2.0f, 100.0f);
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("cocosgui/potentiometerProgress.png");
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 0.75f, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::RADIAL);
left->getVirtualRenderer()->runAction(RepeatForever::create(to1));
_uiLayer->addChild(left);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("cocosgui/potentiometerProgress.png");
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 0.75f, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::RADIAL);
// Makes the ridial CCW
right->setReverseProgress(true);
right->getVirtualRenderer()->runAction(RepeatForever::create(to2));
_uiLayer->addChild(right);
return true;
}
return false;
}
// UIProgressTimerTest_Horizontal
bool UIProgressTimerTest_Horizontal::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer Horizontal");
alert->setFontName("Marker Felt");
alert->setFontSize(26);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.125f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* to1 = ProgressTo::create(2.0f, 100.0f);
ProgressTo* to2 = ProgressTo::create(2.0f, 100.0f);
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("cocosgui/potentiometerProgress.png");
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 0.75f, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the left since the midpoint is 0 for the x
left->setMidPoint(Point(0, 0));
// Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
left->setBarChangeRate(Point(1, 0));
left->getVirtualRenderer()->runAction(RepeatForever::create(to1));
_uiLayer->addChild(left);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("cocosgui/potentiometerProgress.png");
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 0.75f, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the left since the midpoint is 1 for the x
right->setMidPoint(Point(1, 0));
// Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change
right->setBarChangeRate(Point(1, 0));
right->getVirtualRenderer()->runAction(RepeatForever::create(to2));
_uiLayer->addChild(right);
return true;
}
return false;
}
// UIProgressTimerTest_Vertical
bool UIProgressTimerTest_Vertical::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer Vertical");
alert->setFontName("Marker Felt");
alert->setFontSize(26);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.125f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* to1 = ProgressTo::create(2.0f, 100.0f);
ProgressTo* to2 = ProgressTo::create(2.0f, 100.0f);
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("cocosgui/potentiometerProgress.png");
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 0.75f, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
left->setMidPoint(Point(0, 0));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
left->setBarChangeRate(Point(0, 1));
left->getVirtualRenderer()->runAction(RepeatForever::create(to1));
_uiLayer->addChild(left);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("cocosgui/potentiometerProgress.png");
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 0.75f, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
right->setMidPoint(Point(0, 1));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
right->setBarChangeRate(Point(0, 1));
right->getVirtualRenderer()->runAction(RepeatForever::create(to2));
_uiLayer->addChild(right);
return true;
}
return false;
}
// UIProgressTimerTest_RadialMidpointChanged
bool UIProgressTimerTest_RadialMidpointChanged::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer Radial Midpoint Changed");
alert->setFontName("Marker Felt");
alert->setFontSize(17);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.325f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* action = ProgressTo::create(2.0f, 100.0f);
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("cocosgui/potentiometerProgress.png");
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 0.75f, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::RADIAL);
left->setMidPoint(Point(0.25f, 0.75f));
left->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)action->clone()));
_uiLayer->addChild(left);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("cocosgui/potentiometerProgress.png");
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 0.75f, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::RADIAL);
right->setMidPoint(Point(0.75f, 0.25f));
right->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)action->clone()));
_uiLayer->addChild(right);
return true;
}
return false;
}
// UIProgressTimerTest_BarVarious
bool UIProgressTimerTest_BarVarious::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer Bar Various");
alert->setFontName("Marker Felt");
alert->setFontSize(26);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.125f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* to = ProgressTo::create(2.0f, 100.0f);
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("cocosgui/potentiometerProgress.png");
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 1.1, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
left->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
left->setBarChangeRate(Point(1, 0));
left->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
_uiLayer->addChild(left);
gui::ProgressTimer* middle = gui::ProgressTimer::create();
middle->loadTexture("cocosgui/potentiometerProgress.png");
middle->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + middle->getSize().height / 6.0f));
middle->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
middle->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
middle->setBarChangeRate(Point(1, 1));
middle->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
_uiLayer->addChild(middle);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("cocosgui/potentiometerProgress.png");
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 1.1, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
right->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
right->setBarChangeRate(Point(0, 1));
right->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
_uiLayer->addChild(right);
return true;
}
return false;
}
// UIProgressTimerTest_BarTintAndFade
bool UIProgressTimerTest_BarTintAndFade::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer Bar Tint and Fade");
alert->setFontName("Marker Felt");
alert->setFontSize(20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.725f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* to = ProgressTo::create(6, 100.0f);
Action* tint = Sequence::create(TintTo::create(1, 255, 0, 0),
TintTo::create(1, 0, 255, 0),
TintTo::create(1, 0, 0, 255),
NULL);
Action* fade = Sequence::create(FadeTo::create(1.0f, 0),
FadeTo::create(1.0f, 255),
NULL);
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("cocosgui/potentiometerProgress.png");
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 1.1, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
left->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
left->setBarChangeRate(Point(1, 0));
left->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
left->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)tint->clone()));
_uiLayer->addChild(left);
gui::ProgressTimer* middle = gui::ProgressTimer::create();
middle->loadTexture("cocosgui/potentiometerProgress.png");
middle->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + middle->getSize().height / 6.0f));
middle->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
middle->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
middle->setBarChangeRate(Point(1, 1));
middle->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
middle->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)fade->clone()));
_uiLayer->addChild(middle);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("cocosgui/potentiometerProgress.png");
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 1.1, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
right->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
right->setBarChangeRate(Point(0, 1));
right->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
right->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)tint->clone()));
right->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)fade->clone()));
_uiLayer->addChild(right);
return true;
}
return false;
}
// UIProgressTimerTest_WithSpriteFrame
bool UIProgressTimerTest_WithSpriteFrame::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Progress Timer with SpriteFrame");
alert->setFontName("Marker Felt");
alert->setFontSize(20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.725f));
_uiLayer->addChild(alert);
// Create the progress timer
ProgressTo* to = ProgressTo::create(6, 100.0f);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("zwoptex/grossini.plist");
gui::ProgressTimer* left = gui::ProgressTimer::create();
left->loadTexture("grossini_dance_01.png", UI_TEX_TYPE_PLIST);
left->setPosition(Point(widgetSize.width / 2.0f - left->getSize().width * 2.0f, widgetSize.height / 2.0f + left->getSize().height / 6.0f));
left->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
left->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
left->setBarChangeRate(Point(1, 0));
left->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
_uiLayer->addChild(left);
gui::ProgressTimer* middle = gui::ProgressTimer::create();
middle->loadTexture("grossini_dance_04.png", UI_TEX_TYPE_PLIST);
middle->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + middle->getSize().height / 6.0f));
middle->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
middle->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
middle->setBarChangeRate(Point(1, 1));
middle->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
_uiLayer->addChild(middle);
gui::ProgressTimer* right = gui::ProgressTimer::create();
right->loadTexture("grossini_dance_03.png", UI_TEX_TYPE_PLIST);
right->setPosition(Point(widgetSize.width / 2.0f + right->getSize().width * 2.0f, widgetSize.height / 2.0f + right->getSize().height / 6.0f));
right->setType(cocos2d::ProgressTimer::Type::BAR);
// Setup for a bar starting from the bottom since the midpoint is 0 for the y
right->setMidPoint(Point(0.5f, 0.5f));
// Setup for a vertical bar since the bar change rate is 0 for x meaning no horizontal change
right->setBarChangeRate(Point(0, 1));
right->getVirtualRenderer()->runAction(RepeatForever::create((ActionInterval *)to->clone()));
_uiLayer->addChild(right);
return true;
}
return false;
}

View File

@ -1,93 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __TestCpp__UIProgressTimerTest__
#define __TestCpp__UIProgressTimerTest__
#include "../UIScene.h"
class UIProgressTimerTest_Radial : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_Radial)
};
class UIProgressTimerTest_Horizontal : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_Horizontal)
};
class UIProgressTimerTest_Vertical : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_Vertical)
};
class UIProgressTimerTest_RadialMidpointChanged : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_RadialMidpointChanged)
};
class UIProgressTimerTest_BarVarious : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_BarVarious)
};
class UIProgressTimerTest_BarTintAndFade : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_BarTintAndFade)
};
class UIProgressTimerTest_WithSpriteFrame : public UIScene
{
public:
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIProgressTimerTest_WithSpriteFrame)
};
#endif /* defined(__TestCpp__UIProgressTimerTest__) */

View File

@ -1,254 +0,0 @@
#include "UISwitchTest.h"
// UISwitchTest_Horizontal
UISwitchTest_Horizontal::UISwitchTest_Horizontal()
{
}
UISwitchTest_Horizontal::~UISwitchTest_Horizontal()
{
}
bool UISwitchTest_Horizontal::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the switch events will be displayed
_displayValueLabel = gui::Label::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Switch Horizontal");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the switch
Switch* pSwitch = Switch::create();
pSwitch->setTouchEnabled(true);
pSwitch->loadTextures("cocosgui/switch-mask.png", "cocosgui/switch-on.png", "cocosgui/switch-off.png", "cocosgui/switch-thumb.png");
pSwitch->setOnTitleText("On");
pSwitch->setOffTitleText("Off");
pSwitch->setOnTitleFontName("Arial-BoldMT");
pSwitch->setOnTitleFontSize(16);
pSwitch->setOffTitleFontName("Arial-BoldMT");
pSwitch->setOffTitleFontSize(16);
Size switchSize = pSwitch->getSize();
pSwitch->setPosition(Point((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
_uiLayer->addChild(pSwitch);
return true;
}
return false;
}
void UISwitchTest_Horizontal::switchEvent(Object *pSender, SwitchEventType type)
{
Switch* pSwitch = static_cast<Switch*>(pSender);
if (pSwitch->isOn())
{
_displayValueLabel->setText("On");
}
else
{
_displayValueLabel->setText("Off");
}
switch (type)
{
case SWITCH_EVENT_ON:
break;
case SWITCH_EVENT_OFF:
break;
default:
break;
}
}
// UISwitchTest_Vertical
UISwitchTest_Vertical::UISwitchTest_Vertical()
{
}
UISwitchTest_Vertical::~UISwitchTest_Vertical()
{
}
bool UISwitchTest_Vertical::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the switch events will be displayed
_displayValueLabel = gui::Label::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Switch Vertical");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the switch
Switch* pSwitch = Switch::create();
pSwitch->setTouchEnabled(true);
pSwitch->loadTextures("cocosgui/switch-mask_v.png", "cocosgui/switch-on_v.png", "cocosgui/switch-off_v.png", "cocosgui/switch-thumb_v.png");
pSwitch->setOnTitleText("On");
pSwitch->setOffTitleText("Off");
pSwitch->setOnTitleFontName("Arial-BoldMT");
pSwitch->setOnTitleFontSize(16);
pSwitch->setOffTitleFontName("Arial-BoldMT");
pSwitch->setOffTitleFontSize(16);
Size switchSize = pSwitch->getSize();
pSwitch->setPosition(Point((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
_uiLayer->addChild(pSwitch);
pSwitch->setDirection(SWITCH_DIRECTION_VERTICAL);
return true;
}
return false;
}
void UISwitchTest_Vertical::switchEvent(Object *pSender, SwitchEventType type)
{
Switch *pSwitch = static_cast<Switch*>(pSender);
if (pSwitch->isOn())
{
_displayValueLabel->setText("On");
}
else
{
_displayValueLabel->setText("Off");
}
switch (type)
{
case SWITCH_EVENT_ON:
break;
case SWITCH_EVENT_OFF:
break;
default:
break;
}
}
// UISwitchTest_VerticalAndTitleVertical
UISwitchTest_VerticalAndTitleVertical::UISwitchTest_VerticalAndTitleVertical()
{
}
UISwitchTest_VerticalAndTitleVertical::~UISwitchTest_VerticalAndTitleVertical()
{
}
bool UISwitchTest_VerticalAndTitleVertical::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the switch events will be displayed
_displayValueLabel = gui::Label::create();
_displayValueLabel->setText("No Event");
_displayValueLabel->setFontName("Marker Felt");
_displayValueLabel->setFontSize(32);
_displayValueLabel->setAnchorPoint(Point(0.5f, -1.0f));
_displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
gui::Label* alert = gui::Label::create();
alert->setText("Switch Vertical and Title Vertical");
alert->setFontName("Marker Felt");
alert->setFontSize(20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7));
_uiLayer->addChild(alert);
// Create the switch
Switch* pSwitch = Switch::create();
pSwitch->setTouchEnabled(true);
pSwitch->loadTextures("cocosgui/switch-mask_v.png", "cocosgui/switch-on_v.png", "cocosgui/switch-off_v.png", "cocosgui/switch-thumb_v.png");
pSwitch->setOnTitleText("On");
pSwitch->setOffTitleText("Off");
pSwitch->setOnTitleFontName("Arial-BoldMT");
pSwitch->setOnTitleFontSize(16);
pSwitch->setOffTitleFontName("Arial-BoldMT");
pSwitch->setOffTitleFontSize(16);
Size switchSize = pSwitch->getSize();
pSwitch->setPosition(Point((widgetSize.width - switchSize.width) / 2.0f, (widgetSize.height - switchSize.height) / 2.0f));
pSwitch->addEventListenerSwitch(this, switchselector(UISwitchTest_Horizontal::switchEvent));
_uiLayer->addChild(pSwitch);
pSwitch->setDirection(SWITCH_DIRECTION_VERTICAL);
// set unicode text with title vertical direction
pSwitch->setTitleDirection(SWITCH_TITLE_DIRECTION_VERTICAL);
return true;
}
return false;
}
void UISwitchTest_VerticalAndTitleVertical::switchEvent(Object *pSender, SwitchEventType type)
{
Switch* pSwitch = static_cast<Switch*>(pSender);
if (pSwitch->isOn())
{
_displayValueLabel->setText("On");
}
else
{
_displayValueLabel->setText("Off");
}
switch (type)
{
case SWITCH_EVENT_ON:
break;
case SWITCH_EVENT_OFF:
break;
default:
break;
}
}

View File

@ -1,69 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __TestCpp__UISwitchTest__
#define __TestCpp__UISwitchTest__
#include "../UIScene.h"
class UISwitchTest_Horizontal : public UIScene
{
public:
UISwitchTest_Horizontal();
~UISwitchTest_Horizontal();
bool init();
void switchEvent(Object* pSender, SwitchEventType type);
protected:
UI_SCENE_CREATE_FUNC(UISwitchTest_Horizontal)
gui::Label* _displayValueLabel;
};
class UISwitchTest_Vertical : public UIScene
{
public:
UISwitchTest_Vertical();
~UISwitchTest_Vertical();
bool init();
void switchEvent(Object* pSender, SwitchEventType type);
protected:
UI_SCENE_CREATE_FUNC(UISwitchTest_Vertical)
gui::Label* _displayValueLabel;
};
class UISwitchTest_VerticalAndTitleVertical : public UIScene
{
public:
UISwitchTest_VerticalAndTitleVertical();
~UISwitchTest_VerticalAndTitleVertical();
bool init();
void switchEvent(Object* pSender, SwitchEventType type);
protected:
UI_SCENE_CREATE_FUNC(UISwitchTest_VerticalAndTitleVertical)
gui::Label* _displayValueLabel;
};
#endif /* defined(__TestCpp__UISwitchTest__) */