axmol/cocos/ui/UISlider.cpp

640 lines
18 KiB
C++
Raw Normal View History

2014-03-11 17:13:54 +08:00
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
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.
****************************************************************************/
#include "ui/UISlider.h"
#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h"
2014-06-04 14:26:21 +08:00
#include "2d/CCSprite.h"
2014-03-11 17:13:54 +08:00
NS_CC_BEGIN
namespace ui {
static const int BASEBAR_RENDERER_Z = (-2);
static const int PROGRESSBAR_RENDERER_Z = (-2);
static const int SLIDBALL_RENDERER_Z = (-1);
IMPLEMENT_CLASS_GUI_INFO(Slider)
Slider::Slider():
_barRenderer(nullptr),
_progressBarRenderer(nullptr),
_progressBarTextureSize(Size::ZERO),
_slidBallNormalRenderer(nullptr),
_slidBallPressedRenderer(nullptr),
_slidBallDisabledRenderer(nullptr),
_slidBallRenderer(nullptr),
_barLength(0.0),
_percent(0),
_scale9Enabled(false),
_prevIgnoreSize(true),
_textureFile(""),
_progressBarTextureFile(""),
_slidBallNormalTextureFile(""),
_slidBallPressedTextureFile(""),
_slidBallDisabledTextureFile(""),
_capInsetsBarRenderer(Rect::ZERO),
_capInsetsProgressBarRenderer(Rect::ZERO),
_sliderEventListener(nullptr),
_sliderEventSelector(nullptr),
_barTexType(TextureResType::LOCAL),
_progressBarTexType(TextureResType::LOCAL),
_ballNTexType(TextureResType::LOCAL),
_ballPTexType(TextureResType::LOCAL),
_ballDTexType(TextureResType::LOCAL),
2014-04-17 14:08:25 +08:00
_barRendererAdaptDirty(true),
2014-05-12 11:17:06 +08:00
_progressBarRendererDirty(true),
_eventCallback(nullptr)
2014-03-11 17:13:54 +08:00
{
}
Slider::~Slider()
{
_sliderEventListener = nullptr;
_sliderEventSelector = nullptr;
}
Slider* Slider::create()
{
Slider* widget = new Slider();
if (widget && widget->init())
{
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
bool Slider::init()
{
if (Widget::init())
{
return true;
}
return false;
}
void Slider::initRenderer()
{
_barRenderer = Sprite::create();
_progressBarRenderer = Sprite::create();
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
_progressBarRenderer->setAnchorPoint(Vec2(0.0f, 0.5f));
2014-03-24 15:25:44 +08:00
addProtectedChild(_barRenderer, BASEBAR_RENDERER_Z, -1);
addProtectedChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1);
2014-03-11 17:13:54 +08:00
_slidBallNormalRenderer = Sprite::create();
_slidBallPressedRenderer = Sprite::create();
_slidBallPressedRenderer->setVisible(false);
_slidBallDisabledRenderer = Sprite::create();
_slidBallDisabledRenderer->setVisible(false);
_slidBallRenderer = Node::create();
_slidBallRenderer->addChild(_slidBallNormalRenderer);
_slidBallRenderer->addChild(_slidBallPressedRenderer);
_slidBallRenderer->addChild(_slidBallDisabledRenderer);
2014-03-24 15:25:44 +08:00
addProtectedChild(_slidBallRenderer, SLIDBALL_RENDERER_Z, -1);
2014-03-11 17:13:54 +08:00
}
2014-04-03 15:33:57 +08:00
void Slider::loadBarTexture(const std::string& fileName, TextureResType texType)
2014-03-11 17:13:54 +08:00
{
2014-04-03 15:33:57 +08:00
if (fileName.empty())
2014-03-11 17:13:54 +08:00
{
return;
}
_textureFile = fileName;
_barTexType = texType;
switch (_barTexType)
{
case TextureResType::LOCAL:
2014-03-11 17:13:54 +08:00
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_barRenderer)->initWithFile(fileName);
}
else
{
static_cast<Sprite*>(_barRenderer)->setTexture(fileName);
}
break;
case TextureResType::PLIST:
2014-03-11 17:13:54 +08:00
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
}
else
{
static_cast<Sprite*>(_barRenderer)->setSpriteFrame(fileName);
}
break;
default:
break;
}
updateRGBAToRenderer(_barRenderer);
2014-04-17 14:08:25 +08:00
_barRendererAdaptDirty = true;
_progressBarRendererDirty = true;
updateContentSizeWithTextureSize(_barRenderer->getContentSize());
2014-03-11 17:13:54 +08:00
}
2014-04-03 15:33:57 +08:00
void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType)
2014-03-11 17:13:54 +08:00
{
2014-04-03 15:33:57 +08:00
if (fileName.empty())
2014-03-11 17:13:54 +08:00
{
return;
}
_progressBarTextureFile = fileName;
_progressBarTexType = texType;
switch (_progressBarTexType)
{
case TextureResType::LOCAL:
2014-03-11 17:13:54 +08:00
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->initWithFile(fileName);
}
else
{
static_cast<Sprite*>(_progressBarRenderer)->setTexture(fileName);
}
break;
case TextureResType::PLIST:
2014-03-11 17:13:54 +08:00
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->initWithSpriteFrameName(fileName);
}
else
{
static_cast<Sprite*>(_progressBarRenderer)->setSpriteFrame(fileName);
}
break;
default:
break;
}
updateRGBAToRenderer(_progressBarRenderer);
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
_progressBarRenderer->setAnchorPoint(Vec2(0.0f, 0.5f));
2014-03-11 17:13:54 +08:00
_progressBarTextureSize = _progressBarRenderer->getContentSize();
2014-04-17 14:08:25 +08:00
_progressBarRendererDirty = true;
2014-03-11 17:13:54 +08:00
}
void Slider::setScale9Enabled(bool able)
{
if (_scale9Enabled == able)
{
return;
}
_scale9Enabled = able;
2014-03-24 15:25:44 +08:00
removeProtectedChild(_barRenderer);
removeProtectedChild(_progressBarRenderer);
2014-03-11 17:13:54 +08:00
_barRenderer = nullptr;
_progressBarRenderer = nullptr;
if (_scale9Enabled)
{
_barRenderer = extension::Scale9Sprite::create();
_progressBarRenderer = extension::Scale9Sprite::create();
}
else
{
_barRenderer = Sprite::create();
_progressBarRenderer = Sprite::create();
}
2014-04-03 15:33:57 +08:00
loadBarTexture(_textureFile, _barTexType);
loadProgressBarTexture(_progressBarTextureFile, _progressBarTexType);
2014-03-24 15:25:44 +08:00
addProtectedChild(_barRenderer, BASEBAR_RENDERER_Z, -1);
addProtectedChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1);
2014-03-11 17:13:54 +08:00
if (_scale9Enabled)
{
bool ignoreBefore = _ignoreSize;
ignoreContentAdaptWithSize(false);
_prevIgnoreSize = ignoreBefore;
}
else
{
ignoreContentAdaptWithSize(_prevIgnoreSize);
}
setCapInsetsBarRenderer(_capInsetsBarRenderer);
setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer);
}
2014-05-27 10:52:30 +08:00
bool Slider::isScale9Enabled()const
2014-03-11 17:13:54 +08:00
{
return _scale9Enabled;
}
void Slider::ignoreContentAdaptWithSize(bool ignore)
{
if (!_scale9Enabled || (_scale9Enabled && !ignore))
{
Widget::ignoreContentAdaptWithSize(ignore);
_prevIgnoreSize = ignore;
}
}
void Slider::setCapInsets(const Rect &capInsets)
{
setCapInsetsBarRenderer(capInsets);
setCapInsetProgressBarRebderer(capInsets);
}
void Slider::setCapInsetsBarRenderer(const Rect &capInsets)
{
_capInsetsBarRenderer = capInsets;
if (!_scale9Enabled)
{
return;
}
static_cast<extension::Scale9Sprite*>(_barRenderer)->setCapInsets(capInsets);
}
2014-05-27 10:52:30 +08:00
const Rect& Slider::getCapInsetsBarRenderer()const
2014-03-11 17:13:54 +08:00
{
return _capInsetsBarRenderer;
}
void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets)
{
_capInsetsProgressBarRenderer = capInsets;
if (!_scale9Enabled)
{
return;
}
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setCapInsets(capInsets);
}
2014-05-27 10:52:30 +08:00
const Rect& Slider::getCapInsetsProgressBarRebderer()const
2014-03-11 17:13:54 +08:00
{
return _capInsetsProgressBarRenderer;
}
2014-04-03 15:33:57 +08:00
void Slider::loadSlidBallTextures(const std::string& normal,const std::string& pressed,const std::string& disabled,TextureResType texType)
2014-03-11 17:13:54 +08:00
{
loadSlidBallTextureNormal(normal, texType);
loadSlidBallTexturePressed(pressed,texType);
loadSlidBallTextureDisabled(disabled,texType);
}
2014-04-03 15:33:57 +08:00
void Slider::loadSlidBallTextureNormal(const std::string& normal,TextureResType texType)
2014-03-11 17:13:54 +08:00
{
2014-04-03 15:33:57 +08:00
if (normal.empty())
2014-03-11 17:13:54 +08:00
{
return;
}
_slidBallNormalTextureFile = normal;
_ballNTexType = texType;
switch (_ballNTexType)
{
case TextureResType::LOCAL:
2014-03-11 17:13:54 +08:00
_slidBallNormalRenderer->setTexture(normal);
break;
case TextureResType::PLIST:
2014-03-11 17:13:54 +08:00
_slidBallNormalRenderer->setSpriteFrame(normal);
break;
default:
break;
}
updateRGBAToRenderer(_slidBallNormalRenderer);
}
2014-04-03 15:33:57 +08:00
void Slider::loadSlidBallTexturePressed(const std::string& pressed,TextureResType texType)
2014-03-11 17:13:54 +08:00
{
2014-04-03 15:33:57 +08:00
if (pressed.empty())
2014-03-11 17:13:54 +08:00
{
return;
}
_slidBallPressedTextureFile = pressed;
_ballPTexType = texType;
switch (_ballPTexType)
{
case TextureResType::LOCAL:
2014-03-11 17:13:54 +08:00
_slidBallPressedRenderer->setTexture(pressed);
break;
case TextureResType::PLIST:
2014-03-11 17:13:54 +08:00
_slidBallPressedRenderer->setSpriteFrame(pressed);
break;
default:
break;
}
updateRGBAToRenderer(_slidBallPressedRenderer);
}
2014-04-03 15:33:57 +08:00
void Slider::loadSlidBallTextureDisabled(const std::string& disabled,TextureResType texType)
2014-03-11 17:13:54 +08:00
{
2014-04-03 15:33:57 +08:00
if (disabled.empty())
2014-03-11 17:13:54 +08:00
{
return;
}
_slidBallDisabledTextureFile = disabled;
_ballDTexType = texType;
switch (_ballDTexType)
{
case TextureResType::LOCAL:
2014-03-11 17:13:54 +08:00
_slidBallDisabledRenderer->setTexture(disabled);
break;
case TextureResType::PLIST:
2014-03-11 17:13:54 +08:00
_slidBallDisabledRenderer->setSpriteFrame(disabled);
break;
default:
break;
}
updateRGBAToRenderer(_slidBallDisabledRenderer);
}
void Slider::setPercent(int percent)
{
if (percent > 100)
{
percent = 100;
}
if (percent < 0)
{
percent = 0;
}
_percent = percent;
float res = percent / 100.0f;
float dis = _barLength * res;
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
_slidBallRenderer->setPosition(Vec2(dis, _contentSize.height / 2.0f));
2014-03-11 17:13:54 +08:00
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height));
}
else
{
Sprite* spriteRenderer = static_cast<Sprite*>(_progressBarRenderer);
Rect rect = spriteRenderer->getTextureRect();
rect.size.width = _progressBarTextureSize.width * res;
spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.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
bool Slider::hitTest(const cocos2d::Vec2 &pt)
{
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
Vec2 nsp = this->_slidBallNormalRenderer->convertToNodeSpace(pt);
Size ballSize = this->_slidBallNormalRenderer->getContentSize();
Rect ballRect = Rect(0,0, ballSize.width, ballSize.height);
if (ballRect.containsPoint(nsp)) {
return true;
}
return false;
}
2014-03-11 17:13:54 +08:00
bool Slider::onTouchBegan(Touch *touch, Event *unusedEvent)
{
bool pass = Widget::onTouchBegan(touch, unusedEvent);
if (_hitted)
{
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
Vec2 nsp = convertToNodeSpace(_touchStartPos);
2014-03-11 17:13:54 +08:00
setPercent(getPercentWithBallPos(nsp.x));
percentChangedEvent();
}
return pass;
}
void Slider::onTouchMoved(Touch *touch, Event *unusedEvent)
{
_touchMovePos = touch->getLocation();
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
Vec2 nsp = convertToNodeSpace(_touchMovePos);
2014-03-11 17:13:54 +08:00
setPercent(getPercentWithBallPos(nsp.x));
percentChangedEvent();
}
void Slider::onTouchEnded(Touch *touch, Event *unusedEvent)
{
Widget::onTouchEnded(touch, unusedEvent);
}
void Slider::onTouchCancelled(Touch *touch, Event *unusedEvent)
{
Widget::onTouchCancelled(touch, unusedEvent);
}
2014-05-27 10:52:30 +08:00
float Slider::getPercentWithBallPos(float px)const
2014-03-11 17:13:54 +08:00
{
2014-04-17 14:08:25 +08:00
return ((px/_barLength)*100.0f);
2014-03-11 17:13:54 +08:00
}
void Slider::addEventListenerSlider(Ref *target, SEL_SlidPercentChangedEvent selector)
{
_sliderEventListener = target;
_sliderEventSelector = selector;
}
2014-05-12 11:17:06 +08:00
void Slider::addEventListener(const ccSliderCallback& callback)
2014-05-12 11:17:06 +08:00
{
_eventCallback = callback;
}
2014-03-11 17:13:54 +08:00
void Slider::percentChangedEvent()
{
if (_sliderEventListener && _sliderEventSelector)
{
(_sliderEventListener->*_sliderEventSelector)(this,SLIDER_PERCENTCHANGED);
}
2014-05-12 11:17:06 +08:00
if (_eventCallback) {
_eventCallback(this, EventType::ON_PERCENTAGE_CHANGED);
}
2014-03-11 17:13:54 +08:00
}
2014-05-27 10:52:30 +08:00
int Slider::getPercent()const
2014-03-11 17:13:54 +08:00
{
return _percent;
}
void Slider::onSizeChanged()
{
Widget::onSizeChanged();
2014-04-17 14:08:25 +08:00
_barRendererAdaptDirty = true;
_progressBarRendererDirty = true;
}
void Slider::adaptRenderers()
{
if (_barRendererAdaptDirty)
{
barRendererScaleChangedWithSize();
_barRendererAdaptDirty = false;
}
if (_progressBarRendererDirty)
{
progressBarRendererScaleChangedWithSize();
_progressBarRendererDirty = false;
}
2014-03-11 17:13:54 +08:00
}
2014-04-17 14:08:25 +08:00
const Size& Slider::getVirtualRendererSize() const
2014-03-11 17:13:54 +08:00
{
return _barRenderer->getContentSize();
}
Node* Slider::getVirtualRenderer()
{
return _barRenderer;
}
void Slider::barRendererScaleChangedWithSize()
{
if (_ignoreSize)
{
_barRenderer->setScale(1.0f);
_barLength = _size.width;
}
else
{
_barLength = _size.width;
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_barRenderer)->setPreferredSize(_size);
}
else
{
Size btextureSize = _barRenderer->getContentSize();
if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f)
{
_barRenderer->setScale(1.0f);
return;
}
float bscaleX = _size.width / btextureSize.width;
float bscaleY = _size.height / btextureSize.height;
_barRenderer->setScaleX(bscaleX);
_barRenderer->setScaleY(bscaleY);
}
}
2014-04-17 14:08:25 +08:00
_barRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
2014-03-11 17:13:54 +08:00
setPercent(_percent);
}
void Slider::progressBarRendererScaleChangedWithSize()
{
if (_ignoreSize)
{
if (!_scale9Enabled)
{
Size ptextureSize = _progressBarTextureSize;
float pscaleX = _size.width / ptextureSize.width;
float pscaleY = _size.height / ptextureSize.height;
_progressBarRenderer->setScaleX(pscaleX);
_progressBarRenderer->setScaleY(pscaleY);
}
}
else
{
if (_scale9Enabled)
{
static_cast<extension::Scale9Sprite*>(_progressBarRenderer)->setPreferredSize(_size);
_progressBarTextureSize = _progressBarRenderer->getContentSize();
}
else
{
Size ptextureSize = _progressBarTextureSize;
if (ptextureSize.width <= 0.0f || ptextureSize.height <= 0.0f)
{
_progressBarRenderer->setScale(1.0f);
return;
}
float pscaleX = _size.width / ptextureSize.width;
float pscaleY = _size.height / ptextureSize.height;
_progressBarRenderer->setScaleX(pscaleX);
_progressBarRenderer->setScaleY(pscaleY);
}
}
2014-04-17 14:08:25 +08:00
_progressBarRenderer->setPosition(0.0f, _contentSize.height / 2.0f);
2014-03-11 17:13:54 +08:00
setPercent(_percent);
}
void Slider::onPressStateChangedToNormal()
{
_slidBallNormalRenderer->setVisible(true);
_slidBallPressedRenderer->setVisible(false);
_slidBallDisabledRenderer->setVisible(false);
}
void Slider::onPressStateChangedToPressed()
{
_slidBallNormalRenderer->setVisible(false);
_slidBallPressedRenderer->setVisible(true);
_slidBallDisabledRenderer->setVisible(false);
}
void Slider::onPressStateChangedToDisabled()
{
_slidBallNormalRenderer->setVisible(false);
_slidBallPressedRenderer->setVisible(false);
_slidBallDisabledRenderer->setVisible(true);
}
std::string Slider::getDescription() const
{
return "Slider";
}
void Slider::updateTextureColor()
{
updateColorToRenderer(_barRenderer);
updateColorToRenderer(_progressBarRenderer);
updateColorToRenderer(_slidBallNormalRenderer);
updateColorToRenderer(_slidBallPressedRenderer);
updateColorToRenderer(_slidBallDisabledRenderer);
}
void Slider::updateTextureOpacity()
{
updateOpacityToRenderer(_barRenderer);
updateOpacityToRenderer(_progressBarRenderer);
updateOpacityToRenderer(_slidBallNormalRenderer);
updateOpacityToRenderer(_slidBallPressedRenderer);
updateOpacityToRenderer(_slidBallDisabledRenderer);
}
void Slider::updateTextureRGBA()
{
updateRGBAToRenderer(_barRenderer);
updateRGBAToRenderer(_progressBarRenderer);
updateRGBAToRenderer(_slidBallNormalRenderer);
updateRGBAToRenderer(_slidBallPressedRenderer);
updateRGBAToRenderer(_slidBallDisabledRenderer);
}
Widget* Slider::createCloneInstance()
{
return Slider::create();
}
void Slider::copySpecialProperties(Widget *widget)
{
Slider* slider = dynamic_cast<Slider*>(widget);
if (slider)
{
_prevIgnoreSize = slider->_prevIgnoreSize;
setScale9Enabled(slider->_scale9Enabled);
2014-04-03 15:33:57 +08:00
loadBarTexture(slider->_textureFile, slider->_barTexType);
loadProgressBarTexture(slider->_progressBarTextureFile, slider->_progressBarTexType);
loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile, slider->_ballNTexType);
loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile, slider->_ballPTexType);
loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile, slider->_ballDTexType);
2014-03-11 17:13:54 +08:00
setPercent(slider->getPercent());
2014-05-23 15:03:46 +08:00
_sliderEventListener = slider->_sliderEventListener;
_sliderEventSelector = slider->_sliderEventSelector;
_eventCallback = slider->_eventCallback;
2014-03-11 17:13:54 +08:00
}
}
}
NS_CC_END