axmol/tests/cpp-tests/Classes/CocosDenshionTest/CocosDenshionTest.cpp

427 lines
13 KiB
C++
Raw Normal View History

#include "CocosDenshionTest.h"
#include "cocos2d.h"
#include "extensions/GUI/CCControlExtension/CCControlSlider.h"
// android effect only support ogg
2014-01-09 09:50:02 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#define EFFECT_FILE "effect2.ogg"
2014-01-09 09:50:02 +08:00
#elif( CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
#define EFFECT_FILE "effect1.raw"
#else
#define EFFECT_FILE "effect1.wav"
#endif // CC_PLATFOR_ANDROID
2014-01-09 09:50:02 +08:00
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#define MUSIC_FILE "music.mid"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#define MUSIC_FILE "background.wav"
2014-01-09 09:50:02 +08:00
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX )
#define MUSIC_FILE "background.ogg"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#define MUSIC_FILE "background.caf"
#else
#define MUSIC_FILE "background.mp3"
#endif // CC_PLATFOR_WIN32
USING_NS_CC;
using namespace CocosDenshion;
#define LINE_SPACE 40
class Button : public Node//, public TargetedTouchDelegate
{
public:
static Button *createWithSprite(const char *filePath)
{
auto b = new Button();
if (b && !b->initSpriteButton(filePath)) {
delete b;
b = nullptr;
}
b->autorelease();
return b;
}
static Button *createWithText(const char *text)
{
auto b = new Button();
if (b && !b->initTextButton(text)) {
delete b;
b = nullptr;
}
b->autorelease();
return b;
}
~Button()
{
// Director::getInstance()->getTouchDispatcher()->removeDelegate(this);
}
void onTriggered(const std::function<void(void)> &onTriggered)
{
_onTriggered = onTriggered;
}
private:
Button()
: _child(nullptr)
{
// Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, 100, true);
// Register Touch Event
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(Button::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(Button::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(Button::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
bool initSpriteButton(const char *filePath)
{
_child = Sprite::create(filePath);
addChild(_child);
return true;
}
bool initTextButton(const char *text)
{
_child = Label::createWithTTF(text, "fonts/arial.ttf", 16);
addChild(_child);
return true;
}
bool touchHits(Touch *touch)
{
const Rect area(0, 0, _child->getContentSize().width, _child->getContentSize().height);
return area.containsPoint(_child->convertToNodeSpace(touch->getLocation()));
}
bool onTouchBegan(Touch *touch, Event *event)
{
CC_UNUSED_PARAM(event);
const bool hits = touchHits(touch);
if (hits)
scaleButtonTo(0.9f);
return hits;
}
void onTouchEnded(Touch *touch, Event *event)
{
CC_UNUSED_PARAM(event);
const bool hits = touchHits(touch);
if (hits && _onTriggered)
_onTriggered();
scaleButtonTo(1);
}
void onTouchCancelled(Touch *touch, Event *event)
{
CC_UNUSED_PARAM(event);
scaleButtonTo(1);
}
void scaleButtonTo(float scale)
{
auto action = ScaleTo::create(0.1f, scale);
action->setTag(900);
stopActionByTag(900);
runAction(action);
}
Node *_child;
std::function<void(void)> _onTriggered;
};
class AudioSlider : public Node
{
public:
enum Direction {
Vertical,
Horizontal
};
static AudioSlider *create(Direction direction)
{
auto ret = new AudioSlider(direction);
if (ret && !ret->init()) {
delete ret;
ret = nullptr;
}
ret->autorelease();
return ret;
}
float getValue() const
{
return _slider->getValue();
}
void setValue(float minValue, float maxValue, float value)
{
_slider->setMinimumValue(minValue);
_slider->setMaximumValue(maxValue);
_slider->setValue(value);
char buffer[32];
sprintf(buffer, "%.2f", minValue);
if (!_lblMinValue) {
_lblMinValue = Label::createWithTTF(buffer, "fonts/arial.ttf", 8);
addChild(_lblMinValue);
if (_direction == Vertical)
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
_lblMinValue->setPosition(Vec2(12.0, -50.0));
else
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
_lblMinValue->setPosition(Vec2(-50, 12.0));
} else {
_lblMinValue->setString(buffer);
}
sprintf(buffer, "%.2f", maxValue);
if (!_lblMaxValue) {
_lblMaxValue = Label::createWithTTF(buffer, "fonts/arial.ttf", 8);
addChild(_lblMaxValue);
if (_direction == Vertical)
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
_lblMaxValue->setPosition(Vec2(12.0, 50.0));
else
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
_lblMaxValue->setPosition(Vec2(50, 12.0));
} else {
_lblMaxValue->setString(buffer);
}
}
private:
AudioSlider(Direction direction)
: _direction(direction)
, _slider(nullptr)
, _lblMinValue(nullptr)
, _lblMaxValue(nullptr)
{
}
bool init()
{
_slider = extension::ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
_slider->setScale(0.5);
if (_direction == Vertical)
_slider->setRotation(-90.0);
addChild(_slider);
return true;
}
Direction _direction;
extension::ControlSlider *_slider;
Label *_lblMinValue;
Label *_lblMaxValue;
};
CocosDenshionTest::CocosDenshionTest()
: _soundId(0),
_musicVolume(1),
_effectsVolume(1),
_sliderPitch(nullptr),
_sliderPan(nullptr),
_sliderGain(nullptr),
_sliderEffectsVolume(nullptr),
_sliderMusicVolume(nullptr)
{
addButtons();
addSliders();
schedule(schedule_selector(CocosDenshionTest::updateVolumes));
// preload background music and effect
SimpleAudioEngine::getInstance()->preloadBackgroundMusic( MUSIC_FILE );
SimpleAudioEngine::getInstance()->preloadEffect( EFFECT_FILE );
// set default volume
SimpleAudioEngine::getInstance()->setEffectsVolume(0.5);
SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.5);
}
CocosDenshionTest::~CocosDenshionTest()
{
}
void CocosDenshionTest::onExit()
{
Layer::onExit();
SimpleAudioEngine::end();
}
void CocosDenshionTest::addButtons()
{
auto lblMusic = Label::createWithTTF("Control Music", "fonts/arial.ttf", 24);
addChildAt(lblMusic, 0.25f, 0.9f);
Button *btnPlay = Button::createWithText("play");
btnPlay->onTriggered([]() {
SimpleAudioEngine::getInstance()->playBackgroundMusic(MUSIC_FILE, true);
});
addChildAt(btnPlay, 0.1f, 0.75f);
Button *btnStop = Button::createWithText("stop");
btnStop->onTriggered([]() {
SimpleAudioEngine::getInstance()->stopBackgroundMusic();
});
addChildAt(btnStop, 0.25f, 0.75f);
Button *btnRewindMusic = Button::createWithText("rewind");
btnRewindMusic->onTriggered([]() {
SimpleAudioEngine::getInstance()->rewindBackgroundMusic();
});
addChildAt(btnRewindMusic, 0.4f, 0.75f);
Button *btnPause = Button::createWithText("pause");
btnPause->onTriggered([]() {
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
});
addChildAt(btnPause, 0.1f, 0.65f);
Button *btnResumeMusic = Button::createWithText("resume");
btnResumeMusic->onTriggered([]() {
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
});
addChildAt(btnResumeMusic, 0.25f, 0.65f);
Button *btnIsPlayingMusic = Button::createWithText("is playing");
btnIsPlayingMusic->onTriggered([]() {
if (SimpleAudioEngine::getInstance()->isBackgroundMusicPlaying())
CCLOG("background music is playing");
else
CCLOG("background music is not playing");
});
addChildAt(btnIsPlayingMusic, 0.4f, 0.65f);
auto lblSound = Label::createWithTTF("Control Effects", "fonts/arial.ttf", 24);
addChildAt(lblSound, 0.75f, 0.9f);
Button *btnPlayEffect = Button::createWithText("play");
btnPlayEffect->onTriggered([this]() {
const float pitch = _sliderPitch->getValue();
const float pan = _sliderPan->getValue();
const float gain = _sliderGain->getValue();
_soundId = SimpleAudioEngine::getInstance()->playEffect(EFFECT_FILE, false, pitch, pan, gain);
});
addChildAt(btnPlayEffect, 0.6f, 0.8f);
Button *btnPlayEffectInLoop = Button::createWithText("play in loop");
btnPlayEffectInLoop->onTriggered([this]() {
const float pitch = _sliderPitch->getValue();
const float pan = _sliderPan->getValue();
const float gain = _sliderGain->getValue();
_soundId = SimpleAudioEngine::getInstance()->playEffect(EFFECT_FILE, true, pitch, pan, gain);
});
addChildAt(btnPlayEffectInLoop, 0.75f, 0.8f);
Button *btnStopEffect = Button::createWithText("stop");
btnStopEffect->onTriggered([this]() {
SimpleAudioEngine::getInstance()->stopEffect(_soundId);
});
addChildAt(btnStopEffect, 0.9f, 0.8f);
Button *btnUnloadEffect = Button::createWithText("unload");
btnUnloadEffect->onTriggered([this]() {
SimpleAudioEngine::getInstance()->unloadEffect(EFFECT_FILE);
});
addChildAt(btnUnloadEffect, 0.6f, 0.7f);
Button *btnPauseEffect = Button::createWithText("pause");
btnPauseEffect->onTriggered([this]() {
SimpleAudioEngine::getInstance()->pauseEffect(_soundId);
});
addChildAt(btnPauseEffect, 0.75f, 0.7f);
Button *btnResumeEffect = Button::createWithText("resume");
btnResumeEffect->onTriggered([this]() {
SimpleAudioEngine::getInstance()->resumeEffect(_soundId);
});
addChildAt(btnResumeEffect, 0.9f, 0.7f);
Button *btnPauseAll = Button::createWithText("pause all");
btnPauseAll->onTriggered([this]() {
SimpleAudioEngine::getInstance()->pauseAllEffects();
});
addChildAt(btnPauseAll, 0.6f, 0.6f);
Button *btnResumeAll = Button::createWithText("resume all");
btnResumeAll->onTriggered([this]() {
SimpleAudioEngine::getInstance()->resumeAllEffects();
});
addChildAt(btnResumeAll, 0.75f, 0.6f);
Button *btnStopAll = Button::createWithText("stop all");
btnStopAll->onTriggered([this]() {
SimpleAudioEngine::getInstance()->stopAllEffects();
});
addChildAt(btnStopAll, 0.9f, 0.6f);
}
void CocosDenshionTest::addSliders()
{
auto lblPitch = Label::createWithTTF("Pitch", "fonts/arial.ttf", 14);
addChildAt(lblPitch, 0.67f, 0.4f);
_sliderPitch = AudioSlider::create(AudioSlider::Horizontal);
_sliderPitch->setValue(0.5, 2, 1);
addChildAt(_sliderPitch, 0.85f, 0.4f);
auto lblPan = Label::createWithTTF("Pan", "fonts/arial.ttf", 14);
addChildAt(lblPan, 0.67f, 0.3f);
_sliderPan = AudioSlider::create(AudioSlider::Horizontal);
_sliderPan->setValue(-1, 1, 0);
addChildAt(_sliderPan, 0.85f, 0.3f);
auto lblGain = Label::createWithTTF("Gain", "fonts/arial.ttf", 14);
addChildAt(lblGain, 0.67f, 0.2f);
_sliderGain = AudioSlider::create(AudioSlider::Horizontal);
_sliderGain->setValue(0, 1, 1);
addChildAt(_sliderGain, 0.85f, 0.2f);
auto lblEffectsVolume = Label::createWithTTF("Effects Volume", "fonts/arial.ttf", 14);
addChildAt(lblEffectsVolume, 0.62f, 0.5f);
_sliderEffectsVolume = AudioSlider::create(AudioSlider::Horizontal);
_sliderEffectsVolume->setValue(0, 1, 1);
addChildAt(_sliderEffectsVolume, 0.85f, 0.5f);
auto lblMusicVolume = Label::createWithTTF("Music Volume", "fonts/arial.ttf", 14);
addChildAt(lblMusicVolume, 0.12f, 0.5f);
_sliderMusicVolume = AudioSlider::create(AudioSlider::Horizontal);
_sliderMusicVolume->setValue(0, 1, 1);
addChildAt(_sliderMusicVolume, 0.35f, 0.5f);
}
void CocosDenshionTest::addChildAt(Node *node, float percentageX, float percentageY)
{
const Size size = VisibleRect::getVisibleRect().size;
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
node->setPosition(Vec2(percentageX * size.width, percentageY * size.height));
addChild(node);
}
void CocosDenshionTest::updateVolumes(float)
{
const float musicVolume = _sliderMusicVolume->getValue();
if (fabs(musicVolume - _musicVolume) > 0.001) {
_musicVolume = musicVolume;
SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(_musicVolume);
}
const float effectsVolume = _sliderEffectsVolume->getValue();
if (fabs(effectsVolume - _effectsVolume) > 0.001) {
_effectsVolume = effectsVolume;
SimpleAudioEngine::getInstance()->setEffectsVolume(_effectsVolume);
}
}
void CocosDenshionTestScene::runThisTest()
{
auto layer = new CocosDenshionTest();
addChild(layer);
layer->autorelease();
Director::getInstance()->replaceScene(this);
}