From d309286c8486c77b769c1b62c55556aad161288e Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 16:37:59 +0800 Subject: [PATCH 01/17] rename gui folder to ui --- cocos/gui/Android.mk | 48 - cocos/gui/CMakeLists.txt | 31 - cocos/gui/CocosGUI.cpp | 37 - cocos/gui/CocosGUI.h | 54 - cocos/gui/GUIDefine.h | 79 - cocos/gui/UIButton.cpp | 714 ------- cocos/gui/UIButton.h | 226 --- cocos/gui/UICheckBox.cpp | 540 ------ cocos/gui/UICheckBox.h | 211 -- cocos/gui/UIHelper.cpp | 123 -- cocos/gui/UIHelper.h | 81 - cocos/gui/UIImageView.cpp | 316 --- cocos/gui/UIImageView.h | 130 -- cocos/gui/UILayout.cpp | 1404 -------------- cocos/gui/UILayout.h | 358 ---- cocos/gui/UILayoutDefine.cpp | 64 - cocos/gui/UILayoutDefine.h | 96 - cocos/gui/UILayoutParameter.cpp | 175 -- cocos/gui/UILayoutParameter.h | 226 --- cocos/gui/UIListView.cpp | 480 ----- cocos/gui/UIListView.h | 213 -- cocos/gui/UILoadingBar.cpp | 370 ---- cocos/gui/UILoadingBar.h | 161 -- cocos/gui/UIPageView.cpp | 631 ------ cocos/gui/UIPageView.h | 222 --- cocos/gui/UIRichText.cpp | 442 ----- cocos/gui/UIRichText.h | 133 -- cocos/gui/UIScrollInterface.h | 49 - cocos/gui/UIScrollView.cpp | 1719 ----------------- cocos/gui/UIScrollView.h | 430 ----- cocos/gui/UISlider.cpp | 600 ------ cocos/gui/UISlider.h | 249 --- cocos/gui/UIText.cpp | 287 --- cocos/gui/UIText.h | 167 -- cocos/gui/UITextAtlas.cpp | 171 -- cocos/gui/UITextAtlas.h | 103 - cocos/gui/UITextBMFont.cpp | 181 -- cocos/gui/UITextBMFont.h | 93 - cocos/gui/UITextField.cpp | 772 -------- cocos/gui/UITextField.h | 192 -- cocos/gui/UIWidget.cpp | 1139 ----------- cocos/gui/UIWidget.h | 723 ------- .../ButtonReader/ButtonReader.cpp | 158 -- .../WidgetReader/ButtonReader/ButtonReader.h | 47 - .../CheckBoxReader/CheckBoxReader.cpp | 153 -- .../CheckBoxReader/CheckBoxReader.h | 47 - .../ImageViewReader/ImageViewReader.cpp | 98 - .../ImageViewReader/ImageViewReader.h | 47 - .../LayoutReader/LayoutReader.cpp | 119 -- .../WidgetReader/LayoutReader/LayoutReader.h | 47 - .../ListViewReader/ListViewReader.cpp | 48 - .../ListViewReader/ListViewReader.h | 47 - .../LoadingBarReader/LoadingBarReader.cpp | 91 - .../LoadingBarReader/LoadingBarReader.h | 47 - .../PageViewReader/PageViewReader.cpp | 35 - .../PageViewReader/PageViewReader.h | 47 - .../ScrollViewReader/ScrollViewReader.cpp | 47 - .../ScrollViewReader/ScrollViewReader.h | 47 - .../SliderReader/SliderReader.cpp | 192 -- .../WidgetReader/SliderReader/SliderReader.h | 47 - .../TextAtlasReader/TextAtlasReader.cpp | 69 - .../TextAtlasReader/TextAtlasReader.h | 46 - .../TextBMFontReader/TextBMFontReader.cpp | 65 - .../TextBMFontReader/TextBMFontReader.h | 47 - .../TextFieldReader/TextFieldReader.cpp | 84 - .../TextFieldReader/TextFieldReader.h | 47 - .../WidgetReader/TextReader/TextReader.cpp | 74 - .../gui/WidgetReader/TextReader/TextReader.h | 47 - cocos/gui/WidgetReader/WidgetReader.cpp | 172 -- cocos/gui/WidgetReader/WidgetReader.h | 51 - cocos/gui/WidgetReader/WidgetReaderProtocol.h | 53 - cocos/gui/proj.win32/libGUI.vcxproj | 135 -- cocos/gui/proj.win32/libGUI.vcxproj.filters | 141 -- cocos/gui/proj.win32/libGUI.vcxproj.user | 4 - 74 files changed, 16839 deletions(-) delete mode 100644 cocos/gui/Android.mk delete mode 100644 cocos/gui/CMakeLists.txt delete mode 100644 cocos/gui/CocosGUI.cpp delete mode 100644 cocos/gui/CocosGUI.h delete mode 100644 cocos/gui/GUIDefine.h delete mode 100644 cocos/gui/UIButton.cpp delete mode 100644 cocos/gui/UIButton.h delete mode 100644 cocos/gui/UICheckBox.cpp delete mode 100644 cocos/gui/UICheckBox.h delete mode 100644 cocos/gui/UIHelper.cpp delete mode 100644 cocos/gui/UIHelper.h delete mode 100644 cocos/gui/UIImageView.cpp delete mode 100644 cocos/gui/UIImageView.h delete mode 100644 cocos/gui/UILayout.cpp delete mode 100644 cocos/gui/UILayout.h delete mode 100644 cocos/gui/UILayoutDefine.cpp delete mode 100644 cocos/gui/UILayoutDefine.h delete mode 100644 cocos/gui/UILayoutParameter.cpp delete mode 100644 cocos/gui/UILayoutParameter.h delete mode 100644 cocos/gui/UIListView.cpp delete mode 100644 cocos/gui/UIListView.h delete mode 100644 cocos/gui/UILoadingBar.cpp delete mode 100644 cocos/gui/UILoadingBar.h delete mode 100644 cocos/gui/UIPageView.cpp delete mode 100644 cocos/gui/UIPageView.h delete mode 100644 cocos/gui/UIRichText.cpp delete mode 100644 cocos/gui/UIRichText.h delete mode 100644 cocos/gui/UIScrollInterface.h delete mode 100644 cocos/gui/UIScrollView.cpp delete mode 100644 cocos/gui/UIScrollView.h delete mode 100644 cocos/gui/UISlider.cpp delete mode 100644 cocos/gui/UISlider.h delete mode 100644 cocos/gui/UIText.cpp delete mode 100644 cocos/gui/UIText.h delete mode 100644 cocos/gui/UITextAtlas.cpp delete mode 100644 cocos/gui/UITextAtlas.h delete mode 100644 cocos/gui/UITextBMFont.cpp delete mode 100644 cocos/gui/UITextBMFont.h delete mode 100644 cocos/gui/UITextField.cpp delete mode 100644 cocos/gui/UITextField.h delete mode 100644 cocos/gui/UIWidget.cpp delete mode 100644 cocos/gui/UIWidget.h delete mode 100644 cocos/gui/WidgetReader/ButtonReader/ButtonReader.cpp delete mode 100644 cocos/gui/WidgetReader/ButtonReader/ButtonReader.h delete mode 100644 cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp delete mode 100644 cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.h delete mode 100644 cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.cpp delete mode 100644 cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.h delete mode 100644 cocos/gui/WidgetReader/LayoutReader/LayoutReader.cpp delete mode 100644 cocos/gui/WidgetReader/LayoutReader/LayoutReader.h delete mode 100644 cocos/gui/WidgetReader/ListViewReader/ListViewReader.cpp delete mode 100644 cocos/gui/WidgetReader/ListViewReader/ListViewReader.h delete mode 100644 cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp delete mode 100644 cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.h delete mode 100644 cocos/gui/WidgetReader/PageViewReader/PageViewReader.cpp delete mode 100644 cocos/gui/WidgetReader/PageViewReader/PageViewReader.h delete mode 100644 cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp delete mode 100644 cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.h delete mode 100644 cocos/gui/WidgetReader/SliderReader/SliderReader.cpp delete mode 100644 cocos/gui/WidgetReader/SliderReader/SliderReader.h delete mode 100644 cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp delete mode 100644 cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.h delete mode 100644 cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp delete mode 100644 cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.h delete mode 100644 cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.cpp delete mode 100644 cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.h delete mode 100644 cocos/gui/WidgetReader/TextReader/TextReader.cpp delete mode 100644 cocos/gui/WidgetReader/TextReader/TextReader.h delete mode 100644 cocos/gui/WidgetReader/WidgetReader.cpp delete mode 100644 cocos/gui/WidgetReader/WidgetReader.h delete mode 100644 cocos/gui/WidgetReader/WidgetReaderProtocol.h delete mode 100644 cocos/gui/proj.win32/libGUI.vcxproj delete mode 100644 cocos/gui/proj.win32/libGUI.vcxproj.filters delete mode 100644 cocos/gui/proj.win32/libGUI.vcxproj.user diff --git a/cocos/gui/Android.mk b/cocos/gui/Android.mk deleted file mode 100644 index ba8a3dcf17..0000000000 --- a/cocos/gui/Android.mk +++ /dev/null @@ -1,48 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := cocos_gui_static - -LOCAL_MODULE_FILENAME := libgui - -LOCAL_SRC_FILES := \ -UIWidget.cpp \ -UILayout.cpp \ -UILayoutParameter.cpp \ -UILayoutDefine.cpp \ -CocosGUI.cpp \ -UIHelper.cpp \ -UIListView.cpp \ -UIPageView.cpp \ -UIScrollView.cpp \ -UIButton.cpp \ -UICheckBox.cpp \ -UIImageView.cpp \ -UIText.cpp \ -UITextAtlas.cpp \ -UITextBMFont.cpp \ -UILoadingBar.cpp \ -UISlider.cpp \ -UITextField.cpp \ -UIRichText.cpp - - -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \ -$(LOCAL_PATH)/../editor-support - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../2d \ -$(LOCAL_PATH)/../../external \ -$(LOCAL_PATH)/.. \ -$(LOCAL_PATH)/../.. \ -$(LOCAL_PATH)/../editor-support - -LOCAL_CFLAGS += -Wno-psabi -LOCAL_EXPORT_CFLAGS += -Wno-psabi - -LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static -LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static - -include $(BUILD_STATIC_LIBRARY) - -$(call import-module,extensions) -$(call import-module,2d) diff --git a/cocos/gui/CMakeLists.txt b/cocos/gui/CMakeLists.txt deleted file mode 100644 index 4b78830596..0000000000 --- a/cocos/gui/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -set(GUI_SRC - UIWidget.cpp - UILayout.cpp - UILayoutParameter.cpp - UILayoutDefine.cpp - CocosGUI.cpp - UIHelper.cpp - UIListView.cpp - UIPageView.cpp - UIScrollView.cpp - UIButton.cpp - UICheckBox.cpp - UIImageView.cpp - UIText.cpp - UITextAtlas.cpp - UITextBMFont.cpp - UILoadingBar.cpp - UISlider.cpp - UITextField.cpp - UIRichText.cpp -) - -add_library(gui STATIC - ${GUI_SRC} -) - -set_target_properties(gui - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" -) diff --git a/cocos/gui/CocosGUI.cpp b/cocos/gui/CocosGUI.cpp deleted file mode 100644 index 59a4f1a45d..0000000000 --- a/cocos/gui/CocosGUI.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -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 "gui/CocosGUI.h" - -NS_CC_BEGIN - -namespace ui { - -const char* CocosGUIVersion() -{ - return "CocosGUI v1.0.0.0"; -} - -} -NS_CC_END diff --git a/cocos/gui/CocosGUI.h b/cocos/gui/CocosGUI.h deleted file mode 100644 index e390c0c4fd..0000000000 --- a/cocos/gui/CocosGUI.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __COCOSGUI_H__ -#define __COCOSGUI_H__ - - -#include "gui/UIWidget.h" -#include "gui/UILayout.h" -#include "gui/UIButton.h" -#include "gui/UICheckBox.h" -#include "gui/UIImageView.h" -#include "gui/UIText.h" -#include "gui/UITextAtlas.h" -#include "gui/UILoadingBar.h" -#include "gui/UIScrollView.h" -#include "gui/UIListView.h" -#include "gui/UISlider.h" -#include "gui/UITextField.h" -#include "gui/UITextBMFont.h" -#include "gui/UIPageView.h" -#include "gui/UIHelper.h" -#include "gui/UIRichText.h" - -NS_CC_BEGIN -namespace ui { - -const char* CocosGUIVersion(); - -} -NS_CC_END - -#endif /* defined(__CocosGUITest__Cocos__) */ diff --git a/cocos/gui/GUIDefine.h b/cocos/gui/GUIDefine.h deleted file mode 100644 index 8cd44b664a..0000000000 --- a/cocos/gui/GUIDefine.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__GUIDefine__ -#define __TestCpp__GUIDefine__ - -#include "cocos2d.h" -#include "../../extensions/ExtensionMacros.h" -#include -#include "cocostudio/ObjectFactory.h" - -#pragma mark - -#pragma mark Widget macro -#pragma mark - - -#define DECLARE_CLASS_GUI_INFO \ - public: \ - static cocostudio::ObjectFactory::TInfo Type; \ - static cocos2d::Ref* createInstance(void); \ - -#define IMPLEMENT_CLASS_GUI_INFO(className) \ - cocos2d::Ref* className::createInstance(void) \ - { \ - return className::create(); \ - } \ - cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \ - -#define CREATE_CLASS_GUI_INFO(className) \ - cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \ - - -#pragma mark - -#pragma mark Reader macro -#pragma mark - - -#define DECLARE_CLASS_WIDGET_READER_INFO \ - public: \ - static cocostudio::ObjectFactory::TInfo Type; \ - static cocos2d::Ref* createInstance(void); \ - -#define IMPLEMENT_CLASS_WIDGET_READER_INFO(className) \ - cocos2d::Ref* className::createInstance(void) \ - { \ - return className::getInstance(); \ - } \ - cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \ - -#define CREATE_CLASS_WIDGET_READER_INFO(className) \ - cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \ - - - - - -//#define CUSTOM_GUI_PARSE_FUNCTION(className, functionName) \ -// className::functionName \ - -#endif /* defined(__TestCpp__GUIDefine__) */ diff --git a/cocos/gui/UIButton.cpp b/cocos/gui/UIButton.cpp deleted file mode 100644 index 99586097ac..0000000000 --- a/cocos/gui/UIButton.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** -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 "gui/UIButton.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" - -NS_CC_BEGIN - -namespace ui { - -static const int NORMAL_RENDERER_Z = (-2); -static const int PRESSED_RENDERER_Z = (-2); -static const int DISABLED_RENDERER_Z = (-2); -static const int TITLE_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(Button) - -Button::Button(): -_buttonNormalRenderer(nullptr), -_buttonClickedRenderer(nullptr), -_buttonDisableRenderer(nullptr), -_titleRenderer(nullptr), -_normalFileName(""), -_clickedFileName(""), -_disabledFileName(""), -_prevIgnoreSize(true), -_scale9Enabled(false), -_capInsetsNormal(Rect::ZERO), -_capInsetsPressed(Rect::ZERO), -_capInsetsDisabled(Rect::ZERO), -_normalTexType(UI_TEX_TYPE_LOCAL), -_pressedTexType(UI_TEX_TYPE_LOCAL), -_disabledTexType(UI_TEX_TYPE_LOCAL), -_normalTextureSize(_size), -_pressedTextureSize(_size), -_disabledTextureSize(_size), -_pressedActionEnabled(false), -_titleColor(Color3B::WHITE), -_normalTextureScaleXInSize(1.0f), -_normalTextureScaleYInSize(1.0f), -_pressedTextureScaleXInSize(1.0f), -_pressedTextureScaleYInSize(1.0f), -_normalTextureLoaded(false), -_pressedTextureLoaded(false), -_disabledTextureLoaded(false) -{ - -} - -Button::~Button() -{ -} - -Button* Button::create() -{ - Button* widget = new Button(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -bool Button::init() -{ - if (Widget::init()) - { - setTouchEnabled(true); - return true; - } - return false; -} - -void Button::initRenderer() -{ - _buttonNormalRenderer = Sprite::create(); - _buttonClickedRenderer = Sprite::create(); - _buttonDisableRenderer = Sprite::create(); - _titleRenderer = LabelTTF::create(); - - Node::addChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1); - Node::addChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1); - Node::addChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1); - Node::addChild(_titleRenderer, TITLE_RENDERER_Z, -1); -} - -void Button::setScale9Enabled(bool able) -{ - if (_scale9Enabled == able) - { - return; - } - _brightStyle = BRIGHT_NONE; - _scale9Enabled = able; - Node::removeChild(_buttonNormalRenderer); - Node::removeChild(_buttonClickedRenderer); - Node::removeChild(_buttonDisableRenderer); - _buttonNormalRenderer = nullptr; - _buttonClickedRenderer = nullptr; - _buttonDisableRenderer = nullptr; - if (_scale9Enabled) - { - _buttonNormalRenderer = extension::Scale9Sprite::create(); - _buttonClickedRenderer = extension::Scale9Sprite::create(); - _buttonDisableRenderer = extension::Scale9Sprite::create(); - } - else - { - _buttonNormalRenderer = Sprite::create(); - _buttonClickedRenderer = Sprite::create(); - _buttonDisableRenderer = Sprite::create(); - } - - loadTextureNormal(_normalFileName.c_str(), _normalTexType); - loadTexturePressed(_clickedFileName.c_str(), _pressedTexType); - loadTextureDisabled(_disabledFileName.c_str(), _disabledTexType); - Node::addChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1); - Node::addChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1); - Node::addChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1); - if (_scale9Enabled) - { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; - } - else - { - ignoreContentAdaptWithSize(_prevIgnoreSize); - } - setCapInsetsNormalRenderer(_capInsetsNormal); - setCapInsetsPressedRenderer(_capInsetsPressed); - setCapInsetsDisabledRenderer(_capInsetsDisabled); - setBright(_bright); -} - -bool Button::isScale9Enabled() -{ - return _scale9Enabled; -} - -void Button::ignoreContentAdaptWithSize(bool ignore) -{ - if (!_scale9Enabled || (_scale9Enabled && !ignore)) - { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; - } -} - -void Button::loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType) -{ - loadTextureNormal(normal,texType); - loadTexturePressed(selected,texType); - loadTextureDisabled(disabled,texType); -} - -void Button::loadTextureNormal(const char* normal,TextureResType texType) -{ - if (!normal || strcmp(normal, "") == 0) - { - return; - } - _normalFileName = normal; - _normalTexType = texType; - if (_scale9Enabled) - { - extension::Scale9Sprite* normalRendererScale9 = static_cast(_buttonNormalRenderer); - switch (_normalTexType) - { - case UI_TEX_TYPE_LOCAL: - normalRendererScale9->initWithFile(normal); - break; - case UI_TEX_TYPE_PLIST: - normalRendererScale9->initWithSpriteFrameName(normal); - break; - default: - break; - } - normalRendererScale9->setCapInsets(_capInsetsNormal); - } - else - { - Sprite* normalRenderer = static_cast(_buttonNormalRenderer); - switch (_normalTexType) - { - case UI_TEX_TYPE_LOCAL: - normalRenderer->setTexture(normal); - break; - case UI_TEX_TYPE_PLIST: - normalRenderer->setSpriteFrame(normal); - break; - default: - break; - } - } - _normalTextureSize = _buttonNormalRenderer->getContentSize(); - normalTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_buttonNormalRenderer); - _normalTextureLoaded = true; -} - -void Button::loadTexturePressed(const char* selected,TextureResType texType) -{ - if (!selected || strcmp(selected, "") == 0) - { - return; - } - _clickedFileName = selected; - _pressedTexType = texType; - if (_scale9Enabled) - { - extension::Scale9Sprite* clickedRendererScale9 = static_cast(_buttonClickedRenderer); - switch (_pressedTexType) - { - case UI_TEX_TYPE_LOCAL: - clickedRendererScale9->initWithFile(selected); - break; - case UI_TEX_TYPE_PLIST: - clickedRendererScale9->initWithSpriteFrameName(selected); - break; - default: - break; - } - clickedRendererScale9->setCapInsets(_capInsetsPressed); - } - else - { - Sprite* clickedRenderer = static_cast(_buttonClickedRenderer); - switch (_pressedTexType) - { - case UI_TEX_TYPE_LOCAL: - clickedRenderer->setTexture(selected); - break; - case UI_TEX_TYPE_PLIST: - clickedRenderer->setSpriteFrame(selected); - break; - default: - break; - } - } - _pressedTextureSize = _buttonClickedRenderer->getContentSize(); - pressedTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_buttonDisableRenderer); - _pressedTextureLoaded = true; -} - -void Button::loadTextureDisabled(const char* disabled,TextureResType texType) -{ - if (!disabled || strcmp(disabled, "") == 0) - { - return; - } - _disabledFileName = disabled; - _disabledTexType = texType; - if (_scale9Enabled) - { - extension::Scale9Sprite* disabledScale9 = static_cast(_buttonDisableRenderer); - switch (_disabledTexType) - { - case UI_TEX_TYPE_LOCAL: - disabledScale9->initWithFile(disabled); - break; - case UI_TEX_TYPE_PLIST: - disabledScale9->initWithSpriteFrameName(disabled); - break; - default: - break; - } - disabledScale9->setCapInsets(_capInsetsDisabled); - } - else - { - Sprite* disabledRenderer = static_cast(_buttonDisableRenderer); - switch (_disabledTexType) - { - case UI_TEX_TYPE_LOCAL: - disabledRenderer->setTexture(disabled); - break; - case UI_TEX_TYPE_PLIST: - disabledRenderer->setSpriteFrame(disabled); - break; - default: - break; - } - } - _disabledTextureSize = _buttonDisableRenderer->getContentSize(); - disabledTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_buttonDisableRenderer); - _disabledTextureLoaded = true; -} - -void Button::setCapInsets(const Rect &capInsets) -{ - setCapInsetsNormalRenderer(capInsets); - setCapInsetsPressedRenderer(capInsets); - setCapInsetsDisabledRenderer(capInsets); -} - -void Button::setCapInsetsNormalRenderer(const Rect &capInsets) -{ - _capInsetsNormal = capInsets; - if (!_scale9Enabled) - { - return; - } - static_cast(_buttonNormalRenderer)->setCapInsets(capInsets); -} - -const Rect& Button::getCapInsetsNormalRenderer() -{ - return _capInsetsNormal; -} - -void Button::setCapInsetsPressedRenderer(const Rect &capInsets) -{ - _capInsetsPressed = capInsets; - if (!_scale9Enabled) - { - return; - } - static_cast(_buttonClickedRenderer)->setCapInsets(capInsets); -} - -const Rect& Button::getCapInsetsPressedRenderer() -{ - return _capInsetsPressed; -} - -void Button::setCapInsetsDisabledRenderer(const Rect &capInsets) -{ - _capInsetsDisabled = capInsets; - if (!_scale9Enabled) - { - return; - } - static_cast(_buttonDisableRenderer)->setCapInsets(capInsets); -} - -const Rect& Button::getCapInsetsDisabledRenderer() -{ - return _capInsetsDisabled; -} - -void Button::onPressStateChangedToNormal() -{ - _buttonNormalRenderer->setVisible(true); - _buttonClickedRenderer->setVisible(false); - _buttonDisableRenderer->setVisible(false); - if (_pressedTextureLoaded) - { - if (_pressedActionEnabled) - { - _buttonNormalRenderer->stopAllActions(); - _buttonClickedRenderer->stopAllActions(); - Action *zoomAction = ScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize); - _buttonNormalRenderer->runAction(zoomAction); - _buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize); - } - } - else - { - _buttonNormalRenderer->stopAllActions(); - _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); - } -} - -void Button::onPressStateChangedToPressed() -{ - if (_pressedTextureLoaded) - { - _buttonNormalRenderer->setVisible(false); - _buttonClickedRenderer->setVisible(true); - _buttonDisableRenderer->setVisible(false); - if (_pressedActionEnabled) - { - _buttonNormalRenderer->stopAllActions(); - _buttonClickedRenderer->stopAllActions(); - Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); - _buttonClickedRenderer->runAction(zoomAction); - _buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); - } - } - else - { - _buttonNormalRenderer->setVisible(true); - _buttonClickedRenderer->setVisible(true); - _buttonDisableRenderer->setVisible(false); - _buttonNormalRenderer->stopAllActions(); - _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); - } -} - -void Button::onPressStateChangedToDisabled() -{ - _buttonNormalRenderer->setVisible(false); - _buttonClickedRenderer->setVisible(false); - _buttonDisableRenderer->setVisible(true); - _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); - _buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize); -} - -void Button::updateFlippedX() -{ - _titleRenderer->setFlippedX(_flippedX); - if (_scale9Enabled) - { - int flip = _flippedX ? -1 : 1; - _buttonNormalRenderer->setScaleX(flip); - _buttonClickedRenderer->setScaleX(flip); - _buttonDisableRenderer->setScaleX(flip); - } - else - { - static_cast(_buttonNormalRenderer)->setFlippedX(_flippedX); - static_cast(_buttonClickedRenderer)->setFlippedX(_flippedX); - static_cast(_buttonDisableRenderer)->setFlippedX(_flippedX); - } -} - -void Button::updateFlippedY() -{ - _titleRenderer->setFlippedY(_flippedY); - if (_scale9Enabled) - { - int flip = _flippedY ? -1 : 1; - _buttonNormalRenderer->setScaleY(flip); - _buttonClickedRenderer->setScaleY(flip); - _buttonDisableRenderer->setScaleY(flip); - } - else - { - static_cast(_buttonNormalRenderer)->setFlippedY(_flippedY); - static_cast(_buttonClickedRenderer)->setFlippedY(_flippedY); - static_cast(_buttonDisableRenderer)->setFlippedY(_flippedY); - } -} - -void Button::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _buttonNormalRenderer->setAnchorPoint(pt); - _buttonClickedRenderer->setAnchorPoint(pt); - _buttonDisableRenderer->setAnchorPoint(pt); - _titleRenderer->setPosition(Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y))); -} - -void Button::onSizeChanged() -{ - Widget::onSizeChanged(); - normalTextureScaleChangedWithSize(); - pressedTextureScaleChangedWithSize(); - disabledTextureScaleChangedWithSize(); -} - -const Size& Button::getContentSize() const -{ - return _normalTextureSize; -} - -Node* Button::getVirtualRenderer() -{ - if (_bright) - { - switch (_brightStyle) - { - case BRIGHT_NORMAL: - return _buttonNormalRenderer; - case BRIGHT_HIGHLIGHT: - return _buttonClickedRenderer; - default: - return nullptr; - } - } - else - { - return _buttonDisableRenderer; - } -} - -void Button::normalTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - if (!_scale9Enabled) - { - _buttonNormalRenderer->setScale(1.0f); - _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; - _size = _normalTextureSize; - } - } - else - { - if (_scale9Enabled) - { - static_cast(_buttonNormalRenderer)->setPreferredSize(_size); - _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; - } - else - { - Size textureSize = _normalTextureSize; - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _buttonNormalRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _buttonNormalRenderer->setScaleX(scaleX); - _buttonNormalRenderer->setScaleY(scaleY); - _normalTextureScaleXInSize = scaleX; - _normalTextureScaleYInSize = scaleY; - } - } -} - -void Button::pressedTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - if (!_scale9Enabled) - { - _buttonClickedRenderer->setScale(1.0f); - _pressedTextureScaleXInSize = _pressedTextureScaleYInSize = 1.0f; - } - } - else - { - if (_scale9Enabled) - { - static_cast(_buttonClickedRenderer)->setPreferredSize(_size); - _pressedTextureScaleXInSize = _pressedTextureScaleYInSize = 1.0f; - } - else - { - Size textureSize = _pressedTextureSize; - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _buttonClickedRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / _pressedTextureSize.width; - float scaleY = _size.height / _pressedTextureSize.height; - _buttonClickedRenderer->setScaleX(scaleX); - _buttonClickedRenderer->setScaleY(scaleY); - _pressedTextureScaleXInSize = scaleX; - _pressedTextureScaleYInSize = scaleY; - } - } -} - -void Button::disabledTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - if (!_scale9Enabled) - { - _buttonDisableRenderer->setScale(1.0f); - } - } - else - { - if (_scale9Enabled) - { - static_cast(_buttonDisableRenderer)->setPreferredSize(_size); - } - else - { - Size textureSize = _disabledTextureSize; - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _buttonDisableRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / _disabledTextureSize.width; - float scaleY = _size.height / _disabledTextureSize.height; - _buttonDisableRenderer->setScaleX(scaleX); - _buttonDisableRenderer->setScaleY(scaleY); - } - } -} - -void Button::setPressedActionEnabled(bool enabled) -{ - _pressedActionEnabled = enabled; -} - -void Button::setTitleText(const std::string& text) -{ - _titleRenderer->setString(text); -} - -const std::string& Button::getTitleText() const -{ - return _titleRenderer->getString(); -} - -void Button::setTitleColor(const Color3B& color) -{ - _titleColor = color; - _titleRenderer->updateDisplayedColor(color); -} - -const Color3B& Button::getTitleColor() const -{ - return _titleRenderer->getColor(); -} - -void Button::setTitleFontSize(float size) -{ - _titleRenderer->setFontSize(size); -} - -float Button::getTitleFontSize() const -{ - return _titleRenderer->getFontSize(); -} - -void Button::setTitleFontName(const char* fontName) -{ - _titleRenderer->setFontName(fontName); -} - -const char* Button::getTitleFontName() const -{ - return _titleRenderer->getFontName().c_str(); -} - -std::string Button::getDescription() const -{ - return "Button"; -} - -void Button::updateTextureColor() -{ - updateColorToRenderer(_buttonNormalRenderer); - updateColorToRenderer(_buttonClickedRenderer); - updateColorToRenderer(_buttonDisableRenderer); -} - -void Button::updateTextureOpacity() -{ - updateOpacityToRenderer(_buttonNormalRenderer); - updateOpacityToRenderer(_buttonClickedRenderer); - updateOpacityToRenderer(_buttonDisableRenderer); -} - -void Button::updateTextureRGBA() -{ - updateRGBAToRenderer(_buttonNormalRenderer); - updateRGBAToRenderer(_buttonClickedRenderer); - updateRGBAToRenderer(_buttonDisableRenderer); -} - -Widget* Button::createCloneInstance() -{ - return Button::create(); -} - -void Button::copySpecialProperties(Widget *widget) -{ - Button* button = dynamic_cast(widget); - if (button) - { - _prevIgnoreSize = button->_prevIgnoreSize; - setScale9Enabled(button->_scale9Enabled); - loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType); - loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType); - loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType); - setCapInsetsNormalRenderer(button->_capInsetsNormal); - setCapInsetsPressedRenderer(button->_capInsetsPressed); - setCapInsetsDisabledRenderer(button->_capInsetsDisabled); - setTitleText(button->getTitleText()); - setTitleFontName(button->getTitleFontName()); - setTitleFontSize(button->getTitleFontSize()); - setTitleColor(button->getTitleColor()); - setPressedActionEnabled(button->_pressedActionEnabled); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UIButton.h b/cocos/gui/UIButton.h deleted file mode 100644 index 3411c20af8..0000000000 --- a/cocos/gui/UIButton.h +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UIBUTTON_H__ -#define __UIBUTTON_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui{ - -/** -* @js NA -* @lua NA -*/ -class Button : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - Button(); - - /** - * Default destructor - */ - virtual ~Button(); - - /** - * Allocates and initializes. - */ - static Button* create(); - - /** - * Load textures for button. - * - * @param normal normal state texture. - * - * @param selected selected state texture. - * - * @param disabled dark state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load normal state texture for button. - * - * @param normal normal state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureNormal(const char* normal, TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load selected state texture for button. - * - * @param selected selected state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTexturePressed(const char* selected, TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load dark state texture for button. - * - * @param disabled dark state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureDisabled(const char* disabled, TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Sets capinsets for button, if button is using scale9 renderer. - * - * @param capInsets capinsets for button - */ - void setCapInsets(const Rect &capInsets); - - /** - * Sets capinsets for button, if button is using scale9 renderer. - * - * @param capInsets capinsets for button - */ - void setCapInsetsNormalRenderer(const Rect &capInsets); - - const Rect& getCapInsetsNormalRenderer(); - - /** - * Sets capinsets for button, if button is using scale9 renderer. - * - * @param capInsets capinsets for button - */ - void setCapInsetsPressedRenderer(const Rect &capInsets); - - const Rect& getCapInsetsPressedRenderer(); - - /** - * Sets capinsets for button, if button is using scale9 renderer. - * - * @param capInsets capinsets for button - */ - void setCapInsetsDisabledRenderer(const Rect &capInsets); - - const Rect& getCapInsetsDisabledRenderer(); - - //override "setAnchorPoint" of widget. - virtual void setAnchorPoint(const Point &pt) override; - - /** - * Sets if button is using scale9 renderer. - * - * @param true that using scale9 renderer, false otherwise. - */ - virtual void setScale9Enabled(bool able); - - bool isScale9Enabled(); - - /** - * Changes if button can be clicked zoom effect. - * - * @param true that can be clicked zoom effect, false otherwise. - */ - void setPressedActionEnabled(bool enabled); - - //override "ignoreContentAdaptWithSize" method of widget. - virtual void ignoreContentAdaptWithSize(bool ignore) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; - - //override "getVirtualRenderer" method of widget. - virtual Node* getVirtualRenderer() override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - void setTitleText(const std::string& text); - const std::string& getTitleText() const; - void setTitleColor(const Color3B& color); - const Color3B& getTitleColor() const; - void setTitleFontSize(float size); - float getTitleFontSize() const; - void setTitleFontName(const char* fontName); - const char* getTitleFontName() const; - -protected: - virtual bool init() override; - virtual void initRenderer() override; - virtual void onPressStateChangedToNormal() override; - virtual void onPressStateChangedToPressed() override; - virtual void onPressStateChangedToDisabled() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; - void normalTextureScaleChangedWithSize(); - void pressedTextureScaleChangedWithSize(); - void disabledTextureScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - Node* _buttonNormalRenderer; - Node* _buttonClickedRenderer; - Node* _buttonDisableRenderer; - LabelTTF* _titleRenderer; - std::string _normalFileName; - std::string _clickedFileName; - std::string _disabledFileName; - bool _prevIgnoreSize; - bool _scale9Enabled; - Rect _capInsetsNormal; - Rect _capInsetsPressed; - Rect _capInsetsDisabled; - TextureResType _normalTexType; - TextureResType _pressedTexType; - TextureResType _disabledTexType; - Size _normalTextureSize; - Size _pressedTextureSize; - Size _disabledTextureSize; - bool _pressedActionEnabled; - Color3B _titleColor; - float _normalTextureScaleXInSize; - float _normalTextureScaleYInSize; - float _pressedTextureScaleXInSize; - float _pressedTextureScaleYInSize; - bool _normalTextureLoaded; - bool _pressedTextureLoaded; - bool _disabledTextureLoaded; -}; - -} - -NS_CC_END - -#endif /* defined(__CocoGUI__Button__) */ diff --git a/cocos/gui/UICheckBox.cpp b/cocos/gui/UICheckBox.cpp deleted file mode 100644 index 45664c99e8..0000000000 --- a/cocos/gui/UICheckBox.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/**************************************************************************** -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 "gui/UICheckBox.h" - -NS_CC_BEGIN - -namespace ui { - -static const int BACKGROUNDBOX_RENDERER_Z = (-1); -static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1); -static const int FRONTCROSS_RENDERER_Z = (-1); -static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1); -static const int FRONTCROSSDISABLED_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(CheckBox) - -CheckBox::CheckBox(): -_backGroundBoxRenderer(nullptr), -_backGroundSelectedBoxRenderer(nullptr), -_frontCrossRenderer(nullptr), -_backGroundBoxDisabledRenderer(nullptr), -_frontCrossDisabledRenderer(nullptr), -_isSelected(true), -_checkBoxEventListener(nullptr), -_checkBoxEventSelector(nullptr), -_backGroundTexType(UI_TEX_TYPE_LOCAL), -_backGroundSelectedTexType(UI_TEX_TYPE_LOCAL), -_frontCrossTexType(UI_TEX_TYPE_LOCAL), -_backGroundDisabledTexType(UI_TEX_TYPE_LOCAL), -_frontCrossDisabledTexType(UI_TEX_TYPE_LOCAL), -_backGroundFileName(""), -_backGroundSelectedFileName(""), -_frontCrossFileName(""), -_backGroundDisabledFileName(""), -_frontCrossDisabledFileName("") -{ -} - -CheckBox::~CheckBox() -{ - _checkBoxEventListener = nullptr; - _checkBoxEventSelector = nullptr; -} - -CheckBox* CheckBox::create() -{ - CheckBox* widget = new CheckBox(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -bool CheckBox::init() -{ - if (Widget::init()) - { - setSelectedState(false); - setTouchEnabled(true); - return true; - } - return false; -} - -void CheckBox::initRenderer() -{ - _backGroundBoxRenderer = Sprite::create(); - _backGroundSelectedBoxRenderer = Sprite::create(); - _frontCrossRenderer = Sprite::create(); - _backGroundBoxDisabledRenderer = Sprite::create(); - _frontCrossDisabledRenderer = Sprite::create(); - - Node::addChild(_backGroundBoxRenderer, BACKGROUNDBOX_RENDERER_Z, -1); - Node::addChild(_backGroundSelectedBoxRenderer, BACKGROUNDSELECTEDBOX_RENDERER_Z, -1); - Node::addChild(_frontCrossRenderer, FRONTCROSS_RENDERER_Z, -1); - Node::addChild(_backGroundBoxDisabledRenderer, BACKGROUNDBOXDISABLED_RENDERER_Z, -1); - Node::addChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1); -} - -void CheckBox::loadTextures(const char *backGround, const char *backGroundSelected, const char *cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType) -{ - loadTextureBackGround(backGround,texType); - loadTextureBackGroundSelected(backGroundSelected,texType); - loadTextureFrontCross(cross,texType); - loadTextureBackGroundDisabled(backGroundDisabled,texType); - loadTextureFrontCrossDisabled(frontCrossDisabled,texType); -} - -void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texType) -{ - if (!backGround || strcmp(backGround, "") == 0) - { - return; - } - _backGroundFileName = backGround; - _backGroundTexType = texType; - switch (_backGroundTexType) - { - case UI_TEX_TYPE_LOCAL: - _backGroundBoxRenderer->setTexture(backGround); - break; - case UI_TEX_TYPE_PLIST: - _backGroundBoxRenderer->setSpriteFrame(backGround); - break; - default: - break; - } - backGroundTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_backGroundBoxRenderer); -} - -void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,TextureResType texType) -{ - if (!backGroundSelected || strcmp(backGroundSelected, "") == 0) - { - return; - } - _backGroundSelectedFileName = backGroundSelected; - _backGroundSelectedTexType = texType; - switch (_backGroundSelectedTexType) - { - case UI_TEX_TYPE_LOCAL: - _backGroundSelectedBoxRenderer->setTexture(backGroundSelected); - break; - case UI_TEX_TYPE_PLIST: - _backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected); - break; - default: - break; - } - backGroundSelectedTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_backGroundSelectedBoxRenderer); -} - -void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType) -{ - if (!cross || strcmp(cross, "") == 0) - { - return; - } - _frontCrossFileName = cross; - _frontCrossTexType = texType; - switch (_frontCrossTexType) - { - case UI_TEX_TYPE_LOCAL: - _frontCrossRenderer->setTexture(cross); - break; - case UI_TEX_TYPE_PLIST: - _frontCrossRenderer->setSpriteFrame(cross); - break; - default: - break; - } - frontCrossTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_frontCrossRenderer); -} - -void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,TextureResType texType) -{ - if (!backGroundDisabled || strcmp(backGroundDisabled, "") == 0) - { - return; - } - _backGroundDisabledFileName = backGroundDisabled; - _backGroundDisabledTexType = texType; - switch (_backGroundDisabledTexType) - { - case UI_TEX_TYPE_LOCAL: - _backGroundBoxDisabledRenderer->setTexture(backGroundDisabled); - break; - case UI_TEX_TYPE_PLIST: - _backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled); - break; - default: - break; - } - backGroundDisabledTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_backGroundBoxDisabledRenderer); -} - -void CheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,TextureResType texType) -{ - if (!frontCrossDisabled || strcmp(frontCrossDisabled, "") == 0) - { - return; - } - _frontCrossDisabledFileName = frontCrossDisabled; - _frontCrossDisabledTexType = texType; - switch (_frontCrossDisabledTexType) - { - case UI_TEX_TYPE_LOCAL: - _frontCrossDisabledRenderer->setTexture(frontCrossDisabled); - break; - case UI_TEX_TYPE_PLIST: - _frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled); - break; - default: - break; - } - frontCrossDisabledTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_frontCrossDisabledRenderer); -} - -void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent) -{ - _touchEndPos = touch->getLocation(); - if (_focus) - { - releaseUpEvent(); - if (_isSelected){ - setSelectedState(false); - unSelectedEvent(); - } - else - { - setSelectedState(true); - selectedEvent(); - } - } - setFocused(false); - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - widgetParent->checkChildInfo(2,this,_touchEndPos); - } -} - -void CheckBox::onPressStateChangedToNormal() -{ - _backGroundBoxRenderer->setVisible(true); - _backGroundSelectedBoxRenderer->setVisible(false); - _backGroundBoxDisabledRenderer->setVisible(false); - _frontCrossDisabledRenderer->setVisible(false); -} - -void CheckBox::onPressStateChangedToPressed() -{ - _backGroundBoxRenderer->setVisible(false); - _backGroundSelectedBoxRenderer->setVisible(true); - _backGroundBoxDisabledRenderer->setVisible(false); - _frontCrossDisabledRenderer->setVisible(false); -} - -void CheckBox::onPressStateChangedToDisabled() -{ - _backGroundBoxRenderer->setVisible(false); - _backGroundSelectedBoxRenderer->setVisible(false); - _backGroundBoxDisabledRenderer->setVisible(true); - _frontCrossRenderer->setVisible(false); - if (_isSelected) - { - _frontCrossDisabledRenderer->setVisible(true); - } -} - -void CheckBox::setSelectedState(bool selected) -{ - if (selected == _isSelected) - { - return; - } - _isSelected = selected; - _frontCrossRenderer->setVisible(_isSelected); -} - -bool CheckBox::getSelectedState() -{ - return _isSelected; -} - -void CheckBox::selectedEvent() -{ - if (_checkBoxEventListener && _checkBoxEventSelector) - { - (_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_SELECTED); - } -} - -void CheckBox::unSelectedEvent() -{ - if (_checkBoxEventListener && _checkBoxEventSelector) - { - (_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_UNSELECTED); - } -} - -void CheckBox::addEventListenerCheckBox(Ref *target, SEL_SelectedStateEvent selector) -{ - _checkBoxEventListener = target; - _checkBoxEventSelector = selector; -} - -void CheckBox::updateFlippedX() -{ - _backGroundBoxRenderer->setFlippedX(_flippedX); - _backGroundSelectedBoxRenderer->setFlippedX(_flippedX); - _frontCrossRenderer->setFlippedX(_flippedX); - _backGroundBoxDisabledRenderer->setFlippedX(_flippedX); - _frontCrossDisabledRenderer->setFlippedX(_flippedX); -} - -void CheckBox::updateFlippedY() -{ - _backGroundBoxRenderer->setFlippedY(_flippedY); - _backGroundSelectedBoxRenderer->setFlippedY(_flippedY); - _frontCrossRenderer->setFlippedY(_flippedY); - _backGroundBoxDisabledRenderer->setFlippedY(_flippedY); - _frontCrossDisabledRenderer->setFlippedY(_flippedY); -} - -void CheckBox::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _backGroundBoxRenderer->setAnchorPoint(pt); - _backGroundSelectedBoxRenderer->setAnchorPoint(pt); - _backGroundBoxDisabledRenderer->setAnchorPoint(pt); - _frontCrossRenderer->setAnchorPoint(pt); - _frontCrossDisabledRenderer->setAnchorPoint(pt); -} - -void CheckBox::onSizeChanged() -{ - Widget::onSizeChanged(); - backGroundTextureScaleChangedWithSize(); - backGroundSelectedTextureScaleChangedWithSize(); - frontCrossTextureScaleChangedWithSize(); - backGroundDisabledTextureScaleChangedWithSize(); - frontCrossDisabledTextureScaleChangedWithSize(); -} - -const Size& CheckBox::getContentSize() const -{ - return _backGroundBoxRenderer->getContentSize(); -} - -Node* CheckBox::getVirtualRenderer() -{ - return _backGroundBoxRenderer; -} - -void CheckBox::backGroundTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _backGroundBoxRenderer->setScale(1.0f); - _size = _backGroundBoxRenderer->getContentSize(); - } - else - { - Size textureSize = _backGroundBoxRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _backGroundBoxRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _backGroundBoxRenderer->setScaleX(scaleX); - _backGroundBoxRenderer->setScaleY(scaleY); - } -} - -void CheckBox::backGroundSelectedTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _backGroundSelectedBoxRenderer->setScale(1.0f); - } - else - { - Size textureSize = _backGroundSelectedBoxRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _backGroundSelectedBoxRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _backGroundSelectedBoxRenderer->setScaleX(scaleX); - _backGroundSelectedBoxRenderer->setScaleY(scaleY); - } -} - -void CheckBox::frontCrossTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _frontCrossRenderer->setScale(1.0f); - } - else - { - Size textureSize = _frontCrossRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _frontCrossRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _frontCrossRenderer->setScaleX(scaleX); - _frontCrossRenderer->setScaleY(scaleY); - } -} - -void CheckBox::backGroundDisabledTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _backGroundBoxDisabledRenderer->setScale(1.0f); - } - else - { - Size textureSize = _backGroundBoxDisabledRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _backGroundBoxDisabledRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _backGroundBoxDisabledRenderer->setScaleX(scaleX); - _backGroundBoxDisabledRenderer->setScaleY(scaleY); - } -} - -void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _frontCrossDisabledRenderer->setScale(1.0f); - } - else - { - Size textureSize = _frontCrossDisabledRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _frontCrossDisabledRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _frontCrossDisabledRenderer->setScaleX(scaleX); - _frontCrossDisabledRenderer->setScaleY(scaleY); - } -} - -std::string CheckBox::getDescription() const -{ - return "CheckBox"; -} - -void CheckBox::updateTextureColor() -{ - updateColorToRenderer(_backGroundBoxRenderer); - updateColorToRenderer(_backGroundSelectedBoxRenderer); - updateColorToRenderer(_frontCrossRenderer); - updateColorToRenderer(_backGroundBoxDisabledRenderer); - updateColorToRenderer(_frontCrossDisabledRenderer); -} - -void CheckBox::updateTextureOpacity() -{ - updateOpacityToRenderer(_backGroundBoxRenderer); - updateOpacityToRenderer(_backGroundSelectedBoxRenderer); - updateOpacityToRenderer(_frontCrossRenderer); - updateOpacityToRenderer(_backGroundBoxDisabledRenderer); - updateOpacityToRenderer(_frontCrossDisabledRenderer); -} - -void CheckBox::updateTextureRGBA() -{ - updateRGBAToRenderer(_backGroundBoxRenderer); - updateRGBAToRenderer(_backGroundSelectedBoxRenderer); - updateRGBAToRenderer(_frontCrossRenderer); - updateRGBAToRenderer(_backGroundBoxDisabledRenderer); - updateRGBAToRenderer(_frontCrossDisabledRenderer); -} - -Widget* CheckBox::createCloneInstance() -{ - return CheckBox::create(); -} - -void CheckBox::copySpecialProperties(Widget *widget) -{ - CheckBox* checkBox = dynamic_cast(widget); - if (checkBox) - { - loadTextureBackGround(checkBox->_backGroundFileName.c_str(), checkBox->_backGroundTexType); - loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName.c_str(), checkBox->_backGroundSelectedTexType); - loadTextureFrontCross(checkBox->_frontCrossFileName.c_str(), checkBox->_frontCrossTexType); - loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName.c_str(), checkBox->_backGroundDisabledTexType); - loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName.c_str(), checkBox->_frontCrossDisabledTexType); - setSelectedState(checkBox->_isSelected); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UICheckBox.h b/cocos/gui/UICheckBox.h deleted file mode 100644 index 40ac36eacf..0000000000 --- a/cocos/gui/UICheckBox.h +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UICHECKBOX_H__ -#define __UICHECKBOX_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - CHECKBOX_STATE_EVENT_SELECTED, - CHECKBOX_STATE_EVENT_UNSELECTED -}CheckBoxEventType; - -typedef void (Ref::*SEL_SelectedStateEvent)(Ref*,CheckBoxEventType); -#define checkboxselectedeventselector(_SELECTOR) (SEL_SelectedStateEvent)(&_SELECTOR) - -/** -* @js NA -* @lua NA -*/ -class CheckBox : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - CheckBox(); - - /** - * Default destructor - */ - virtual ~CheckBox(); - - /** - * Allocates and initializes. - */ - static CheckBox* create(); - - /** - * Load textures for checkbox. - * - * @param backGround backGround texture. - * - * @param backGroundSelected backGround selected state texture. - * - * @param cross cross texture. - * - * @param frontCrossDisabled cross dark state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextures(const char* backGround,const char* backGroundSelected,const char* cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load backGround texture for checkbox. - * - * @param backGround backGround texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureBackGround(const char* backGround,TextureResType type = UI_TEX_TYPE_LOCAL); - - /** - * Load backGroundSelected texture for checkbox. - * - * @param backGroundSelected backGround selected state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureBackGroundSelected(const char* backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load cross texture for checkbox. - * - * @param cross cross texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureFrontCross(const char* cross,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load backGroundDisabled texture for checkbox. - * - * @param backGroundDisabled backGroundDisabled texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureBackGroundDisabled(const char* backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load frontCrossDisabled texture for checkbox. - * - * @param frontCrossDisabled frontCrossDisabled texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTextureFrontCrossDisabled(const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Sets selcted state for checkbox. - * - * @param selected true that checkbox is selected, false otherwise. - */ - void setSelectedState(bool selected); - - /** - * Gets selcted state of checkbox. - * - * @return selected true that checkbox is selected, false otherwise. - */ - bool getSelectedState(); - - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - - //add a call back function would called when checkbox is selected or unselected. - void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector); - - //override "onTouchEnded" method of widget. - virtual void onTouchEnded(Touch *touch, Event *unusedEvent); - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; - - //override "getVirtualRenderer" method of widget. - virtual Node* getVirtualRenderer() override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - -protected: - virtual bool init() override; - virtual void initRenderer() override; - virtual void onPressStateChangedToNormal() override; - virtual void onPressStateChangedToPressed() override; - virtual void onPressStateChangedToDisabled() override; - void selectedEvent(); - void unSelectedEvent(); - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; - void backGroundTextureScaleChangedWithSize(); - void backGroundSelectedTextureScaleChangedWithSize(); - void frontCrossTextureScaleChangedWithSize(); - void backGroundDisabledTextureScaleChangedWithSize(); - void frontCrossDisabledTextureScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - Sprite* _backGroundBoxRenderer; - Sprite* _backGroundSelectedBoxRenderer; - Sprite* _frontCrossRenderer; - Sprite* _backGroundBoxDisabledRenderer; - Sprite* _frontCrossDisabledRenderer; - bool _isSelected; - - Ref* _checkBoxEventListener; - SEL_SelectedStateEvent _checkBoxEventSelector; - - TextureResType _backGroundTexType; - TextureResType _backGroundSelectedTexType; - TextureResType _frontCrossTexType; - TextureResType _backGroundDisabledTexType; - TextureResType _frontCrossDisabledTexType; - - std::string _backGroundFileName; - std::string _backGroundSelectedFileName; - std::string _frontCrossFileName; - std::string _backGroundDisabledFileName; - std::string _frontCrossDisabledFileName; -}; - -} - -NS_CC_END - -#endif /* defined(__CocoGUI__CheckBox__) */ diff --git a/cocos/gui/UIHelper.cpp b/cocos/gui/UIHelper.cpp deleted file mode 100644 index 4bb3d4ee8b..0000000000 --- a/cocos/gui/UIHelper.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -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 "CocosGUI.h" - -NS_CC_BEGIN - -namespace ui { - -Widget* Helper::seekWidgetByTag(Widget* root, int tag) -{ - if (!root) - { - return nullptr; - } - if (root->getTag() == tag) - { - return root; - } - const auto& arrayRootChildren = root->getChildren(); - ssize_t length = arrayRootChildren.size(); - for (ssize_t i=0;i(arrayRootChildren.at(i)); - Widget* res = seekWidgetByTag(child,tag); - if (res != nullptr) - { - return res; - } - } - return nullptr; -} - -Widget* Helper::seekWidgetByName(Widget* root, const char *name) -{ - if (!root) - { - return nullptr; - } - if (strcmp(root->getName(), name) == 0) - { - return root; - } - const auto& arrayRootChildren = root->getChildren(); - for (auto& subWidget : arrayRootChildren) - { - Widget* child = static_cast(subWidget); - Widget* res = seekWidgetByName(child,name); - if (res != nullptr) - { - return res; - } - } - return nullptr; -} - -Widget* Helper::seekWidgetByRelativeName(Widget *root, const char *name) -{ - if (!root) - { - return nullptr; - } - const auto& arrayRootChildren = root->getChildren(); - for (auto& subWidget : arrayRootChildren) - { - Widget* child = static_cast(subWidget); - RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); - if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0) - { - return child; - } - } - return nullptr; -} - -/*temp action*/ -Widget* Helper::seekActionWidgetByActionTag(Widget* root, int tag) -{ - if (!root) - { - return nullptr; - } - if (root->getActionTag() == tag) - { - return root; - } - const auto& arrayRootChildren = root->getChildren(); - for (auto& subWidget : arrayRootChildren) - { - Widget* child = static_cast(subWidget); - Widget* res = seekActionWidgetByActionTag(child,tag); - if (res != nullptr) - { - return res; - } - } - return nullptr; -} - -} - -NS_CC_END diff --git a/cocos/gui/UIHelper.h b/cocos/gui/UIHelper.h deleted file mode 100644 index 035df13cdb..0000000000 --- a/cocos/gui/UIHelper.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UIHELPER_H__ -#define __UIHELPER_H__ - -NS_CC_BEGIN - -namespace ui { - -/** -* @js NA -* @lua NA -*/ -class Helper -{ -public: - /** - * Finds a widget whose tag equals to param tag from root widget. - * - * @param root widget which will be seeked. - * - * @tag tag value. - * - * @return finded result. - */ - static Widget* seekWidgetByTag(Widget* root, int tag); - - /** - * Finds a widget whose name equals to param name from root widget. - * - * @param root widget which will be seeked. - * - * @name name value. - * - * @return finded result. - */ - static Widget* seekWidgetByName(Widget* root, const char* name); - - /** - * Finds a widget whose name equals to param name from root widget. - * - * RelativeLayout will call this method to find the widget witch is needed. - * - * @param root widget which will be seeked. - * - * @name name value. - * - * @return finded result. - */ - static Widget* seekWidgetByRelativeName(Widget* root, const char* name); - - /*temp action*/ - static Widget* seekActionWidgetByActionTag(Widget* root, int tag); -}; -} - -NS_CC_END - -#endif /* defined(__CocoGUI__UISystem__) */ diff --git a/cocos/gui/UIImageView.cpp b/cocos/gui/UIImageView.cpp deleted file mode 100644 index e42fe3d070..0000000000 --- a/cocos/gui/UIImageView.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/**************************************************************************** -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 "gui/UIImageView.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" - -NS_CC_BEGIN - -namespace ui { - - -#define STATIC_CAST_CCSPRITE static_cast(_imageRenderer) -#define STATIC_CAST_SCALE9SPRITE static_cast(_imageRenderer) - -static const int IMAGE_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(ImageView) - -ImageView::ImageView(): -_scale9Enabled(false), -_prevIgnoreSize(true), -_capInsets(Rect::ZERO), -_imageRenderer(nullptr), -_textureFile(""), -_imageTexType(UI_TEX_TYPE_LOCAL), -_imageTextureSize(_size) -{ - -} - -ImageView::~ImageView() -{ - -} - -ImageView* ImageView::create() -{ - ImageView* widget = new ImageView(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -void ImageView::initRenderer() -{ - _imageRenderer = Sprite::create(); - Node::addChild(_imageRenderer, IMAGE_RENDERER_Z, -1); -} - -void ImageView::loadTexture(const char *fileName, TextureResType texType) -{ - if (!fileName || strcmp(fileName, "") == 0) - { - return; - } - _textureFile = fileName; - _imageTexType = texType; - switch (_imageTexType) - { - case UI_TEX_TYPE_LOCAL: - if (_scale9Enabled) - { - extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; - imageRendererScale9->initWithFile(fileName); - imageRendererScale9->setCapInsets(_capInsets); - } - else - { - Sprite* imageRenderer = STATIC_CAST_CCSPRITE; - imageRenderer->setTexture(fileName); - } - break; - case UI_TEX_TYPE_PLIST: - if (_scale9Enabled) - { - extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; - imageRendererScale9->initWithSpriteFrameName(fileName); - imageRendererScale9->setCapInsets(_capInsets); - } - else - { - Sprite* imageRenderer = STATIC_CAST_CCSPRITE; - imageRenderer->setSpriteFrame(fileName); - } - break; - default: - break; - } - _imageTextureSize = _imageRenderer->getContentSize(); - imageTextureScaleChangedWithSize(); - updateAnchorPoint(); - updateFlippedX(); - updateFlippedY(); - updateRGBAToRenderer(_imageRenderer); -} - -void ImageView::setTextureRect(const Rect &rect) -{ - if (_scale9Enabled) - { - } - else - { - STATIC_CAST_CCSPRITE->setTextureRect(rect); - } -} - -void ImageView::updateFlippedX() -{ - if (_scale9Enabled) - { - int flip = _flippedX ? -1 : 1; - STATIC_CAST_SCALE9SPRITE->setScaleX(flip); - } - else - { - STATIC_CAST_CCSPRITE->setFlippedX(_flippedX); - } -} - -void ImageView::updateFlippedY() -{ - if (_scale9Enabled) - { - int flip = _flippedY ? -1 : 1; - STATIC_CAST_SCALE9SPRITE->setScaleY(flip); - } - else - { - STATIC_CAST_CCSPRITE->setFlippedY(_flippedY); - } - -} - -void ImageView::setScale9Enabled(bool able) -{ - if (_scale9Enabled == able) - { - return; - } - - - _scale9Enabled = able; - Node::removeChild(_imageRenderer); - _imageRenderer = nullptr; - if (_scale9Enabled) - { - _imageRenderer = extension::Scale9Sprite::create(); - } - else - { - _imageRenderer = Sprite::create(); - } - loadTexture(_textureFile.c_str(),_imageTexType); - Node::addChild(_imageRenderer, IMAGE_RENDERER_Z, -1); - if (_scale9Enabled) - { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; - } - else - { - ignoreContentAdaptWithSize(_prevIgnoreSize); - } - setCapInsets(_capInsets); -} - -bool ImageView::isScale9Enabled() -{ - return _scale9Enabled; -} - -void ImageView::ignoreContentAdaptWithSize(bool ignore) -{ - if (!_scale9Enabled || (_scale9Enabled && !ignore)) - { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; - } -} - -void ImageView::setCapInsets(const Rect &capInsets) -{ - _capInsets = capInsets; - if (!_scale9Enabled) - { - return; - } - STATIC_CAST_SCALE9SPRITE->setCapInsets(capInsets); -} - -const Rect& ImageView::getCapInsets() -{ - return _capInsets; -} - -void ImageView::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _imageRenderer->setAnchorPoint(pt); -} - -void ImageView::onSizeChanged() -{ - Widget::onSizeChanged(); - imageTextureScaleChangedWithSize(); -} - -const Size& ImageView::getContentSize() const -{ - return _imageTextureSize; -} - -Node* ImageView::getVirtualRenderer() -{ - return _imageRenderer; -} - -void ImageView::imageTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - if (!_scale9Enabled) - { - _imageRenderer->setScale(1.0f); - _size = _imageTextureSize; - } - } - else - { - if (_scale9Enabled) - { - static_cast(_imageRenderer)->setPreferredSize(_size); - } - else - { - Size textureSize = _imageRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _imageRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _imageRenderer->setScaleX(scaleX); - _imageRenderer->setScaleY(scaleY); - } - } -} - -std::string ImageView::getDescription() const -{ - return "ImageView"; -} - -void ImageView::updateTextureColor() -{ - updateColorToRenderer(_imageRenderer); -} - -void ImageView::updateTextureOpacity() -{ - updateOpacityToRenderer(_imageRenderer); -} - -void ImageView::updateTextureRGBA() -{ - updateRGBAToRenderer(_imageRenderer); -} - -Widget* ImageView::createCloneInstance() -{ - return ImageView::create(); -} - -void ImageView::copySpecialProperties(Widget *widget) -{ - ImageView* imageView = dynamic_cast(widget); - if (imageView) - { - _prevIgnoreSize = imageView->_prevIgnoreSize; - setScale9Enabled(imageView->_scale9Enabled); - loadTexture(imageView->_textureFile.c_str(), imageView->_imageTexType); - setCapInsets(imageView->_capInsets); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UIImageView.h b/cocos/gui/UIImageView.h deleted file mode 100644 index 644372d9cc..0000000000 --- a/cocos/gui/UIImageView.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UIIMAGEVIEW_H__ -#define __UIIMAGEVIEW_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -/** -* @js NA -* @lua NA -*/ -class ImageView : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - ImageView(); - - /** - * Default destructor - */ - virtual ~ImageView(); - - /** - * Allocates and initializes. - */ - static ImageView* create(); - - /** - * Load texture for imageview. - * - * @param fileName file name of texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Updates the texture rect of the ImageView in points. - * It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size. - */ - void setTextureRect(const Rect& rect); - - /** - * Sets if imageview is using scale9 renderer. - * - * @param true that using scale9 renderer, false otherwise. - */ - void setScale9Enabled(bool able); - - bool isScale9Enabled(); - - /** - * Sets capinsets for imageview, if imageview is using scale9 renderer. - * - * @param capInsets capinsets for imageview - */ - void setCapInsets(const Rect &capInsets); - - const Rect& getCapInsets(); - - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - - //override "ignoreContentAdaptWithSize" method of widget. - virtual void ignoreContentAdaptWithSize(bool ignore) override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - virtual const Size& getContentSize() const override; - virtual Node* getVirtualRenderer() override; -protected: - virtual void initRenderer() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; - void imageTextureScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - bool _scale9Enabled; - bool _prevIgnoreSize; - Rect _capInsets; - Node* _imageRenderer; - std::string _textureFile; - TextureResType _imageTexType; - Size _imageTextureSize; -}; - -} - -NS_CC_END - -#endif /* defined(__CocoGUI__ImageView__) */ diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp deleted file mode 100644 index 7460c03723..0000000000 --- a/cocos/gui/UILayout.cpp +++ /dev/null @@ -1,1404 +0,0 @@ -/**************************************************************************** -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 "gui/UILayout.h" -#include "gui/UIHelper.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" -#include "kazmath/GL/matrix.h" -#include "CCGLProgram.h" -#include "CCShaderCache.h" -#include "CCDirector.h" -#include "CCDrawingPrimitives.h" -#include "renderer/CCRenderer.h" -#include "renderer/CCGroupCommand.h" -#include "renderer/CCCustomCommand.h" - -NS_CC_BEGIN - -namespace ui { - -static const int BACKGROUNDIMAGE_Z = (-1); -static const int BCAKGROUNDCOLORRENDERER_Z = (-2); - -static GLint g_sStencilBits = -1; -static GLint s_layer = -1; - -IMPLEMENT_CLASS_GUI_INFO(Layout) - -Layout::Layout(): -_clippingEnabled(false), -_backGroundScale9Enabled(false), -_backGroundImage(nullptr), -_backGroundImageFileName(""), -_backGroundImageCapInsets(Rect::ZERO), -_colorType(LAYOUT_COLOR_NONE), -_bgImageTexType(UI_TEX_TYPE_LOCAL), -_colorRender(nullptr), -_gradientRender(nullptr), -_cColor(Color3B::WHITE), -_gStartColor(Color3B::WHITE), -_gEndColor(Color3B::WHITE), -_alongVector(Point(0.0f, -1.0f)), -_cOpacity(255), -_backGroundImageTextureSize(Size::ZERO), -_layoutType(LAYOUT_ABSOLUTE), -_clippingType(LAYOUT_CLIPPING_STENCIL), -_clippingStencil(nullptr), -_scissorRectDirty(false), -_clippingRect(Rect::ZERO), -_clippingParent(nullptr), -_doLayoutDirty(true), -_clippingRectDirty(true), -_currentStencilEnabled(GL_FALSE), -_currentStencilWriteMask(~0), -_currentStencilFunc(GL_ALWAYS), -_currentStencilRef(0), -_currentStencilValueMask(~0), -_currentStencilFail(GL_KEEP), -_currentStencilPassDepthFail(GL_KEEP), -_currentStencilPassDepthPass(GL_KEEP), -_currentDepthWriteMask(GL_TRUE), -_currentAlphaTestEnabled(GL_FALSE), -_currentAlphaTestFunc(GL_ALWAYS), -_currentAlphaTestRef(1), -_backGroundImageColor(Color3B::WHITE), -_backGroundImageOpacity(255) -{ - _widgetType = WidgetTypeContainer; -} - -Layout::~Layout() -{ - CC_SAFE_RELEASE(_clippingStencil); -} - -void Layout::onEnter() -{ - Widget::onEnter(); - if (_clippingStencil) - { - _clippingStencil->onEnter(); - } - _doLayoutDirty = true; - _clippingRectDirty = true; -} - -void Layout::onExit() -{ - Widget::onExit(); - if (_clippingStencil) - { - _clippingStencil->onExit(); - } -} - -Layout* Layout::create() -{ - Layout* layout = new Layout(); - if (layout && layout->init()) - { - layout->autorelease(); - return layout; - } - CC_SAFE_DELETE(layout); - return nullptr; -} - -bool Layout::init() -{ - if (Node::init()) - { - initRenderer(); - setBright(true); - ignoreContentAdaptWithSize(false); - setSize(Size::ZERO); - setAnchorPoint(Point::ZERO); - return true; - } - return false; -} - -void Layout::addChild(Node *child) -{ - Widget::addChild(child); -} - -void Layout::addChild(Node * child, int zOrder) -{ - Widget::addChild(child, zOrder); -} - -void Layout::addChild(Node *child, int zOrder, int tag) -{ - supplyTheLayoutParameterLackToChild(static_cast(child)); - Widget::addChild(child, zOrder, tag); - _doLayoutDirty = true; -} - -void Layout::removeChild(Node *child, bool cleanup) -{ - Widget::removeChild(child, cleanup); - _doLayoutDirty = true; -} - -void Layout::removeAllChildren() -{ - Widget::removeAllChildren(); -} - -void Layout::removeAllChildrenWithCleanup(bool cleanup) -{ - Widget::removeAllChildrenWithCleanup(cleanup); - _doLayoutDirty = true; -} - -bool Layout::isClippingEnabled() -{ - return _clippingEnabled; -} - -bool Layout::hitTest(const Point &pt) -{ - Point nsp = convertToNodeSpace(pt); - Rect bb = Rect(0.0f, 0.0f, _size.width, _size.height); - if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) - { - return true; - } - return false; -} - -void Layout::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) -{ - if (!_enabled) - { - return; - } - if (_clippingEnabled) - { - switch (_clippingType) - { - case LAYOUT_CLIPPING_STENCIL: - stencilClippingVisit(renderer, parentTransform, parentTransformUpdated); - break; - case LAYOUT_CLIPPING_SCISSOR: - scissorClippingVisit(renderer, parentTransform, parentTransformUpdated); - break; - default: - break; - } - } - else - { - Node::visit(renderer, parentTransform, parentTransformUpdated); - } -} - -void Layout::sortAllChildren() -{ - Widget::sortAllChildren(); - doLayout(); -} - -void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) -{ - if(!_visible) - return; - - bool dirty = parentTransformUpdated || _transformUpdated; - if(dirty) - _modelViewTransform = transform(parentTransform); - _transformUpdated = false; - - // IMPORTANT: - // To ease the migration to v3.0, we still support the kmGL stack, - // but it is deprecated and your code should not rely on it - kmGLPushMatrix(); - kmGLLoadMatrix(&_modelViewTransform); - - //Add group command - - _groupCommand.init(_globalZOrder); - renderer->addCommand(&_groupCommand); - - renderer->pushGroup(_groupCommand.getRenderQueueID()); - - _beforeVisitCmdStencil.init(_globalZOrder); - _beforeVisitCmdStencil.func = CC_CALLBACK_0(Layout::onBeforeVisitStencil, this); - renderer->addCommand(&_beforeVisitCmdStencil); - - _clippingStencil->visit(renderer, _modelViewTransform, dirty); - - _afterDrawStencilCmd.init(_globalZOrder); - _afterDrawStencilCmd.func = CC_CALLBACK_0(Layout::onAfterDrawStencil, this); - renderer->addCommand(&_afterDrawStencilCmd); - - int i = 0; - - if(!_children.empty()) - { - sortAllChildren(); - // draw children zOrder < 0 - for( ; i < _children.size(); i++ ) - { - auto node = _children.at(i); - - if ( node && node->getLocalZOrder() < 0 ) - node->visit(renderer, _modelViewTransform, dirty); - else - break; - } - // self draw - this->draw(renderer, _modelViewTransform, dirty); - - for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) - (*it)->visit(renderer, _modelViewTransform, dirty); - } - else - { - this->draw(renderer, _modelViewTransform, dirty); - } - - _afterVisitCmdStencil.init(_globalZOrder); - _afterVisitCmdStencil.func = CC_CALLBACK_0(Layout::onAfterVisitStencil, this); - renderer->addCommand(&_afterVisitCmdStencil); - - renderer->popGroup(); - - kmGLPopMatrix(); -} - -void Layout::onBeforeVisitStencil() -{ - s_layer++; - GLint mask_layer = 0x1 << s_layer; - GLint mask_layer_l = mask_layer - 1; - _mask_layer_le = mask_layer | mask_layer_l; - _currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST); - glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)&_currentStencilWriteMask); - glGetIntegerv(GL_STENCIL_FUNC, (GLint *)&_currentStencilFunc); - glGetIntegerv(GL_STENCIL_REF, &_currentStencilRef); - glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)&_currentStencilValueMask); - glGetIntegerv(GL_STENCIL_FAIL, (GLint *)&_currentStencilFail); - glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)&_currentStencilPassDepthFail); - glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)&_currentStencilPassDepthPass); - - glEnable(GL_STENCIL_TEST); - CHECK_GL_ERROR_DEBUG(); - glStencilMask(mask_layer); - glGetBooleanv(GL_DEPTH_WRITEMASK, &_currentDepthWriteMask); - glDepthMask(GL_FALSE); - glStencilFunc(GL_NEVER, mask_layer, mask_layer); - glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPushMatrix(); - kmGLLoadIdentity(); - - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPushMatrix(); - kmGLLoadIdentity(); - - DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1)); - - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPopMatrix(); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPopMatrix(); - glStencilFunc(GL_NEVER, mask_layer, mask_layer); - glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP); -} - -void Layout::onAfterDrawStencil() -{ - glDepthMask(_currentDepthWriteMask); - glStencilFunc(GL_EQUAL, _mask_layer_le, _mask_layer_le); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); -} - - -void Layout::onAfterVisitStencil() -{ - glStencilFunc(_currentStencilFunc, _currentStencilRef, _currentStencilValueMask); - glStencilOp(_currentStencilFail, _currentStencilPassDepthFail, _currentStencilPassDepthPass); - glStencilMask(_currentStencilWriteMask); - if (!_currentStencilEnabled) - { - glDisable(GL_STENCIL_TEST); - } - s_layer--; -} - -void Layout::onBeforeVisitScissor() -{ - Rect clippingRect = getClippingRect(); - glEnable(GL_SCISSOR_TEST); - auto glview = Director::getInstance()->getOpenGLView(); - glview->setScissorInPoints(clippingRect.origin.x, clippingRect.origin.y, clippingRect.size.width, clippingRect.size.height); -} - -void Layout::onAfterVisitScissor() -{ - glDisable(GL_SCISSOR_TEST); -} - -void Layout::scissorClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated) -{ - _beforeVisitCmdScissor.init(_globalZOrder); - _beforeVisitCmdScissor.func = CC_CALLBACK_0(Layout::onBeforeVisitScissor, this); - renderer->addCommand(&_beforeVisitCmdScissor); - - Node::visit(renderer, parentTransform, parentTransformUpdated); - - _afterVisitCmdScissor.init(_globalZOrder); - _afterVisitCmdScissor.func = CC_CALLBACK_0(Layout::onAfterVisitScissor, this); - renderer->addCommand(&_afterVisitCmdScissor); -} - -void Layout::setClippingEnabled(bool able) -{ - if (able == _clippingEnabled) - { - return; - } - _clippingEnabled = able; - switch (_clippingType) - { - case LAYOUT_CLIPPING_STENCIL: - if (able) - { - static bool once = true; - if (once) - { - glGetIntegerv(GL_STENCIL_BITS, &g_sStencilBits); - if (g_sStencilBits <= 0) - { - CCLOG("Stencil buffer is not enabled."); - } - once = false; - } - _clippingStencil = DrawNode::create(); - if (_running) - { - _clippingStencil->onEnter(); - } - _clippingStencil->retain(); - setStencilClippingSize(_size); - } - else - { - if (_running) - { - _clippingStencil->onExit(); - } - _clippingStencil->release(); - _clippingStencil = nullptr; - } - break; - default: - break; - } -} - -void Layout::setClippingType(LayoutClippingType type) -{ - if (type == _clippingType) - { - return; - } - bool clippingEnabled = isClippingEnabled(); - setClippingEnabled(false); - _clippingType = type; - setClippingEnabled(clippingEnabled); -} - -LayoutClippingType Layout::getClippingType() -{ - return _clippingType; -} - -void Layout::setStencilClippingSize(const Size &size) -{ - if (_clippingEnabled && _clippingType == LAYOUT_CLIPPING_STENCIL) - { - Point rect[4]; - rect[0] = Point::ZERO; - rect[1] = Point(_size.width, 0); - rect[2] = Point(_size.width, _size.height); - rect[3] = Point(0, _size.height); - Color4F green(0, 1, 0, 1); - _clippingStencil->clear(); - _clippingStencil->drawPolygon(rect, 4, green, 0, green); - } -} - -const Rect& Layout::getClippingRect() -{ - if (_clippingRectDirty) - { - Point worldPos = convertToWorldSpace(Point::ZERO); - AffineTransform t = getNodeToWorldAffineTransform(); - float scissorWidth = _size.width*t.a; - float scissorHeight = _size.height*t.d; - Rect parentClippingRect; - Layout* parent = this; - bool firstClippingParentFounded = false; - while (parent) - { - parent = dynamic_cast(parent->getParent()); - if(parent) - { - if (parent->isClippingEnabled()) - { - if (!firstClippingParentFounded) - { - _clippingParent = parent; - firstClippingParentFounded = true; - break; - } - } - } - } - - if (_clippingParent) - { - parentClippingRect = _clippingParent->getClippingRect(); - float finalX = worldPos.x - (scissorWidth * _anchorPoint.x); - float finalY = worldPos.y - (scissorHeight * _anchorPoint.y); - float finalWidth = scissorWidth; - float finalHeight = scissorHeight; - - float leftOffset = worldPos.x - parentClippingRect.origin.x; - if (leftOffset < 0.0f) - { - finalX = parentClippingRect.origin.x; - finalWidth += leftOffset; - } - float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width); - if (rightOffset > 0.0f) - { - finalWidth -= rightOffset; - } - float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height); - if (topOffset > 0.0f) - { - finalHeight -= topOffset; - } - float bottomOffset = worldPos.y - parentClippingRect.origin.y; - if (bottomOffset < 0.0f) - { - finalY = parentClippingRect.origin.x; - finalHeight += bottomOffset; - } - if (finalWidth < 0.0f) - { - finalWidth = 0.0f; - } - if (finalHeight < 0.0f) - { - finalHeight = 0.0f; - } - _clippingRect.origin.x = finalX; - _clippingRect.origin.y = finalY; - _clippingRect.size.width = finalWidth; - _clippingRect.size.height = finalHeight; - } - else - { - _clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x); - _clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y); - _clippingRect.size.width = scissorWidth; - _clippingRect.size.height = scissorHeight; - } - _clippingRectDirty = false; - } - return _clippingRect; -} - -void Layout::onSizeChanged() -{ - Widget::onSizeChanged(); - setContentSize(_size); - setStencilClippingSize(_size); - _doLayoutDirty = true; - _clippingRectDirty = true; - if (_backGroundImage) - { - _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); - if (_backGroundScale9Enabled && _backGroundImage) - { - static_cast(_backGroundImage)->setPreferredSize(_size); - } - } - if (_colorRender) - { - _colorRender->setContentSize(_size); - } - if (_gradientRender) - { - _gradientRender->setContentSize(_size); - } -} - -void Layout::setBackGroundImageScale9Enabled(bool able) -{ - if (_backGroundScale9Enabled == able) - { - return; - } - Node::removeChild(_backGroundImage); - _backGroundImage = nullptr; - _backGroundScale9Enabled = able; - if (_backGroundScale9Enabled) - { - _backGroundImage = extension::Scale9Sprite::create(); - Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); - } - else - { - _backGroundImage = Sprite::create(); - Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); - } - setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType); - setBackGroundImageCapInsets(_backGroundImageCapInsets); -} - -bool Layout::isBackGroundImageScale9Enabled() -{ - return _backGroundScale9Enabled; -} - -void Layout::setBackGroundImage(const char* fileName,TextureResType texType) -{ - if (!fileName || strcmp(fileName, "") == 0) - { - return; - } - if (_backGroundImage == nullptr) - { - addBackGroundImage(); - } - _backGroundImageFileName = fileName; - _bgImageTexType = texType; - if (_backGroundScale9Enabled) - { - extension::Scale9Sprite* bgiScale9 = static_cast(_backGroundImage); - switch (_bgImageTexType) - { - case UI_TEX_TYPE_LOCAL: - bgiScale9->initWithFile(fileName); - break; - case UI_TEX_TYPE_PLIST: - bgiScale9->initWithSpriteFrameName(fileName); - break; - default: - break; - } - bgiScale9->setPreferredSize(_size); - } - else - { - switch (_bgImageTexType) - { - case UI_TEX_TYPE_LOCAL: - static_cast(_backGroundImage)->setTexture(fileName); - break; - case UI_TEX_TYPE_PLIST: - static_cast(_backGroundImage)->setSpriteFrame(fileName); - break; - default: - break; - } - } - _backGroundImageTextureSize = _backGroundImage->getContentSize(); - _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); - updateBackGroundImageRGBA(); -} - -void Layout::setBackGroundImageCapInsets(const Rect &capInsets) -{ - _backGroundImageCapInsets = capInsets; - if (_backGroundScale9Enabled && _backGroundImage) - { - static_cast(_backGroundImage)->setCapInsets(capInsets); - } -} - -const Rect& Layout::getBackGroundImageCapInsets() -{ - return _backGroundImageCapInsets; -} - -void Layout::supplyTheLayoutParameterLackToChild(Widget *child) -{ - if (!child) - { - return; - } - switch (_layoutType) - { - case LAYOUT_ABSOLUTE: - break; - case LAYOUT_LINEAR_HORIZONTAL: - case LAYOUT_LINEAR_VERTICAL: - { - LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); - if (!layoutParameter) - { - child->setLayoutParameter(LinearLayoutParameter::create()); - } - break; - } - case LAYOUT_RELATIVE: - { - RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); - if (!layoutParameter) - { - child->setLayoutParameter(RelativeLayoutParameter::create()); - } - break; - } - default: - break; - } -} - -void Layout::addBackGroundImage() -{ - if (_backGroundScale9Enabled) - { - _backGroundImage = extension::Scale9Sprite::create(); - _backGroundImage->setLocalZOrder(-1); - Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); - static_cast(_backGroundImage)->setPreferredSize(_size); - } - else - { - _backGroundImage = Sprite::create(); - _backGroundImage->setLocalZOrder(-1); - Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); - } - _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); -} - -void Layout::removeBackGroundImage() -{ - if (!_backGroundImage) - { - return; - } - Node::removeChild(_backGroundImage); - _backGroundImage = nullptr; - _backGroundImageFileName = ""; - _backGroundImageTextureSize = Size::ZERO; -} - -void Layout::setBackGroundColorType(LayoutBackGroundColorType type) -{ - if (_colorType == type) - { - return; - } - switch (_colorType) - { - case LAYOUT_COLOR_NONE: - if (_colorRender) - { - Node::removeChild(_colorRender); - _colorRender = nullptr; - } - if (_gradientRender) - { - Node::removeChild(_gradientRender); - _gradientRender = nullptr; - } - break; - case LAYOUT_COLOR_SOLID: - if (_colorRender) - { - Node::removeChild(_colorRender); - _colorRender = nullptr; - } - break; - case LAYOUT_COLOR_GRADIENT: - if (_gradientRender) - { - Node::removeChild(_gradientRender); - _gradientRender = nullptr; - } - break; - default: - break; - } - _colorType = type; - switch (_colorType) - { - case LAYOUT_COLOR_NONE: - break; - case LAYOUT_COLOR_SOLID: - _colorRender = LayerColor::create(); - _colorRender->setContentSize(_size); - _colorRender->setOpacity(_cOpacity); - _colorRender->setColor(_cColor); - Node::addChild(_colorRender, BCAKGROUNDCOLORRENDERER_Z, -1); - break; - case LAYOUT_COLOR_GRADIENT: - _gradientRender = LayerGradient::create(); - _gradientRender->setContentSize(_size); - _gradientRender->setOpacity(_cOpacity); - _gradientRender->setStartColor(_gStartColor); - _gradientRender->setEndColor(_gEndColor); - _gradientRender->setVector(_alongVector); - Node::addChild(_gradientRender, BCAKGROUNDCOLORRENDERER_Z, -1); - break; - default: - break; - } -} - -LayoutBackGroundColorType Layout::getBackGroundColorType() -{ - return _colorType; -} - -void Layout::setBackGroundColor(const Color3B &color) -{ - _cColor = color; - if (_colorRender) - { - _colorRender->setColor(color); - } -} - -const Color3B& Layout::getBackGroundColor() -{ - return _cColor; -} - -void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endColor) -{ - _gStartColor = startColor; - if (_gradientRender) - { - _gradientRender->setStartColor(startColor); - } - _gEndColor = endColor; - if (_gradientRender) - { - _gradientRender->setEndColor(endColor); - } -} - -const Color3B& Layout::getBackGroundStartColor() -{ - return _gStartColor; -} - -const Color3B& Layout::getBackGroundEndColor() -{ - return _gEndColor; -} - -void Layout::setBackGroundColorOpacity(GLubyte opacity) -{ - _cOpacity = opacity; - switch (_colorType) - { - case LAYOUT_COLOR_NONE: - break; - case LAYOUT_COLOR_SOLID: - _colorRender->setOpacity(opacity); - break; - case LAYOUT_COLOR_GRADIENT: - _gradientRender->setOpacity(opacity); - break; - default: - break; - } -} - -GLubyte Layout::getBackGroundColorOpacity() -{ - return _cOpacity; -} - -void Layout::setBackGroundColorVector(const Point &vector) -{ - _alongVector = vector; - if (_gradientRender) - { - _gradientRender->setVector(vector); - } -} - -const Point& Layout::getBackGroundColorVector() -{ - return _alongVector; -} - -void Layout::setBackGroundImageColor(const Color3B &color) -{ - _backGroundImageColor = color; - updateBackGroundImageColor(); -} - -void Layout::setBackGroundImageOpacity(GLubyte opacity) -{ - _backGroundImageOpacity = opacity; - updateBackGroundImageOpacity(); -} - -const Color3B& Layout::getBackGroundImageColor() -{ - return _backGroundImageColor; -} - -GLubyte Layout::getBackGroundImageOpacity() -{ - return _backGroundImageOpacity; -} - -void Layout::updateBackGroundImageColor() -{ - if (_backGroundImage) - { - _backGroundImage->setColor(_backGroundImageColor); - } -} - -void Layout::updateBackGroundImageOpacity() -{ - if (_backGroundImage) - { - _backGroundImage->setOpacity(_backGroundImageOpacity); - } -} - -void Layout::updateBackGroundImageRGBA() -{ - if (_backGroundImage) - { - _backGroundImage->setColor(_backGroundImageColor); - _backGroundImage->setOpacity(_backGroundImageOpacity); - } -} - -const Size& Layout::getBackGroundImageTextureSize() const -{ - return _backGroundImageTextureSize; -} - -void Layout::setLayoutType(LayoutType type) -{ - _layoutType = type; - for (auto& child : _widgetChildren) - { - if (child) - { - supplyTheLayoutParameterLackToChild(static_cast(child)); - } - } - _doLayoutDirty = true; -} - -LayoutType Layout::getLayoutType() const -{ - return _layoutType; -} - -void Layout::requestDoLayout() -{ - _doLayoutDirty = true; -} - -void Layout::doLayout() -{ - if (!_doLayoutDirty) - { - return; - } - switch (_layoutType) - { - case LAYOUT_ABSOLUTE: - break; - case LAYOUT_LINEAR_VERTICAL: - { - Size layoutSize = getSize(); - float topBoundary = layoutSize.height; - - for (auto& subWidget : _widgetChildren) - { - Widget* child = static_cast(subWidget); - LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); - - if (layoutParameter) - { - LinearGravity childGravity = layoutParameter->getGravity(); - Point ap = child->getAnchorPoint(); - Size cs = child->getSize(); - float finalPosX = ap.x * cs.width; - float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height); - switch (childGravity) - { - case LINEAR_GRAVITY_NONE: - case LINEAR_GRAVITY_LEFT: - break; - case LINEAR_GRAVITY_RIGHT: - finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); - break; - case LINEAR_GRAVITY_CENTER_HORIZONTAL: - finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x); - break; - default: - break; - } - Margin mg = layoutParameter->getMargin(); - finalPosX += mg.left; - finalPosY -= mg.top; - child->setPosition(Point(finalPosX, finalPosY)); - topBoundary = child->getBottomInParent() - mg.bottom; - } - } - break; - } - case LAYOUT_LINEAR_HORIZONTAL: - { - Size layoutSize = getSize(); - float leftBoundary = 0.0f; - for (auto& subWidget : _widgetChildren) - { - Widget* child = static_cast(subWidget); - LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); - - if (layoutParameter) - { - LinearGravity childGravity = layoutParameter->getGravity(); - Point ap = child->getAnchorPoint(); - Size cs = child->getSize(); - float finalPosX = leftBoundary + (ap.x * cs.width); - float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height; - switch (childGravity) - { - case LINEAR_GRAVITY_NONE: - case LINEAR_GRAVITY_TOP: - break; - case LINEAR_GRAVITY_BOTTOM: - finalPosY = ap.y * cs.height; - break; - case LINEAR_GRAVITY_CENTER_VERTICAL: - finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y); - break; - default: - break; - } - Margin mg = layoutParameter->getMargin(); - finalPosX += mg.left; - finalPosY -= mg.top; - child->setPosition(Point(finalPosX, finalPosY)); - leftBoundary = child->getRightInParent() + mg.right; - } - } - break; - } - case LAYOUT_RELATIVE: - { - ssize_t unlayoutChildCount = _widgetChildren.size(); - Size layoutSize = getSize(); - for (auto& subWidget : _widgetChildren) - { - Widget* child = static_cast(subWidget); - RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); - layoutParameter->_put = false; - } - while (unlayoutChildCount > 0) - { - for (auto& subWidget : _widgetChildren) - { - Widget* child = static_cast(subWidget); - RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); - - if (layoutParameter) - { - if (layoutParameter->_put) - { - continue; - } - Point ap = child->getAnchorPoint(); - Size cs = child->getSize(); - RelativeAlign align = layoutParameter->getAlign(); - const char* relativeName = layoutParameter->getRelativeToWidgetName(); - Widget* relativeWidget = nullptr; - RelativeLayoutParameter* relativeWidgetLP = nullptr; - float finalPosX = 0.0f; - float finalPosY = 0.0f; - if (relativeName && strcmp(relativeName, "")) - { - relativeWidget = Helper::seekWidgetByRelativeName(this, relativeName); - if (relativeWidget) - { - relativeWidgetLP = dynamic_cast(relativeWidget->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); - } - } - switch (align) - { - case RELATIVE_ALIGN_NONE: - case RELATIVE_ALIGN_PARENT_TOP_LEFT: - finalPosX = ap.x * cs.width; - finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height); - break; - case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL: - finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x); - finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height); - break; - case RELATIVE_ALIGN_PARENT_TOP_RIGHT: - finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); - finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height); - break; - case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL: - finalPosX = ap.x * cs.width; - finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y); - break; - case RELATIVE_CENTER_IN_PARENT: - finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x); - finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y); - break; - case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL: - finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); - finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y); - break; - case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM: - finalPosX = ap.x * cs.width; - finalPosY = ap.y * cs.height; - break; - case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL: - finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x); - finalPosY = ap.y * cs.height; - break; - case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM: - finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); - finalPosY = ap.y * cs.height; - break; - - case RELATIVE_LOCATION_ABOVE_LEFTALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationBottom = relativeWidget->getTopInParent(); - float locationLeft = relativeWidget->getLeftInParent(); - finalPosY = locationBottom + ap.y * cs.height; - finalPosX = locationLeft + ap.x * cs.width; - } - break; - case RELATIVE_LOCATION_ABOVE_CENTER: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - Size rbs = relativeWidget->getSize(); - float locationBottom = relativeWidget->getTopInParent(); - - finalPosY = locationBottom + ap.y * cs.height; - finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f; - } - break; - case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationBottom = relativeWidget->getTopInParent(); - float locationRight = relativeWidget->getRightInParent(); - finalPosY = locationBottom + ap.y * cs.height; - finalPosX = locationRight - (1.0f - ap.x) * cs.width; - } - break; - case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationTop = relativeWidget->getTopInParent(); - float locationRight = relativeWidget->getLeftInParent(); - finalPosY = locationTop - (1.0f - ap.y) * cs.height; - finalPosX = locationRight - (1.0f - ap.x) * cs.width; - } - break; - case RELATIVE_LOCATION_LEFT_OF_CENTER: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - Size rbs = relativeWidget->getSize(); - float locationRight = relativeWidget->getLeftInParent(); - finalPosX = locationRight - (1.0f - ap.x) * cs.width; - - finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f; - } - break; - case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationBottom = relativeWidget->getBottomInParent(); - float locationRight = relativeWidget->getLeftInParent(); - finalPosY = locationBottom + ap.y * cs.height; - finalPosX = locationRight - (1.0f - ap.x) * cs.width; - } - break; - case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationTop = relativeWidget->getTopInParent(); - float locationLeft = relativeWidget->getRightInParent(); - finalPosY = locationTop - (1.0f - ap.y) * cs.height; - finalPosX = locationLeft + ap.x * cs.width; - } - break; - case RELATIVE_LOCATION_RIGHT_OF_CENTER: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - Size rbs = relativeWidget->getSize(); - float locationLeft = relativeWidget->getRightInParent(); - finalPosX = locationLeft + ap.x * cs.width; - - finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f; - } - break; - case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationBottom = relativeWidget->getBottomInParent(); - float locationLeft = relativeWidget->getRightInParent(); - finalPosY = locationBottom + ap.y * cs.height; - finalPosX = locationLeft + ap.x * cs.width; - } - break; - case RELATIVE_LOCATION_BELOW_LEFTALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationTop = relativeWidget->getBottomInParent(); - float locationLeft = relativeWidget->getLeftInParent(); - finalPosY = locationTop - (1.0f - ap.y) * cs.height; - finalPosX = locationLeft + ap.x * cs.width; - } - break; - case RELATIVE_LOCATION_BELOW_CENTER: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - Size rbs = relativeWidget->getSize(); - float locationTop = relativeWidget->getBottomInParent(); - - finalPosY = locationTop - (1.0f - ap.y) * cs.height; - finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f; - } - break; - case RELATIVE_LOCATION_BELOW_RIGHTALIGN: - if (relativeWidget) - { - if (relativeWidgetLP && !relativeWidgetLP->_put) - { - continue; - } - float locationTop = relativeWidget->getBottomInParent(); - float locationRight = relativeWidget->getRightInParent(); - finalPosY = locationTop - (1.0f - ap.y) * cs.height; - finalPosX = locationRight - (1.0f - ap.x) * cs.width; - } - break; - default: - break; - } - Margin relativeWidgetMargin; - Margin mg = layoutParameter->getMargin(); - if (relativeWidgetLP) - { - relativeWidgetMargin = relativeWidgetLP->getMargin(); - } - //handle margin - switch (align) - { - case RELATIVE_ALIGN_NONE: - case RELATIVE_ALIGN_PARENT_TOP_LEFT: - finalPosX += mg.left; - finalPosY -= mg.top; - break; - case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL: - finalPosY -= mg.top; - break; - case RELATIVE_ALIGN_PARENT_TOP_RIGHT: - finalPosX -= mg.right; - finalPosY -= mg.top; - break; - case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL: - finalPosX += mg.left; - break; - case RELATIVE_CENTER_IN_PARENT: - break; - case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL: - finalPosX -= mg.right; - break; - case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM: - finalPosX += mg.left; - finalPosY += mg.bottom; - break; - case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL: - finalPosY += mg.bottom; - break; - case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM: - finalPosX -= mg.right; - finalPosY += mg.bottom; - break; - - case RELATIVE_LOCATION_ABOVE_LEFTALIGN: - finalPosY += mg.bottom; - finalPosX += mg.left; - break; - case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: - finalPosY += mg.bottom; - finalPosX -= mg.right; - break; - case RELATIVE_LOCATION_ABOVE_CENTER: - finalPosY += mg.bottom; - break; - - case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: - finalPosX -= mg.right; - finalPosY -= mg.top; - break; - case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: - finalPosX -= mg.right; - finalPosY += mg.bottom; - break; - case RELATIVE_LOCATION_LEFT_OF_CENTER: - finalPosX -= mg.right; - break; - - case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: - finalPosX += mg.left; - finalPosY -= mg.top; - break; - case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: - finalPosX += mg.left; - finalPosY += mg.bottom; - break; - case RELATIVE_LOCATION_RIGHT_OF_CENTER: - finalPosX += mg.left; - break; - - case RELATIVE_LOCATION_BELOW_LEFTALIGN: - finalPosY -= mg.top; - finalPosX += mg.left; - break; - case RELATIVE_LOCATION_BELOW_RIGHTALIGN: - finalPosY -= mg.top; - finalPosX -= mg.right; - break; - case RELATIVE_LOCATION_BELOW_CENTER: - finalPosY -= mg.top; - break; - default: - break; - } - child->setPosition(Point(finalPosX, finalPosY)); - layoutParameter->_put = true; - unlayoutChildCount--; - } - } - } - break; - } - default: - break; - } - _doLayoutDirty = false; -} - -std::string Layout::getDescription() const -{ - return "Layout"; -} - -Widget* Layout::createCloneInstance() -{ - return Layout::create(); -} - -void Layout::copyClonedWidgetChildren(Widget* model) -{ - Widget::copyClonedWidgetChildren(model); -} - -void Layout::copySpecialProperties(Widget *widget) -{ - Layout* layout = dynamic_cast(widget); - if (layout) - { - setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled); - setBackGroundImage(layout->_backGroundImageFileName.c_str(),layout->_bgImageTexType); - setBackGroundImageCapInsets(layout->_backGroundImageCapInsets); - setBackGroundColorType(layout->_colorType); - setBackGroundColor(layout->_cColor); - setBackGroundColor(layout->_gStartColor, layout->_gEndColor); - setBackGroundColorOpacity(layout->_cOpacity); - setBackGroundColorVector(layout->_alongVector); - setLayoutType(layout->_layoutType); - setClippingEnabled(layout->_clippingEnabled); - setClippingType(layout->_clippingType); - } -} -} -NS_CC_END diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h deleted file mode 100644 index 479e14bee1..0000000000 --- a/cocos/gui/UILayout.h +++ /dev/null @@ -1,358 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __LAYOUT_H__ -#define __LAYOUT_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - LAYOUT_COLOR_NONE, - LAYOUT_COLOR_SOLID, - LAYOUT_COLOR_GRADIENT -}LayoutBackGroundColorType; - -typedef enum -{ - LAYOUT_ABSOLUTE, - LAYOUT_LINEAR_VERTICAL, - LAYOUT_LINEAR_HORIZONTAL, - LAYOUT_RELATIVE -}LayoutType; - -typedef enum { - LAYOUT_CLIPPING_STENCIL, - LAYOUT_CLIPPING_SCISSOR -}LayoutClippingType; - -/** - * @js NA - * @lua NA - */ -class Layout : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - Layout(); - - /** - * Default destructor - */ - virtual ~Layout(); - - /** - * Allocates and initializes a layout. - */ - static Layout* create(); - - //background - /** - * Sets a background image for layout - * - * @param fileName image file path. - * - * @param texType @see TextureResType. UI_TEX_TYPE_LOCAL means local file, UI_TEX_TYPE_PLIST means sprite frame. - */ - void setBackGroundImage(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Sets a background image capinsets for layout, if the background image is a scale9 render. - * - * @param capinsets of background image. - * - */ - void setBackGroundImageCapInsets(const Rect& capInsets); - - const Rect& getBackGroundImageCapInsets(); - - /** - * Sets Color Type for layout. - * - * @param type @see LayoutBackGroundColorType. - */ - void setBackGroundColorType(LayoutBackGroundColorType type); - - LayoutBackGroundColorType getBackGroundColorType(); - - /** - * Sets background iamge use scale9 renderer. - * - * @param enabled true that use scale9 renderer, false otherwise. - */ - void setBackGroundImageScale9Enabled(bool enabled); - - bool isBackGroundImageScale9Enabled(); - - /** - * Sets background color for layout, if color type is LAYOUT_COLOR_SOLID - * - * @param color - */ - void setBackGroundColor(const Color3B &color); - - const Color3B& getBackGroundColor(); - - /** - * Sets background color for layout, if color type is LAYOUT_COLOR_GRADIENT - * - * @param start color - * - * @param end color - */ - void setBackGroundColor(const Color3B &startColor, const Color3B &endColor); - - const Color3B& getBackGroundStartColor(); - - const Color3B& getBackGroundEndColor(); - - /** - * Sets background opacity layout. - * - * @param opacity - */ - void setBackGroundColorOpacity(GLubyte opacity); - - GLubyte getBackGroundColorOpacity(); - - /** - * Sets background color vector for layout, if color type is LAYOUT_COLOR_GRADIENT - * - * @param vector - */ - void setBackGroundColorVector(const Point &vector); - - const Point& getBackGroundColorVector(); - - void setBackGroundImageColor(const ccColor3B& color); - - void setBackGroundImageOpacity(GLubyte opacity); - - const ccColor3B& getBackGroundImageColor(); - - GLubyte getBackGroundImageOpacity(); - - /** - * Remove the background image of layout. - */ - void removeBackGroundImage(); - - /** - * Gets background image texture size. - * - * @return background image texture size. - */ - const Size& getBackGroundImageTextureSize() const; - - /** - * Changes if layout can clip it's content and child. - * - * If you really need this, please enable it. But it would reduce the rendering efficiency. - * - * @param clipping enabled. - */ - virtual void setClippingEnabled(bool enabled); - - void setClippingType(LayoutClippingType type); - - LayoutClippingType getClippingType(); - - /** - * Gets if layout is clipping enabled. - * - * @return if layout is clipping enabled. - */ - virtual bool isClippingEnabled(); - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - /** - * Sets LayoutType. - * - * @see LayoutType - * - * @param LayoutType - */ - virtual void setLayoutType(LayoutType type); - - /** - * Gets LayoutType. - * - * @see LayoutType - * - * @return LayoutType - */ - virtual LayoutType getLayoutType() const; - - virtual void addChild(Node * child) override; - /** - * Adds a child to the container with a z-order - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - */ - virtual void addChild(Node * child, int zOrder) override; - /** - * Adds a child to the container with z order and tag - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - * @param tag A interger to identify the node easily. Please refer to setTag(int) - */ - virtual void addChild(Node* child, int zOrder, int tag) override; - - virtual void visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; - - virtual void removeChild(Node* child, bool cleanup = true) override; - - /** - * Removes all children from the container with a cleanup. - * - * @see `removeAllChildrenWithCleanup(bool)` - */ - virtual void removeAllChildren() override; - /** - * Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. - * - * @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise. - * @js removeAllChildren - * @lua removeAllChildren - */ - virtual void removeAllChildrenWithCleanup(bool cleanup) override; - - virtual void sortAllChildren() override; - - void requestDoLayout(); - - virtual void onEnter() override; - virtual void onExit() override; - - virtual bool hitTest(const Point &pt); -protected: - //override "init" method of widget. - virtual bool init() override; - - //override "onSizeChanged" method of widget. - virtual void onSizeChanged() override; - - //init background image renderer. - void addBackGroundImage(); - - void supplyTheLayoutParameterLackToChild(Widget* child); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; - virtual void copyClonedWidgetChildren(Widget* model) override; - - void stencilClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated); - void scissorClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated); - - void setStencilClippingSize(const Size& size); - const Rect& getClippingRect(); - virtual void doLayout(); - - //clipping - void onBeforeVisitStencil(); - void onAfterDrawStencil(); - void onAfterVisitStencil(); - - void onBeforeVisitScissor(); - void onAfterVisitScissor(); - void updateBackGroundImageColor(); - void updateBackGroundImageOpacity(); - void updateBackGroundImageRGBA(); -protected: - bool _clippingEnabled; - - //background - bool _backGroundScale9Enabled; - Node* _backGroundImage; - std::string _backGroundImageFileName; - Rect _backGroundImageCapInsets; - LayoutBackGroundColorType _colorType; - TextureResType _bgImageTexType; - LayerColor* _colorRender; - LayerGradient* _gradientRender; - Color3B _cColor; - Color3B _gStartColor; - Color3B _gEndColor; - Point _alongVector; - GLubyte _cOpacity; - Size _backGroundImageTextureSize; - LayoutType _layoutType; - LayoutClippingType _clippingType; - DrawNode* _clippingStencil; - bool _scissorRectDirty; - Rect _clippingRect; - Layout* _clippingParent; - bool _doLayoutDirty; - bool _clippingRectDirty; - - //clipping - - GLboolean _currentStencilEnabled; - GLuint _currentStencilWriteMask; - GLenum _currentStencilFunc; - GLint _currentStencilRef; - GLuint _currentStencilValueMask; - GLenum _currentStencilFail; - GLenum _currentStencilPassDepthFail; - GLenum _currentStencilPassDepthPass; - GLboolean _currentDepthWriteMask; - - GLboolean _currentAlphaTestEnabled; - GLenum _currentAlphaTestFunc; - GLclampf _currentAlphaTestRef; - - - Color3B _backGroundImageColor; - GLubyte _backGroundImageOpacity; - - GLint _mask_layer_le; - GroupCommand _groupCommand; - CustomCommand _beforeVisitCmdStencil; - CustomCommand _afterDrawStencilCmd; - CustomCommand _afterVisitCmdStencil; - CustomCommand _beforeVisitCmdScissor; - CustomCommand _afterVisitCmdScissor; -}; - -} -NS_CC_END -#endif /* defined(__Layout__) */ diff --git a/cocos/gui/UILayoutDefine.cpp b/cocos/gui/UILayoutDefine.cpp deleted file mode 100644 index b1cc88d46b..0000000000 --- a/cocos/gui/UILayoutDefine.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -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 "UILayoutDefine.h" - -NS_CC_BEGIN - -namespace ui { - - -Margin::Margin(void) : left(0), top(0), right(0), bottom(0) -{ -} - -Margin::Margin(float l, float t, float r, float b) : left(l), top(t), right(r), bottom(b) -{ -} - -Margin::Margin(const Margin& other) : left(other.left), top(other.top), right(other.right), bottom(other.bottom) -{ -} - -Margin& Margin::operator= (const Margin& other) -{ - setMargin(other.left, other.top, other.right, other.bottom); - return *this; -} - -void Margin::setMargin(float l, float t, float r, float b) -{ - left = l; - top = t; - right = r; - bottom = b; -} - -bool Margin::equals(const Margin &target) const -{ - return (left == target.left && top == target.top && right == target.right && bottom == target.bottom); -} - -} - -NS_CC_END diff --git a/cocos/gui/UILayoutDefine.h b/cocos/gui/UILayoutDefine.h deleted file mode 100644 index dc1af74a65..0000000000 --- a/cocos/gui/UILayoutDefine.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UILAYOUTDEFINE_H__ -#define __UILAYOUTDEFINE_H__ - -#include "cocos2d.h" - -NS_CC_BEGIN - -namespace ui { -/** -* @js NA -* @lua NA -*/ -class Margin -{ -public: - float left; - float top; - float right; - float bottom; - -public: - Margin(); - Margin(float l, float t, float r, float b); - Margin(const Margin& other); - Margin& operator= (const Margin& other); - void setMargin(float l, float t, float r, float b); - bool equals(const Margin& target) const; -}; - -const Margin MarginZero = Margin(); - -typedef enum -{ - LINEAR_GRAVITY_NONE, - LINEAR_GRAVITY_LEFT, - LINEAR_GRAVITY_TOP, - LINEAR_GRAVITY_RIGHT, - LINEAR_GRAVITY_BOTTOM, - LINEAR_GRAVITY_CENTER_VERTICAL, - LINEAR_GRAVITY_CENTER_HORIZONTAL -}LinearGravity; - -typedef enum -{ - RELATIVE_ALIGN_NONE, - RELATIVE_ALIGN_PARENT_TOP_LEFT, - RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL, - RELATIVE_ALIGN_PARENT_TOP_RIGHT, - RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL, - RELATIVE_CENTER_IN_PARENT, - RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL, - RELATIVE_ALIGN_PARENT_LEFT_BOTTOM, - RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL, - RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM, - - RELATIVE_LOCATION_ABOVE_LEFTALIGN, - RELATIVE_LOCATION_ABOVE_CENTER, - RELATIVE_LOCATION_ABOVE_RIGHTALIGN, - RELATIVE_LOCATION_LEFT_OF_TOPALIGN, - RELATIVE_LOCATION_LEFT_OF_CENTER, - RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN, - RELATIVE_LOCATION_RIGHT_OF_TOPALIGN, - RELATIVE_LOCATION_RIGHT_OF_CENTER, - RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN, - RELATIVE_LOCATION_BELOW_LEFTALIGN, - RELATIVE_LOCATION_BELOW_CENTER, - RELATIVE_LOCATION_BELOW_RIGHTALIGN -}RelativeAlign; - -} -NS_CC_END -#endif /* defined(__UILayoutDefine__) */ diff --git a/cocos/gui/UILayoutParameter.cpp b/cocos/gui/UILayoutParameter.cpp deleted file mode 100644 index 93ba0edf31..0000000000 --- a/cocos/gui/UILayoutParameter.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** - 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 "gui/UILayoutParameter.h" -#include "gui/UILayout.h" - -NS_CC_BEGIN - -namespace ui { - - -LayoutParameter* LayoutParameter::create() -{ - LayoutParameter* parameter = new LayoutParameter(); - if (parameter) - { - parameter->autorelease(); - return parameter; - } - CC_SAFE_DELETE(parameter); - return nullptr; -} - -void LayoutParameter::setMargin(const Margin &margin) -{ - _margin = margin; -} - -const Margin& LayoutParameter::getMargin() const -{ - return _margin; -} - -LayoutParameterType LayoutParameter::getLayoutType() const -{ - return _layoutParameterType; -} - -LayoutParameter* LayoutParameter::clone() -{ - LayoutParameter* clonedParameter = createCloneInstance(); - clonedParameter->copyProperties(this); - return clonedParameter; -} - -LayoutParameter* LayoutParameter::createCloneInstance() -{ - return LayoutParameter::create(); -} - -void LayoutParameter::copyProperties(LayoutParameter *model) -{ - _margin = model->_margin; -} - -LinearLayoutParameter* LinearLayoutParameter::create() -{ - LinearLayoutParameter* parameter = new LinearLayoutParameter(); - if (parameter) - { - parameter->autorelease(); - return parameter; - } - CC_SAFE_DELETE(parameter); - return nullptr; -} - -void LinearLayoutParameter::setGravity(LinearGravity gravity) -{ - _linearGravity = gravity; -} - -LinearGravity LinearLayoutParameter::getGravity() const -{ - return _linearGravity; -} - -LayoutParameter* LinearLayoutParameter::createCloneInstance() -{ - return LinearLayoutParameter::create(); -} - -void LinearLayoutParameter::copyProperties(LayoutParameter *model) -{ - LayoutParameter::copyProperties(model); - LinearLayoutParameter* parameter = dynamic_cast(model); - if (parameter) - { - setGravity(parameter->_linearGravity); - } -} - -RelativeLayoutParameter* RelativeLayoutParameter::create() -{ - RelativeLayoutParameter* parameter = new RelativeLayoutParameter(); - if (parameter) - { - parameter->autorelease(); - return parameter; - } - CC_SAFE_DELETE(parameter); - return nullptr; -} - -void RelativeLayoutParameter::setAlign(RelativeAlign align) -{ - _relativeAlign = align; -} - -RelativeAlign RelativeLayoutParameter::getAlign() const -{ - return _relativeAlign; -} - -void RelativeLayoutParameter::setRelativeToWidgetName(const char *name) -{ - _relativeWidgetName = name; -} - -const char* RelativeLayoutParameter::getRelativeToWidgetName() const -{ - return _relativeWidgetName.c_str(); -} - -void RelativeLayoutParameter::setRelativeName(const char* name) -{ - _relativeLayoutName = name; -} - -const char* RelativeLayoutParameter::getRelativeName() const -{ - return _relativeLayoutName.c_str(); -} - -LayoutParameter* RelativeLayoutParameter::createCloneInstance() -{ - return RelativeLayoutParameter::create(); -} - -void RelativeLayoutParameter::copyProperties(LayoutParameter *model) -{ - LayoutParameter::copyProperties(model); - RelativeLayoutParameter* parameter = dynamic_cast(model); - if (parameter) - { - setAlign(parameter->_relativeAlign); - setRelativeName(parameter->_relativeLayoutName.c_str()); - setRelativeToWidgetName(parameter->_relativeWidgetName.c_str()); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UILayoutParameter.h b/cocos/gui/UILayoutParameter.h deleted file mode 100644 index bf3dae2d6a..0000000000 --- a/cocos/gui/UILayoutParameter.h +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** - 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. - ****************************************************************************/ - -#ifndef __LAYOUTPARMETER_H__ -#define __LAYOUTPARMETER_H__ - -#include "gui/UILayoutDefine.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - LAYOUT_PARAMETER_NONE, - LAYOUT_PARAMETER_LINEAR, - LAYOUT_PARAMETER_RELATIVE -}LayoutParameterType; -/** -* @js NA -* @lua NA -*/ -class LayoutParameter : public Ref -{ -public: - /** - * Default constructor - */ - LayoutParameter() : _margin(Margin()){_layoutParameterType = LAYOUT_PARAMETER_NONE;}; - - /** - * Default destructor - */ - virtual ~LayoutParameter(){}; - - /** - * Allocates and initializes. - * @return A initialized LayoutParameter which is marked as "autorelease". - */ - static LayoutParameter* create(); - - /** - * Sets Margin parameter for LayoutParameter. - * - * @see Margin - * - * @param margin - */ - void setMargin(const Margin& margin); - - /** - * Gets Margin parameter of LayoutParameter. - * - * @see Margin - * - * @return const Margin& - */ - const Margin& getMargin() const; - - /** - * Gets LayoutParameterType of LayoutParameter. - * - * @see LayoutParameterType - * - * @return LayoutParameterType - */ - LayoutParameterType getLayoutType() const; - - LayoutParameter* clone(); - virtual LayoutParameter* createCloneInstance(); - virtual void copyProperties(LayoutParameter* model); -protected: - Margin _margin; - LayoutParameterType _layoutParameterType; -}; -/** -* @js NA -* @lua NA -*/ -class LinearLayoutParameter : public LayoutParameter -{ -public: - /** - * Default constructor - */ - LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE){_layoutParameterType = LAYOUT_PARAMETER_LINEAR;}; - - /** - * Default destructor - */ - virtual ~LinearLayoutParameter(){}; - - /** - * Allocates and initializes. - * @return A initialized LayoutParameter which is marked as "autorelease". - */ - static LinearLayoutParameter* create(); - - /** - * Sets LinearGravity parameter for LayoutParameter. - * - * @see LinearGravity - * - * @param LinearGravity - */ - void setGravity(LinearGravity gravity); - - /** - * Gets LinearGravity parameter for LayoutParameter. - * - * @see LinearGravity - * - * @return LinearGravity - */ - LinearGravity getGravity() const; - virtual LayoutParameter* createCloneInstance() override; - virtual void copyProperties(LayoutParameter* model) override; -protected: - LinearGravity _linearGravity; -}; -/** -* @js NA -* @lua NA -*/ - -class RelativeLayoutParameter : public LayoutParameter -{ -public: - /** - * Default constructor - */ - RelativeLayoutParameter() : _relativeAlign(RELATIVE_ALIGN_NONE),_relativeWidgetName(""),_relativeLayoutName(""),_put(false){_layoutParameterType = LAYOUT_PARAMETER_RELATIVE;}; - - /** - * Default destructor - */ - virtual ~RelativeLayoutParameter(){}; - - /** - * Allocates and initializes. - * @return A initialized LayoutParameter which is marked as "autorelease". - */ - static RelativeLayoutParameter* create(); - - /** - * Sets RelativeAlign parameter for LayoutParameter. - * - * @see RelativeAlign - * - * @param RelativeAlign - */ - void setAlign(RelativeAlign align); - - /** - * Gets RelativeAlign parameter for LayoutParameter. - * - * @see RelativeAlign - * - * @return RelativeAlign - */ - RelativeAlign getAlign() const; - - /** - * Sets a key for LayoutParameter. Witch widget named this is relative to. - * - * @param name - */ - void setRelativeToWidgetName(const char* name); - - /** - * Gets the key of LayoutParameter. Witch widget named this is relative to. - * - * @return name - */ - const char* getRelativeToWidgetName() const; - - /** - * Sets a name in Relative Layout for LayoutParameter. - * - * @param name - */ - void setRelativeName(const char* name); - - /** - * Gets a name in Relative Layout of LayoutParameter. - * - * @return name - */ - const char* getRelativeName() const; - - virtual LayoutParameter* createCloneInstance() override; - virtual void copyProperties(LayoutParameter* model) override; -protected: - RelativeAlign _relativeAlign; - std::string _relativeWidgetName; - std::string _relativeLayoutName; - bool _put; - friend class Layout; -}; - -} - -NS_CC_END - -#endif /* defined(__LayoutParameter__) */ diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp deleted file mode 100644 index ba3b3084bb..0000000000 --- a/cocos/gui/UIListView.cpp +++ /dev/null @@ -1,480 +0,0 @@ -/**************************************************************************** -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 "gui/UIListView.h" -#include "gui/UIHelper.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" - -NS_CC_BEGIN - -namespace ui { - -IMPLEMENT_CLASS_GUI_INFO(ListView) - -ListView::ListView(): -_model(nullptr), -_gravity(LISTVIEW_GRAVITY_CENTER_HORIZONTAL), -_itemsMargin(0.0f), -_listViewEventListener(nullptr), -_listViewEventSelector(nullptr), -_curSelectedIndex(0), -_refreshViewDirty(true) -{ - -} - -ListView::~ListView() -{ - _listViewEventListener = nullptr; - _listViewEventSelector = nullptr; - _items.clear(); -} - -ListView* ListView::create() -{ - ListView* widget = new ListView(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -bool ListView::init() -{ - if (ScrollView::init()) - { - setLayoutType(LAYOUT_LINEAR_VERTICAL); - return true; - } - return false; -} - -void ListView::setItemModel(Widget *model) -{ - if (!model) - { - return; - } - CC_SAFE_RELEASE_NULL(_model); - _model = model; - CC_SAFE_RETAIN(_model); -} - -void ListView::updateInnerContainerSize() -{ - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: - { - size_t length = _items.size(); - float totalHeight = (length - 1) * _itemsMargin; - for (auto& item : _items) - { - totalHeight += item->getSize().height; - } - float finalWidth = _size.width; - float finalHeight = totalHeight; - setInnerContainerSize(Size(finalWidth, finalHeight)); - break; - } - case SCROLLVIEW_DIR_HORIZONTAL: - { - size_t length = _items.size(); - float totalWidth = (length - 1) * _itemsMargin; - for (auto& item : _items) - { - totalWidth += item->getSize().width; - } - float finalWidth = totalWidth; - float finalHeight = _size.height; - setInnerContainerSize(Size(finalWidth, finalHeight)); - break; - } - default: - break; - } -} - -void ListView::remedyLayoutParameter(Widget *item) -{ - if (!item) - { - return; - } - switch (_direction) { - case SCROLLVIEW_DIR_VERTICAL: - { - LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); - if (!llp) - { - LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); - switch (_gravity) { - case LISTVIEW_GRAVITY_LEFT: - defaultLp->setGravity(LINEAR_GRAVITY_LEFT); - break; - case LISTVIEW_GRAVITY_RIGHT: - defaultLp->setGravity(LINEAR_GRAVITY_RIGHT); - break; - case LISTVIEW_GRAVITY_CENTER_HORIZONTAL: - defaultLp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); - break; - default: - break; - } - if (getIndex(item) == 0) - { - defaultLp->setMargin(MarginZero); - } - else - { - defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); - } - item->setLayoutParameter(defaultLp); - } - else - { - if (getIndex(item) == 0) - { - llp->setMargin(MarginZero); - } - else - { - llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); - } - switch (_gravity) { - case LISTVIEW_GRAVITY_LEFT: - llp->setGravity(LINEAR_GRAVITY_LEFT); - break; - case LISTVIEW_GRAVITY_RIGHT: - llp->setGravity(LINEAR_GRAVITY_RIGHT); - break; - case LISTVIEW_GRAVITY_CENTER_HORIZONTAL: - llp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); - break; - default: - break; - } - } - break; - } - case SCROLLVIEW_DIR_HORIZONTAL: - { - LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); - if (!llp) - { - LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); - switch (_gravity) { - case LISTVIEW_GRAVITY_TOP: - defaultLp->setGravity(LINEAR_GRAVITY_TOP); - break; - case LISTVIEW_GRAVITY_BOTTOM: - defaultLp->setGravity(LINEAR_GRAVITY_BOTTOM); - break; - case LISTVIEW_GRAVITY_CENTER_VERTICAL: - defaultLp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL); - break; - default: - break; - } - if (getIndex(item) == 0) - { - defaultLp->setMargin(MarginZero); - } - else - { - defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); - } - item->setLayoutParameter(defaultLp); - } - else - { - if (getIndex(item) == 0) - { - llp->setMargin(MarginZero); - } - else - { - llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); - } - switch (_gravity) { - case LISTVIEW_GRAVITY_TOP: - llp->setGravity(LINEAR_GRAVITY_TOP); - break; - case LISTVIEW_GRAVITY_BOTTOM: - llp->setGravity(LINEAR_GRAVITY_BOTTOM); - break; - case LISTVIEW_GRAVITY_CENTER_VERTICAL: - llp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL); - break; - default: - break; - } - } - break; - } - default: - break; - } - -} - -void ListView::pushBackDefaultItem() -{ - if (!_model) - { - return; - } - Widget* newItem = _model->clone(); - _items.pushBack(newItem); - remedyLayoutParameter(newItem); - addChild(newItem); - _refreshViewDirty = true; -} - -void ListView::insertDefaultItem(ssize_t index) -{ - if (!_model) - { - return; - } - Widget* newItem = _model->clone(); - _items.insert(index, newItem); - remedyLayoutParameter(newItem); - addChild(newItem); - _refreshViewDirty = true; -} - -void ListView::pushBackCustomItem(Widget* item) -{ - _items.pushBack(item); - remedyLayoutParameter(item); - addChild(item); - _refreshViewDirty = true; -} - -void ListView::insertCustomItem(Widget* item, ssize_t index) -{ - _items.insert(index, item); - remedyLayoutParameter(item); - addChild(item); - _refreshViewDirty = true; -} - -void ListView::removeItem(ssize_t index) -{ - Widget* item = getItem(index); - if (!item) - { - return; - } - _items.eraseObject(item); - removeChild(item); - _refreshViewDirty = true; -} - -void ListView::removeLastItem() -{ - removeItem(_items.size() -1); -} - -void ListView::removeAllItems() -{ - _items.clear(); - removeAllChildren(); -} - -Widget* ListView::getItem(ssize_t index) -{ - if (index < 0 || index >= _items.size()) - { - return nullptr; - } - return _items.at(index); -} - -Vector& ListView::getItems() -{ - return _items; -} - -ssize_t ListView::getIndex(Widget *item) const -{ - if (!item) - { - return -1; - } - return _items.getIndex(item); -} - -void ListView::setGravity(ListViewGravity gravity) -{ - if (_gravity == gravity) - { - return; - } - _gravity = gravity; - _refreshViewDirty = true; -} - -void ListView::setItemsMargin(float margin) -{ - if (_itemsMargin == margin) - { - return; - } - _itemsMargin = margin; - _refreshViewDirty = true; -} - -float ListView::getItemsMargin() -{ - return _itemsMargin; -} - -void ListView::setDirection(SCROLLVIEW_DIR dir) -{ - switch (dir) - { - case SCROLLVIEW_DIR_VERTICAL: - setLayoutType(LAYOUT_LINEAR_VERTICAL); - break; - case SCROLLVIEW_DIR_HORIZONTAL: - setLayoutType(LAYOUT_LINEAR_HORIZONTAL); - break; - case SCROLLVIEW_DIR_BOTH: - return; - default: - return; - break; - } - ScrollView::setDirection(dir); -} - -void ListView::requestRefreshView() -{ - _refreshViewDirty = true; -} - -void ListView::refreshView() -{ - ssize_t length = _items.size(); - for (int i=0; isetLocalZOrder(i); - remedyLayoutParameter(item); - } - updateInnerContainerSize(); -} - -void ListView::sortAllChildren() -{ - ScrollView::sortAllChildren(); - if (_refreshViewDirty) - { - refreshView(); - _refreshViewDirty = false; - } -} - -void ListView::addEventListenerListView(Ref *target, SEL_ListViewEvent selector) -{ - _listViewEventListener = target; - _listViewEventSelector = selector; -} - -void ListView::selectedItemEvent() -{ - if (_listViewEventListener && _listViewEventSelector) - { - (_listViewEventListener->*_listViewEventSelector)(this, LISTVIEW_ONSELECTEDITEM); - } -} - -void ListView::interceptTouchEvent(int handleState, Widget *sender, const Point &touchPoint) -{ - ScrollView::interceptTouchEvent(handleState, sender, touchPoint); - if (handleState != 1) - { - Widget* parent = sender; - while (parent) - { - if (parent && parent->getParent() == _innerContainer) - { - _curSelectedIndex = getIndex(parent); - break; - } - parent = dynamic_cast(parent->getParent()); - } - selectedItemEvent(); - } -} - -ssize_t ListView::getCurSelectedIndex() const -{ - return _curSelectedIndex; -} - -void ListView::onSizeChanged() -{ - ScrollView::onSizeChanged(); - _refreshViewDirty = true; -} - -std::string ListView::getDescription() const -{ - return "ListView"; -} - -Widget* ListView::createCloneInstance() -{ - return ListView::create(); -} - -void ListView::copyClonedWidgetChildren(Widget* model) -{ - auto& arrayItems = static_cast(model)->getItems(); - for (auto& item : arrayItems) - { - pushBackCustomItem(item->clone()); - } -} - -void ListView::copySpecialProperties(Widget *widget) -{ - ListView* listViewEx = dynamic_cast(widget); - if (listViewEx) - { - ScrollView::copySpecialProperties(widget); - setItemModel(listViewEx->_model); - setItemsMargin(listViewEx->_itemsMargin); - setGravity(listViewEx->_gravity); - } -} - -} -NS_CC_END diff --git a/cocos/gui/UIListView.h b/cocos/gui/UIListView.h deleted file mode 100644 index 58cf81ff46..0000000000 --- a/cocos/gui/UIListView.h +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - - -#ifndef __UILISTVIEW_H__ -#define __UILISTVIEW_H__ - -#include "gui/UIScrollView.h" - -NS_CC_BEGIN - -namespace ui{ - -typedef enum -{ - LISTVIEW_GRAVITY_LEFT, - LISTVIEW_GRAVITY_RIGHT, - LISTVIEW_GRAVITY_CENTER_HORIZONTAL, - - LISTVIEW_GRAVITY_TOP, - LISTVIEW_GRAVITY_BOTTOM, - LISTVIEW_GRAVITY_CENTER_VERTICAL, -}ListViewGravity; - -typedef enum -{ - LISTVIEW_ONSELECTEDITEM -}ListViewEventType; - -typedef void (Ref::*SEL_ListViewEvent)(Ref*,ListViewEventType); -#define listvieweventselector(_SELECTOR) (SEL_ListViewEvent)(&_SELECTOR) - -class ListView : public ScrollView -{ - - DECLARE_CLASS_GUI_INFO - -public: - - /** - * Default constructor - */ - ListView(); - - /** - * Default destructor - */ - virtual ~ListView(); - - /** - * Allocates and initializes. - */ - static ListView* create(); - - /** - * Sets a item model for listview - * - * A model will be cloned for adding default item. - * - * @param model item model for listview - */ - void setItemModel(Widget* model); - - /** - * Push back a default item(create by a cloned model) into listview. - */ - void pushBackDefaultItem(); - - /** - * Insert a default item(create by a cloned model) into listview. - */ - void insertDefaultItem(ssize_t index); - - /** - * Push back custom item into listview. - */ - void pushBackCustomItem(Widget* item); - - /** - * Insert custom item into listview. - */ - void insertCustomItem(Widget* item, ssize_t index); - - /** - * Removes the last item of listview. - */ - void removeLastItem(); - - /** - * Removes a item whose index is same as the parameter. - * - * @param index of item. - */ - void removeItem(ssize_t index); - - void removeAllItems(); - - /** - * Returns a item whose index is same as the parameter. - * - * @param index of item. - * - * @return the item widget. - */ - Widget* getItem(ssize_t index); - - /** - * Returns the item container. - */ - Vector& getItems(); - - /** - * Returns the index of item. - * - * @param item the item which need to be checked. - * - * @return the index of item. - */ - ssize_t getIndex(Widget* item) const; - - /** - * Changes the gravity of listview. - * @see ListViewGravity - */ - void setGravity(ListViewGravity gravity); - - /** - * Changes the margin between each item. - * - * @param margin - */ - void setItemsMargin(float margin); - - float getItemsMargin(); - - virtual void sortAllChildren() override; - - ssize_t getCurSelectedIndex() const; - - void addEventListenerListView(Ref* target, SEL_ListViewEvent selector); - - /** - * Changes scroll direction of scrollview. - * - * @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll - * - * @param SCROLLVIEW_DIR - */ - virtual void setDirection(SCROLLVIEW_DIR dir) override; - - virtual std::string getDescription() const override; - - void requestRefreshView(); - void refreshView(); -protected: - virtual void addChild(Node* child) override{ScrollView::addChild(child);}; - virtual void addChild(Node * child, int zOrder) override{ScrollView::addChild(child, zOrder);}; - virtual void addChild(Node* child, int zOrder, int tag) override{ScrollView::addChild(child, zOrder, tag);}; - virtual void removeChild(Node* widget, bool cleanup = true) override{ScrollView::removeChild(widget, cleanup);}; - - virtual void removeAllChildren() override{removeAllChildrenWithCleanup(true);}; - virtual void removeAllChildrenWithCleanup(bool cleanup) override {ScrollView::removeAllChildrenWithCleanup(cleanup);}; - virtual Vector& getChildren() override{return ScrollView::getChildren();}; - virtual const Vector& getChildren() const override{return ScrollView::getChildren();}; - virtual ssize_t getChildrenCount() const override {return ScrollView::getChildrenCount();}; - virtual Node * getChildByTag(int tag) override {return ScrollView::getChildByTag(tag);}; - virtual Widget* getChildByName(const char* name) override {return ScrollView::getChildByName(name);}; - virtual bool init() override; - void updateInnerContainerSize(); - void remedyLayoutParameter(Widget* item); - virtual void onSizeChanged() override; - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; - virtual void copyClonedWidgetChildren(Widget* model) override; - void selectedItemEvent(); - virtual void interceptTouchEvent(int handleState,Widget* sender,const Point &touchPoint) override; -protected: - - Widget* _model; - Vector _items; - ListViewGravity _gravity; - float _itemsMargin; - Ref* _listViewEventListener; - SEL_ListViewEvent _listViewEventSelector; - ssize_t _curSelectedIndex; - bool _refreshViewDirty; -}; - -} -NS_CC_END - -#endif /* defined(__ListView__) */ diff --git a/cocos/gui/UILoadingBar.cpp b/cocos/gui/UILoadingBar.cpp deleted file mode 100644 index 1b41e50721..0000000000 --- a/cocos/gui/UILoadingBar.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/**************************************************************************** -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 "gui/UILoadingBar.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" - -NS_CC_BEGIN - -namespace ui { - -static const int BAR_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(LoadingBar) - -LoadingBar::LoadingBar(): -_barType(LoadingBarTypeLeft), -_percent(100), -_totalLength(0), -_barRenderer(nullptr), -_renderBarTexType(UI_TEX_TYPE_LOCAL), -_barRendererTextureSize(Size::ZERO), -_scale9Enabled(false), -_prevIgnoreSize(true), -_capInsets(Rect::ZERO), -_textureFile("") -{ -} - -LoadingBar::~LoadingBar() -{ - -} - -LoadingBar* LoadingBar::create() -{ - LoadingBar* widget = new LoadingBar(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -void LoadingBar::initRenderer() -{ - _barRenderer = Sprite::create(); - Node::addChild(_barRenderer, BAR_RENDERER_Z, -1); - _barRenderer->setAnchorPoint(Point(0.0,0.5)); -} - -void LoadingBar::setDirection(LoadingBarType dir) -{ - if (_barType == dir) - { - return; - } - _barType = dir; - - switch (_barType) - { - case LoadingBarTypeLeft: - _barRenderer->setAnchorPoint(Point(0.0f,0.5f)); - _barRenderer->setPosition(Point(-_totalLength*0.5f,0.0f)); - if (!_scale9Enabled) - { - static_cast(_barRenderer)->setFlippedX(false); - } - break; - case LoadingBarTypeRight: - _barRenderer->setAnchorPoint(Point(1.0f,0.5f)); - _barRenderer->setPosition(Point(_totalLength*0.5f,0.0f)); - if (!_scale9Enabled) - { - static_cast(_barRenderer)->setFlippedX(true); - } - break; - } -} - -int LoadingBar::getDirection() -{ - return _barType; -} - -void LoadingBar::loadTexture(const char* texture,TextureResType texType) -{ - if (!texture || strcmp(texture, "") == 0) - { - return; - } - _renderBarTexType = texType; - _textureFile = texture; - switch (_renderBarTexType) - { - case UI_TEX_TYPE_LOCAL: - if (_scale9Enabled) - { - extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); - barRendererScale9->initWithFile(texture); - barRendererScale9->setCapInsets(_capInsets); - } - else - { - static_cast(_barRenderer)->setTexture(texture); - } - break; - case UI_TEX_TYPE_PLIST: - if (_scale9Enabled) - { - extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); - barRendererScale9->initWithSpriteFrameName(texture); - barRendererScale9->setCapInsets(_capInsets); - } - else - { - static_cast(_barRenderer)->setSpriteFrame(texture); - } - break; - default: - break; - } - updateRGBAToRenderer(_barRenderer); - _barRendererTextureSize = _barRenderer->getContentSize(); - - switch (_barType) - { - case LoadingBarTypeLeft: - _barRenderer->setAnchorPoint(Point(0.0f,0.5f)); - if (!_scale9Enabled) - { - static_cast(_barRenderer)->setFlippedX(false); - } - break; - case LoadingBarTypeRight: - _barRenderer->setAnchorPoint(Point(1.0f,0.5f)); - if (!_scale9Enabled) - { - static_cast(_barRenderer)->setFlippedX(true); - } - break; - } - barRendererScaleChangedWithSize(); -} - -void LoadingBar::setScale9Enabled(bool enabled) -{ - if (_scale9Enabled == enabled) - { - return; - } - _scale9Enabled = enabled; - Node::removeChild(_barRenderer); - _barRenderer = nullptr; - if (_scale9Enabled) - { - _barRenderer = extension::Scale9Sprite::create(); - } - else - { - _barRenderer = Sprite::create(); - } - loadTexture(_textureFile.c_str(),_renderBarTexType); - Node::addChild(_barRenderer, BAR_RENDERER_Z, -1); - if (_scale9Enabled) - { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; - } - else - { - ignoreContentAdaptWithSize(_prevIgnoreSize); - } - setCapInsets(_capInsets); - setPercent(_percent); -} - -bool LoadingBar::isScale9Enabled() -{ - return _scale9Enabled; -} - -void LoadingBar::setCapInsets(const Rect &capInsets) -{ - _capInsets = capInsets; - if (!_scale9Enabled) - { - return; - } - static_cast(_barRenderer)->setCapInsets(capInsets); -} - -const Rect& LoadingBar::getCapInsets() -{ - return _capInsets; -} - -void LoadingBar::setPercent(int percent) -{ - if ( percent < 0 || percent > 100) - { - return; - } - if (_totalLength <= 0) - { - return; - } - _percent = percent; - float res = _percent / 100.0f; - - if (_scale9Enabled) - { - setScale9Scale(); - } - else - { - Sprite* spriteRenderer = static_cast(_barRenderer); - Rect rect = spriteRenderer->getTextureRect(); - rect.size.width = _barRendererTextureSize.width * res; - spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size); - } -} - -int LoadingBar::getPercent() -{ - return _percent; -} - -void LoadingBar::onSizeChanged() -{ - Widget::onSizeChanged(); - barRendererScaleChangedWithSize(); -} - -void LoadingBar::ignoreContentAdaptWithSize(bool ignore) -{ - if (!_scale9Enabled || (_scale9Enabled && !ignore)) - { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; - } -} - -const Size& LoadingBar::getContentSize() const -{ - return _barRendererTextureSize; -} - -Node* LoadingBar::getVirtualRenderer() -{ - return _barRenderer; -} - -void LoadingBar::barRendererScaleChangedWithSize() -{ - if (_ignoreSize) - { - if (!_scale9Enabled) - { - _totalLength = _barRendererTextureSize.width; - _barRenderer->setScale(1.0f); - _size = _barRendererTextureSize; - } - } - else - { - _totalLength = _size.width; - if (_scale9Enabled) - { - setScale9Scale(); - } - else - { - - Size textureSize = _barRendererTextureSize; - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _barRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _barRenderer->setScaleX(scaleX); - _barRenderer->setScaleY(scaleY); - } - } - switch (_barType) - { - case LoadingBarTypeLeft: - _barRenderer->setPosition(Point(-_totalLength * 0.5f, 0.0f)); - break; - case LoadingBarTypeRight: - _barRenderer->setPosition(Point(_totalLength * 0.5f, 0.0f)); - break; - default: - break; - } -} - -void LoadingBar::setScale9Scale() -{ - float width = (float)(_percent) / 100.0f * _totalLength; - static_cast(_barRenderer)->setPreferredSize(Size(width, _size.height)); -} - -std::string LoadingBar::getDescription() const -{ - return "LoadingBar"; -} - -void LoadingBar::updateTextureColor() -{ - updateColorToRenderer(_barRenderer); -} - -void LoadingBar::updateTextureOpacity() -{ - updateOpacityToRenderer(_barRenderer); -} - -void LoadingBar::updateTextureRGBA() -{ - updateRGBAToRenderer(_barRenderer); -} - -Widget* LoadingBar::createCloneInstance() -{ - return LoadingBar::create(); -} - -void LoadingBar::copySpecialProperties(Widget *widget) -{ - LoadingBar* loadingBar = dynamic_cast(widget); - if (loadingBar) - { - _prevIgnoreSize = loadingBar->_prevIgnoreSize; - setScale9Enabled(loadingBar->_scale9Enabled); - loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType); - setCapInsets(loadingBar->_capInsets); - setPercent(loadingBar->_percent); - setDirection(loadingBar->_barType); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UILoadingBar.h b/cocos/gui/UILoadingBar.h deleted file mode 100644 index 7694280680..0000000000 --- a/cocos/gui/UILoadingBar.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UILOADINGBAR_H__ -#define __UILOADINGBAR_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - LoadingBarTypeLeft, - LoadingBarTypeRight -}LoadingBarType; -/** -* @js NA -* @lua NA -*/ -class LoadingBar : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - LoadingBar(); - - /** - * Default destructor - */ - virtual ~LoadingBar(); - - /** - * Allocates and initializes. - */ - static LoadingBar* create(); - - /** - * Changes the progress direction of loadingbar. - * - * @see LoadingBarType LoadingBarTypeLeft means progress left to right, LoadingBarTypeRight otherwise. - * - * @param LoadingBarType - */ - void setDirection(LoadingBarType dir); - - /** - * Gets the progress direction of loadingbar. - * - * @see LoadingBarType LoadingBarTypeLeft means progress left to right, LoadingBarTypeRight otherwise. - * - * @param LoadingBarType - */ - int getDirection(); - - /** - * Load texture for loadingbar. - * - * @param fileName file name of texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadTexture(const char* texture,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Changes the progress direction of loadingbar. - * - * @param percent percent value from 1 to 100. - */ - void setPercent(int percent); - - /** - * Gets the progress direction of loadingbar. - * - * @return percent percent value from 1 to 100. - */ - int getPercent(); - - /** - * Sets if loadingbar is using scale9 renderer. - * - * @param true that using scale9 renderer, false otherwise. - */ - void setScale9Enabled(bool enabled); - - bool isScale9Enabled(); - - /** - * Sets capinsets for loadingbar, if loadingbar is using scale9 renderer. - * - * @param capInsets capinsets for loadingbar - */ - void setCapInsets(const Rect &capInsets); - - const Rect& getCapInsets(); - - //override "ignoreContentAdaptWithSize" method of widget. - virtual void ignoreContentAdaptWithSize(bool ignore) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; - - //override "getVirtualRenderer" method of widget. - virtual Node* getVirtualRenderer() override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; -protected: - virtual void initRenderer() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - void setScale9Scale(); - void barRendererScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - LoadingBarType _barType; - int _percent; - float _totalLength; - Node* _barRenderer; - TextureResType _renderBarTexType; - Size _barRendererTextureSize; - bool _scale9Enabled; - bool _prevIgnoreSize; - Rect _capInsets; - std::string _textureFile; -}; - -} -NS_CC_END -#endif /* defined(__CocoGUI__LoadingBar__) */ diff --git a/cocos/gui/UIPageView.cpp b/cocos/gui/UIPageView.cpp deleted file mode 100644 index d230faeccb..0000000000 --- a/cocos/gui/UIPageView.cpp +++ /dev/null @@ -1,631 +0,0 @@ -/**************************************************************************** -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 "gui/UIPageView.h" - -NS_CC_BEGIN - -namespace ui { - -IMPLEMENT_CLASS_GUI_INFO(PageView) - -PageView::PageView(): -_curPageIdx(0), -_touchMoveDir(PAGEVIEW_TOUCHLEFT), -_touchStartLocation(0.0f), -_touchMoveStartLocation(0.0f), -_movePagePoint(Point::ZERO), -_leftChild(nullptr), -_rightChild(nullptr), -_leftBoundary(0.0f), -_rightBoundary(0.0f), -_isAutoScrolling(false), -_autoScrollDistance(0.0f), -_autoScrollSpeed(0.0f), -_autoScrollDir(0), -_childFocusCancelOffset(5.0f), -_pageViewEventListener(nullptr), -_pageViewEventSelector(nullptr) -{ -} - -PageView::~PageView() -{ - _pages.clear(); - _pageViewEventListener = nullptr; - _pageViewEventSelector = nullptr; -} - -PageView* PageView::create() -{ - PageView* widget = new PageView(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -void PageView::onEnter() -{ - Layout::onEnter(); - scheduleUpdate(); -} - -bool PageView::init() -{ - if (Layout::init()) - { - setClippingEnabled(true); - setTouchEnabled(true); - return true; - } - return false; -} - -void PageView::addWidgetToPage(Widget *widget, ssize_t pageIdx, bool forceCreate) -{ - if (!widget) - { - return; - } - if (pageIdx < 0) - { - return; - } - ssize_t pageCount = _pages.size(); - if (pageIdx < 0 || pageIdx >= pageCount) - { - if (forceCreate) - { - if (pageIdx > pageCount) - { - CCLOG("pageIdx is %d, it will be added as page id [%d]",static_cast(pageIdx),static_cast(pageCount)); - } - Layout* newPage = createPage(); - newPage->addChild(widget); - addPage(newPage); - } - } - else - { - Layout * page = _pages.at(pageIdx); - page->addChild(widget); - } -} - -Layout* PageView::createPage() -{ - Layout* newPage = Layout::create(); - newPage->setSize(getSize()); - return newPage; -} - -void PageView::addPage(Layout* page) -{ - if (!page) - { - return; - } - if (page->getWidgetType() != WidgetTypeContainer) - { - return; - } - if (_pages.contains(page)) - { - return; - } - Size pSize = page->getSize(); - Size pvSize = getSize(); - if (!pSize.equals(pvSize)) - { - CCLOG("page size does not match pageview size, it will be force sized!"); - page->setSize(pvSize); - } - page->setPosition(Point(getPositionXByIndex(_pages.size()), 0)); - _pages.pushBack(page); - addChild(page); - updateBoundaryPages(); -} - -void PageView::insertPage(Layout* page, int idx) -{ - if (idx < 0) - { - return; - } - if (!page) - { - return; - } - if (page->getWidgetType() != WidgetTypeContainer) - { - return; - } - if (_pages.contains(page)) - { - return; - } - - ssize_t pageCount = _pages.size(); - if (idx >= pageCount) - { - addPage(page); - } - else - { - _pages.insert(idx, page); - page->setPosition(Point(getPositionXByIndex(idx), 0)); - addChild(page); - Size pSize = page->getSize(); - Size pvSize = getSize(); - if (!pSize.equals(pvSize)) - { - CCLOG("page size does not match pageview size, it will be force sized!"); - page->setSize(pvSize); - } - ssize_t length = _pages.size(); - for (ssize_t i=(idx+1); igetPosition(); - behindPage->setPosition(Point(formerPos.x+getSize().width, 0)); - } - updateBoundaryPages(); - } -} - -void PageView::removePage(Layout* page) -{ - if (!page) - { - return; - } - removeChild(page); - updateChildrenPosition(); - updateBoundaryPages(); -} - -void PageView::removePageAtIndex(ssize_t index) -{ - if (index < 0 || index >= _pages.size()) - { - return; - } - Layout* page = _pages.at(index); - removePage(page); -} - -void PageView::removeAllPages() -{ - removeAllChildren(); -} - -void PageView::updateBoundaryPages() -{ - if (_pages.size() <= 0) - { - _leftChild = nullptr; - _rightChild = nullptr; - return; - } - _leftChild = _pages.at(0); - _rightChild = _pages.at(_pages.size()-1); -} - -float PageView::getPositionXByIndex(ssize_t idx) -{ - return (getSize().width*(idx-_curPageIdx)); -} - -void PageView::addChild(Node *child) -{ - Layout::addChild(child); -} - -void PageView::addChild(Node * child, int zOrder) -{ - Layout::addChild(child, zOrder); -} - -void PageView::addChild(Node *child, int zOrder, int tag) -{ - Layout::addChild(child, zOrder, tag); -} - -void PageView::removeChild(Node *child, bool cleanup) -{ - if (_pages.contains(static_cast(child))) - { - _pages.eraseObject(static_cast(child)); - } - Layout::removeChild(child, cleanup); -} - -void PageView::onSizeChanged() -{ - Layout::onSizeChanged(); - _rightBoundary = getSize().width; - updateChildrenSize(); - updateChildrenPosition(); -} - -void PageView::updateChildrenSize() -{ - Size selfSize = getSize(); - for (auto& page : _pages) - { - page->setSize(selfSize); - } -} - -void PageView::updateChildrenPosition() -{ - ssize_t pageCount = _pages.size(); - if (pageCount <= 0) - { - _curPageIdx = 0; - return; - } - if (_curPageIdx >= pageCount) - { - _curPageIdx = pageCount-1; - } - float pageWidth = getSize().width; - for (int i=0; isetPosition(Point((i-_curPageIdx)*pageWidth, 0)); - } -} - -void PageView::removeAllChildren() -{ - removeAllChildrenWithCleanup(true); -} - -void PageView::removeAllChildrenWithCleanup(bool cleanup) -{ - _pages.clear(); - Layout::removeAllChildrenWithCleanup(cleanup); -} - -void PageView::scrollToPage(ssize_t idx) -{ - if (idx < 0 || idx >= _pages.size()) - { - return; - } - _curPageIdx = idx; - Widget* curPage = _pages.at(idx); - _autoScrollDistance = -(curPage->getPosition().x); - _autoScrollSpeed = fabs(_autoScrollDistance)/0.2f; - _autoScrollDir = _autoScrollDistance > 0 ? 1 : 0; - _isAutoScrolling = true; -} - -void PageView::update(float dt) -{ - if (_isAutoScrolling) - { - switch (_autoScrollDir) - { - case 0: - { - float step = _autoScrollSpeed*dt; - if (_autoScrollDistance + step >= 0.0f) - { - step = -_autoScrollDistance; - _autoScrollDistance = 0.0f; - _isAutoScrolling = false; - } - else - { - _autoScrollDistance += step; - } - scrollPages(-step); - if (!_isAutoScrolling) - { - pageTurningEvent(); - } - break; - } - break; - case 1: - { - float step = _autoScrollSpeed*dt; - if (_autoScrollDistance - step <= 0.0f) - { - step = _autoScrollDistance; - _autoScrollDistance = 0.0f; - _isAutoScrolling = false; - } - else - { - _autoScrollDistance -= step; - } - scrollPages(step); - if (!_isAutoScrolling) - { - pageTurningEvent(); - } - break; - } - default: - break; - } - } -} - -bool PageView::onTouchBegan(Touch *touch, Event *unusedEvent) -{ - bool pass = Layout::onTouchBegan(touch, unusedEvent); - if (_hitted) - { - handlePressLogic(touch->getLocation()); - } - return pass; -} - -void PageView::onTouchMoved(Touch *touch, Event *unusedEvent) -{ - _touchMovePos = touch->getLocation(); - handleMoveLogic(_touchMovePos); - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - widgetParent->checkChildInfo(1,this,_touchMovePos); - } - moveEvent(); -} - -void PageView::onTouchEnded(Touch *touch, Event *unusedEvent) -{ - Layout::onTouchEnded(touch, unusedEvent); - handleReleaseLogic(_touchEndPos); -} - -void PageView::onTouchCancelled(Touch *touch, Event *unusedEvent) -{ - Layout::onTouchCancelled(touch, unusedEvent); - handleReleaseLogic(touch->getLocation()); -} - -void PageView::movePages(float offset) -{ - for (auto& page : _pages) - { - _movePagePoint.x = page->getPosition().x + offset; - _movePagePoint.y = page->getPosition().y; - page->setPosition(_movePagePoint); - } -} - -bool PageView::scrollPages(float touchOffset) -{ - if (_pages.size() <= 0) - { - return false; - } - - if (!_leftChild || !_rightChild) - { - return false; - } - - float realOffset = touchOffset; - - switch (_touchMoveDir) - { - case PAGEVIEW_TOUCHLEFT: // left - if (_rightChild->getRightInParent() + touchOffset <= _rightBoundary) - { - realOffset = _rightBoundary - _rightChild->getRightInParent(); - movePages(realOffset); - return false; - } - break; - - case PAGEVIEW_TOUCHRIGHT: // right - if (_leftChild->getLeftInParent() + touchOffset >= _leftBoundary) - { - realOffset = _leftBoundary - _leftChild->getLeftInParent(); - movePages(realOffset); - return false; - } - break; - default: - break; - } - - movePages(realOffset); - return true; -} - -void PageView::handlePressLogic(const Point &touchPoint) -{ - Point nsp = convertToNodeSpace(touchPoint); - _touchMoveStartLocation = nsp.x; - _touchStartLocation = nsp.x; -} - -void PageView::handleMoveLogic(const Point &touchPoint) -{ - Point nsp = convertToNodeSpace(touchPoint); - float offset = 0.0; - float moveX = nsp.x; - offset = moveX - _touchMoveStartLocation; - _touchMoveStartLocation = moveX; - if (offset < 0) - { - _touchMoveDir = PAGEVIEW_TOUCHLEFT; - } - else if (offset > 0) - { - _touchMoveDir = PAGEVIEW_TOUCHRIGHT; - } - scrollPages(offset); -} - -void PageView::handleReleaseLogic(const Point &touchPoint) -{ - if (_pages.size() <= 0) - { - return; - } - Widget* curPage = _pages.at(_curPageIdx); - if (curPage) - { - Point curPagePos = curPage->getPosition(); - ssize_t pageCount = _pages.size(); - float curPageLocation = curPagePos.x; - float pageWidth = getSize().width; - float boundary = pageWidth/2.0f; - if (curPageLocation <= -boundary) - { - if (_curPageIdx >= pageCount-1) - { - scrollPages(-curPageLocation); - } - else - { - scrollToPage(_curPageIdx+1); - } - } - else if (curPageLocation >= boundary) - { - if (_curPageIdx <= 0) - { - scrollPages(-curPageLocation); - } - else - { - scrollToPage(_curPageIdx-1); - } - } - else - { - scrollToPage(_curPageIdx); - } - } -} - -void PageView::checkChildInfo(int handleState,Widget* sender, const Point &touchPoint) -{ - interceptTouchEvent(handleState, sender, touchPoint); -} - -void PageView::interceptTouchEvent(int handleState, Widget *sender, const Point &touchPoint) -{ - switch (handleState) - { - case 0: - handlePressLogic(touchPoint); - break; - case 1: - { - float offset = 0; - offset = fabs(sender->getTouchStartPos().x - touchPoint.x); - if (offset > _childFocusCancelOffset) - { - sender->setFocused(false); - handleMoveLogic(touchPoint); - } - } - break; - case 2: - handleReleaseLogic(touchPoint); - break; - - case 3: - handleReleaseLogic(touchPoint); - break; - } -} - -void PageView::pageTurningEvent() -{ - if (_pageViewEventListener && _pageViewEventSelector) - { - (_pageViewEventListener->*_pageViewEventSelector)(this, PAGEVIEW_EVENT_TURNING); - } -} - -void PageView::addEventListenerPageView(Ref *target, SEL_PageViewEvent selector) -{ - _pageViewEventListener = target; - _pageViewEventSelector = selector; -} - -ssize_t PageView::getCurPageIndex() const -{ - return _curPageIdx; -} - -Vector& PageView::getPages() -{ - return _pages; -} - -Layout* PageView::getPage(ssize_t index) -{ - if (index < 0 || index >= _pages.size()) - { - return nullptr; - } - return _pages.at(index); -} - -std::string PageView::getDescription() const -{ - return "PageView"; -} - -Widget* PageView::createCloneInstance() -{ - return PageView::create(); -} - -void PageView::copyClonedWidgetChildren(Widget* model) -{ - auto& modelPages = static_cast(model)->getPages(); - for (auto& page : modelPages) - { - addPage(dynamic_cast(page->clone())); - } -} - -void PageView::copySpecialProperties(Widget *widget) -{ - PageView* pageView = dynamic_cast(widget); - if (pageView) - { - Layout::copySpecialProperties(widget); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UIPageView.h b/cocos/gui/UIPageView.h deleted file mode 100644 index 94dad0536e..0000000000 --- a/cocos/gui/UIPageView.h +++ /dev/null @@ -1,222 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UIPAGEVIEW_H__ -#define __UIPAGEVIEW_H__ - -#include "gui/UILayout.h" -#include "gui/UIScrollInterface.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - PAGEVIEW_EVENT_TURNING, -}PageViewEventType; - -typedef void (Ref::*SEL_PageViewEvent)(Ref*, PageViewEventType); -#define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR) - -typedef enum { - PAGEVIEW_TOUCHLEFT, - PAGEVIEW_TOUCHRIGHT -}PVTouchDir; - -class PageView : public Layout , public UIScrollInterface -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - PageView(); - - /** - * Default destructor - */ - virtual ~PageView(); - - /** - * Allocates and initializes. - */ - static PageView* create(); - - /** - * Add a widget to a page of pageview. - * - * @param widget widget to be added to pageview. - * - * @param pageIdx index of page. - * - * @param forceCreate if force create and there is no page exsit, pageview would create a default page for adding widget. - */ - void addWidgetToPage(Widget* widget, ssize_t pageIdx, bool forceCreate); - - /** - * Push back a page to pageview. - * - * @param page page to be added to pageview. - */ - void addPage(Layout* page); - - /** - * Inert a page to pageview. - * - * @param page page to be added to pageview. - */ - void insertPage(Layout* page, int idx); - - /** - * Remove a page of pageview. - * - * @param page page which will be removed. - */ - void removePage(Layout* page); - - /** - * Remove a page at index of pageview. - * - * @param index index of page. - */ - void removePageAtIndex(ssize_t index); - - void removeAllPages(); - - /** - * scroll pageview to index. - * - * @param idx index of page. - */ - void scrollToPage(ssize_t idx); - - /** - * Gets current page index. - * - * @return current page index. - */ - ssize_t getCurPageIndex() const; - - Vector& getPages(); - - Layout* getPage(ssize_t index); - - // event - void addEventListenerPageView(Ref *target, SEL_PageViewEvent selector); - - - - - virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; - virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; - virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; - virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; - - //override "update" method of widget. - virtual void update(float dt) override; - /** - * Sets LayoutType. - * - * @see LayoutType - * - * @param LayoutType - */ - virtual void setLayoutType(LayoutType type) override{}; - - /** - * Gets LayoutType. - * - * @see LayoutType - * - * @return LayoutType - */ - virtual LayoutType getLayoutType() const override{return LAYOUT_ABSOLUTE;}; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - virtual void onEnter() override; - -protected: - virtual void addChild(Node * child) override; - virtual void addChild(Node * child, int zOrder) override; - virtual void addChild(Node* child, int zOrder, int tag) override; - virtual void removeChild(Node* widget, bool cleanup = true) override; - virtual void removeAllChildren() override; - virtual void removeAllChildrenWithCleanup(bool cleanup) override; - virtual Vector& getChildren() override{return Widget::getChildren();}; - virtual const Vector& getChildren() const override{return Widget::getChildren();}; - virtual ssize_t getChildrenCount() const override {return Widget::getChildrenCount();}; - virtual Node * getChildByTag(int tag) override {return Widget::getChildByTag(tag);}; - virtual Widget* getChildByName(const char* name) override {return Widget::getChildByName(name);}; - virtual bool init() override; - Layout* createPage(); - float getPositionXByIndex(ssize_t idx); - void updateBoundaryPages(); - virtual void handlePressLogic(const Point &touchPoint) override; - virtual void handleMoveLogic(const Point &touchPoint) override; - virtual void handleReleaseLogic(const Point &touchPoint) override; - virtual void interceptTouchEvent(int handleState, Widget* sender, const Point &touchPoint) override; - virtual void checkChildInfo(int handleState, Widget* sender, const Point &touchPoint) override; - virtual bool scrollPages(float touchOffset); - void movePages(float offset); - void pageTurningEvent(); - void updateChildrenSize(); - void updateChildrenPosition(); - virtual void onSizeChanged() override; - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; - virtual void copyClonedWidgetChildren(Widget* model) override; - virtual void setClippingEnabled(bool enabled) override {Layout::setClippingEnabled(enabled);}; - virtual void doLayout() override{if (!_doLayoutDirty){return;} _doLayoutDirty = false;}; -protected: - ssize_t _curPageIdx; - Vector _pages; - PVTouchDir _touchMoveDir; - float _touchStartLocation; - float _touchMoveStartLocation; - Point _movePagePoint; - Widget* _leftChild; - Widget* _rightChild; - float _leftBoundary; - float _rightBoundary; - bool _isAutoScrolling; - float _autoScrollDistance; - float _autoScrollSpeed; - int _autoScrollDir; - float _childFocusCancelOffset; - Ref* _pageViewEventListener; - SEL_PageViewEvent _pageViewEventSelector; - -}; - -} -NS_CC_END - -#endif /* defined(__PageView__) */ diff --git a/cocos/gui/UIRichText.cpp b/cocos/gui/UIRichText.cpp deleted file mode 100644 index 8e153ec123..0000000000 --- a/cocos/gui/UIRichText.cpp +++ /dev/null @@ -1,442 +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. - ****************************************************************************/ - -#include "UIRichText.h" - - -NS_CC_BEGIN - -namespace ui { - -bool RichElement::init(int tag, const Color3B &color, GLubyte opacity) -{ - _tag = tag; - _color = color; - _opacity = opacity; - return true; -} - - -RichElementText* RichElementText::create(int tag, const Color3B &color, GLubyte opacity, const char *text, const char *fontName, float fontSize) -{ - RichElementText* element = new RichElementText(); - if (element && element->init(tag, color, opacity, text, fontName, fontSize)) - { - element->autorelease(); - return element; - } - CC_SAFE_DELETE(element); - return NULL; -} - -bool RichElementText::init(int tag, const Color3B &color, GLubyte opacity, const char *text, const char *fontName, float fontSize) -{ - if (RichElement::init(tag, color, opacity)) - { - _text = text; - _fontName = fontName; - _fontSize = fontSize; - return true; - } - return false; -} - -RichElementImage* RichElementImage::create(int tag, const Color3B &color, GLubyte opacity, const char *filePath) -{ - RichElementImage* element = new RichElementImage(); - if (element && element->init(tag, color, opacity, filePath)) - { - element->autorelease(); - return element; - } - CC_SAFE_DELETE(element); - return NULL; -} - -bool RichElementImage::init(int tag, const Color3B &color, GLubyte opacity, const char *filePath) -{ - if (RichElement::init(tag, color, opacity)) - { - _filePath = filePath; - return true; - } - return false; -} - -RichElementCustomNode* RichElementCustomNode::create(int tag, const Color3B &color, GLubyte opacity, cocos2d::Node *customNode) -{ - RichElementCustomNode* element = new RichElementCustomNode(); - if (element && element->init(tag, color, opacity, customNode)) - { - element->autorelease(); - return element; - } - CC_SAFE_DELETE(element); - return NULL; -} - -bool RichElementCustomNode::init(int tag, const Color3B &color, GLubyte opacity, cocos2d::Node *customNode) -{ - if (RichElement::init(tag, color, opacity)) - { - _customNode = customNode; - _customNode->retain(); - return true; - } - return false; -} - -RichText::RichText(): -_formatTextDirty(true), -_richElements(NULL), -_elementRenders(NULL), -_leftSpaceWidth(0.0f), -_verticalSpace(0.0f), -_elementRenderersContainer(NULL) -{ - -} - -RichText::~RichText() -{ - _richElements.clear(); -} - -RichText* RichText::create() -{ - RichText* widget = new RichText(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return NULL; -} - -bool RichText::init() -{ - if (Widget::init()) - { - return true; - } - return false; -} - -void RichText::initRenderer() -{ - _elementRenderersContainer = Node::create(); - _elementRenderersContainer->setAnchorPoint(Point(0.5f, 0.5f)); - Node::addChild(_elementRenderersContainer, 0, -1); -} - -void RichText::insertElement(RichElement *element, int index) -{ - _richElements.insert(index, element); - _formatTextDirty = true; -} - -void RichText::pushBackElement(RichElement *element) -{ - _richElements.pushBack(element); - _formatTextDirty = true; -} - -void RichText::removeElement(int index) -{ - _richElements.erase(index); - _formatTextDirty = true; -} - -void RichText::removeElement(RichElement *element) -{ - _richElements.eraseObject(element); - _formatTextDirty = true; -} - -void RichText::formatText() -{ - if (_formatTextDirty) - { - _elementRenderersContainer->removeAllChildren(); - _elementRenders.clear(); - if (_ignoreSize) - { - addNewLine(); - for (int i=0; i<_richElements.size(); i++) - { - RichElement* element = _richElements.at(i); - Node* elementRenderer = NULL; - switch (element->_type) - { - case RICH_TEXT: - { - RichElementText* elmtText = static_cast(element); - elementRenderer = LabelTTF::create(elmtText->_text.c_str(), elmtText->_fontName.c_str(), elmtText->_fontSize); - break; - } - case RICH_IMAGE: - { - RichElementImage* elmtImage = static_cast(element); - elementRenderer = Sprite::create(elmtImage->_filePath.c_str()); - break; - } - case RICH_CUSTOM: - { - RichElementCustomNode* elmtCustom = static_cast(element); - elementRenderer = elmtCustom->_customNode; - break; - } - default: - break; - } - elementRenderer->setColor(element->_color); - elementRenderer->setOpacity(element->_opacity); - pushToContainer(elementRenderer); - } - } - else - { - addNewLine(); - for (int i=0; i<_richElements.size(); i++) - { - - RichElement* element = static_cast(_richElements.at(i)); - switch (element->_type) - { - case RICH_TEXT: - { - RichElementText* elmtText = static_cast(element); - handleTextRenderer(elmtText->_text.c_str(), elmtText->_fontName.c_str(), elmtText->_fontSize, elmtText->_color, elmtText->_opacity); - break; - } - case RICH_IMAGE: - { - RichElementImage* elmtImage = static_cast(element); - handleImageRenderer(elmtImage->_filePath.c_str(), elmtImage->_color, elmtImage->_opacity); - break; - } - case RICH_CUSTOM: - { - RichElementCustomNode* elmtCustom = static_cast(element); - handleCustomRenderer(elmtCustom->_customNode); - break; - } - default: - break; - } - } - } - formarRenderers(); - _formatTextDirty = false; - } -} - -void RichText::handleTextRenderer(const char *text, const char *fontName, float fontSize, const Color3B &color, GLubyte opacity) -{ - LabelTTF* textRenderer = LabelTTF::create(text, fontName, fontSize); - float textRendererWidth = textRenderer->getContentSize().width; - _leftSpaceWidth -= textRendererWidth; - if (_leftSpaceWidth < 0.0f) - { - float overstepPercent = (-_leftSpaceWidth) / textRendererWidth; - std::string curText = text; - int stringLength = curText.length(); - int leftLength = stringLength * (1.0f - overstepPercent); - std::string leftWords = curText.substr(0, leftLength); - std::string cutWords = curText.substr(leftLength, curText.length()-1); - if (leftLength > 0) - { - LabelTTF* leftRenderer = LabelTTF::create(leftWords.substr(0, leftLength).c_str(), fontName, fontSize); - leftRenderer->setColor(color); - leftRenderer->setOpacity(opacity); - pushToContainer(leftRenderer); - } - - addNewLine(); - handleTextRenderer(cutWords.c_str(), fontName, fontSize, color, opacity); - } - else - { - textRenderer->setColor(color); - textRenderer->setOpacity(opacity); - pushToContainer(textRenderer); - } -} - -void RichText::handleImageRenderer(const char *fileParh, const Color3B &color, GLubyte opacity) -{ - Sprite* imageRenderer = Sprite::create(fileParh); - handleCustomRenderer(imageRenderer); -} - -void RichText::handleCustomRenderer(cocos2d::Node *renderer) -{ - Size imgSize = renderer->getContentSize(); - _leftSpaceWidth -= imgSize.width; - if (_leftSpaceWidth < 0.0f) - { - addNewLine(); - pushToContainer(renderer); - _leftSpaceWidth -= imgSize.width; - } - else - { - pushToContainer(renderer); - } -} - -void RichText::addNewLine() -{ - _leftSpaceWidth = _customSize.width; - _elementRenders.push_back(new Vector()); -} - -void RichText::formarRenderers() -{ - if (_ignoreSize) - { - float newContentSizeWidth = 0.0f; - float newContentSizeHeight = 0.0f; - - Vector* row = (_elementRenders[0]); - float nextPosX = 0.0f; - for (int j=0; jsize(); j++) - { - Node* l = row->at(j); - l->setAnchorPoint(Point::ZERO); - l->setPosition(Point(nextPosX, 0.0f)); - _elementRenderersContainer->addChild(l, 1, j); - Size iSize = l->getContentSize(); - newContentSizeWidth += iSize.width; - newContentSizeHeight = MAX(newContentSizeHeight, iSize.height); - nextPosX += iSize.width; - } - _elementRenderersContainer->setContentSize(Size(newContentSizeWidth, newContentSizeHeight)); - } - else - { - float newContentSizeHeight = 0.0f; - float *maxHeights = new float[_elementRenders.size()]; - - for (int i=0; i<_elementRenders.size(); i++) - { - Vector* row = (_elementRenders[i]); - float maxHeight = 0.0f; - for (int j=0; jsize(); j++) - { - Node* l = row->at(j); - maxHeight = MAX(l->getContentSize().height, maxHeight); - } - maxHeights[i] = maxHeight; - newContentSizeHeight += maxHeights[i]; - } - - - float nextPosY = _customSize.height; - for (int i=0; i<_elementRenders.size(); i++) - { - Vector* row = (_elementRenders[i]); - float nextPosX = 0.0f; - nextPosY -= (maxHeights[i] + _verticalSpace); - - for (int j=0; jsize(); j++) - { - Node* l = row->at(j); - l->setAnchorPoint(Point::ZERO); - l->setPosition(Point(nextPosX, nextPosY)); - _elementRenderersContainer->addChild(l, 1, i*10 + j); - nextPosX += l->getContentSize().width; - } - } - _elementRenderersContainer->setContentSize(_size); - delete [] maxHeights; - } - - int length = _elementRenders.size(); - for (size_t i = 0; i* l = _elementRenders[i]; - l->clear(); - delete l; - } - _elementRenders.clear(); - - if (_ignoreSize) - { - Size s = getContentSize(); - _size = s; - } - else - { - _size = _customSize; - } -} - -void RichText::pushToContainer(cocos2d::Node *renderer) -{ - if (_elementRenders.size() <= 0) - { - return; - } - _elementRenders[_elementRenders.size()-1]->pushBack(renderer); -} - -void RichText::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) -{ - if (_enabled) - { - formatText(); - Widget::visit(renderer, parentTransform, parentTransformUpdated); - } -} - -void RichText::setVerticalSpace(float space) -{ - _verticalSpace = space; -} - -void RichText::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _elementRenderersContainer->setAnchorPoint(pt); -} - -const Size& RichText::getContentSize() const -{ - return _elementRenderersContainer->getContentSize(); -} - -void RichText::ignoreContentAdaptWithSize(bool ignore) -{ - if (_ignoreSize != ignore) - { - _formatTextDirty = true; - Widget::ignoreContentAdaptWithSize(ignore); - } -} - -} - -NS_CC_END \ No newline at end of file diff --git a/cocos/gui/UIRichText.h b/cocos/gui/UIRichText.h deleted file mode 100644 index 444c8fd03a..0000000000 --- a/cocos/gui/UIRichText.h +++ /dev/null @@ -1,133 +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 __UIRICHTEXT_H__ -#define __UIRICHTEXT_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum { - RICH_TEXT, - RICH_IMAGE, - RICH_CUSTOM -}RichElementType; - -class RichElement : public Ref -{ -public: - RichElement(){}; - virtual ~RichElement(){}; - bool init(int tag, const Color3B& color, GLubyte opacity); -protected: - RichElementType _type; - int _tag; - Color3B _color; - GLubyte _opacity; - friend class RichText; -}; - -class RichElementText : public RichElement -{ -public: - RichElementText(){_type = RICH_TEXT;}; - virtual ~RichElementText(){}; - bool init(int tag, const Color3B& color, GLubyte opacity, const char* text, const char* fontName, float fontSize); - static RichElementText* create(int tag, const Color3B& color, GLubyte opacity, const char* text, const char* fontName, float fontSize); -protected: - std::string _text; - std::string _fontName; - float _fontSize; - friend class RichText; - -}; - -class RichElementImage : public RichElement -{ -public: - RichElementImage(){_type = RICH_IMAGE;}; - virtual ~RichElementImage(){}; - bool init(int tag, const Color3B& color, GLubyte opacity, const char* filePath); - static RichElementImage* create(int tag, const Color3B& color, GLubyte opacity, const char* filePath); -protected: - std::string _filePath; - Rect _textureRect; - int _textureType; - friend class RichText; -}; - -class RichElementCustomNode : public RichElement -{ -public: - RichElementCustomNode(){_type = RICH_CUSTOM;}; - virtual ~RichElementCustomNode(){CC_SAFE_RELEASE(_customNode);}; - bool init(int tag, const Color3B& color, GLubyte opacity, Node* customNode); - static RichElementCustomNode* create(int tag, const Color3B& color, GLubyte opacity, Node* customNode); -protected: - Node* _customNode; - friend class RichText; -}; - -class RichText : public Widget -{ -public: - RichText(); - virtual ~RichText(); - static RichText* create(); - void insertElement(RichElement* element, int index); - void pushBackElement(RichElement* element); - void removeElement(int index); - void removeElement(RichElement* element); - virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; - void setVerticalSpace(float space); - virtual void setAnchorPoint(const Point &pt); - virtual const Size& getContentSize() const; - void formatText(); - virtual void ignoreContentAdaptWithSize(bool ignore); -protected: - virtual bool init(); - virtual void initRenderer(); - void pushToContainer(Node* renderer); - void handleTextRenderer(const char* text, const char* fontName, float fontSize, const Color3B& color, GLubyte opacity); - void handleImageRenderer(const char* fileParh, const Color3B& color, GLubyte opacity); - void handleCustomRenderer(Node* renderer); - void formarRenderers(); - void addNewLine(); -protected: - bool _formatTextDirty; - Vector _richElements; - std::vector*> _elementRenders; - float _leftSpaceWidth; - float _verticalSpace; - Node* _elementRenderersContainer; -}; - -} - -NS_CC_END - -#endif /* defined(__UIRichText__) */ diff --git a/cocos/gui/UIScrollInterface.h b/cocos/gui/UIScrollInterface.h deleted file mode 100644 index cb9101118a..0000000000 --- a/cocos/gui/UIScrollInterface.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UISCROLLDELEGATE_H__ -#define __UISCROLLDELEGATE_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -class UIScrollInterface -{ -public: - virtual ~UIScrollInterface() {} - -protected: - virtual void handlePressLogic(const Point &touchPoint) = 0; - virtual void handleMoveLogic(const Point &touchPoint) = 0; - virtual void handleReleaseLogic(const Point &touchPoint) = 0; - virtual void interceptTouchEvent(int handleState, Widget* sender, const Point &touchPoint) = 0; -}; - -} -NS_CC_END - -#endif /* defined(__UIScrollDelegate__) */ diff --git a/cocos/gui/UIScrollView.cpp b/cocos/gui/UIScrollView.cpp deleted file mode 100644 index 754baccd2b..0000000000 --- a/cocos/gui/UIScrollView.cpp +++ /dev/null @@ -1,1719 +0,0 @@ -/**************************************************************************** -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 "gui/UIScrollView.h" - -NS_CC_BEGIN - -namespace ui { - -static const float AUTOSCROLLMAXSPEED = 1000.0f; - -const Point SCROLLDIR_UP = Point(0.0f, 1.0f); -const Point SCROLLDIR_DOWN = Point(0.0f, -1.0f); -const Point SCROLLDIR_LEFT = Point(-1.0f, 0.0f); -const Point SCROLLDIR_RIGHT = Point(1.0f, 0.0f); - -IMPLEMENT_CLASS_GUI_INFO(ScrollView) - -ScrollView::ScrollView(): -_innerContainer(nullptr), -_direction(SCROLLVIEW_DIR_VERTICAL), -_touchBeganPoint(Point::ZERO), -_touchMovedPoint(Point::ZERO), -_touchEndedPoint(Point::ZERO), -_touchMovingPoint(Point::ZERO), -_autoScrollDir(Point::ZERO), -_topBoundary(0.0f), -_bottomBoundary(0.0f), -_leftBoundary(0.0f), -_rightBoundary(0.0f), -_bounceTopBoundary(0.0f), -_bounceBottomBoundary(0.0f), -_bounceLeftBoundary(0.0f), -_bounceRightBoundary(0.0f), -_autoScroll(false), -_autoScrollAddUpTime(0.0f), -_autoScrollOriginalSpeed(0.0f), -_autoScrollAcceleration(-1000.0f), -_isAutoScrollSpeedAttenuated(false), -_needCheckAutoScrollDestination(false), -_autoScrollDestination(Point::ZERO), -_bePressed(false), -_slidTime(0.0f), -_moveChildPoint(Point::ZERO), -_childFocusCancelOffset(5.0f), -_leftBounceNeeded(false), -_topBounceNeeded(false), -_rightBounceNeeded(false), -_bottomBounceNeeded(false), -_bounceEnabled(false), -_bouncing(false), -_bounceDir(Point::ZERO), -_bounceOriginalSpeed(0.0f), -_inertiaScrollEnabled(true), -_scrollViewEventListener(nullptr), -_scrollViewEventSelector(nullptr) -{ -} - -ScrollView::~ScrollView() -{ - _scrollViewEventListener = nullptr; - _scrollViewEventSelector = nullptr; -} - -ScrollView* ScrollView::create() -{ - ScrollView* widget = new ScrollView(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -void ScrollView::onEnter() -{ - Layout::onEnter(); - scheduleUpdate(); -} - -bool ScrollView::init() -{ - if (Layout::init()) - { - setTouchEnabled(true); - setClippingEnabled(true); - _innerContainer->setTouchEnabled(false); - return true; - } - return false; -} - -void ScrollView::initRenderer() -{ - Layout::initRenderer(); - _innerContainer = Layout::create(); - Layout::addChild(_innerContainer,1,1); -} - -void ScrollView::onSizeChanged() -{ - Layout::onSizeChanged(); - _topBoundary = _size.height; - _rightBoundary = _size.width; - float bounceBoundaryParameterX = _size.width / 3.0f; - float bounceBoundaryParameterY = _size.height / 3.0f; - _bounceTopBoundary = _size.height - bounceBoundaryParameterY; - _bounceBottomBoundary = bounceBoundaryParameterY; - _bounceLeftBoundary = bounceBoundaryParameterX; - _bounceRightBoundary = _size.width - bounceBoundaryParameterX; - Size innerSize = _innerContainer->getSize(); - float orginInnerSizeWidth = innerSize.width; - float orginInnerSizeHeight = innerSize.height; - float innerSizeWidth = MAX(orginInnerSizeWidth, _size.width); - float innerSizeHeight = MAX(orginInnerSizeHeight, _size.height); - _innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight)); - _innerContainer->setPosition(Point(0, _size.height - _innerContainer->getSize().height)); -} - -void ScrollView::setInnerContainerSize(const Size &size) -{ - float innerSizeWidth = _size.width; - float innerSizeHeight = _size.height; - Size originalInnerSize = _innerContainer->getSize(); - if (size.width < _size.width) - { - CCLOG("Inner width <= scrollview width, it will be force sized!"); - } - else - { - innerSizeWidth = size.width; - } - if (size.height < _size.height) - { - CCLOG("Inner height <= scrollview height, it will be force sized!"); - } - else - { - innerSizeHeight = size.height; - } - _innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight)); - - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: - { - Size newInnerSize = _innerContainer->getSize(); - float offset = originalInnerSize.height - newInnerSize.height; - scrollChildren(0.0f, offset); - break; - } - case SCROLLVIEW_DIR_HORIZONTAL: - { - if (_innerContainer->getRightInParent() <= _size.width) - { - Size newInnerSize = _innerContainer->getSize(); - float offset = originalInnerSize.width - newInnerSize.width; - scrollChildren(offset, 0.0f); - } - break; - } - case SCROLLVIEW_DIR_BOTH: - { - Size newInnerSize = _innerContainer->getSize(); - float offsetY = originalInnerSize.height - newInnerSize.height; - float offsetX = 0.0f; - if (_innerContainer->getRightInParent() <= _size.width) - { - offsetX = originalInnerSize.width - newInnerSize.width; - } - scrollChildren(offsetX, offsetY); - break; - } - default: - break; - } - if (_innerContainer->getLeftInParent() > 0.0f) - { - _innerContainer->setPosition(Point(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, _innerContainer->getPosition().y)); - } - if (_innerContainer->getRightInParent() < _size.width) - { - _innerContainer->setPosition(Point(_size.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), _innerContainer->getPosition().y)); - } - if (_innerContainer->getPosition().y > 0.0f) - { - _innerContainer->setPosition(Point(_innerContainer->getPosition().x, _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height)); - } - if (_innerContainer->getTopInParent() < _size.height) - { - _innerContainer->setPosition(Point(_innerContainer->getPosition().x, _size.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height)); - } -} - -const Size& ScrollView::getInnerContainerSize() const -{ - return _innerContainer->getSize(); -} - -void ScrollView::addChild(Node *child) -{ - Layout::addChild(child); -} - -void ScrollView::addChild(Node * child, int zOrder) -{ - Layout::addChild(child, zOrder); -} - -void ScrollView::addChild(Node *child, int zOrder, int tag) -{ - return _innerContainer->addChild(child, zOrder, tag); -} - -void ScrollView::removeAllChildren() -{ - removeAllChildrenWithCleanup(true); -} - -void ScrollView::removeAllChildrenWithCleanup(bool cleanup) -{ - _innerContainer->removeAllChildrenWithCleanup(cleanup); -} - -void ScrollView::removeChild(Node* child, bool cleanup) -{ - return _innerContainer->removeChild(child, cleanup); -} - -Vector& ScrollView::getChildren() -{ - return _innerContainer->getChildren(); -} - -const Vector& ScrollView::getChildren() const -{ - return _innerContainer->getChildren(); -} - -ssize_t ScrollView::getChildrenCount() const -{ - return _innerContainer->getChildrenCount(); -} - -Node* ScrollView::getChildByTag(int tag) -{ - return _innerContainer->getChildByTag(tag); -} - -Widget* ScrollView::getChildByName(const char *name) -{ - return _innerContainer->getChildByName(name); -} - -void ScrollView::addNode(Node* node) -{ - Layout::addNode(node); -} - -void ScrollView::addNode(Node * node, int zOrder) -{ - Layout::addNode(node, zOrder); -} - -void ScrollView::addNode(Node* node, int zOrder, int tag) -{ - _innerContainer->addNode(node, zOrder, tag); -} - -Node* ScrollView::getNodeByTag(int tag) -{ - return _innerContainer->getNodeByTag(tag); -} - -Vector& ScrollView::getNodes() -{ - return _innerContainer->getNodes(); -} - -void ScrollView::removeNode(Node* node) -{ - _innerContainer->removeNode(node); -} - -void ScrollView::removeNodeByTag(int tag) -{ - _innerContainer->removeNodeByTag(tag); -} - -void ScrollView::removeAllNodes() -{ - _innerContainer->removeAllNodes(); -} - -void ScrollView::moveChildren(float offsetX, float offsetY) -{ - _moveChildPoint = _innerContainer->getPosition() + Point(offsetX, offsetY); - _innerContainer->setPosition(_moveChildPoint); -} - -void ScrollView::autoScrollChildren(float dt) -{ - float lastTime = _autoScrollAddUpTime; - _autoScrollAddUpTime += dt; - if (_isAutoScrollSpeedAttenuated) - { - float nowSpeed = _autoScrollOriginalSpeed + _autoScrollAcceleration * _autoScrollAddUpTime; - if (nowSpeed <= 0.0f) - { - stopAutoScrollChildren(); - checkNeedBounce(); - } - else - { - float timeParam = lastTime * 2 + dt; - float offset = (_autoScrollOriginalSpeed + _autoScrollAcceleration * timeParam * 0.5f) * dt; - float offsetX = offset * _autoScrollDir.x; - float offsetY = offset * _autoScrollDir.y; - if (!scrollChildren(offsetX, offsetY)) - { - stopAutoScrollChildren(); - checkNeedBounce(); - } - } - } - else - { - if (_needCheckAutoScrollDestination) - { - float xOffset = _autoScrollDir.x * dt * _autoScrollOriginalSpeed; - float yOffset = _autoScrollDir.y * dt * _autoScrollOriginalSpeed; - bool notDone = checkCustomScrollDestination(&xOffset, &yOffset); - bool scrollCheck = scrollChildren(xOffset, yOffset); - if (!notDone || !scrollCheck) - { - stopAutoScrollChildren(); - checkNeedBounce(); - } - } - else - { - if (!scrollChildren(_autoScrollDir.x * dt * _autoScrollOriginalSpeed, _autoScrollDir.y * dt * _autoScrollOriginalSpeed)) - { - stopAutoScrollChildren(); - checkNeedBounce(); - } - } - } -} - -void ScrollView::bounceChildren(float dt) -{ - if (_bounceOriginalSpeed <= 0.0f) - { - stopBounceChildren(); - } - if (!bounceScrollChildren(_bounceDir.x * dt * _bounceOriginalSpeed, _bounceDir.y * dt * _bounceOriginalSpeed)) - { - stopBounceChildren(); - } -} - -bool ScrollView::checkNeedBounce() -{ - if (!_bounceEnabled) - { - return false; - } - checkBounceBoundary(); - if (_topBounceNeeded || _bottomBounceNeeded || _leftBounceNeeded || _rightBounceNeeded) - { - if (_topBounceNeeded && _leftBounceNeeded) - { - Point scrollVector = Point(0.0f, _size.height) - Point(_innerContainer->getLeftInParent(), _innerContainer->getTopInParent()); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_topBounceNeeded && _rightBounceNeeded) - { - Point scrollVector = Point(_size.width, _size.height) - Point(_innerContainer->getRightInParent(), _innerContainer->getTopInParent()); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_bottomBounceNeeded && _leftBounceNeeded) - { - Point scrollVector = Point::ZERO - Point(_innerContainer->getLeftInParent(), _innerContainer->getBottomInParent()); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_bottomBounceNeeded && _rightBounceNeeded) - { - Point scrollVector = Point(_size.width, 0.0f) - Point(_innerContainer->getRightInParent(), _innerContainer->getBottomInParent()); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_topBounceNeeded) - { - Point scrollVector = Point(0.0f, _size.height) - Point(0.0f, _innerContainer->getTopInParent()); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_bottomBounceNeeded) - { - Point scrollVector = Point::ZERO - Point(0.0f, _innerContainer->getBottomInParent()); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_leftBounceNeeded) - { - Point scrollVector = Point::ZERO - Point(_innerContainer->getLeftInParent(), 0.0f); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - else if (_rightBounceNeeded) - { - Point scrollVector = Point(_size.width, 0.0f) - Point(_innerContainer->getRightInParent(), 0.0f); - float orSpeed = scrollVector.getLength()/(0.2f); - _bounceDir = scrollVector.normalize(); - startBounceChildren(orSpeed); - } - return true; - } - return false; -} - -void ScrollView::checkBounceBoundary() -{ - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos > _bottomBoundary) - { - scrollToBottomEvent(); - _bottomBounceNeeded = true; - } - else - { - _bottomBounceNeeded = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos < _topBoundary) - { - scrollToTopEvent(); - _topBounceNeeded = true; - } - else - { - _topBounceNeeded = false; - } - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos < _rightBoundary) - { - scrollToRightEvent(); - _rightBounceNeeded = true; - } - else - { - _rightBounceNeeded = false; - } - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos > _leftBoundary) - { - scrollToLeftEvent(); - _leftBounceNeeded = true; - } - else - { - _leftBounceNeeded = false; - } -} - -void ScrollView::startBounceChildren(float v) -{ - _bounceOriginalSpeed = v; - _bouncing = true; -} - -void ScrollView::stopBounceChildren() -{ - _bouncing = false; - _bounceOriginalSpeed = 0.0f; - _leftBounceNeeded = false; - _rightBounceNeeded = false; - _topBounceNeeded = false; - _bottomBounceNeeded = false; -} - -void ScrollView::startAutoScrollChildrenWithOriginalSpeed(const Point& dir, float v, bool attenuated, float acceleration) -{ - stopAutoScrollChildren(); - _autoScrollDir = dir; - _isAutoScrollSpeedAttenuated = attenuated; - _autoScrollOriginalSpeed = v; - _autoScroll = true; - _autoScrollAcceleration = acceleration; -} - -void ScrollView::startAutoScrollChildrenWithDestination(const Point& des, float time, bool attenuated) -{ - _needCheckAutoScrollDestination = false; - _autoScrollDestination = des; - Point dis = des - _innerContainer->getPosition(); - Point dir = dis.normalize(); - float orSpeed = 0.0f; - float acceleration = -1000.0f; - if (attenuated) - { - acceleration = (-(2 * dis.getLength())) / (time * time); - orSpeed = 2 * dis.getLength() / time; - } - else - { - _needCheckAutoScrollDestination = true; - orSpeed = dis.getLength() / time; - } - startAutoScrollChildrenWithOriginalSpeed(dir, orSpeed, attenuated, acceleration); -} - -void ScrollView::jumpToDestination(const Point &des) -{ - float finalOffsetX = des.x; - float finalOffsetY = des.y; - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: - if (des.y <= 0) - { - finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height); - } - break; - case SCROLLVIEW_DIR_HORIZONTAL: - if (des.x <= 0) - { - finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width); - } - break; - case SCROLLVIEW_DIR_BOTH: - if (des.y <= 0) - { - finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height); - } - if (des.x <= 0) - { - finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width); - } - break; - default: - break; - } - _innerContainer->setPosition(Point(finalOffsetX, finalOffsetY)); -} - -void ScrollView::stopAutoScrollChildren() -{ - _autoScroll = false; - _autoScrollOriginalSpeed = 0.0f; - _autoScrollAddUpTime = 0.0f; -} - -bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY) -{ - bool scrollenabled = true; - if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) //first quadrant //bounce to top-right - { - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + realOffsetX >= _rightBoundary) - { - realOffsetX = _rightBoundary - icRightPos; - bounceRightEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY >= _topBoundary) - { - realOffsetY = _topBoundary - icTopPos; - bounceTopEvent(); - scrollenabled = false; - } - moveChildren(realOffsetX, realOffsetY); - } - else if(touchOffsetX < 0.0f && touchOffsetY > 0.0f) //second quadrant //bounce to top-left - { - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - float icLefrPos = _innerContainer->getLeftInParent(); - if (icLefrPos + realOffsetX <= _leftBoundary) - { - realOffsetX = _leftBoundary - icLefrPos; - bounceLeftEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY >= _topBoundary) - { - realOffsetY = _topBoundary - icTopPos; - bounceTopEvent(); - scrollenabled = false; - } - moveChildren(realOffsetX, realOffsetY); - } - else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) //third quadrant //bounce to bottom-left - { - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - float icLefrPos = _innerContainer->getLeftInParent(); - if (icLefrPos + realOffsetX <= _leftBoundary) - { - realOffsetX = _leftBoundary - icLefrPos; - bounceLeftEvent(); - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY <= _bottomBoundary) - { - realOffsetY = _bottomBoundary - icBottomPos; - bounceBottomEvent(); - scrollenabled = false; - } - moveChildren(realOffsetX, realOffsetY); - } - else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) //forth quadrant //bounce to bottom-right - { - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + realOffsetX >= _rightBoundary) - { - realOffsetX = _rightBoundary - icRightPos; - bounceRightEvent(); - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY <= _bottomBoundary) - { - realOffsetY = _bottomBoundary - icBottomPos; - bounceBottomEvent(); - scrollenabled = false; - } - moveChildren(realOffsetX, realOffsetY); - } - else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // bounce to top - { - float realOffsetY = touchOffsetY; - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY >= _topBoundary) - { - realOffsetY = _topBoundary - icTopPos; - bounceTopEvent(); - scrollenabled = false; - } - moveChildren(0.0f, realOffsetY); - } - else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) //bounce to bottom - { - float realOffsetY = touchOffsetY; - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY <= _bottomBoundary) - { - realOffsetY = _bottomBoundary - icBottomPos; - bounceBottomEvent(); - scrollenabled = false; - } - moveChildren(0.0f, realOffsetY); - } - else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) //bounce to right - { - float realOffsetX = touchOffsetX; - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + realOffsetX >= _rightBoundary) - { - realOffsetX = _rightBoundary - icRightPos; - bounceRightEvent(); - scrollenabled = false; - } - moveChildren(realOffsetX, 0.0f); - } - else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) //bounce to left - { - float realOffsetX = touchOffsetX; - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + realOffsetX <= _leftBoundary) - { - realOffsetX = _leftBoundary - icLeftPos; - bounceLeftEvent(); - scrollenabled = false; - } - moveChildren(realOffsetX, 0.0f); - } - return scrollenabled; -} - -bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY) -{ - bool scrollenabled = true; - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: // vertical - { - if (_autoScrollDir.y > 0) - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icBottomPos; - scrollenabled = false; - } - } - else - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + *touchOffsetY <= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icBottomPos; - scrollenabled = false; - } - } - break; - } - case SCROLLVIEW_DIR_HORIZONTAL: // horizontal - { - if (_autoScrollDir.x > 0) - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icLeftPos; - scrollenabled = false; - } - } - else - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + *touchOffsetX <= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icLeftPos; - scrollenabled = false; - } - } - break; - } - case SCROLLVIEW_DIR_BOTH: - { - if (*touchOffsetX > 0.0f && *touchOffsetY > 0.0f) // up right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icLeftPos; - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icBottomPos; - scrollenabled = false; - } - } - else if (*touchOffsetX < 0.0f && *touchOffsetY > 0.0f) // up left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icRightPos; - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icBottomPos; - scrollenabled = false; - } - } - else if (*touchOffsetX < 0.0f && *touchOffsetY < 0.0f) // down left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icRightPos; - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icTopPos; - scrollenabled = false; - } - } - else if (*touchOffsetX > 0.0f && *touchOffsetY < 0.0f) // down right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icLeftPos; - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icTopPos; - scrollenabled = false; - } - } - else if (*touchOffsetX == 0.0f && *touchOffsetY > 0.0f) // up - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icBottomPos; - scrollenabled = false; - } - } - else if (*touchOffsetX < 0.0f && *touchOffsetY == 0.0f) // left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icRightPos; - scrollenabled = false; - } - } - else if (*touchOffsetX == 0.0f && *touchOffsetY < 0.0f) // down - { - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) - { - *touchOffsetY = _autoScrollDestination.y - icTopPos; - scrollenabled = false; - } - } - else if (*touchOffsetX > 0.0f && *touchOffsetY == 0.0f) // right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) - { - *touchOffsetX = _autoScrollDestination.x - icLeftPos; - scrollenabled = false; - } - } - break; - } - default: - break; - } - return scrollenabled; -} - -bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) -{ - bool scrollenabled = true; - scrollingEvent(); - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: // vertical - { - float realOffset = touchOffsetY; - if (_bounceEnabled) - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) - { - realOffset = _bounceBottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _bounceTopBoundary) - { - realOffset = _bounceTopBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bottomBoundary) - { - realOffset = _bottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _topBoundary) - { - realOffset = _topBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - moveChildren(0.0f, realOffset); - break; - } - case SCROLLVIEW_DIR_HORIZONTAL: // horizontal - { - float realOffset = touchOffsetX; - if (_bounceEnabled) - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _bounceRightBoundary) - { - realOffset = _bounceRightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) - { - realOffset = _bounceLeftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - } - else - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _rightBoundary) - { - realOffset = _rightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _leftBoundary) - { - realOffset = _leftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - } - moveChildren(realOffset, 0.0f); - break; - } - case SCROLLVIEW_DIR_BOTH: - { - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - if (_bounceEnabled) - { - if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) - { - realOffsetX = _bounceLeftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) - { - realOffsetY = _bounceBottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _bounceRightBoundary) - { - realOffsetX = _bounceRightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) - { - realOffsetY = _bounceBottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _bounceRightBoundary) - { - realOffsetX = _bounceRightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _bounceTopBoundary) - { - realOffsetY = _bounceTopBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) - { - realOffsetX = _bounceLeftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _bounceTopBoundary) - { - realOffsetY = _bounceTopBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) - { - realOffsetY = _bounceBottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _bounceRightBoundary) - { - realOffsetX = _bounceRightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down - { - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _bounceTopBoundary) - { - realOffsetY = _bounceTopBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) - { - realOffsetX = _bounceLeftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - } - } - else - { - if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _leftBoundary) - { - realOffsetX = _leftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bottomBoundary) - { - realOffsetY = _bottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _rightBoundary) - { - realOffsetX = _rightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bottomBoundary) - { - realOffsetY = _bottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _rightBoundary) - { - realOffsetX = _rightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _topBoundary) - { - realOffsetY = _topBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _leftBoundary) - { - realOffsetX = _leftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _topBoundary) - { - realOffsetY = _topBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up - { - float icBottomPos = _innerContainer->getBottomInParent(); - if (icBottomPos + touchOffsetY >= _bottomBoundary) - { - realOffsetY = _bottomBoundary - icBottomPos; - scrollToBottomEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left - { - float icRightPos = _innerContainer->getRightInParent(); - if (icRightPos + touchOffsetX <= _rightBoundary) - { - realOffsetX = _rightBoundary - icRightPos; - scrollToRightEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down - { - float icTopPos = _innerContainer->getTopInParent(); - if (icTopPos + touchOffsetY <= _topBoundary) - { - realOffsetY = _topBoundary - icTopPos; - scrollToTopEvent(); - scrollenabled = false; - } - } - else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right - { - float icLeftPos = _innerContainer->getLeftInParent(); - if (icLeftPos + touchOffsetX >= _leftBoundary) - { - realOffsetX = _leftBoundary - icLeftPos; - scrollToLeftEvent(); - scrollenabled = false; - } - } - } - moveChildren(realOffsetX, realOffsetY); - break; - } - default: - break; - } - return scrollenabled; -} - -void ScrollView::scrollToBottom(float time, bool attenuated) -{ - startAutoScrollChildrenWithDestination(Point(_innerContainer->getPosition().x, 0.0f), time, attenuated); -} - -void ScrollView::scrollToTop(float time, bool attenuated) -{ - startAutoScrollChildrenWithDestination(Point(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height), time, attenuated); -} - -void ScrollView::scrollToLeft(float time, bool attenuated) -{ - startAutoScrollChildrenWithDestination(Point(0.0f, _innerContainer->getPosition().y), time, attenuated); -} - -void ScrollView::scrollToRight(float time, bool attenuated) -{ - startAutoScrollChildrenWithDestination(Point(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y), time, attenuated); -} - -void ScrollView::scrollToTopLeft(float time, bool attenuated) -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - startAutoScrollChildrenWithDestination(Point(0.0f, _size.height - _innerContainer->getSize().height), time, attenuated); -} - -void ScrollView::scrollToTopRight(float time, bool attenuated) -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - startAutoScrollChildrenWithDestination(Point(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height), time, attenuated); -} - -void ScrollView::scrollToBottomLeft(float time, bool attenuated) -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - startAutoScrollChildrenWithDestination(Point::ZERO, time, attenuated); -} - -void ScrollView::scrollToBottomRight(float time, bool attenuated) -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - startAutoScrollChildrenWithDestination(Point(_size.width - _innerContainer->getSize().width, 0.0f), time, attenuated); -} - -void ScrollView::scrollToPercentVertical(float percent, float time, bool attenuated) -{ - float minY = _size.height - _innerContainer->getSize().height; - float h = - minY; - startAutoScrollChildrenWithDestination(Point(_innerContainer->getPosition().x, minY + percent * h / 100.0f), time, attenuated); -} - -void ScrollView::scrollToPercentHorizontal(float percent, float time, bool attenuated) -{ - float w = _innerContainer->getSize().width - _size.width; - startAutoScrollChildrenWithDestination(Point(-(percent * w / 100.0f), _innerContainer->getPosition().y), time, attenuated); -} - -void ScrollView::scrollToPercentBothDirection(const Point& percent, float time, bool attenuated) -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - return; - } - float minY = _size.height - _innerContainer->getSize().height; - float h = - minY; - float w = _innerContainer->getSize().width - _size.width; - startAutoScrollChildrenWithDestination(Point(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), time, attenuated); -} - -void ScrollView::jumpToBottom() -{ - jumpToDestination(Point(_innerContainer->getPosition().x, 0.0f)); -} - -void ScrollView::jumpToTop() -{ - jumpToDestination(Point(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height)); -} - -void ScrollView::jumpToLeft() -{ - jumpToDestination(Point(0.0f, _innerContainer->getPosition().y)); -} - -void ScrollView::jumpToRight() -{ - jumpToDestination(Point(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y)); -} - -void ScrollView::jumpToTopLeft() -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - jumpToDestination(Point(0.0f, _size.height - _innerContainer->getSize().height)); -} - -void ScrollView::jumpToTopRight() -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - jumpToDestination(Point(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height)); -} - -void ScrollView::jumpToBottomLeft() -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - jumpToDestination(Point::ZERO); -} - -void ScrollView::jumpToBottomRight() -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - CCLOG("Scroll diretion is not both!"); - return; - } - jumpToDestination(Point(_size.width - _innerContainer->getSize().width, 0.0f)); -} - -void ScrollView::jumpToPercentVertical(float percent) -{ - float minY = _size.height - _innerContainer->getSize().height; - float h = - minY; - jumpToDestination(Point(_innerContainer->getPosition().x, minY + percent * h / 100.0f)); -} - -void ScrollView::jumpToPercentHorizontal(float percent) -{ - float w = _innerContainer->getSize().width - _size.width; - jumpToDestination(Point(-(percent * w / 100.0f), _innerContainer->getPosition().y)); -} - -void ScrollView::jumpToPercentBothDirection(const Point& percent) -{ - if (_direction != SCROLLVIEW_DIR_BOTH) - { - return; - } - float minY = _size.height - _innerContainer->getSize().height; - float h = - minY; - float w = _innerContainer->getSize().width - _size.width; - jumpToDestination(Point(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f)); -} - -void ScrollView::startRecordSlidAction() -{ - if (_autoScroll) - { - stopAutoScrollChildren(); - } - if (_bouncing) - { - stopBounceChildren(); - } - _slidTime = 0.0f; -} - -void ScrollView::endRecordSlidAction() -{ - if (!checkNeedBounce() && _inertiaScrollEnabled) - { - if (_slidTime <= 0.016f) - { - return; - } - float totalDis = 0.0f; - Point dir; - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: - totalDis = _touchEndedPoint.y - _touchBeganPoint.y; - if (totalDis < 0.0f) - { - dir = SCROLLDIR_DOWN; - } - else - { - dir = SCROLLDIR_UP; - } - break; - case SCROLLVIEW_DIR_HORIZONTAL: - totalDis = _touchEndedPoint.x - _touchBeganPoint.x; - if (totalDis < 0.0f) - { - dir = SCROLLDIR_LEFT; - } - else - { - dir = SCROLLDIR_RIGHT; - } - break; - case SCROLLVIEW_DIR_BOTH: - { - Point subVector = _touchEndedPoint - _touchBeganPoint; - totalDis = subVector.getLength(); - dir = subVector.normalize(); - break; - } - default: - break; - } - float orSpeed = MIN(fabs(totalDis)/(_slidTime), AUTOSCROLLMAXSPEED); - startAutoScrollChildrenWithOriginalSpeed(dir, orSpeed, true, -1000); - _slidTime = 0.0f; - } -} - -void ScrollView::handlePressLogic(const Point &touchPoint) -{ - _touchBeganPoint = convertToNodeSpace(touchPoint); - _touchMovingPoint = _touchBeganPoint; - startRecordSlidAction(); - _bePressed = true; -} - -void ScrollView::handleMoveLogic(const Point &touchPoint) -{ - _touchMovedPoint = convertToNodeSpace(touchPoint); - Point delta = _touchMovedPoint - _touchMovingPoint; - _touchMovingPoint = _touchMovedPoint; - switch (_direction) - { - case SCROLLVIEW_DIR_VERTICAL: // vertical - { - scrollChildren(0.0f, delta.y); - break; - } - case SCROLLVIEW_DIR_HORIZONTAL: // horizontal - { - scrollChildren(delta.x, 0.0f); - break; - } - case SCROLLVIEW_DIR_BOTH: // both - { - scrollChildren(delta.x, delta.y); - break; - } - default: - break; - } -} - -void ScrollView::handleReleaseLogic(const Point &touchPoint) -{ - _touchEndedPoint = convertToNodeSpace(touchPoint); - endRecordSlidAction(); - _bePressed = false; -} - -bool ScrollView::onTouchBegan(Touch *touch, Event *unusedEvent) -{ - bool pass = Layout::onTouchBegan(touch, unusedEvent); - if (_hitted) - { - handlePressLogic(_touchStartPos); - } - return pass; -} - -void ScrollView::onTouchMoved(Touch *touch, Event *unusedEvent) -{ - Layout::onTouchMoved(touch, unusedEvent); - handleMoveLogic(_touchMovePos); -} - -void ScrollView::onTouchEnded(Touch *touch, Event *unusedEvent) -{ - Layout::onTouchEnded(touch, unusedEvent); - handleReleaseLogic(_touchEndPos); -} - -void ScrollView::onTouchCancelled(Touch *touch, Event *unusedEvent) -{ - Layout::onTouchCancelled(touch, unusedEvent); - handleReleaseLogic(touch->getLocation()); -} - -void ScrollView::update(float dt) -{ - if (_autoScroll) - { - autoScrollChildren(dt); - } - if (_bouncing) - { - bounceChildren(dt); - } - recordSlidTime(dt); -} - -void ScrollView::recordSlidTime(float dt) -{ - if (_bePressed) - { - _slidTime += dt; - } -} - -void ScrollView::interceptTouchEvent(int handleState, Widget *sender, const Point &touchPoint) -{ - switch (handleState) - { - case 0: - handlePressLogic(touchPoint); - break; - - case 1: - { - float offset = (sender->getTouchStartPos() - touchPoint).getLength(); - if (offset > _childFocusCancelOffset) - { - sender->setFocused(false); - handleMoveLogic(touchPoint); - } - } - break; - - case 2: - handleReleaseLogic(touchPoint); - break; - - case 3: - handleReleaseLogic(touchPoint); - break; - } -} - -void ScrollView::checkChildInfo(int handleState,Widget* sender,const Point &touchPoint) -{ - interceptTouchEvent(handleState, sender, touchPoint); -} - -void ScrollView::scrollToTopEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP); - } -} - -void ScrollView::scrollToBottomEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM); - } -} - -void ScrollView::scrollToLeftEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT); - } -} - -void ScrollView::scrollToRightEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_RIGHT); - } -} - -void ScrollView::scrollingEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLLING); - } -} - -void ScrollView::bounceTopEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_TOP); - } -} - -void ScrollView::bounceBottomEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_BOTTOM); - } -} - -void ScrollView::bounceLeftEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_LEFT); - } -} - -void ScrollView::bounceRightEvent() -{ - if (_scrollViewEventListener && _scrollViewEventSelector) - { - (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_RIGHT); - } -} - -void ScrollView::addEventListenerScrollView(Ref *target, SEL_ScrollViewEvent selector) -{ - _scrollViewEventListener = target; - _scrollViewEventSelector = selector; -} - -void ScrollView::setDirection(SCROLLVIEW_DIR dir) -{ - _direction = dir; -} - -SCROLLVIEW_DIR ScrollView::getDirection() -{ - return _direction; -} - -void ScrollView::setBounceEnabled(bool enabled) -{ - _bounceEnabled = enabled; -} - -bool ScrollView::isBounceEnabled() const -{ - return _bounceEnabled; -} - -void ScrollView::setInertiaScrollEnabled(bool enabled) -{ - _inertiaScrollEnabled = enabled; -} - -bool ScrollView::isInertiaScrollEnabled() const -{ - return _inertiaScrollEnabled; -} - -Layout* ScrollView::getInnerContainer() -{ - return _innerContainer; -} - -void ScrollView::setLayoutType(LayoutType type) -{ - _innerContainer->setLayoutType(type); -} - -LayoutType ScrollView::getLayoutType() const -{ - return _innerContainer->getLayoutType(); -} - -void ScrollView::doLayout() -{ - if (!_doLayoutDirty) - { - return; - } - _doLayoutDirty = false; -} - -std::string ScrollView::getDescription() const -{ - return "ScrollView"; -} - -Widget* ScrollView::createCloneInstance() -{ - return ScrollView::create(); -} - -void ScrollView::copyClonedWidgetChildren(Widget* model) -{ - Layout::copyClonedWidgetChildren(model); -} - -void ScrollView::copySpecialProperties(Widget *widget) -{ - ScrollView* scrollView = dynamic_cast(widget); - if (scrollView) - { - Layout::copySpecialProperties(widget); - setInnerContainerSize(scrollView->getInnerContainerSize()); - setDirection(scrollView->_direction); - setBounceEnabled(scrollView->_bounceEnabled); - setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UIScrollView.h b/cocos/gui/UIScrollView.h deleted file mode 100644 index 267d444f01..0000000000 --- a/cocos/gui/UIScrollView.h +++ /dev/null @@ -1,430 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UISCROLLVIEW_H__ -#define __UISCROLLVIEW_H__ - -#include "gui/UILayout.h" -#include "gui/UIScrollInterface.h" - -NS_CC_BEGIN - -namespace ui { - -enum SCROLLVIEW_DIR -{ - SCROLLVIEW_DIR_NONE, - SCROLLVIEW_DIR_VERTICAL, - SCROLLVIEW_DIR_HORIZONTAL, - SCROLLVIEW_DIR_BOTH -}; - -typedef enum -{ - SCROLLVIEW_EVENT_SCROLL_TO_TOP, - SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM, - SCROLLVIEW_EVENT_SCROLL_TO_LEFT, - SCROLLVIEW_EVENT_SCROLL_TO_RIGHT, - SCROLLVIEW_EVENT_SCROLLING, - SCROLLVIEW_EVENT_BOUNCE_TOP, - SCROLLVIEW_EVENT_BOUNCE_BOTTOM, - SCROLLVIEW_EVENT_BOUNCE_LEFT, - SCROLLVIEW_EVENT_BOUNCE_RIGHT -}ScrollviewEventType; - -typedef void (Ref::*SEL_ScrollViewEvent)(Ref*, ScrollviewEventType); -#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR) - - -class ScrollView : public Layout , public UIScrollInterface -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - ScrollView(); - - /** - * Default destructor - */ - virtual ~ScrollView(); - - /** - * Allocates and initializes. - */ - static ScrollView* create(); - - /** - * Changes scroll direction of scrollview. - * - * @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll - * - * @param SCROLLVIEW_DIR - */ - virtual void setDirection(SCROLLVIEW_DIR dir); - - /** - * Gets scroll direction of scrollview. - * - * @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll - * - * @return SCROLLVIEW_DIR - */ - SCROLLVIEW_DIR getDirection(); - - /** - * Gets inner container of scrollview. - * - * Inner container is the container of scrollview's children. - * - * @return inner container. - */ - Layout* getInnerContainer(); - - /** - * Scroll inner container to bottom boundary of scrollview. - */ - void scrollToBottom(float time, bool attenuated); - - /** - * Scroll inner container to top boundary of scrollview. - */ - void scrollToTop(float time, bool attenuated); - - /** - * Scroll inner container to left boundary of scrollview. - */ - void scrollToLeft(float time, bool attenuated); - - /** - * Scroll inner container to right boundary of scrollview. - */ - void scrollToRight(float time, bool attenuated); - - /** - * Scroll inner container to top and left boundary of scrollview. - */ - void scrollToTopLeft(float time, bool attenuated); - - /** - * Scroll inner container to top and right boundary of scrollview. - */ - void scrollToTopRight(float time, bool attenuated); - - /** - * Scroll inner container to bottom and left boundary of scrollview. - */ - void scrollToBottomLeft(float time, bool attenuated); - - /** - * Scroll inner container to bottom and right boundary of scrollview. - */ - void scrollToBottomRight(float time, bool attenuated); - - /** - * Scroll inner container to vertical percent position of scrollview. - */ - void scrollToPercentVertical(float percent, float time, bool attenuated); - - /** - * Scroll inner container to horizontal percent position of scrollview. - */ - void scrollToPercentHorizontal(float percent, float time, bool attenuated); - - /** - * Scroll inner container to both direction percent position of scrollview. - */ - void scrollToPercentBothDirection(const Point& percent, float time, bool attenuated); - - /** - * Move inner container to bottom boundary of scrollview. - */ - void jumpToBottom(); - - /** - * Move inner container to top boundary of scrollview. - */ - void jumpToTop(); - - /** - * Move inner container to left boundary of scrollview. - */ - void jumpToLeft(); - - /** - * Move inner container to right boundary of scrollview. - */ - void jumpToRight(); - - /** - * Move inner container to top and left boundary of scrollview. - */ - void jumpToTopLeft(); - - /** - * Move inner container to top and right boundary of scrollview. - */ - void jumpToTopRight(); - - /** - * Move inner container to bottom and left boundary of scrollview. - */ - void jumpToBottomLeft(); - - /** - * Move inner container to bottom and right boundary of scrollview. - */ - void jumpToBottomRight(); - - /** - * Move inner container to vertical percent position of scrollview. - */ - void jumpToPercentVertical(float percent); - - /** - * Move inner container to horizontal percent position of scrollview. - */ - void jumpToPercentHorizontal(float percent); - - /** - * Move inner container to both direction percent position of scrollview. - */ - void jumpToPercentBothDirection(const Point& percent); - - /** - * Changes inner container size of scrollview. - * - * Inner container size must be larger than or equal scrollview's size. - * - * @param inner container size. - */ - void setInnerContainerSize(const Size &size); - - /** - * Gets inner container size of scrollview. - * - * Inner container size must be larger than or equal scrollview's size. - * - * @return inner container size. - */ - const Size& getInnerContainerSize() const; - - /** - * Add call back function called scrollview event triggered - */ - void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector); - - virtual void addChild(Node * child) override; - /** - * Adds a child to the container with a z-order - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - */ - virtual void addChild(Node * child, int zOrder) override; - /** - * Adds a child to the container with z order and tag - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - * @param tag A interger to identify the node easily. Please refer to setTag(int) - */ - virtual void addChild(Node* child, int zOrder, int tag) override; - - //override "removeAllChildrenAndCleanUp" method of widget. - virtual void removeAllChildren() override; - - virtual void removeAllChildrenWithCleanup(bool cleanup) override; - - //override "removeChild" method of widget. - virtual void removeChild(Node* child, bool cleaup = true) override; - - //override "getChildren" method of widget. - virtual Vector& getChildren() override; - virtual const Vector& getChildren() const override; - - virtual ssize_t getChildrenCount() const override; - - virtual Node * getChildByTag(int tag) override; - - virtual Widget* getChildByName(const char* name) override; - - virtual void addNode(Node* node) override; - - virtual void addNode(Node * node, int zOrder) override; - - virtual void addNode(Node* node, int zOrder, int tag) override; - - virtual Node * getNodeByTag(int tag) override; - - virtual Vector& getNodes() override; - - virtual void removeNode(Node* node) override; - - virtual void removeNodeByTag(int tag) override; - - virtual void removeAllNodes() override; - - virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; - virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; - virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; - virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; - - virtual void update(float dt) override; - - void setBounceEnabled(bool enabled); - - bool isBounceEnabled() const; - - void setInertiaScrollEnabled(bool enabled); - - bool isInertiaScrollEnabled() const; - - /** - * Sets LayoutType. - * - * @see LayoutType - * - * @param LayoutType - */ - virtual void setLayoutType(LayoutType type) override; - - /** - * Gets LayoutType. - * - * @see LayoutType - * - * @return LayoutType - */ - virtual LayoutType getLayoutType() const override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - virtual void onEnter() override; -protected: - virtual bool init() override; - virtual void initRenderer() override; - void moveChildren(float offsetX, float offsetY); - void autoScrollChildren(float dt); - void bounceChildren(float dt); - void checkBounceBoundary(); - bool checkNeedBounce(); - void startAutoScrollChildrenWithOriginalSpeed(const Point& dir, float v, bool attenuated, float acceleration); - void startAutoScrollChildrenWithDestination(const Point& des, float time, bool attenuated); - void jumpToDestination(const Point& des); - void stopAutoScrollChildren(); - void startBounceChildren(float v); - void stopBounceChildren(); - bool checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY); - virtual bool scrollChildren(float touchOffsetX, float touchOffsetY); - bool bounceScrollChildren(float touchOffsetX, float touchOffsetY); - void startRecordSlidAction(); - virtual void endRecordSlidAction(); - virtual void handlePressLogic(const Point &touchPoint) override; - virtual void handleMoveLogic(const Point &touchPoint) override; - virtual void handleReleaseLogic(const Point &touchPoint) override; - virtual void interceptTouchEvent(int handleState,Widget* sender,const Point &touchPoint) override; - virtual void checkChildInfo(int handleState,Widget* sender,const Point &touchPoint) override; - void recordSlidTime(float dt); - void scrollToTopEvent(); - void scrollToBottomEvent(); - void scrollToLeftEvent(); - void scrollToRightEvent(); - void scrollingEvent(); - void bounceTopEvent(); - void bounceBottomEvent(); - void bounceLeftEvent(); - void bounceRightEvent(); - virtual void onSizeChanged() override; - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; - virtual void copyClonedWidgetChildren(Widget* model) override; - virtual void setClippingEnabled(bool able) override{Layout::setClippingEnabled(able);}; - virtual void doLayout() override; -protected: - Layout* _innerContainer; - - SCROLLVIEW_DIR _direction; - - Point _touchBeganPoint; - Point _touchMovedPoint; - Point _touchEndedPoint; - Point _touchMovingPoint; - Point _autoScrollDir; - - float _topBoundary; - float _bottomBoundary; - float _leftBoundary; - float _rightBoundary; - - float _bounceTopBoundary; - float _bounceBottomBoundary; - float _bounceLeftBoundary; - float _bounceRightBoundary; - - - bool _autoScroll; - float _autoScrollAddUpTime; - - float _autoScrollOriginalSpeed; - float _autoScrollAcceleration; - bool _isAutoScrollSpeedAttenuated; - bool _needCheckAutoScrollDestination; - Point _autoScrollDestination; - - bool _bePressed; - float _slidTime; - Point _moveChildPoint; - float _childFocusCancelOffset; - - bool _leftBounceNeeded; - bool _topBounceNeeded; - bool _rightBounceNeeded; - bool _bottomBounceNeeded; - - bool _bounceEnabled; - bool _bouncing; - Point _bounceDir; - float _bounceOriginalSpeed; - bool _inertiaScrollEnabled; - - - - Ref* _scrollViewEventListener; - SEL_ScrollViewEvent _scrollViewEventSelector; -}; - -} -NS_CC_END -#endif /* defined(__CocoGUI__ScrollView__) */ diff --git a/cocos/gui/UISlider.cpp b/cocos/gui/UISlider.cpp deleted file mode 100644 index 1fdc8524fb..0000000000 --- a/cocos/gui/UISlider.cpp +++ /dev/null @@ -1,600 +0,0 @@ -/**************************************************************************** -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 "gui/UISlider.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" - -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(UI_TEX_TYPE_LOCAL), -_progressBarTexType(UI_TEX_TYPE_LOCAL), -_ballNTexType(UI_TEX_TYPE_LOCAL), -_ballPTexType(UI_TEX_TYPE_LOCAL), -_ballDTexType(UI_TEX_TYPE_LOCAL) -{ -} - -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()) - { - setTouchEnabled(true); - return true; - } - return false; -} - -void Slider::initRenderer() -{ - _barRenderer = Sprite::create(); - _progressBarRenderer = Sprite::create(); - _progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f)); - Node::addChild(_barRenderer, BASEBAR_RENDERER_Z, -1); - Node::addChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1); - _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); - Node::addChild(_slidBallRenderer, SLIDBALL_RENDERER_Z, -1); -} - -void Slider::loadBarTexture(const char* fileName, TextureResType texType) -{ - if (!fileName || strcmp(fileName, "") == 0) - { - return; - } - _textureFile = fileName; - _barTexType = texType; - switch (_barTexType) - { - case UI_TEX_TYPE_LOCAL: - if (_scale9Enabled) - { - static_cast(_barRenderer)->initWithFile(fileName); - } - else - { - static_cast(_barRenderer)->setTexture(fileName); - } - break; - case UI_TEX_TYPE_PLIST: - if (_scale9Enabled) - { - static_cast(_barRenderer)->initWithSpriteFrameName(fileName); - } - else - { - static_cast(_barRenderer)->setSpriteFrame(fileName); - } - break; - default: - break; - } - updateRGBAToRenderer(_barRenderer); - barRendererScaleChangedWithSize(); - progressBarRendererScaleChangedWithSize(); -} - -void Slider::loadProgressBarTexture(const char *fileName, TextureResType texType) -{ - if (!fileName || strcmp(fileName, "") == 0) - { - return; - } - _progressBarTextureFile = fileName; - _progressBarTexType = texType; - switch (_progressBarTexType) - { - case UI_TEX_TYPE_LOCAL: - if (_scale9Enabled) - { - static_cast(_progressBarRenderer)->initWithFile(fileName); - } - else - { - static_cast(_progressBarRenderer)->setTexture(fileName); - } - break; - case UI_TEX_TYPE_PLIST: - if (_scale9Enabled) - { - static_cast(_progressBarRenderer)->initWithSpriteFrameName(fileName); - } - else - { - static_cast(_progressBarRenderer)->setSpriteFrame(fileName); - } - break; - default: - break; - } - updateRGBAToRenderer(_progressBarRenderer); - _progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f)); - _progressBarTextureSize = _progressBarRenderer->getContentSize(); - progressBarRendererScaleChangedWithSize(); -} - -void Slider::setScale9Enabled(bool able) -{ - if (_scale9Enabled == able) - { - return; - } - - _scale9Enabled = able; - Node::removeChild(_barRenderer); - Node::removeChild(_progressBarRenderer); - _barRenderer = nullptr; - _progressBarRenderer = nullptr; - if (_scale9Enabled) - { - _barRenderer = extension::Scale9Sprite::create(); - _progressBarRenderer = extension::Scale9Sprite::create(); - } - else - { - _barRenderer = Sprite::create(); - _progressBarRenderer = Sprite::create(); - } - loadBarTexture(_textureFile.c_str(), _barTexType); - loadProgressBarTexture(_progressBarTextureFile.c_str(), _progressBarTexType); - Node::addChild(_barRenderer, BASEBAR_RENDERER_Z, -1); - Node::addChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1); - if (_scale9Enabled) - { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; - } - else - { - ignoreContentAdaptWithSize(_prevIgnoreSize); - } - setCapInsetsBarRenderer(_capInsetsBarRenderer); - setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer); -} - -bool Slider::isScale9Enabled() -{ - 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(_barRenderer)->setCapInsets(capInsets); -} - -const Rect& Slider::getCapInsetsBarRenderer() -{ - return _capInsetsBarRenderer; -} - -void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets) -{ - _capInsetsProgressBarRenderer = capInsets; - if (!_scale9Enabled) - { - return; - } - static_cast(_progressBarRenderer)->setCapInsets(capInsets); -} - -const Rect& Slider::getCapInsetsProgressBarRebderer() -{ - return _capInsetsProgressBarRenderer; -} - -void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType) -{ - loadSlidBallTextureNormal(normal, texType); - loadSlidBallTexturePressed(pressed,texType); - loadSlidBallTextureDisabled(disabled,texType); -} - -void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType) -{ - if (!normal || strcmp(normal, "") == 0) - { - return; - } - _slidBallNormalTextureFile = normal; - _ballNTexType = texType; - switch (_ballNTexType) - { - case UI_TEX_TYPE_LOCAL: - _slidBallNormalRenderer->setTexture(normal); - break; - case UI_TEX_TYPE_PLIST: - _slidBallNormalRenderer->setSpriteFrame(normal); - break; - default: - break; - } - updateRGBAToRenderer(_slidBallNormalRenderer); -} - -void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texType) -{ - if (!pressed || strcmp(pressed, "") == 0) - { - return; - } - _slidBallPressedTextureFile = pressed; - _ballPTexType = texType; - switch (_ballPTexType) - { - case UI_TEX_TYPE_LOCAL: - _slidBallPressedRenderer->setTexture(pressed); - break; - case UI_TEX_TYPE_PLIST: - _slidBallPressedRenderer->setSpriteFrame(pressed); - break; - default: - break; - } - updateRGBAToRenderer(_slidBallPressedRenderer); -} - -void Slider::loadSlidBallTextureDisabled(const char* disabled,TextureResType texType) -{ - if (!disabled || strcmp(disabled, "") == 0) - { - return; - } - _slidBallDisabledTextureFile = disabled; - _ballDTexType = texType; - switch (_ballDTexType) - { - case UI_TEX_TYPE_LOCAL: - _slidBallDisabledRenderer->setTexture(disabled); - break; - case UI_TEX_TYPE_PLIST: - _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; - _slidBallRenderer->setPosition(Point(-_barLength/2.0f + dis, 0.0f)); - if (_scale9Enabled) - { - static_cast(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height)); - } - else - { - Sprite* spriteRenderer = static_cast(_progressBarRenderer); - Rect rect = spriteRenderer->getTextureRect(); - rect.size.width = _progressBarTextureSize.width * res; - spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size); - } -} - -bool Slider::onTouchBegan(Touch *touch, Event *unusedEvent) -{ - bool pass = Widget::onTouchBegan(touch, unusedEvent); - if (_hitted) - { - Point nsp = convertToNodeSpace(_touchStartPos); - setPercent(getPercentWithBallPos(nsp.x)); - percentChangedEvent(); - } - return pass; -} - -void Slider::onTouchMoved(Touch *touch, Event *unusedEvent) -{ - _touchMovePos = touch->getLocation(); - Point nsp = convertToNodeSpace(_touchMovePos); - _slidBallRenderer->setPosition(Point(nsp.x,0)); - 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); -} - -float Slider::getPercentWithBallPos(float px) -{ - return (((px-(-_barLength/2.0f))/_barLength)*100.0f); -} - -void Slider::addEventListenerSlider(Ref *target, SEL_SlidPercentChangedEvent selector) -{ - _sliderEventListener = target; - _sliderEventSelector = selector; -} - -void Slider::percentChangedEvent() -{ - if (_sliderEventListener && _sliderEventSelector) - { - (_sliderEventListener->*_sliderEventSelector)(this,SLIDER_PERCENTCHANGED); - } -} - -int Slider::getPercent() -{ - return _percent; -} - -void Slider::onSizeChanged() -{ - Widget::onSizeChanged(); - barRendererScaleChangedWithSize(); - progressBarRendererScaleChangedWithSize(); -} - -const Size& Slider::getContentSize() const -{ - return _barRenderer->getContentSize(); -} - -Node* Slider::getVirtualRenderer() -{ - return _barRenderer; -} - -void Slider::barRendererScaleChangedWithSize() -{ - if (_ignoreSize) - { - - _barRenderer->setScale(1.0f); - _size = _barRenderer->getContentSize(); - _barLength = _size.width; - } - else - { - _barLength = _size.width; - if (_scale9Enabled) - { - static_cast(_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); - } - } - 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(_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); - } - } - _progressBarRenderer->setPosition(Point(-_barLength * 0.5f, 0.0f)); - 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(widget); - if (slider) - { - _prevIgnoreSize = slider->_prevIgnoreSize; - setScale9Enabled(slider->_scale9Enabled); - loadBarTexture(slider->_textureFile.c_str(), slider->_barTexType); - loadProgressBarTexture(slider->_progressBarTextureFile.c_str(), slider->_progressBarTexType); - loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile.c_str(), slider->_ballNTexType); - loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile.c_str(), slider->_ballPTexType); - loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile.c_str(), slider->_ballDTexType); - setPercent(slider->getPercent()); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UISlider.h b/cocos/gui/UISlider.h deleted file mode 100644 index 9ceb50e849..0000000000 --- a/cocos/gui/UISlider.h +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UISLIDER_H__ -#define __UISLIDER_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - SLIDER_PERCENTCHANGED -}SliderEventType; - -typedef void (Ref::*SEL_SlidPercentChangedEvent)(Ref*,SliderEventType); -#define sliderpercentchangedselector(_SELECTOR) (SEL_SlidPercentChangedEvent)(&_SELECTOR) - -/** -* @js NA -* @lua NA -*/ -class Slider : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - Slider(); - - /** - * Default destructor - */ - virtual ~Slider(); - - /** - * Allocates and initializes. - */ - static Slider* create(); - - /** - * Load texture for slider bar. - * - * @param fileName file name of texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadBarTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Sets if slider is using scale9 renderer. - * - * @param true that using scale9 renderer, false otherwise. - */ - void setScale9Enabled(bool able); - - bool isScale9Enabled(); - - /** - * Sets capinsets for slider, if slider is using scale9 renderer. - * - * @param capInsets capinsets for slider - */ - void setCapInsets(const Rect &capInsets); - - /** - * Sets capinsets for slider, if slider is using scale9 renderer. - * - * @param capInsets capinsets for slider - */ - void setCapInsetsBarRenderer(const Rect &capInsets); - - const Rect& getCapInsetsBarRenderer(); - - /** - * Sets capinsets for slider, if slider is using scale9 renderer. - * - * @param capInsets capinsets for slider - */ - void setCapInsetProgressBarRebderer(const Rect &capInsets); - - const Rect& getCapInsetsProgressBarRebderer(); - - /** - * Load textures for slider ball. - * - * @param slider ball normal normal state texture. - * - * @param slider ball selected selected state texture. - * - * @param slider ball disabled dark state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load normal state texture for slider ball. - * - * @param normal normal state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadSlidBallTextureNormal(const char* normal,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load selected state texture for slider ball. - * - * @param selected selected state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadSlidBallTexturePressed(const char* pressed,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load dark state texture for slider ball. - * - * @param disabled dark state texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadSlidBallTextureDisabled(const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Load dark state texture for slider progress bar. - * - * @param fileName file path of texture. - * - * @param texType @see UI_TEX_TYPE_LOCAL - */ - void loadProgressBarTexture(const char* fileName, TextureResType texType = UI_TEX_TYPE_LOCAL); - - /** - * Changes the progress direction of slider. - * - * @param percent percent value from 1 to 100. - */ - void setPercent(int percent); - - /** - * Gets the progress direction of slider. - * - * @return percent percent value from 1 to 100. - */ - int getPercent(); - - /** - * Add call back function called when slider's percent has changed to slider. - */ - void addEventListenerSlider(Ref* target,SEL_SlidPercentChangedEvent selector); - - virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; - virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; - virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; - virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; - - //override "getVirtualRenderer" method of widget. - virtual Node* getVirtualRenderer() override; - - //override "ignoreContentAdaptWithSize" method of widget. - virtual void ignoreContentAdaptWithSize(bool ignore) override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - -protected: - virtual bool init() override; - virtual void initRenderer() override; - float getPercentWithBallPos(float location); - void percentChangedEvent(); - virtual void onPressStateChangedToNormal() override; - virtual void onPressStateChangedToPressed() override; - virtual void onPressStateChangedToDisabled() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - void barRendererScaleChangedWithSize(); - void progressBarRendererScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - Node* _barRenderer; - Node* _progressBarRenderer; - Size _progressBarTextureSize; - - Sprite* _slidBallNormalRenderer; - Sprite* _slidBallPressedRenderer; - Sprite* _slidBallDisabledRenderer; - Node* _slidBallRenderer; - - float _barLength; - int _percent; - - bool _scale9Enabled; - bool _prevIgnoreSize; - std::string _textureFile; - std::string _progressBarTextureFile; - std::string _slidBallNormalTextureFile; - std::string _slidBallPressedTextureFile; - std::string _slidBallDisabledTextureFile; - - Rect _capInsetsBarRenderer; - Rect _capInsetsProgressBarRenderer; - - Ref* _sliderEventListener; - SEL_SlidPercentChangedEvent _sliderEventSelector; - TextureResType _barTexType; - TextureResType _progressBarTexType; - TextureResType _ballNTexType; - TextureResType _ballPTexType; - TextureResType _ballDTexType; -}; - -} -NS_CC_END - -#endif /* defined(__CocoGUI__Slider__) */ diff --git a/cocos/gui/UIText.cpp b/cocos/gui/UIText.cpp deleted file mode 100644 index 429228935e..0000000000 --- a/cocos/gui/UIText.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/**************************************************************************** -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 "gui/UIText.h" - -NS_CC_BEGIN - -namespace ui { - -static const int LABEL_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(Text) - -Text::Text(): -_touchScaleChangeEnabled(false), -_normalScaleValueX(1.0f), -_normalScaleValueY(1.0f), -_fontName("Thonburi"), -_fontSize(10), -_onSelectedScaleOffset(0.5), -_labelRenderer(nullptr) -{ -} - -Text::~Text() -{ - -} - -Text* Text::create() -{ - Text* widget = new Text(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -bool Text::init() -{ - if (Widget::init()) - { - return true; - } - return false; -} - -void Text::initRenderer() -{ - _labelRenderer = LabelTTF::create(); - Node::addChild(_labelRenderer, LABEL_RENDERER_Z, -1); -} - -void Text::setText(const std::string& text) -{ - _labelRenderer->setString(text); - labelScaleChangedWithSize(); -} - -const std::string& Text::getStringValue() -{ - return _labelRenderer->getString(); -} - -ssize_t Text::getStringLength() -{ - return _labelRenderer->getString().size(); -} - -void Text::setFontSize(int size) -{ - _fontSize = size; - _labelRenderer->setFontSize(size); - labelScaleChangedWithSize(); -} - -int Text::getFontSize() -{ - return _fontSize; -} - -void Text::setFontName(const std::string& name) -{ - _fontName = name; - _labelRenderer->setFontName(name); - labelScaleChangedWithSize(); -} - -const std::string& Text::getFontName() -{ - return _fontName; -} - -void Text::setTextAreaSize(const Size &size) -{ - _labelRenderer->setDimensions(size); - labelScaleChangedWithSize(); -} - -const Size& Text::getTextAreaSize() -{ - return _labelRenderer->getDimensions(); -} - -void Text::setTextHorizontalAlignment(TextHAlignment alignment) -{ - _labelRenderer->setHorizontalAlignment(alignment); - labelScaleChangedWithSize(); -} - -TextHAlignment Text::getTextHorizontalAlignment() -{ - return _labelRenderer->getHorizontalAlignment(); -} - -void Text::setTextVerticalAlignment(TextVAlignment alignment) -{ - _labelRenderer->setVerticalAlignment(alignment); - labelScaleChangedWithSize(); -} - -TextVAlignment Text::getTextVerticalAlignment() -{ - return _labelRenderer->getVerticalAlignment(); -} - -void Text::setTouchScaleChangeEnabled(bool enable) -{ - _touchScaleChangeEnabled = enable; -} - -bool Text::isTouchScaleChangeEnabled() -{ - return _touchScaleChangeEnabled; -} - -void Text::onPressStateChangedToNormal() -{ - if (!_touchScaleChangeEnabled) - { - return; - } - _labelRenderer->setScale(_normalScaleValueX, _normalScaleValueY); -} - -void Text::onPressStateChangedToPressed() -{ - if (!_touchScaleChangeEnabled) - { - return; - } - _labelRenderer->setScale(_normalScaleValueX + _onSelectedScaleOffset, _normalScaleValueY + _onSelectedScaleOffset); -} - -void Text::onPressStateChangedToDisabled() -{ - -} - -void Text::updateFlippedX() -{ - _labelRenderer->setFlippedX(_flippedX); - -} - -void Text::updateFlippedY() -{ - _labelRenderer->setFlippedY(_flippedY); -} - -void Text::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _labelRenderer->setAnchorPoint(pt); -} - -void Text::onSizeChanged() -{ - Widget::onSizeChanged(); - labelScaleChangedWithSize(); -} - -const Size& Text::getContentSize() const -{ - return _labelRenderer->getContentSize(); -} - -Node* Text::getVirtualRenderer() -{ - return _labelRenderer; -} - -void Text::labelScaleChangedWithSize() -{ - if (_ignoreSize) - { - _labelRenderer->setDimensions(Size::ZERO); - _labelRenderer->setScale(1.0f); - _size = _labelRenderer->getContentSize(); - _normalScaleValueX = _normalScaleValueY = 1.0f; - } - else - { - _labelRenderer->setDimensions(_size); - Size textureSize = _labelRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _labelRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _labelRenderer->setScaleX(scaleX); - _labelRenderer->setScaleY(scaleY); - _normalScaleValueX = scaleX; - _normalScaleValueY = scaleY; - } - -} - -std::string Text::getDescription() const -{ - return "Label"; -} - -void Text::updateTextureColor() -{ - updateColorToRenderer(_labelRenderer); -} - -void Text::updateTextureOpacity() -{ - updateOpacityToRenderer(_labelRenderer); -} - -void Text::updateTextureRGBA() -{ - updateRGBAToRenderer(_labelRenderer); -} - -Widget* Text::createCloneInstance() -{ - return Text::create(); -} - -void Text::copySpecialProperties(Widget *widget) -{ - Text* label = dynamic_cast(widget); - if (label) - { - setFontName(label->_fontName.c_str()); - setFontSize(label->_labelRenderer->getFontSize()); - setText(label->getStringValue()); - setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled); - setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment()); - setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment()); - setTextAreaSize(label->_labelRenderer->getDimensions()); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UIText.h b/cocos/gui/UIText.h deleted file mode 100644 index d811a59bcc..0000000000 --- a/cocos/gui/UIText.h +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UILABEL_H__ -#define __UILABEL_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -/** -* @js NA -* @lua NA -*/ -class Text : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - Text(); - - /** - * Default destructor - */ - virtual ~Text(); - - /** - * Allocates and initializes. - */ - static Text* create(); - - /** - * Changes the string value of label. - * - * @param text string value. - */ - void setText(const std::string& text); - - /** - * Gets the string value of label. - * - * @return text string value. - */ - const std::string& getStringValue(); - - /** - * Gets the string length of label. - * - * @return string length. - */ - ssize_t getStringLength(); - - /** - * Sets the font size of label. - * - * @param font size. - */ - void setFontSize(int size); - - int getFontSize(); - - /** - * Sets the font name of label. - * - * @param font name. - */ - void setFontName(const std::string& name); - - const std::string& getFontName(); - - /** - * Sets the touch scale enabled of label. - * - * @param touch scale enabled of label. - */ - void setTouchScaleChangeEnabled(bool enabled); - - /** - * Gets the touch scale enabled of label. - * - * @return touch scale enabled of label. - */ - bool isTouchScaleChangeEnabled(); - - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; - - //override "getVirtualRenderer" method of widget. - virtual Node* getVirtualRenderer() override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - void setTextAreaSize(const Size &size); - - const Size& getTextAreaSize(); - - void setTextHorizontalAlignment(TextHAlignment alignment); - - TextHAlignment getTextHorizontalAlignment(); - - void setTextVerticalAlignment(TextVAlignment alignment); - - TextVAlignment getTextVerticalAlignment(); - -protected: - virtual bool init() override; - virtual void initRenderer() override; - virtual void onPressStateChangedToNormal() override; - virtual void onPressStateChangedToPressed() override; - virtual void onPressStateChangedToDisabled() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - virtual void updateFlippedX() override; - virtual void updateFlippedY() override; - void labelScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - bool _touchScaleChangeEnabled; - float _normalScaleValueX; - float _normalScaleValueY; - std::string _fontName; - int _fontSize; - float _onSelectedScaleOffset; - LabelTTF* _labelRenderer; -}; - -} - -NS_CC_END - -#endif /* defined(__CocoGUI__Label__) */ diff --git a/cocos/gui/UITextAtlas.cpp b/cocos/gui/UITextAtlas.cpp deleted file mode 100644 index 1dd49fce11..0000000000 --- a/cocos/gui/UITextAtlas.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** -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 "gui/UITextAtlas.h" - -NS_CC_BEGIN - -namespace ui { - -static const int LABELATLAS_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(TextAtlas) - -TextAtlas::TextAtlas(): -_labelAtlasRenderer(nullptr), -_stringValue(""), -_charMapFileName(""), -_itemWidth(0), -_itemHeight(0), -_startCharMap("") -{ -} - -TextAtlas::~TextAtlas() -{ - -} - -TextAtlas* TextAtlas::create() -{ - TextAtlas* widget = new TextAtlas(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -void TextAtlas::initRenderer() -{ - _labelAtlasRenderer = LabelAtlas::create(); - Node::addChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1); -} - -void TextAtlas::setProperty(const std::string& stringValue, const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap) -{ - _stringValue = stringValue; - _charMapFileName = charMapFile; - _itemWidth = itemWidth; - _itemHeight = itemHeight; - _startCharMap = startCharMap; - _labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0])); - updateAnchorPoint(); - labelAtlasScaleChangedWithSize(); -} - -void TextAtlas::setStringValue(const std::string& value) -{ - _stringValue = value; - _labelAtlasRenderer->setString(value); - labelAtlasScaleChangedWithSize(); -} - -const std::string& TextAtlas::getStringValue() const -{ - return _labelAtlasRenderer->getString(); -} - -void TextAtlas::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _labelAtlasRenderer->setAnchorPoint(Point(pt.x, pt.y)); -} - -void TextAtlas::onSizeChanged() -{ - Widget::onSizeChanged(); - labelAtlasScaleChangedWithSize(); -} - -const Size& TextAtlas::getContentSize() const -{ - return _labelAtlasRenderer->getContentSize(); -} - -Node* TextAtlas::getVirtualRenderer() -{ - return _labelAtlasRenderer; -} - -void TextAtlas::labelAtlasScaleChangedWithSize() -{ - if (_ignoreSize) - { - _labelAtlasRenderer->setScale(1.0f); - _size = _labelAtlasRenderer->getContentSize(); - } - else - { - Size textureSize = _labelAtlasRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _labelAtlasRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _labelAtlasRenderer->setScaleX(scaleX); - _labelAtlasRenderer->setScaleY(scaleY); - } -} - -std::string TextAtlas::getDescription() const -{ - return "TextAtlas"; -} - -void TextAtlas::updateTextureColor() -{ - updateColorToRenderer(_labelAtlasRenderer); -} - -void TextAtlas::updateTextureOpacity() -{ - updateOpacityToRenderer(_labelAtlasRenderer); -} - -void TextAtlas::updateTextureRGBA() -{ - updateRGBAToRenderer(_labelAtlasRenderer); -} - -Widget* TextAtlas::createCloneInstance() -{ - return TextAtlas::create(); -} - -void TextAtlas::copySpecialProperties(Widget *widget) -{ - TextAtlas* labelAtlas = dynamic_cast(widget); - if (labelAtlas) - { - setProperty(labelAtlas->_stringValue, labelAtlas->_charMapFileName, labelAtlas->_itemWidth, labelAtlas->_itemHeight, labelAtlas->_startCharMap); - } -} - -} -NS_CC_END diff --git a/cocos/gui/UITextAtlas.h b/cocos/gui/UITextAtlas.h deleted file mode 100644 index f169598d8a..0000000000 --- a/cocos/gui/UITextAtlas.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UILABELATLAS_H__ -#define __UILABELATLAS_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -/** - * @js NA - * @lua NA - */ -class TextAtlas : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - TextAtlas(); - - /** - * Default destructor - */ - virtual ~TextAtlas(); - - /** - * Allocates and initializes. - */ - static TextAtlas* create(); - - /** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ - void setProperty(const std::string& stringValue,const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap); - - //set string value for labelatlas. - void setStringValue(const std::string& value); - - //get string value for labelatlas. - const std::string& getStringValue() const; - - //override "setAnchorPoint" method of widget. - virtual void setAnchorPoint(const Point &pt) override; - - //override "getContentSize" method of widget. - virtual const Size& getContentSize() const override; - - //override "getVirtualRenderer" method of widget. - virtual Node* getVirtualRenderer() override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - -protected: - virtual void initRenderer() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - void labelAtlasScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - LabelAtlas* _labelAtlasRenderer; - std::string _stringValue; - std::string _charMapFileName; - int _itemWidth; - int _itemHeight; - std::string _startCharMap; -}; - -} -NS_CC_END - -#endif /* defined(__CocoGUI__LabelAtlas__) */ diff --git a/cocos/gui/UITextBMFont.cpp b/cocos/gui/UITextBMFont.cpp deleted file mode 100644 index 485801fa2d..0000000000 --- a/cocos/gui/UITextBMFont.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/**************************************************************************** -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 "gui/UITextBMFont.h" - -NS_CC_BEGIN - -namespace ui { - -static const int LABELBMFONT_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(TextBMFont) - -TextBMFont::TextBMFont(): -_labelBMFontRenderer(nullptr), -_fntFileHasInit(false), -_fntFileName(""), -_stringValue("") -{ -} - -TextBMFont::~TextBMFont() -{ - -} - -TextBMFont* TextBMFont::create() -{ - TextBMFont* widget = new TextBMFont(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -void TextBMFont::initRenderer() -{ - _labelBMFontRenderer = cocos2d::LabelBMFont::create(); - Node::addChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1); -} - -void TextBMFont::setFntFile(const char *fileName) -{ - if (!fileName || strcmp(fileName, "") == 0) - { - return; - } - _fntFileName = fileName; - _labelBMFontRenderer->initWithString("", fileName); - updateAnchorPoint(); - labelBMFontScaleChangedWithSize(); - _fntFileHasInit = true; - setText(_stringValue.c_str()); -} - -void TextBMFont::setText(const char* value) -{ - if (!value) - { - return; - } - _stringValue = value; - if (!_fntFileHasInit) - { - return; - } - _labelBMFontRenderer->setString(value); - labelBMFontScaleChangedWithSize(); -} - -const char* TextBMFont::getStringValue() -{ - return _stringValue.c_str(); -} - -void TextBMFont::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _labelBMFontRenderer->setAnchorPoint(pt); -} - -void TextBMFont::onSizeChanged() -{ - Widget::onSizeChanged(); - labelBMFontScaleChangedWithSize(); -} - -const Size& TextBMFont::getContentSize() const -{ - return _labelBMFontRenderer->getContentSize(); -} - -Node* TextBMFont::getVirtualRenderer() -{ - return _labelBMFontRenderer; -} - -void TextBMFont::labelBMFontScaleChangedWithSize() -{ - if (_ignoreSize) - { - _labelBMFontRenderer->setScale(1.0f); - _size = _labelBMFontRenderer->getContentSize(); - } - else - { - Size textureSize = _labelBMFontRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _labelBMFontRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _labelBMFontRenderer->setScaleX(scaleX); - _labelBMFontRenderer->setScaleY(scaleY); - } -} - -std::string TextBMFont::getDescription() const -{ - return "TextBMFont"; -} - -void TextBMFont::updateTextureColor() -{ - updateColorToRenderer(_labelBMFontRenderer); -} - -void TextBMFont::updateTextureOpacity() -{ - updateOpacityToRenderer(_labelBMFontRenderer); -} - -void TextBMFont::updateTextureRGBA() -{ - updateRGBAToRenderer(_labelBMFontRenderer); -} - -Widget* TextBMFont::createCloneInstance() -{ - return TextBMFont::create(); -} - -void TextBMFont::copySpecialProperties(Widget *widget) -{ - TextBMFont* labelBMFont = dynamic_cast(widget); - if (labelBMFont) - { - setFntFile(labelBMFont->_fntFileName.c_str()); - setText(labelBMFont->_stringValue.c_str()); - } -} - -} - -NS_CC_END diff --git a/cocos/gui/UITextBMFont.h b/cocos/gui/UITextBMFont.h deleted file mode 100644 index 3ef62803c1..0000000000 --- a/cocos/gui/UITextBMFont.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UILABELBMFONT_H__ -#define __UILABELBMFONT_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -/** -* @js NA -* @lua NA -*/ -class TextBMFont : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * Default constructor - */ - TextBMFont(); - - /** - * Default destructor - */ - virtual ~TextBMFont(); - - /** - * Allocates and initializes. - */ - static TextBMFont* create(); - - /** init a bitmap font atlas with an initial string and the FNT file */ - void setFntFile(const char* fileName); - - /** set string value for labelbmfont*/ - void setText(const char* value); - - /** get string value for labelbmfont*/ - const char* getStringValue(); - virtual void setAnchorPoint(const Point &pt) override; - virtual const Size& getContentSize() const override; - virtual Node* getVirtualRenderer() override; - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; -protected: - virtual void initRenderer() override; - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - void labelBMFontScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - cocos2d::LabelBMFont* _labelBMFontRenderer; - bool _fntFileHasInit; - std::string _fntFileName; - std::string _stringValue; -}; - -} -NS_CC_END - -#endif /* defined(__LabelBMFont__) */ diff --git a/cocos/gui/UITextField.cpp b/cocos/gui/UITextField.cpp deleted file mode 100644 index b07baf43f3..0000000000 --- a/cocos/gui/UITextField.cpp +++ /dev/null @@ -1,772 +0,0 @@ -/**************************************************************************** -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 "gui/UITextField.h" - -NS_CC_BEGIN - -namespace ui { - -static int _calcCharCount(const char * pszText) -{ - int n = 0; - char ch = 0; - while ((ch = *pszText)) - { - CC_BREAK_IF(! ch); - - if (0x80 != (0xC0 & ch)) - { - ++n; - } - ++pszText; - } - return n; -} - -UICCTextField::UICCTextField() -: _maxLengthEnabled(false) -, _maxLength(0) -, _passwordEnabled(false) -, _passwordStyleText("*") -, _attachWithIME(false) -, _detachWithIME(false) -, _insertText(false) -, _deleteBackward(false) -{ -} - -UICCTextField::~UICCTextField() -{ -} - -UICCTextField * UICCTextField::create(const char *placeholder, const char *fontName, float fontSize) -{ - UICCTextField *pRet = new UICCTextField(); - - if(pRet && pRet->initWithString("", fontName, fontSize)) - { - pRet->autorelease(); - if (placeholder) - { - pRet->setPlaceHolder(placeholder); - } - return pRet; - } - CC_SAFE_DELETE(pRet); - - return nullptr; -} - -void UICCTextField::onEnter() -{ - TextFieldTTF::setDelegate(this); -} - - -bool UICCTextField::onTextFieldAttachWithIME(TextFieldTTF *pSender) -{ - setAttachWithIME(true); - return false; -} - -bool UICCTextField::onTextFieldInsertText(TextFieldTTF *pSender, const char *text, int nLen) -{ - if (nLen == 1 && strcmp(text, "\n") == 0) - { - return false; - } - setInsertText(true); - if (_maxLengthEnabled) - { - if (TextFieldTTF::getCharCount() >= _maxLength) - { - return true; - } - } - - return false; -} - -bool UICCTextField::onTextFieldDeleteBackward(TextFieldTTF *pSender, const char *delText, int nLen) -{ - setDeleteBackward(true); - return false; -} - -bool UICCTextField::onTextFieldDetachWithIME(TextFieldTTF *pSender) -{ - setDetachWithIME(true); - return false; -} - -void UICCTextField::insertText(const char * text, int len) -{ - std::string input_text = text; - - if (strcmp(text, "\n") != 0) - { - if (_maxLengthEnabled) - { - int text_count = _calcCharCount(getString().c_str()); - if (text_count >= _maxLength) - { - // password - if (_passwordEnabled) - { - setPasswordText(getString().c_str()); - } - return; - } - -#if ((CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)) - int input_count = _calcCharCount(text); - int total = total = text_count + input_count; - - if (total > _maxLength) - { - int end = 0; - int length = _maxLength - text_count; - - for (int i = 0; i < length; ++i) - { - char value = text[i]; - - if (value >= 0 && value <= 127) // ascii - { - end++; - } - else - { - end += 3; - } - } - input_text = input_text.substr(0, end); - len = end; - } -#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - int input_count = _calcCharCount(text); - if (input_count > _maxLength) - { - int ascii = 0; - int unicode = 0; - int end = 0; - int count = 0; - - for (int i = 0; i < input_count * 3; ++i) - { - char value = text[i]; - - if (value >= 0 && value <= 127) // ascii - { - ascii++; - count++; - } - else - { - unicode++; - if (unicode % 3 == 0) - { - count++; - } - } - - if (count == _maxLength) - { - break; - } - } - end = ascii + unicode; - input_text = input_text.substr(0, end); - len = end; - } -#endif - } - } - TextFieldTTF::insertText(input_text.c_str(), len); - - // password - if (_passwordEnabled) - { - if (TextFieldTTF::getCharCount() > 0) - { - setPasswordText(getString().c_str()); - } - } -} - -void UICCTextField::deleteBackward() -{ - TextFieldTTF::deleteBackward(); - - if (TextFieldTTF::getCharCount() > 0) - { - // password - if (_passwordEnabled) - { - setPasswordText(_inputText.c_str()); - } - } -} - -void UICCTextField::openIME() -{ - TextFieldTTF::attachWithIME(); -} - -void UICCTextField::closeIME() -{ - TextFieldTTF::detachWithIME(); -} - -void UICCTextField::setMaxLengthEnabled(bool enable) -{ - _maxLengthEnabled = enable; -} - -bool UICCTextField::isMaxLengthEnabled() -{ - return _maxLengthEnabled; -} - -void UICCTextField::setMaxLength(int length) -{ - _maxLength = length; -} - -int UICCTextField::getMaxLength() -{ - return _maxLength; -} - -int UICCTextField::getCharCount() -{ - return TextFieldTTF::getCharCount(); -} - -void UICCTextField::setPasswordEnabled(bool enable) -{ - _passwordEnabled = enable; -} - -bool UICCTextField::isPasswordEnabled() -{ - return _passwordEnabled; -} - -void UICCTextField::setPasswordStyleText(const char* styleText) -{ - if (strlen(styleText) > 1) - { - return; - } - char value = styleText[0]; - if (value < 33 || value > 126) - { - return; - } - _passwordStyleText = styleText; -} - -void UICCTextField::setPasswordText(const char *text) -{ - std::string tempStr; - for (size_t i = 0; i < strlen(text); ++i) - { - tempStr.append(_passwordStyleText); - } - LabelTTF::setString(tempStr.c_str()); -} - -void UICCTextField::setAttachWithIME(bool attach) -{ - _attachWithIME = attach; -} - -bool UICCTextField::getAttachWithIME() -{ - return _attachWithIME; -} - -void UICCTextField::setDetachWithIME(bool detach) -{ - _detachWithIME = detach; -} - -bool UICCTextField::getDetachWithIME() -{ - return _detachWithIME; -} - -void UICCTextField::setInsertText(bool insert) -{ - _insertText = insert; -} - -bool UICCTextField::getInsertText() -{ - return _insertText; -} - -void UICCTextField::setDeleteBackward(bool deleteBackward) -{ - _deleteBackward = deleteBackward; -} - -bool UICCTextField::getDeleteBackward() -{ - return _deleteBackward; -} - -static const int TEXTFIELD_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(TextField) - - -TextField::TextField(): -_textFieldRenderer(nullptr), -_touchWidth(0.0f), -_touchHeight(0.0f), -_useTouchArea(false), -_textFieldEventListener(nullptr), -_textFieldEventSelector(nullptr), -_passwordStyleText("") -{ -} - -TextField::~TextField() -{ - _textFieldEventListener = nullptr; - _textFieldEventSelector = nullptr; -} - -TextField* TextField::create() -{ - TextField* widget = new TextField(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -bool TextField::init() -{ - if (Widget::init()) - { - setTouchEnabled(true); - return true; - } - return false; -} - -void TextField::onEnter() -{ - Widget::onEnter(); - scheduleUpdate(); -} - -void TextField::initRenderer() -{ - _textFieldRenderer = UICCTextField::create("input words here", "Thonburi", 20); - Node::addChild(_textFieldRenderer, TEXTFIELD_RENDERER_Z, -1); -} - -void TextField::setTouchSize(const Size &size) -{ - _touchWidth = size.width; - _touchHeight = size.height; -} - -void TextField::setTouchAreaEnabled(bool enable) -{ - _useTouchArea = enable; -} - -bool TextField::hitTest(const Point &pt) -{ - if (_useTouchArea) - { - Point nsp = convertToNodeSpace(pt); - Rect bb = Rect(-_touchWidth * _anchorPoint.x, -_touchHeight * _anchorPoint.y, _touchWidth, _touchHeight); - if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) - { - return true; - } - } - else - { - return Widget::hitTest(pt); - } - - return false; -} - -Size TextField::getTouchSize() -{ - return Size(_touchWidth, _touchHeight); -} - -void TextField::setText(const std::string& text) -{ - std::string strText(text); - if (isMaxLengthEnabled()) - { - strText = strText.substr(0, getMaxLength()); - } - const char* content = strText.c_str(); - if (isPasswordEnabled()) - { - _textFieldRenderer->setPasswordText(content); - _textFieldRenderer->setString(""); - _textFieldRenderer->insertText(content, static_cast(strlen(content))); - } - else - { - _textFieldRenderer->setString(content); - } - textfieldRendererScaleChangedWithSize(); -} - -void TextField::setPlaceHolder(const std::string& value) -{ - _textFieldRenderer->setPlaceHolder(value); - textfieldRendererScaleChangedWithSize(); -} - -const std::string& TextField::getPlaceHolder() -{ - return _textFieldRenderer->getPlaceHolder(); -} - -void TextField::setFontSize(int size) -{ - _textFieldRenderer->setFontSize(size); - textfieldRendererScaleChangedWithSize(); -} - -int TextField::getFontSize() -{ - return _textFieldRenderer->getFontSize(); -} - -void TextField::setFontName(const std::string& name) -{ - _textFieldRenderer->setFontName(name); - textfieldRendererScaleChangedWithSize(); -} - -const std::string& TextField::getFontName() -{ - return _textFieldRenderer->getFontName(); -} - -void TextField::didNotSelectSelf() -{ - _textFieldRenderer->detachWithIME(); -} - -const std::string& TextField::getStringValue() -{ - return _textFieldRenderer->getString(); -} - -bool TextField::onTouchBegan(Touch *touch, Event *unusedEvent) -{ - bool pass = Widget::onTouchBegan(touch, unusedEvent); - if (_hitted) - { - _textFieldRenderer->attachWithIME(); - } - return pass; -} - -void TextField::setMaxLengthEnabled(bool enable) -{ - _textFieldRenderer->setMaxLengthEnabled(enable); -} - -bool TextField::isMaxLengthEnabled() -{ - return _textFieldRenderer->isMaxLengthEnabled(); -} - -void TextField::setMaxLength(int length) -{ - _textFieldRenderer->setMaxLength(length); - - setText(getStringValue()); -} - -int TextField::getMaxLength() -{ - return _textFieldRenderer->getMaxLength(); -} - -void TextField::setPasswordEnabled(bool enable) -{ - _textFieldRenderer->setPasswordEnabled(enable); -} - -bool TextField::isPasswordEnabled() -{ - return _textFieldRenderer->isPasswordEnabled(); -} - -void TextField::setPasswordStyleText(const char *styleText) -{ - _textFieldRenderer->setPasswordStyleText(styleText); - - _passwordStyleText = styleText; - - setText(getStringValue()); -} - -const char* TextField::getPasswordStyleText() -{ - return _passwordStyleText.c_str(); -} - -void TextField::update(float dt) -{ - if (getAttachWithIME()) - { - attachWithIMEEvent(); - setAttachWithIME(false); - } - if (getDetachWithIME()) - { - detachWithIMEEvent(); - setDetachWithIME(false); - } - if (getInsertText()) - { - insertTextEvent(); - setInsertText(false); - - textfieldRendererScaleChangedWithSize(); - } - if (getDeleteBackward()) - { - deleteBackwardEvent(); - setDeleteBackward(false); - - textfieldRendererScaleChangedWithSize(); - } -} - -bool TextField::getAttachWithIME() -{ - return _textFieldRenderer->getAttachWithIME(); -} - -void TextField::setAttachWithIME(bool attach) -{ - _textFieldRenderer->setAttachWithIME(attach); -} - -bool TextField::getDetachWithIME() -{ - return _textFieldRenderer->getDetachWithIME(); -} - -void TextField::setDetachWithIME(bool detach) -{ - _textFieldRenderer->setDetachWithIME(detach); -} - -bool TextField::getInsertText() -{ - return _textFieldRenderer->getInsertText(); -} - -void TextField::setInsertText(bool insertText) -{ - _textFieldRenderer->setInsertText(insertText); -} - -bool TextField::getDeleteBackward() -{ - return _textFieldRenderer->getDeleteBackward(); -} - -void TextField::setDeleteBackward(bool deleteBackward) -{ - _textFieldRenderer->setDeleteBackward(deleteBackward); -} - -void TextField::attachWithIMEEvent() -{ - if (_textFieldEventListener && _textFieldEventSelector) - { - (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_ATTACH_WITH_IME); - } -} - -void TextField::detachWithIMEEvent() -{ - if (_textFieldEventListener && _textFieldEventSelector) - { - (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_DETACH_WITH_IME); - } -} - -void TextField::insertTextEvent() -{ - if (_textFieldEventListener && _textFieldEventSelector) - { - (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_INSERT_TEXT); - } -} - -void TextField::deleteBackwardEvent() -{ - if (_textFieldEventListener && _textFieldEventSelector) - { - (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_DELETE_BACKWARD); - } -} - -void TextField::addEventListenerTextField(Ref *target, SEL_TextFieldEvent selecor) -{ - _textFieldEventListener = target; - _textFieldEventSelector = selecor; -} - -void TextField::setAnchorPoint(const Point &pt) -{ - Widget::setAnchorPoint(pt); - _textFieldRenderer->setAnchorPoint(pt); -} - -void TextField::onSizeChanged() -{ - Widget::onSizeChanged(); - textfieldRendererScaleChangedWithSize(); -} - -void TextField::textfieldRendererScaleChangedWithSize() -{ - if (_ignoreSize) - { - _textFieldRenderer->setDimensions(Size::ZERO); - _textFieldRenderer->setScale(1.0f); - _size = getContentSize(); - } - else - { - _textFieldRenderer->setDimensions(_size); - Size textureSize = getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _textFieldRenderer->setScale(1.0f); - return; - } - float scaleX = _size.width / textureSize.width; - float scaleY = _size.height / textureSize.height; - _textFieldRenderer->setScaleX(scaleX); - _textFieldRenderer->setScaleY(scaleY); - } -} - -const Size& TextField::getContentSize() const -{ - return _textFieldRenderer->getContentSize(); -} - -Node* TextField::getVirtualRenderer() -{ - return _textFieldRenderer; -} - -std::string TextField::getDescription() const -{ - return "TextField"; -} - -void TextField::updateTextureColor() -{ - updateColorToRenderer(_textFieldRenderer); -} - -void TextField::updateTextureOpacity() -{ - updateOpacityToRenderer(_textFieldRenderer); -} - -void TextField::updateTextureRGBA() -{ - updateRGBAToRenderer(_textFieldRenderer); -} - -void TextField::attachWithIME() -{ - _textFieldRenderer->attachWithIME(); -} - -Widget* TextField::createCloneInstance() -{ - return TextField::create(); -} - -void TextField::copySpecialProperties(Widget *widget) -{ - TextField* textField = dynamic_cast(widget); - if (textField) - { - setText(textField->_textFieldRenderer->getString()); - setPlaceHolder(textField->getStringValue()); - setFontSize(textField->_textFieldRenderer->getFontSize()); - setFontName(textField->_textFieldRenderer->getFontName().c_str()); - setMaxLengthEnabled(textField->isMaxLengthEnabled()); - setMaxLength(textField->getMaxLength()); - setPasswordEnabled(textField->isPasswordEnabled()); - setPasswordStyleText(textField->_passwordStyleText.c_str()); - setAttachWithIME(textField->getAttachWithIME()); - setDetachWithIME(textField->getDetachWithIME()); - setInsertText(textField->getInsertText()); - setDeleteBackward(textField->getDeleteBackward()); - } -} - -void TextField::setTextAreaSize(const Size &size) -{ - _textFieldRenderer->setDimensions(size); -} - -void TextField::setTextHorizontalAlignment(TextHAlignment alignment) -{ - _textFieldRenderer->setHorizontalAlignment(alignment); -} - -void TextField::setTextVerticalAlignment(TextVAlignment alignment) -{ - _textFieldRenderer->setVerticalAlignment(alignment); -} - -} - -NS_CC_END diff --git a/cocos/gui/UITextField.h b/cocos/gui/UITextField.h deleted file mode 100644 index 06cc3bcc60..0000000000 --- a/cocos/gui/UITextField.h +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UITEXTFIELD_H__ -#define __UITEXTFIELD_H__ - -#include "gui/UIWidget.h" - -NS_CC_BEGIN - -namespace ui { - -/** - * @js NA - * @lua NA - */ -class UICCTextField: public TextFieldTTF, public TextFieldDelegate -{ -public: - UICCTextField(); - ~UICCTextField(); - - virtual void onEnter() override; - - // static - static UICCTextField* create(const char *placeholder, const char *fontName, float fontSize); - - // CCTextFieldDelegate - virtual bool onTextFieldAttachWithIME(TextFieldTTF *pSender) override; - virtual bool onTextFieldDetachWithIME(TextFieldTTF * pSender) override; - virtual bool onTextFieldInsertText(TextFieldTTF * pSender, const char * text, int nLen) override; - virtual bool onTextFieldDeleteBackward(TextFieldTTF * pSender, const char * delText, int nLen) override; - - void insertText(const char* text, int len); - void deleteBackward(); - - void openIME(); - void closeIME(); - - void setMaxLengthEnabled(bool enable); - bool isMaxLengthEnabled(); - void setMaxLength(int length); - int getMaxLength(); - int getCharCount(); - void setPasswordEnabled(bool enable); - bool isPasswordEnabled(); - void setPasswordStyleText(const char* styleText); - void setPasswordText(const char* text); - void setAttachWithIME(bool attach); - bool getAttachWithIME(); - void setDetachWithIME(bool detach); - bool getDetachWithIME(); - void setInsertText(bool insert); - bool getInsertText(); - void setDeleteBackward(bool deleteBackward); - bool getDeleteBackward(); -protected: - bool _maxLengthEnabled; - int _maxLength; - bool _passwordEnabled; - std::string _passwordStyleText; - bool _attachWithIME; - bool _detachWithIME; - bool _insertText; - bool _deleteBackward; -}; - -typedef enum -{ - TEXTFIELD_EVENT_ATTACH_WITH_IME, - TEXTFIELD_EVENT_DETACH_WITH_IME, - TEXTFIELD_EVENT_INSERT_TEXT, - TEXTFIELD_EVENT_DELETE_BACKWARD, -}TextFiledEventType; - -typedef void (Ref::*SEL_TextFieldEvent)(Ref*, TextFiledEventType); -#define textfieldeventselector(_SELECTOR) (SEL_TextFieldEvent)(&_SELECTOR) - -/** class UITextField : public Widget -* @js NA -* @lua NA -*/ -class TextField : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - TextField(); - virtual ~TextField(); - static TextField* create(); - void setTouchSize(const Size &size); - Size getTouchSize(); - void setTouchAreaEnabled(bool enable); - virtual bool hitTest(const Point &pt); - void setText(const std::string& text); - void setPlaceHolder(const std::string& value); - const std::string& getPlaceHolder(); - void setFontSize(int size); - int getFontSize(); - void setFontName(const std::string& name); - const std::string& getFontName(); - virtual void didNotSelectSelf(); - const std::string& getStringValue(); - virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; - void setMaxLengthEnabled(bool enable); - bool isMaxLengthEnabled(); - void setMaxLength(int length); - int getMaxLength(); - void setPasswordEnabled(bool enable); - bool isPasswordEnabled(); - void setPasswordStyleText(const char* styleText); - const char* getPasswordStyleText(); - virtual void update(float dt) override; - bool getAttachWithIME(); - void setAttachWithIME(bool attach); - bool getDetachWithIME(); - void setDetachWithIME(bool detach); - bool getInsertText(); - void setInsertText(bool insertText); - bool getDeleteBackward(); - void setDeleteBackward(bool deleteBackward); - void addEventListenerTextField(Ref* target, SEL_TextFieldEvent selecor); - - virtual void setAnchorPoint(const Point &pt) override; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - virtual const Size& getContentSize() const override; - virtual Node* getVirtualRenderer() override; - void attachWithIME(); - virtual void onEnter() override; - - void setTextAreaSize(const Size &size); - void setTextHorizontalAlignment(TextHAlignment alignment); - void setTextVerticalAlignment(TextVAlignment alignment); -protected: - virtual bool init() override; - virtual void initRenderer() override; - void attachWithIMEEvent(); - void detachWithIMEEvent(); - void insertTextEvent(); - void deleteBackwardEvent(); - virtual void onSizeChanged() override; - virtual void updateTextureColor() override; - virtual void updateTextureOpacity() override; - virtual void updateTextureRGBA() override; - void textfieldRendererScaleChangedWithSize(); - virtual Widget* createCloneInstance() override; - virtual void copySpecialProperties(Widget* model) override; -protected: - UICCTextField* _textFieldRenderer; - - float _touchWidth; - float _touchHeight; - bool _useTouchArea; - - Ref* _textFieldEventListener; - SEL_TextFieldEvent _textFieldEventSelector; - - std::string _passwordStyleText; -}; - -} - -NS_CC_END - -#endif /* defined(__TextField__) */ diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp deleted file mode 100644 index a1984c95d0..0000000000 --- a/cocos/gui/UIWidget.cpp +++ /dev/null @@ -1,1139 +0,0 @@ -/**************************************************************************** -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 "gui/UIWidget.h" -#include "gui/UILayout.h" -#include "gui/UIHelper.h" - -NS_CC_BEGIN - -namespace ui { - -Widget::Widget(): -_enabled(true), -_bright(true), -_touchEnabled(false), -_touchPassedEnabled(false), -_focus(false), -_brightStyle(BRIGHT_NONE), -_touchStartPos(Point::ZERO), -_touchMovePos(Point::ZERO), -_touchEndPos(Point::ZERO), -_touchEventListener(nullptr), -_touchEventSelector(nullptr), -_name("default"), -_widgetType(WidgetTypeWidget), -_actionTag(0), -_size(Size::ZERO), -_customSize(Size::ZERO), -_ignoreSize(false), -_affectByClipping(false), -_sizeType(SIZE_ABSOLUTE), -_sizePercent(Point::ZERO), -_positionType(POSITION_ABSOLUTE), -_positionPercent(Point::ZERO), -_reorderWidgetChildDirty(true), -_hitted(false), -_touchListener(nullptr), -_nodes(NULL), -_color(Color3B::WHITE), -_opacity(255), -_flippedX(false), -_flippedY(false) -{ - -} - -Widget::~Widget() -{ - _touchEventListener = nullptr; - _touchEventSelector = nullptr; - _widgetChildren.clear(); - setTouchEnabled(false); - _nodes.clear(); -} - -Widget* Widget::create() -{ - Widget* widget = new Widget(); - if (widget && widget->init()) - { - widget->autorelease(); - return widget; - } - CC_SAFE_DELETE(widget); - return nullptr; -} - -bool Widget::init() -{ - if (Node::init()) - { - initRenderer(); - setBright(true); - ignoreContentAdaptWithSize(true); - setAnchorPoint(Point(0.5f, 0.5f)); - return true; - } - return false; -} - -void Widget::onEnter() -{ - updateSizeAndPosition(); - Node::onEnter(); -} - -void Widget::onExit() -{ - unscheduleUpdate(); - Node::onExit(); -} - -void Widget::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) -{ - if (_enabled) - { - Node::visit(renderer, parentTransform, parentTransformUpdated); - } -} - -void Widget::addChild(Node *child) -{ - Node::addChild(child); -} - -void Widget::addChild(Node * child, int zOrder) -{ - Node::addChild(child, zOrder); -} - -void Widget::addChild(Node* child, int zOrder, int tag) -{ - CCASSERT(dynamic_cast(child) != nullptr, "Widget only supports Widgets as children"); - Node::addChild(child, zOrder, tag); - _widgetChildren.pushBack(child); -} - -void Widget::sortAllChildren() -{ - _reorderWidgetChildDirty = _reorderChildDirty; - Node::sortAllChildren(); - if( _reorderWidgetChildDirty ) - { - std::sort( std::begin(_widgetChildren), std::end(_widgetChildren), nodeComparisonLess ); - _reorderWidgetChildDirty = false; - } -} - -Node* Widget::getChildByTag(int aTag) -{ - CCASSERT( aTag != Node::INVALID_TAG, "Invalid tag"); - - for (auto& child : _widgetChildren) - { - if(child && child->getTag() == aTag) - return child; - } - return nullptr; -} - -Vector& Widget::getChildren() -{ - return _widgetChildren; -} - -const Vector& Widget::getChildren() const -{ - return _widgetChildren; -} - -ssize_t Widget::getChildrenCount() const -{ - return _widgetChildren.size(); -} - -Widget* Widget::getWidgetParent() -{ - return dynamic_cast(getParent()); -} - -void Widget::removeFromParent() -{ - removeFromParentAndCleanup(true); -} - -void Widget::removeFromParentAndCleanup(bool cleanup) -{ - Node::removeFromParentAndCleanup(cleanup); -} - -void Widget::removeChild(Node *child, bool cleanup) -{ - Node::removeChild(child, cleanup); - _widgetChildren.eraseObject(child); -} - -void Widget::removeChildByTag(int tag, bool cleanup) -{ - CCASSERT( tag != Node::INVALID_TAG, "Invalid tag"); - - Node *child = getChildByTag(tag); - - if (child == nullptr) - { - CCLOG("cocos2d: removeChildByTag(tag = %d): child not found!", tag); - } - else - { - removeChild(child, cleanup); - } -} - -void Widget::removeAllChildren() -{ - removeAllChildrenWithCleanup(true); -} - -void Widget::removeAllChildrenWithCleanup(bool cleanup) -{ - for (auto& child : _widgetChildren) - { - if (child) - { - Node::removeChild(child); - } - } - _widgetChildren.clear(); -} - -void Widget::setEnabled(bool enabled) -{ - _enabled = enabled; - for (auto& child : _widgetChildren) - { - if (child) - { - static_cast(child)->setEnabled(enabled); - } - } -} - -Widget* Widget::getChildByName(const char *name) -{ - for (auto& child : _widgetChildren) - { - if (child) - { - Widget* widgetChild = static_cast(child); - if (strcmp(widgetChild->getName(), name) == 0) - { - return widgetChild; - } - } - } - return nullptr; -} - -void Widget::addNode(Node* node) -{ - addNode(node, node->getLocalZOrder(), node->getTag()); -} - -void Widget::addNode(Node * node, int zOrder) -{ - addNode(node, zOrder, node->getTag()); -} - -void Widget::addNode(Node* node, int zOrder, int tag) -{ - CCAssert(dynamic_cast(node) == nullptr, "Widget only supports Nodes as renderer"); - Node::addChild(node, zOrder, tag); - _nodes.pushBack(node); -} - -Node* Widget::getNodeByTag(int tag) -{ - CCAssert( tag != Node::INVALID_TAG, "Invalid tag"); - - for (auto& node : _nodes) - { - if(node && node->getTag() == tag) - return node; - } - return nullptr; -} - -Vector& Widget::getNodes() -{ - return _nodes; -} - -void Widget::removeNode(Node* node) -{ - Node::removeChild(node); - _nodes.eraseObject(node); -} - -void Widget::removeNodeByTag(int tag) -{ - CCAssert( tag != Node::INVALID_TAG, "Invalid tag"); - - Node *node = this->getNodeByTag(tag); - - if (node == nullptr) - { - CCLOG("cocos2d: removeNodeByTag(tag = %d): child not found!", tag); - } - else - { - this->removeNode(node); - } -} - -void Widget::removeAllNodes() -{ - for (auto& node : _nodes) - { - if (node) - { - Node::removeChild(node); - } - } - _nodes.clear(); -} - - -void Widget::initRenderer() -{ -} - -void Widget::setSize(const Size &size) -{ - _customSize = size; - if (_ignoreSize) - { - _size = getContentSize(); - } - else - { - _size = size; - } - if (_running) - { - Widget* widgetParent = getWidgetParent(); - Size pSize; - if (widgetParent) - { - pSize = widgetParent->getSize(); - } - else - { - pSize = _parent->getContentSize(); - } - float spx = 0.0f; - float spy = 0.0f; - if (pSize.width > 0.0f) - { - spx = _customSize.width / pSize.width; - } - if (pSize.height > 0.0f) - { - spy = _customSize.height / pSize.height; - } - _sizePercent = Point(spx, spy); - } - onSizeChanged(); -} - -void Widget::setSizePercent(const Point &percent) -{ - _sizePercent = percent; - Size cSize = _customSize; - if (_running) - { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - cSize = Size(widgetParent->getSize().width * percent.x , widgetParent->getSize().height * percent.y); - } - else - { - cSize = Size(_parent->getContentSize().width * percent.x , _parent->getContentSize().height * percent.y); - } - } - if (_ignoreSize) - { - _size = getContentSize(); - } - else - { - _size = cSize; - } - _customSize = cSize; - onSizeChanged(); -} - -void Widget::updateSizeAndPosition() -{ - switch (_sizeType) - { - case SIZE_ABSOLUTE: - { - if (_ignoreSize) - { - _size = getContentSize(); - } - else - { - _size = _customSize; - } - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - Size pSize = widgetParent->getSize(); - float spx = 0.0f; - float spy = 0.0f; - if (pSize.width > 0.0f) - { - spx = _customSize.width / pSize.width; - } - if (pSize.height > 0.0f) - { - spy = _customSize.height / pSize.height; - } - _sizePercent = Point(spx, spy); - } - else - { - Size pSize = _parent->getContentSize(); - float spx = 0.0f; - float spy = 0.0f; - if (pSize.width > 0.0f) - { - spx = _customSize.width / pSize.width; - } - if (pSize.height > 0.0f) - { - spy = _customSize.height / pSize.height; - } - _sizePercent = Point(spx, spy); - } - break; - } - case SIZE_PERCENT: - { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - Size cSize = Size(widgetParent->getSize().width * _sizePercent.x , widgetParent->getSize().height * _sizePercent.y); - if (_ignoreSize) - { - _size = getContentSize(); - } - else - { - _size = cSize; - } - _customSize = cSize; - } - else - { - Size cSize = Size(_parent->getContentSize().width * _sizePercent.x , _parent->getContentSize().height * _sizePercent.y); - if (_ignoreSize) - { - _size = getContentSize(); - } - else - { - _size = cSize; - } - _customSize = cSize; - } - } - break; - default: - break; - } - onSizeChanged(); - Point absPos = getPosition(); - switch (_positionType) - { - case POSITION_ABSOLUTE: - { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - Size pSize = widgetParent->getSize(); - if (pSize.width <= 0.0f || pSize.height <= 0.0f) - { - _positionPercent = Point::ZERO; - } - else - { - _positionPercent = Point(absPos.x / pSize.width, absPos.y / pSize.height); - } - } - else - { - Size pSize = _parent->getContentSize(); - if (pSize.width <= 0.0f || pSize.height <= 0.0f) - { - _positionPercent = Point::ZERO; - } - else - { - _positionPercent = Point(absPos.x / pSize.width, absPos.y / pSize.height); - } - } - break; - } - case POSITION_PERCENT: - { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - Size parentSize = widgetParent->getSize(); - absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); - } - else - { - Size parentSize = _parent->getContentSize(); - absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); - } - break; - } - default: - break; - } - setPosition(absPos); -} - -void Widget::setSizeType(SizeType type) -{ - _sizeType = type; -} - -SizeType Widget::getSizeType() const -{ - return _sizeType; -} - -void Widget::ignoreContentAdaptWithSize(bool ignore) -{ - if (_ignoreSize == ignore) - { - return; - } - _ignoreSize = ignore; - if (_ignoreSize) - { - Size s = getContentSize(); - _size = s; - } - else - { - _size = _customSize; - } - onSizeChanged(); -} - -bool Widget::isIgnoreContentAdaptWithSize() const -{ - return _ignoreSize; -} - -const Size& Widget::getSize() const -{ - return _size; -} - -const Size& Widget::getCustomSize() const -{ - return _customSize; -} - -const Point& Widget::getSizePercent() const -{ - return _sizePercent; -} - -Point Widget::getWorldPosition() -{ - return convertToWorldSpace(Point::ZERO); -} - -Node* Widget::getVirtualRenderer() -{ - return this; -} - -void Widget::onSizeChanged() -{ - for (auto& child : getChildren()) - { - if (child) - { - static_cast(child)->updateSizeAndPosition(); - } - } -} - -const Size& Widget::getContentSize() const -{ - return _size; -} - -void Widget::setTouchEnabled(bool enable) -{ - if (enable == _touchEnabled) - { - return; - } - _touchEnabled = enable; - if (_touchEnabled) - { - _touchListener = EventListenerTouchOneByOne::create(); - CC_SAFE_RETAIN(_touchListener); - _touchListener->setSwallowTouches(true); - _touchListener->onTouchBegan = CC_CALLBACK_2(Widget::onTouchBegan, this); - _touchListener->onTouchMoved = CC_CALLBACK_2(Widget::onTouchMoved, this); - _touchListener->onTouchEnded = CC_CALLBACK_2(Widget::onTouchEnded, this); - _touchListener->onTouchCancelled = CC_CALLBACK_2(Widget::onTouchCancelled, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this); - } - else - { - _eventDispatcher->removeEventListener(_touchListener); - CC_SAFE_RELEASE_NULL(_touchListener); - } -} - -bool Widget::isTouchEnabled() const -{ - return _touchEnabled; -} - -bool Widget::isFocused() const -{ - return _focus; -} - -void Widget::setFocused(bool fucos) -{ - if (fucos == _focus) - { - return; - } - _focus = fucos; - if (_bright) - { - if (_focus) - { - setBrightStyle(BRIGHT_HIGHLIGHT); - } - else - { - setBrightStyle(BRIGHT_NORMAL); - } - } - else - { - onPressStateChangedToDisabled(); - } -} - -void Widget::setBright(bool bright) -{ - _bright = bright; - if (_bright) - { - _brightStyle = BRIGHT_NONE; - setBrightStyle(BRIGHT_NORMAL); - } - else - { - onPressStateChangedToDisabled(); - } -} - -void Widget::setBrightStyle(BrightStyle style) -{ - if (_brightStyle == style) - { - return; - } - _brightStyle = style; - switch (_brightStyle) - { - case BRIGHT_NORMAL: - onPressStateChangedToNormal(); - break; - case BRIGHT_HIGHLIGHT: - onPressStateChangedToPressed(); - break; - default: - break; - } -} - -void Widget::onPressStateChangedToNormal() -{ - -} - -void Widget::onPressStateChangedToPressed() -{ - -} - -void Widget::onPressStateChangedToDisabled() -{ - -} - -void Widget::didNotSelectSelf() -{ - -} - -bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent) -{ - _hitted = false; - if (isEnabled() && isTouchEnabled()) - { - _touchStartPos = touch->getLocation(); - if(hitTest(_touchStartPos) && clippingParentAreaContainPoint(_touchStartPos)) - { - _hitted = true; - } - } - if (!_hitted) - { - return false; - } - setFocused(true); - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - widgetParent->checkChildInfo(0,this,_touchStartPos); - } - pushDownEvent(); - return !_touchPassedEnabled; -} - -void Widget::onTouchMoved(Touch *touch, Event *unusedEvent) -{ - _touchMovePos = touch->getLocation(); - setFocused(hitTest(_touchMovePos)); - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - widgetParent->checkChildInfo(1,this,_touchMovePos); - } - moveEvent(); -} - -void Widget::onTouchEnded(Touch *touch, Event *unusedEvent) -{ - _touchEndPos = touch->getLocation(); - bool focus = _focus; - setFocused(false); - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - widgetParent->checkChildInfo(2,this,_touchEndPos); - } - if (focus) - { - releaseUpEvent(); - } - else - { - cancelUpEvent(); - } -} - -void Widget::onTouchCancelled(Touch *touch, Event *unusedEvent) -{ - setFocused(false); - cancelUpEvent(); -} - -void Widget::pushDownEvent() -{ - if (_touchEventListener && _touchEventSelector) - { - (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_BEGAN); - } -} - -void Widget::moveEvent() -{ - if (_touchEventListener && _touchEventSelector) - { - (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_MOVED); - } -} - -void Widget::releaseUpEvent() -{ - if (_touchEventListener && _touchEventSelector) - { - (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_ENDED); - } -} - -void Widget::cancelUpEvent() -{ - if (_touchEventListener && _touchEventSelector) - { - (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_CANCELED); - } -} - -void Widget::addTouchEventListener(Ref *target, SEL_TouchEvent selector) -{ - _touchEventListener = target; - _touchEventSelector = selector; -} - -bool Widget::hitTest(const Point &pt) -{ - Point nsp = convertToNodeSpace(pt); - Rect bb = Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height); - if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) - { - return true; - } - return false; -} - -bool Widget::clippingParentAreaContainPoint(const Point &pt) -{ - _affectByClipping = false; - Widget* parent = getWidgetParent(); - Widget* clippingParent = nullptr; - while (parent) - { - Layout* layoutParent = dynamic_cast(parent); - if (layoutParent) - { - if (layoutParent->isClippingEnabled()) - { - _affectByClipping = true; - clippingParent = layoutParent; - break; - } - } - parent = parent->getWidgetParent(); - } - - if (!_affectByClipping) - { - return true; - } - - - if (clippingParent) - { - bool bRet = false; - if (clippingParent->hitTest(pt)) - { - bRet = true; - } - if (bRet) - { - return clippingParent->clippingParentAreaContainPoint(pt); - } - return false; - } - return true; -} - -void Widget::checkChildInfo(int handleState, Widget *sender, const Point &touchPoint) -{ - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - widgetParent->checkChildInfo(handleState,sender,touchPoint); - } -} - -void Widget::setPosition(const Point &pos) -{ - if (_running) - { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - Size pSize = widgetParent->getSize(); - if (pSize.width <= 0.0f || pSize.height <= 0.0f) - { - _positionPercent = Point::ZERO; - } - else - { - _positionPercent = Point(pos.x / pSize.width, pos.y / pSize.height); - } - } - } - Node::setPosition(pos); -} - -void Widget::setPositionPercent(const Point &percent) -{ - _positionPercent = percent; - if (_running) - { - Widget* widgetParent = getWidgetParent(); - if (widgetParent) - { - Size parentSize = widgetParent->getSize(); - Point absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); - setPosition(absPos); - } - } -} - -void Widget::updateAnchorPoint() -{ - setAnchorPoint(getAnchorPoint()); -} - -const Point& Widget::getPositionPercent() -{ - return _positionPercent; -} - -void Widget::setPositionType(PositionType type) -{ - _positionType = type; -} - -PositionType Widget::getPositionType() const -{ - return _positionType; -} - -bool Widget::isBright() const -{ - return _bright; -} - -bool Widget::isEnabled() const -{ - return _enabled; -} - -float Widget::getLeftInParent() -{ - return getPosition().x - getAnchorPoint().x * _size.width;; -} - -float Widget::getBottomInParent() -{ - return getPosition().y - getAnchorPoint().y * _size.height;; -} - -float Widget::getRightInParent() -{ - return getLeftInParent() + _size.width; -} - -float Widget::getTopInParent() -{ - return getBottomInParent() + _size.height; -} - -const Point& Widget::getTouchStartPos() -{ - return _touchStartPos; -} - -const Point& Widget::getTouchMovePos() -{ - return _touchMovePos; -} - -const Point& Widget::getTouchEndPos() -{ - return _touchEndPos; -} - -void Widget::setName(const char* name) -{ - _name = name; -} - -const char* Widget::getName() const -{ - return _name.c_str(); -} - -WidgetType Widget::getWidgetType() const -{ - return _widgetType; -} - -void Widget::setLayoutParameter(LayoutParameter *parameter) -{ - if (!parameter) - { - return; - } - _layoutParameterDictionary.insert(parameter->getLayoutType(), parameter); -} - -LayoutParameter* Widget::getLayoutParameter(LayoutParameterType type) -{ - return dynamic_cast(_layoutParameterDictionary.at(type)); -} - -std::string Widget::getDescription() const -{ - return "Widget"; -} - -Widget* Widget::clone() -{ - Widget* clonedWidget = createCloneInstance(); - clonedWidget->copyProperties(this); - clonedWidget->copyClonedWidgetChildren(this); - return clonedWidget; -} - -Widget* Widget::createCloneInstance() -{ - return Widget::create(); -} - -void Widget::copyClonedWidgetChildren(Widget* model) -{ - auto& modelChildren = model->getChildren(); - - for (auto& subWidget : modelChildren) - { - Widget* child = static_cast(subWidget); - addChild(child->clone()); - } -} - -void Widget::copySpecialProperties(Widget* model) -{ - -} - -void Widget::copyProperties(Widget *widget) -{ - setEnabled(widget->isEnabled()); - setVisible(widget->isVisible()); - setBright(widget->isBright()); - setTouchEnabled(widget->isTouchEnabled()); - _touchPassedEnabled = false; - setLocalZOrder(widget->getLocalZOrder()); - setTag(widget->getTag()); - setName(widget->getName()); - setActionTag(widget->getActionTag()); - _ignoreSize = widget->_ignoreSize; - _size = widget->_size; - _customSize = widget->_customSize; - copySpecialProperties(widget); - _sizeType = widget->getSizeType(); - _sizePercent = widget->_sizePercent; - _positionType = widget->_positionType; - _positionPercent = widget->_positionPercent; - setPosition(widget->getPosition()); - setAnchorPoint(widget->getAnchorPoint()); - setScaleX(widget->getScaleX()); - setScaleY(widget->getScaleY()); - setRotation(widget->getRotation()); - setRotationX(widget->getRotationX()); - setRotationY(widget->getRotationY()); - setFlippedX(widget->isFlippedX()); - setFlippedY(widget->isFlippedY()); - setColor(widget->getColor()); - setOpacity(widget->getOpacity()); - Map& layoutParameterDic = widget->_layoutParameterDictionary; - for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter) - { - setLayoutParameter(iter->second->clone()); - } - onSizeChanged(); -} - -void Widget::setColor(const Color3B& color) -{ - _color = color; - updateTextureColor(); -} - -void Widget::setOpacity(GLubyte opacity) -{ - _opacity = opacity; - updateTextureOpacity(); -} - -void Widget::setFlippedX(bool flippedX) -{ - _flippedX = flippedX; - updateFlippedX(); -} - -void Widget::setFlippedY(bool flippedY) -{ - _flippedY = flippedY; - updateFlippedY(); -} - -void Widget::updateColorToRenderer(Node* renderer) -{ - renderer->setColor(_color); -} - -void Widget::updateOpacityToRenderer(Node* renderer) -{ - renderer->setOpacity(_opacity); -} - -void Widget::updateRGBAToRenderer(Node* renderer) -{ - renderer->setColor(_color); - renderer->setOpacity(_opacity); -} - -/*temp action*/ -void Widget::setActionTag(int tag) -{ - _actionTag = tag; -} - -int Widget::getActionTag() -{ - return _actionTag; -} - -} - -NS_CC_END diff --git a/cocos/gui/UIWidget.h b/cocos/gui/UIWidget.h deleted file mode 100644 index 38b19bcceb..0000000000 --- a/cocos/gui/UIWidget.h +++ /dev/null @@ -1,723 +0,0 @@ -/**************************************************************************** -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. -****************************************************************************/ - -#ifndef __UIWIDGET_H__ -#define __UIWIDGET_H__ - -#include "CCNode.h" -#include "gui/UILayoutDefine.h" -#include "gui/UILayoutParameter.h" -#include "gui/GUIDefine.h" - -NS_CC_BEGIN - -namespace ui { - -typedef enum -{ - BRIGHT_NONE = -1, - BRIGHT_NORMAL, - BRIGHT_HIGHLIGHT -}BrightStyle; - -typedef enum -{ - WidgetTypeWidget, //control - WidgetTypeContainer //container -}WidgetType; - -typedef enum -{ - UI_TEX_TYPE_LOCAL, - UI_TEX_TYPE_PLIST -}TextureResType; - -typedef enum -{ - TOUCH_EVENT_BEGAN, - TOUCH_EVENT_MOVED, - TOUCH_EVENT_ENDED, - TOUCH_EVENT_CANCELED -}TouchEventType; - -typedef enum -{ - SIZE_ABSOLUTE, - SIZE_PERCENT -}SizeType; - -typedef enum -{ - POSITION_ABSOLUTE, - POSITION_PERCENT -}PositionType; - -typedef void (Ref::*SEL_TouchEvent)(Ref*,TouchEventType); -#define toucheventselector(_SELECTOR) (SEL_TouchEvent)(&_SELECTOR) -/** -* @js NA -* @lua NA -*/ -class Widget : public Node -{ -public: - /** - * Default constructor - */ - Widget(void); - - /** - * Default destructor - */ - virtual ~Widget(); - - /** - * Allocates and initializes a widget. - */ - static Widget* create(); - - /** - * Sets whether the widget is enabled - * - * Highest control of widget. - * The default value is true, a widget is default to enabled - * - * @param enabled true if the widget is enabled, widget may be touched and visible, false if the widget is disabled, widget cannot be touched and hidden. - */ - virtual void setEnabled(bool enabled); - - /** - * Determines if the widget is enabled - * - * @return true if the widget is enabled, false if the widget is disabled. - */ - bool isEnabled() const; - - /** - * Sets whether the widget is bright - * - * The default value is true, a widget is default to bright - * - * @param visible true if the widget is bright, false if the widget is dark. - */ - void setBright(bool bright); - - /** - * Determines if the widget is bright - * - * @return true if the widget is bright, false if the widget is dark. - */ - bool isBright() const; - - /** - * Sets whether the widget is touch enabled - * - * The default value is false, a widget is default to touch disabled - * - * @param visible true if the widget is touch enabled, false if the widget is touch disabled. - */ - virtual void setTouchEnabled(bool enabled); - - /** - * To set the bright style of widget. - * - * @see BrightStyle - * - * @param style BRIGHT_NORMAL the widget is normal state, BRIGHT_HIGHLIGHT the widget is height light state. - */ - void setBrightStyle(BrightStyle style); - - /** - * Determines if the widget is touch enabled - * - * @return true if the widget is touch enabled, false if the widget is touch disabled. - */ - bool isTouchEnabled() const; - - /** - * Determines if the widget is on focused - * - * @return true if the widget is on focused, false if the widget is not on focused. - */ - bool isFocused() const; - - /** - * Sets whether the widget is on focused - * - * The default value is false, a widget is default to not on focused - * - * @param fucosed true if the widget is on focused, false if the widget is not on focused. - */ - void setFocused(bool fucosed); - - /** - * Gets the left boundary position of this widget. - * - * @return The left boundary position of this widget. - */ - float getLeftInParent(); - - /** - * Gets the bottom boundary position of this widget. - * - * @return The bottom boundary position of this widget. - */ - float getBottomInParent(); - - /** - * Gets the right boundary position of this widget. - * - * @return The right boundary position of this widget. - */ - float getRightInParent(); - - /** - * Gets the top boundary position of this widget. - * - * @return The top boundary position of this widget. - */ - float getTopInParent(); - - /** - * Adds a child to the container with z-order as 0. - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - */ - virtual void addChild(Node * child) override; - /** - * Adds a child to the container with a z-order - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - */ - virtual void addChild(Node * child, int zOrder) override; - /** - * Adds a child to the container with z order and tag - * - * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. - * - * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) - * @param tag A interger to identify the node easily. Please refer to setTag(int) - */ - virtual void addChild(Node* child, int zOrder, int tag) override; - /** - * Gets a child from the container with its tag - * - * @param tag An identifier to find the child node. - * - * @return a Node object whose tag equals to the input parameter - */ - virtual Node * getChildByTag(int tag) override; - - virtual void sortAllChildren() override; - /** - * Return an array of children - * - * Composing a "tree" structure is a very important feature of Node - * Here's a sample code of traversing children array: - @code - Node* node = NULL; - CCARRAY_FOREACH(parent->getChildren(), node) - { - node->setPosition(0,0); - } - @endcode - * This sample code traverses all children nodes, and set their position to (0,0) - * - * @return An array of children - */ - virtual Vector& getChildren() override; - virtual const Vector& getChildren() const override; - - /** - * Get the amount of children. - * - * @return The amount of children. - */ - virtual ssize_t getChildrenCount() const override; - - /** - * Removes this node itself from its parent node with a cleanup. - * If the node orphan, then nothing happens. - * @see `removeFromParentAndCleanup(bool)` - */ - virtual void removeFromParent() override; - /** - * Removes this node itself from its parent node. - * If the node orphan, then nothing happens. - * @param cleanup true if all actions and callbacks on this node should be removed, false otherwise. - * @js removeFromParent - * @lua removeFromParent - */ - virtual void removeFromParentAndCleanup(bool cleanup) override; - - /** - * Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter. - * - * @param child The child node which will be removed. - * @param cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise. - */ - virtual void removeChild(Node* child, bool cleanup = true) override; - - /** - * Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter - * - * @param tag An interger number that identifies a child node - * @param cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise. - */ - virtual void removeChildByTag(int tag, bool cleanup = true) override; - /** - * Removes all children from the container with a cleanup. - * - * @see `removeAllChildrenWithCleanup(bool)` - */ - virtual void removeAllChildren() override; - /** - * Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. - * - * @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise. - * @js removeAllChildren - * @lua removeAllChildren - */ - virtual void removeAllChildrenWithCleanup(bool cleanup) override; - - /** - * Gets a child from the container with its name - * - * @param name An key to find the child widget. - * - * @return a Widget object whose name equals to the input parameter - */ - virtual Widget* getChildByName(const char* name); - - virtual void addNode(Node* node); - - virtual void addNode(Node * node, int zOrder); - - virtual void addNode(Node* node, int zOrder, int tag); - - virtual Node * getNodeByTag(int tag); - - virtual Vector& getNodes(); - - virtual void removeNode(Node* node); - - virtual void removeNodeByTag(int tag); - - virtual void removeAllNodes(); - - virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; - - /** - * Sets the touch event target/selector of the menu item - */ - void addTouchEventListener(Ref* target,SEL_TouchEvent selector); - - - //cocos2d property - - /** - * Changes the position (x,y) of the widget in OpenGL coordinates - * - * Usually we use p(x,y) to compose Point object. - * The original point (0,0) is at the left-bottom corner of screen. - * - * @param position The position (x,y) of the widget in OpenGL coordinates - */ - virtual void setPosition(const Point &pos) override; - - /** - * Changes the position (x,y) of the widget in OpenGL coordinates - * - * Usually we use p(x,y) to compose Point object. - * The original point (0,0) is at the left-bottom corner of screen. - * - * @param percent The percent (x,y) of the widget in OpenGL coordinates - */ - void setPositionPercent(const Point &percent); - - /** - * Gets the percent (x,y) of the widget in OpenGL coordinates - * - * @see setPosition(const Point&) - * - * @return The percent (x,y) of the widget in OpenGL coordinates - */ - const Point& getPositionPercent(); - - /** - * Changes the position type of the widget - * - * @see PositionType - * - * @param type the position type of widget - */ - void setPositionType(PositionType type); - - /** - * Gets the position type of the widget - * - * @see PositionType - * - * @return type the position type of widget - */ - PositionType getPositionType() const; - - /** - * Sets whether the widget should be flipped horizontally or not. - * - * @param bFlippedX true if the widget should be flipped horizaontally, false otherwise. - */ - virtual void setFlippedX(bool flippedX); - - /** - * Returns the flag which indicates whether the widget is flipped horizontally or not. - * - * It only flips the texture of the widget, and not the texture of the widget's children. - * Also, flipping the texture doesn't alter the anchorPoint. - * If you want to flip the anchorPoint too, and/or to flip the children too use: - * widget->setScaleX(sprite->getScaleX() * -1); - * - * @return true if the widget is flipped horizaontally, false otherwise. - */ - virtual bool isFlippedX(){return _flippedX;}; - - /** - * Sets whether the widget should be flipped vertically or not. - * - * @param bFlippedY true if the widget should be flipped vertically, flase otherwise. - */ - virtual void setFlippedY(bool flippedY); - - /** - * Return the flag which indicates whether the widget is flipped vertically or not. - * - * It only flips the texture of the widget, and not the texture of the widget's children. - * Also, flipping the texture doesn't alter the anchorPoint. - * If you want to flip the anchorPoint too, and/or to flip the children too use: - * widget->setScaleY(widget->getScaleY() * -1); - * - * @return true if the widget is flipped vertically, flase otherwise. - */ - virtual bool isFlippedY(){return _flippedY;}; - - virtual void setColor(const Color3B& color) override; - - virtual void setOpacity(GLubyte opacity) override; - - const Color3B& getColor() const override {return _color;}; - - GLubyte getOpacity() const override {return _opacity;}; - - /** @deprecated Use isFlippedX() instead */ - CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); }; - /** @deprecated Use setFlippedX() instead */ - CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flipX) { setFlippedX(flipX); }; - /** @deprecated Use isFlippedY() instead */ - CC_DEPRECATED_ATTRIBUTE bool isFlipY() { return isFlippedY(); }; - /** @deprecated Use setFlippedY() instead */ - CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); }; - - /** - * A call back function when widget lost of focus. - */ - void didNotSelectSelf(); - - /* - * Checks a point if in parent's area. - * - * @param point - * - * @return true if the point is in parent's area, flase otherwise. - */ - bool clippingParentAreaContainPoint(const Point &pt); - - /* - * Sends the touch event to widget's parent - */ - virtual void checkChildInfo(int handleState,Widget* sender,const Point &touchPoint); - - /* - * Gets the touch began point of widget when widget is selected. - * - * @return the touch began point. - */ - const Point& getTouchStartPos(); - - /* - * Gets the touch move point of widget when widget is selected. - * - * @return the touch move point. - */ - const Point& getTouchMovePos(); - - /* - * Gets the touch end point of widget when widget is selected. - * - * @return the touch end point. - */ - const Point& getTouchEndPos(); - - /** - * Changes the name that is used to identify the widget easily. - * - * @param A const char* that indentifies the widget. - */ - void setName(const char* name); - - /** - * Returns a name that is used to identify the widget easily. - * - * You can set tags to widget then identify them easily. - * - * @return A const char* that identifies the widget. - */ - const char* getName() const; - - /** - * Returns a type that is widget's type - * - * @see WidgetType - * - * @return A WidgetType - */ - WidgetType getWidgetType() const; - - /** - * Changes the size that is widget's size - * - * @param size that is widget's size - */ - virtual void setSize(const Size &size); - - /** - * Changes the percent that is widget's percent size - * - * @param percent that is widget's percent size - */ - virtual void setSizePercent(const Point &percent); - - /** - * Changes the size type of widget. - * - * @see SizeType - * - * @param type that is widget's size type - */ - void setSizeType(SizeType type); - - /** - * Gets the size type of widget. - * - * @see SizeType - * - * @param type that is widget's size type - */ - SizeType getSizeType() const; - - /** - * Returns size of widget - * - * @return size - */ - const Size& getSize() const; - - const Size& getCustomSize() const; - - /** - * Returns size percent of widget - * - * @return size percent - */ - const Point& getSizePercent() const; - - /** - * Checks a point if is in widget's space - * - * @param point - * - * @return true if the point is in widget's space, flase otherwise. - */ - virtual bool hitTest(const Point &pt); - - virtual bool onTouchBegan(Touch *touch, Event *unusedEvent); - virtual void onTouchMoved(Touch *touch, Event *unusedEvent); - virtual void onTouchEnded(Touch *touch, Event *unusedEvent); - virtual void onTouchCancelled(Touch *touch, Event *unusedEvent); - - /** - * Sets a LayoutParameter to widget. - * - * @see LayoutParameter - * - * @param LayoutParameter pointer - * - * @param type Relative or Linear - */ - void setLayoutParameter(LayoutParameter* parameter); - - /** - * Gets LayoutParameter of widget. - * - * @see LayoutParameter - * - * @param type Relative or Linear - * - * @return LayoutParameter - */ - LayoutParameter* getLayoutParameter(LayoutParameterType type); - - /** - * Ignore the widget size - * - * @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true. - */ - virtual void ignoreContentAdaptWithSize(bool ignore); - - /** - * Gets the widget if is ignore it's size. - * - * @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true. - */ - bool isIgnoreContentAdaptWithSize() const; - - /** - * Gets world position of widget. - * - * @return world position of widget. - */ - Point getWorldPosition(); - - /** - * Gets the Virtual Renderer of widget. - * - * For example, a button's Virtual Renderer is it's texture renderer. - * - * @return Node pointer. - */ - virtual Node* getVirtualRenderer(); - - /** - * Gets the content size of widget. - * - * Content size is widget's texture size. - */ - virtual const Size& getContentSize() const; - - /** - * Returns the "class name" of widget. - */ - virtual std::string getDescription() const override; - - Widget* clone(); - - virtual void onEnter() override; - virtual void onExit() override; - - void updateSizeAndPosition(); - - /*temp action*/ - void setActionTag(int tag); - int getActionTag(); -protected: - //call back function called when size changed. - virtual void onSizeChanged(); - - //initializes state of widget. - virtual bool init(); - - //initializes renderer of widget. - virtual void initRenderer(); - - //call back function called widget's state changed to normal. - virtual void onPressStateChangedToNormal(); - - //call back function called widget's state changed to selected. - virtual void onPressStateChangedToPressed(); - - //call back function called widget's state changed to dark. - virtual void onPressStateChangedToDisabled(); - void pushDownEvent(); - void moveEvent(); - void releaseUpEvent(); - void cancelUpEvent(); - void updateAnchorPoint(); - virtual void updateTextureColor(){}; - virtual void updateTextureOpacity(){}; - virtual void updateTextureRGBA(){}; - virtual void updateFlippedX(){}; - virtual void updateFlippedY(){}; - void updateColorToRenderer(Node* renderer); - void updateOpacityToRenderer(Node* renderer); - void updateRGBAToRenderer(Node* renderer); - void copyProperties(Widget* model); - virtual Widget* createCloneInstance(); - virtual void copySpecialProperties(Widget* model); - virtual void copyClonedWidgetChildren(Widget* model); - Widget* getWidgetParent(); -protected: - bool _enabled; ///< Highest control of widget - bool _bright; ///< is this widget bright - bool _touchEnabled; ///< is this widget touch endabled - bool _touchPassedEnabled; ///< is the touch event should be passed - bool _focus; ///< is the widget on focus - BrightStyle _brightStyle; ///< bright style - Point _touchStartPos; ///< touch began point - Point _touchMovePos; ///< touch moved point - Point _touchEndPos; ///< touch ended point - Ref* _touchEventListener; - SEL_TouchEvent _touchEventSelector; - std::string _name; - WidgetType _widgetType; - int _actionTag; - Size _size; - Size _customSize; - bool _ignoreSize; - bool _affectByClipping; - SizeType _sizeType; - Point _sizePercent; - PositionType _positionType; - Point _positionPercent; - bool _reorderWidgetChildDirty; - bool _hitted; - EventListenerTouchOneByOne* _touchListener; - Vector _nodes; - Color3B _color; - GLubyte _opacity; - bool _flippedX; - bool _flippedY; - Map _layoutParameterDictionary; - Vector _widgetChildren; - -}; -} - -NS_CC_END - -#endif /* defined(__Widget__) */ diff --git a/cocos/gui/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/gui/WidgetReader/ButtonReader/ButtonReader.cpp deleted file mode 100644 index 94222c55d8..0000000000 --- a/cocos/gui/WidgetReader/ButtonReader/ButtonReader.cpp +++ /dev/null @@ -1,158 +0,0 @@ - - -#include "ButtonReader.h" -#include "gui/UIButton.h" - -namespace cocostudio -{ - static ButtonReader* instanceButtonReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader) - - ButtonReader::ButtonReader() - { - - } - - ButtonReader::~ButtonReader() - { - - } - - ButtonReader* ButtonReader::getInstance() - { - if (!instanceButtonReader) - { - instanceButtonReader = new ButtonReader(); - } - return instanceButtonReader; - } - - void ButtonReader::purge() - { - CC_SAFE_DELETE(instanceButtonReader); - } - - void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - Button* button = static_cast(widget); - bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); - button->setScale9Enabled(scale9Enable); - - const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData"); - int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - switch (normalType) - { - case 0: - { - std::string tp_n = jsonPath; - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; - button->loadTextureNormal(normalFileName_tp); - break; - } - case 1: - { - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData"); - int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - switch (pressedType) - { - case 0: - { - std::string tp_p = jsonPath; - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; - button->loadTexturePressed(pressedFileName_tp); - break; - } - case 1: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData"); - int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - switch (disabledType) - { - case 0: - { - std::string tp_d = jsonPath; - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; - button->loadTextureDisabled(disabledFileName_tp); - break; - } - case 1: - { - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - if (scale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - - button->setCapInsets(Rect(cx, cy, cw, ch)); - bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); - bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); - if (sw && sh) - { - float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); - float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); - button->setSize(Size(swf, shf)); - } - } - bool tt = DICTOOL->checkObjectExist_json(options, "text"); - if (tt) - { - const char* text = DICTOOL->getStringValue_json(options, "text"); - if (text) - { - button->setTitleText(text); - } - } - - bool cr = DICTOOL->checkObjectExist_json(options, "textColorR"); - bool cg = DICTOOL->checkObjectExist_json(options, "textColorG"); - bool cb = DICTOOL->checkObjectExist_json(options, "textColorB"); - int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255; - int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255; - int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255; - button->setTitleColor(Color3B(cri,cgi,cbi)); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName")); - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/ButtonReader/ButtonReader.h b/cocos/gui/WidgetReader/ButtonReader/ButtonReader.h deleted file mode 100644 index f3ec7b406a..0000000000 --- a/cocos/gui/WidgetReader/ButtonReader/ButtonReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__ButtonReader__ -#define __TestCpp__ButtonReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class ButtonReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - ButtonReader(); - virtual ~ButtonReader(); - - static ButtonReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__ButtonReader__) */ diff --git a/cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp deleted file mode 100644 index 2e22dad751..0000000000 --- a/cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ /dev/null @@ -1,153 +0,0 @@ - - -#include "CheckBoxReader.h" -#include "gui/UICheckBox.h" - -namespace cocostudio -{ - static CheckBoxReader* instanceCheckBoxReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader) - - CheckBoxReader::CheckBoxReader() - { - - } - - CheckBoxReader::~CheckBoxReader() - { - - } - - CheckBoxReader* CheckBoxReader::getInstance() - { - if (!instanceCheckBoxReader) - { - instanceCheckBoxReader = new CheckBoxReader(); - } - return instanceCheckBoxReader; - } - - void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - CheckBox* checkBox = static_cast(widget); - - const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData"); - int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType"); - switch (backGroundType) - { - case 0: - { - std::string tp_b = jsonPath; - const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr; - checkBox->loadTextureBackGround(backGroundFileName_tp); - break; - } - case 1: - { - const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData"); - int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType"); - switch (backGroundSelectedType) - { - case 0: - { - std::string tp_bs = jsonPath; - const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr; - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp); - break; - } - case 1: - { - const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData"); - int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType"); - switch (frontCrossType) - { - case 0: - { - std::string tp_c = jsonPath; - const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); - const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr; - checkBox->loadTextureFrontCross(frontCrossFileName_tp); - break; - } - case 1: - { - const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); - checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData"); - int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType"); - switch (backGroundDisabledType) - { - case 0: - { - std::string tp_bd = jsonPath; - const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr; - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp); - break; - } - case 1: - { - const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData"); - int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType"); - switch (frontCrossDisabledType) - { - case 0: - { - std::string tp_cd = jsonPath; - const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); - const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr; - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp); - break; - } - case 1: - { - const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.h b/cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.h deleted file mode 100644 index cbfed76584..0000000000 --- a/cocos/gui/WidgetReader/CheckBoxReader/CheckBoxReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__CheckBoxReader__ -#define __TestCpp__CheckBoxReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class CheckBoxReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - CheckBoxReader(); - virtual ~CheckBoxReader(); - - static CheckBoxReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__CheckBoxReader__) */ diff --git a/cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.cpp deleted file mode 100644 index 46089a8b4e..0000000000 --- a/cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ /dev/null @@ -1,98 +0,0 @@ - - -#include "ImageViewReader.h" -#include "gui/UIImageView.h" - -namespace cocostudio -{ - static ImageViewReader* instanceImageViewReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader) - - ImageViewReader::ImageViewReader() - { - - } - - ImageViewReader::~ImageViewReader() - { - - } - - ImageViewReader* ImageViewReader::getInstance() - { - if (!instanceImageViewReader) - { - instanceImageViewReader = new ImageViewReader(); - } - return instanceImageViewReader; - } - - void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - ImageView* imageView = static_cast(widget); - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_i = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = nullptr; - if (imageFileName && (strcmp(imageFileName, "") != 0)) - { - imageFileName_tp = tp_i.append(imageFileName).c_str(); - imageView->loadTexture(imageFileName_tp); - } - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable"); - bool scale9Enable = false; - if (scale9EnableExist) - { - scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); - } - imageView->setScale9Enabled(scale9Enable); - - - if (scale9Enable) - { - bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); - bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); - if (sw && sh) - { - float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); - float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); - imageView->setSize(Size(swf, shf)); - } - - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - - imageView->setCapInsets(Rect(cx, cy, cw, ch)); - - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.h b/cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.h deleted file mode 100644 index 09d4ae2b43..0000000000 --- a/cocos/gui/WidgetReader/ImageViewReader/ImageViewReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__ImageViewReader__ -#define __TestCpp__ImageViewReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class ImageViewReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - ImageViewReader(); - virtual ~ImageViewReader(); - - static ImageViewReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__ImageViewReader__) */ diff --git a/cocos/gui/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/gui/WidgetReader/LayoutReader/LayoutReader.cpp deleted file mode 100644 index 40908d7f2b..0000000000 --- a/cocos/gui/WidgetReader/LayoutReader/LayoutReader.cpp +++ /dev/null @@ -1,119 +0,0 @@ - - -#include "LayoutReader.h" -#include "gui/UILayout.h" - -namespace cocostudio -{ - static LayoutReader* instanceLayoutReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader) - - LayoutReader::LayoutReader() - { - - } - - LayoutReader::~LayoutReader() - { - - } - - LayoutReader* LayoutReader::getInstance() - { - if (!instanceLayoutReader) - { - instanceLayoutReader = new LayoutReader(); - } - return instanceLayoutReader; - } - - void LayoutReader::setPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - Layout* panel = static_cast(widget); - - /* adapt screen gui */ - float w = 0, h = 0; - bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); - if (adaptScrenn) - { - Size screenSize = CCDirector::getInstance()->getWinSize(); - w = screenSize.width; - h = screenSize.height; - } - else - { - w = DICTOOL->getFloatValue_json(options, "width"); - h = DICTOOL->getFloatValue_json(options, "height"); - } - panel->setSize(Size(w, h)); - /**/ - - bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable"); - panel->setBackGroundImageScale9Enabled(backGroundScale9Enable); - int cr = DICTOOL->getIntValue_json(options, "bgColorR"); - int cg = DICTOOL->getIntValue_json(options, "bgColorG"); - int cb = DICTOOL->getIntValue_json(options, "bgColorB"); - - int scr = DICTOOL->getIntValue_json(options, "bgStartColorR"); - int scg = DICTOOL->getIntValue_json(options, "bgStartColorG"); - int scb = DICTOOL->getIntValue_json(options, "bgStartColorB"); - - int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR"); - int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG"); - int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB"); - - float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX"); - float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY"); - panel->setBackGroundColorVector(Point(bgcv1, bgcv2)); - - int co = DICTOOL->getIntValue_json(options, "bgColorOpacity"); - - int colorType = DICTOOL->getIntValue_json(options, "colorType"); - panel->setBackGroundColorType(LayoutBackGroundColorType(colorType)); - panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb)); - panel->setBackGroundColor(Color3B(cr, cg, cb)); - panel->setBackGroundColorOpacity(co); - - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_b = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - panel->setBackGroundImage(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - if (backGroundScale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch)); - } - panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType")); - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/LayoutReader/LayoutReader.h b/cocos/gui/WidgetReader/LayoutReader/LayoutReader.h deleted file mode 100644 index e4d2f3b479..0000000000 --- a/cocos/gui/WidgetReader/LayoutReader/LayoutReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__LayoutReader__ -#define __TestCpp__LayoutReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class LayoutReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - LayoutReader(); - virtual ~LayoutReader(); - - static LayoutReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__LayoutReader__) */ diff --git a/cocos/gui/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/gui/WidgetReader/ListViewReader/ListViewReader.cpp deleted file mode 100644 index 788b7a271d..0000000000 --- a/cocos/gui/WidgetReader/ListViewReader/ListViewReader.cpp +++ /dev/null @@ -1,48 +0,0 @@ - - -#include "ListViewReader.h" -#include "gui/UIListView.h" - -namespace cocostudio -{ - static ListViewReader* instanceListViewReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader) - - ListViewReader::ListViewReader() - { - - } - - ListViewReader::~ListViewReader() - { - - } - - ListViewReader* ListViewReader::getInstance() - { - if (!instanceListViewReader) - { - instanceListViewReader = new ListViewReader(); - } - return instanceListViewReader; - } - - void ListViewReader::setPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options) - { - ScrollViewReader::setPropsFromJsonDictionary(widget, options); - - - ListView* listView = static_cast(widget); - - int direction = DICTOOL->getFloatValue_json(options, "direction"); - listView->setDirection((SCROLLVIEW_DIR)direction); - - ListViewGravity gravity = (ListViewGravity)DICTOOL->getIntValue_json(options, "gravity"); - listView->setGravity(gravity); - - float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin"); - listView->setItemsMargin(itemMargin); - } -} - diff --git a/cocos/gui/WidgetReader/ListViewReader/ListViewReader.h b/cocos/gui/WidgetReader/ListViewReader/ListViewReader.h deleted file mode 100644 index 6c10b2114b..0000000000 --- a/cocos/gui/WidgetReader/ListViewReader/ListViewReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__ListViewReader__ -#define __TestCpp__ListViewReader__ - -#include "../ScrollViewReader/ScrollViewReader.h" - -namespace cocostudio -{ - class ListViewReader : public ScrollViewReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - ListViewReader(); - virtual ~ListViewReader(); - - static ListViewReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__ListViewReader__) */ diff --git a/cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp deleted file mode 100644 index 92b10fa845..0000000000 --- a/cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ /dev/null @@ -1,91 +0,0 @@ - - -#include "LoadingBarReader.h" -#include "gui/UILoadingBar.h" - -namespace cocostudio -{ - static LoadingBarReader* instanceLoadingBar = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader) - - LoadingBarReader::LoadingBarReader() - { - - } - - LoadingBarReader::~LoadingBarReader() - { - - } - - LoadingBarReader* LoadingBarReader::getInstance() - { - if (!instanceLoadingBar) - { - instanceLoadingBar = new LoadingBarReader(); - } - return instanceLoadingBar; - } - - void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - LoadingBar* loadingBar = static_cast(widget); - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_i = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = nullptr; - if (imageFileName && (strcmp(imageFileName, "") != 0)) - { - imageFileName_tp = tp_i.append(imageFileName).c_str(); - loadingBar->loadTexture(imageFileName_tp); - } - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - /* gui mark add load bar scale9 parse */ - bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); - loadingBar->setScale9Enabled(scale9Enable); - - if (scale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - - loadingBar->setCapInsets(Rect(cx, cy, cw, ch)); - - float width = DICTOOL->getFloatValue_json(options, "width"); - float height = DICTOOL->getFloatValue_json(options, "height"); - loadingBar->setSize(Size(width, height)); - } - /**/ - - loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction"))); - loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent")); - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.h b/cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.h deleted file mode 100644 index 69d12e3f33..0000000000 --- a/cocos/gui/WidgetReader/LoadingBarReader/LoadingBarReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__LoadingBarReader__ -#define __TestCpp__LoadingBarReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class LoadingBarReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - LoadingBarReader(); - virtual ~LoadingBarReader(); - - static LoadingBarReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__LoadingBarReader__) */ diff --git a/cocos/gui/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/gui/WidgetReader/PageViewReader/PageViewReader.cpp deleted file mode 100644 index aa58079ef9..0000000000 --- a/cocos/gui/WidgetReader/PageViewReader/PageViewReader.cpp +++ /dev/null @@ -1,35 +0,0 @@ - - -#include "PageViewReader.h" -#include "gui/UIPageView.h" - -namespace cocostudio -{ - static PageViewReader* instancePageViewReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader) - - PageViewReader::PageViewReader() - { - - } - - PageViewReader::~PageViewReader() - { - - } - - PageViewReader* PageViewReader::getInstance() - { - if (!instancePageViewReader) - { - instancePageViewReader = new PageViewReader(); - } - return instancePageViewReader; - } - - void PageViewReader::setPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options) - { - LayoutReader::setPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/PageViewReader/PageViewReader.h b/cocos/gui/WidgetReader/PageViewReader/PageViewReader.h deleted file mode 100644 index 5b58c8cfad..0000000000 --- a/cocos/gui/WidgetReader/PageViewReader/PageViewReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__PageViewReader__ -#define __TestCpp__PageViewReader__ - -#include "../LayoutReader/LayoutReader.h" - -namespace cocostudio -{ - class PageViewReader : public LayoutReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - PageViewReader(); - virtual ~PageViewReader(); - - static PageViewReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(gui::Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__PageViewReader__) */ diff --git a/cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp deleted file mode 100644 index 2b726a3eab..0000000000 --- a/cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ /dev/null @@ -1,47 +0,0 @@ - - -#include "ScrollViewReader.h" -#include "gui/UIScrollView.h" - -namespace cocostudio -{ - static ScrollViewReader* instanceScrollViewReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader) - - ScrollViewReader::ScrollViewReader() - { - - } - - ScrollViewReader::~ScrollViewReader() - { - - } - - ScrollViewReader* ScrollViewReader::getInstance() - { - if (!instanceScrollViewReader) - { - instanceScrollViewReader = new ScrollViewReader(); - } - return instanceScrollViewReader; - } - - void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - LayoutReader::setPropsFromJsonDictionary(widget, options); - - - ScrollView* scrollView = static_cast(widget); - float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth"); - float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight"); - scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); - int direction = DICTOOL->getFloatValue_json(options, "direction"); - scrollView->setDirection((SCROLLVIEW_DIR)direction); - scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable")); - - - LayoutReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.h b/cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.h deleted file mode 100644 index 429a2ad9fe..0000000000 --- a/cocos/gui/WidgetReader/ScrollViewReader/ScrollViewReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__ScrollViewReader__ -#define __TestCpp__ScrollViewReader__ - -#include "../LayoutReader/LayoutReader.h" - -namespace cocostudio -{ - class ScrollViewReader : public LayoutReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - ScrollViewReader(); - virtual ~ScrollViewReader(); - - static ScrollViewReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__ScrollViewReader__) */ diff --git a/cocos/gui/WidgetReader/SliderReader/SliderReader.cpp b/cocos/gui/WidgetReader/SliderReader/SliderReader.cpp deleted file mode 100644 index 08d9516add..0000000000 --- a/cocos/gui/WidgetReader/SliderReader/SliderReader.cpp +++ /dev/null @@ -1,192 +0,0 @@ - - -#include "SliderReader.h" -#include "gui/UISlider.h" - -namespace cocostudio -{ - static SliderReader* instanceSliderReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader) - - SliderReader::SliderReader() - { - - } - - SliderReader::~SliderReader() - { - - } - - SliderReader* SliderReader::getInstance() - { - if (!instanceSliderReader) - { - instanceSliderReader = new SliderReader(); - } - return instanceSliderReader; - } - - void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - Slider* slider = static_cast(widget); - - bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable"); - slider->setScale9Enabled(barTextureScale9Enable); - bool bt = DICTOOL->checkObjectExist_json(options, "barFileName"); - float barLength = DICTOOL->getFloatValue_json(options, "length"); - if (bt) - { - if (barTextureScale9Enable) - { - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileType) - { - case 0: - { - std::string tp_b = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - slider->setSize(Size(barLength, slider->getContentSize().height)); - } - else - { - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileType) - { - case 0: - { - std::string tp_b = jsonPath; - const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - } - } - - const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData"); - int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - switch (normalType) - { - case 0: - { - std::string tp_n = jsonPath; - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; - slider->loadSlidBallTextureNormal(normalFileName_tp); - break; - } - case 1: - { - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData"); - int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - switch (pressedType) - { - case 0: - { - std::string tp_p = jsonPath; - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; - slider->loadSlidBallTexturePressed(pressedFileName_tp); - break; - } - case 1: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData"); - int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - switch (disabledType) - { - case 0: - { - std::string tp_d = jsonPath; - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; - slider->loadSlidBallTextureDisabled(disabledFileName_tp); - break; - } - case 1: - { - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - slider->setPercent(DICTOOL->getIntValue_json(options, "percent")); - - const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData"); - int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType"); - switch (progressBarType) - { - case 0: - { - std::string tp_b = jsonPath; - const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadProgressBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); - slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST); - break; - } - default: - break; - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/SliderReader/SliderReader.h b/cocos/gui/WidgetReader/SliderReader/SliderReader.h deleted file mode 100644 index 1fa0390c07..0000000000 --- a/cocos/gui/WidgetReader/SliderReader/SliderReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__SliderReader__ -#define __TestCpp__SliderReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class SliderReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - SliderReader(); - virtual ~SliderReader(); - - static SliderReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__SliderReader__) */ diff --git a/cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp deleted file mode 100644 index e59c6ef492..0000000000 --- a/cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ /dev/null @@ -1,69 +0,0 @@ - - -#include "TextAtlasReader.h" -#include "gui/UITextAtlas.h" - -namespace cocostudio -{ - static TextAtlasReader* instanceTextAtalsReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader) - - TextAtlasReader::TextAtlasReader() - { - - } - - TextAtlasReader::~TextAtlasReader() - { - - } - - TextAtlasReader* TextAtlasReader::getInstance() - { - if (!instanceTextAtalsReader) - { - instanceTextAtalsReader = new TextAtlasReader(); - } - return instanceTextAtalsReader; - } - - void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - TextAtlas* labelAtlas = static_cast(widget); - bool sv = DICTOOL->checkObjectExist_json(options, "stringValue"); - bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile"); - bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth"); - bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight"); - bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap"); - if (sv && cmf && iw && ih && scm) - { - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData"); - int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); - switch (cmfType) - { - case 0: - { - std::string tp_c = jsonPath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); - const char* cmf_tp = tp_c.append(cmfPath).c_str(); - labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap")); - break; - } - case 1: - CCLOG("Wrong res type of LabelAtlas!"); - break; - default: - break; - } - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.h b/cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.h deleted file mode 100644 index a065162769..0000000000 --- a/cocos/gui/WidgetReader/TextAtlasReader/TextAtlasReader.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__TextAtlasReader__ -#define __TestCpp__TextAtlasReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class TextAtlasReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - TextAtlasReader(); - virtual ~TextAtlasReader(); - - static TextAtlasReader* getInstance(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__TextAtlasReader__) */ diff --git a/cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp deleted file mode 100644 index 90186522e2..0000000000 --- a/cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ /dev/null @@ -1,65 +0,0 @@ - - -#include "TextBMFontReader.h" -#include "gui/UITextBMFont.h" - -namespace cocostudio -{ - static TextBMFontReader* instanceTextBMFontReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader) - - TextBMFontReader::TextBMFontReader() - { - - } - - TextBMFontReader::~TextBMFontReader() - { - - } - - TextBMFontReader* TextBMFontReader::getInstance() - { - if (!instanceTextBMFontReader) - { - instanceTextBMFontReader = new TextBMFontReader(); - } - return instanceTextBMFontReader; - } - - void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - TextBMFont* labelBMFont = static_cast(widget); - - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); - int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); - switch (cmfType) - { - case 0: - { - std::string tp_c = jsonPath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); - const char* cmf_tp = tp_c.append(cmfPath).c_str(); - labelBMFont->setFntFile(cmf_tp); - break; - } - case 1: - CCLOG("Wrong res type of LabelAtlas!"); - break; - default: - break; - } - - const char* text = DICTOOL->getStringValue_json(options, "text"); - labelBMFont->setText(text); - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.h b/cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.h deleted file mode 100644 index bfba2f3cfc..0000000000 --- a/cocos/gui/WidgetReader/TextBMFontReader/TextBMFontReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__TextBMFontReader__ -#define __TestCpp__TextBMFontReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class TextBMFontReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - TextBMFontReader(); - virtual ~TextBMFontReader(); - - static TextBMFontReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__TextBMFontReader__) */ diff --git a/cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.cpp deleted file mode 100644 index 301ae2da38..0000000000 --- a/cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ /dev/null @@ -1,84 +0,0 @@ - - -#include "TextFieldReader.h" -#include "gui/UITextField.h" - -namespace cocostudio -{ - static TextFieldReader* instanceTextFieldReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader) - - TextFieldReader::TextFieldReader() - { - - } - - TextFieldReader::~TextFieldReader() - { - - } - - TextFieldReader* TextFieldReader::getInstance() - { - if (!instanceTextFieldReader) - { - instanceTextFieldReader = new TextFieldReader(); - } - return instanceTextFieldReader; - } - - void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - TextField* textField = static_cast(widget); - bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder"); - if (ph) - { - textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder")); - } - textField->setText(DICTOOL->getStringValue_json(options, "text")); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - textField->setFontName(DICTOOL->getStringValue_json(options, "fontName")); - } - bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth"); - bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight"); - if (tsw && tsh) - { - textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight"))); - } - - float dw = DICTOOL->getFloatValue_json(options, "width"); - float dh = DICTOOL->getFloatValue_json(options, "height"); - if (dw > 0.0f || dh > 0.0f) - { - //textField->setSize(Size(dw, dh)); - } - bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable"); - textField->setMaxLengthEnabled(maxLengthEnable); - - if (maxLengthEnable) - { - int maxLength = DICTOOL->getIntValue_json(options, "maxLength"); - textField->setMaxLength(maxLength); - } - bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable"); - textField->setPasswordEnabled(passwordEnable); - if (passwordEnable) - { - textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText")); - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.h b/cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.h deleted file mode 100644 index 30d467787a..0000000000 --- a/cocos/gui/WidgetReader/TextFieldReader/TextFieldReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__TextFieldReader__ -#define __TestCpp__TextFieldReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class TextFieldReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - TextFieldReader(); - virtual ~TextFieldReader(); - - static TextFieldReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__TextFieldReader__) */ diff --git a/cocos/gui/WidgetReader/TextReader/TextReader.cpp b/cocos/gui/WidgetReader/TextReader/TextReader.cpp deleted file mode 100644 index 36d8f23ede..0000000000 --- a/cocos/gui/WidgetReader/TextReader/TextReader.cpp +++ /dev/null @@ -1,74 +0,0 @@ - - -#include "TextReader.h" -#include "gui/UIText.h" - -namespace cocostudio -{ - static TextReader* instanceTextReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(TextReader) - - TextReader::TextReader() - { - - } - - TextReader::~TextReader() - { - - } - - TextReader* TextReader::getInstance() - { - if (!instanceTextReader) - { - instanceTextReader = new TextReader(); - } - return instanceTextReader; - } - - void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) - { - WidgetReader::setPropsFromJsonDictionary(widget, options); - - - std::string jsonPath = GUIReader::getInstance()->getFilePath(); - - Text* label = static_cast(widget); - bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable"); - label->setTouchScaleChangeEnabled(touchScaleChangeAble); - const char* text = DICTOOL->getStringValue_json(options, "text"); - label->setText(text); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); - } - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); - if (aw && ah) - { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); - label->setTextAreaSize(size); - } - bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); - if (ha) - { - label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment")); - } - bool va = DICTOOL->checkObjectExist_json(options, "vAlignment"); - if (va) - { - label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment")); - } - - - WidgetReader::setColorPropsFromJsonDictionary(widget, options); - } -} diff --git a/cocos/gui/WidgetReader/TextReader/TextReader.h b/cocos/gui/WidgetReader/TextReader/TextReader.h deleted file mode 100644 index 18d15e6323..0000000000 --- a/cocos/gui/WidgetReader/TextReader/TextReader.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__TextReader__ -#define __TestCpp__TextReader__ - -#include "../WidgetReader.h" - -namespace cocostudio -{ - class TextReader : public WidgetReader - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - TextReader(); - virtual ~TextReader(); - - static TextReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__TextReader__) */ diff --git a/cocos/gui/WidgetReader/WidgetReader.cpp b/cocos/gui/WidgetReader/WidgetReader.cpp deleted file mode 100644 index 60dfb43a0c..0000000000 --- a/cocos/gui/WidgetReader/WidgetReader.cpp +++ /dev/null @@ -1,172 +0,0 @@ - - -#include "WidgetReader.h" - -namespace cocostudio -{ - static WidgetReader* instanceWidgetReader = NULL; - - IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader) - - WidgetReader::WidgetReader() - { - - } - - WidgetReader::~WidgetReader() - { - - } - - WidgetReader* WidgetReader::getInstance() - { - if (!instanceWidgetReader) - { - instanceWidgetReader = new WidgetReader(); - } - return instanceWidgetReader; - } - - void WidgetReader::purge() - { - CC_SAFE_DELETE(instanceWidgetReader); - } - - void WidgetReader::setPropsFromJsonDictionary(cocos2d::gui::Widget *widget, const rapidjson::Value &options) - { - bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); - if (ignoreSizeExsit) - { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); - } - - widget->setSizeType((SizeType)DICTOOL->getIntValue_json(options, "sizeType")); - widget->setPositionType((PositionType)DICTOOL->getIntValue_json(options, "positionType")); - - widget->setSizePercent(Point(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY"))); - widget->setPositionPercent(Point(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY"))); - - /* adapt screen */ - float w = 0, h = 0; - bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); - if (adaptScrenn) - { - Size screenSize = CCDirector::getInstance()->getWinSize(); - w = screenSize.width; - h = screenSize.height; - } - else - { - w = DICTOOL->getFloatValue_json(options, "width"); - h = DICTOOL->getFloatValue_json(options, "height"); - } - widget->setSize(Size(w, h)); - // before - /* - float w = DICTOOL->getFloatValue_json(options, "width"); - float h = DICTOOL->getFloatValue_json(options, "height"); - widget->setSize(CCSizeMake(w, h)); - */ - /**/ - - widget->setTag(DICTOOL->getIntValue_json(options, "tag")); - widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag")); - widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble")); - const char* name = DICTOOL->getStringValue_json(options, "name"); - const char* widgetName = name?name:"default"; - widget->setName(widgetName); - float x = DICTOOL->getFloatValue_json(options, "x"); - float y = DICTOOL->getFloatValue_json(options, "y"); - widget->setPosition(Point(x,y)); - bool sx = DICTOOL->checkObjectExist_json(options, "scaleX"); - if (sx) - { - widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX")); - } - bool sy = DICTOOL->checkObjectExist_json(options, "scaleY"); - if (sy) - { - widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY")); - } - bool rt = DICTOOL->checkObjectExist_json(options, "rotation"); - if (rt) - { - widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation")); - } - bool vb = DICTOOL->checkObjectExist_json(options, "visible"); - if (vb) - { - widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); - } - int z = DICTOOL->getIntValue_json(options, "ZOrder"); - widget->setLocalZOrder(z); - - bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter"); - if (layout) - { - const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter"); - int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type"); - LayoutParameter* parameter = nullptr; - switch (paramType) - { - case 0: - break; - case 1: - { - parameter = LinearLayoutParameter::create(); - int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity"); - ((LinearLayoutParameter*)parameter)->setGravity((LinearGravity)gravity); - break; - } - case 2: - { - parameter = RelativeLayoutParameter::create(); - RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter; - const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName"); - rParameter->setRelativeName(relativeName); - const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName"); - rParameter->setRelativeToWidgetName(relativeToName); - int align = DICTOOL->getIntValue_json(layoutParameterDic, "align"); - rParameter->setAlign((RelativeAlign)align); - break; - } - default: - break; - } - if (parameter) - { - float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft"); - float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop"); - float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight"); - float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown"); - parameter->setMargin(Margin(mgl, mgt, mgr, mgb)); - widget->setLayoutParameter(parameter); - } - } - } - - void WidgetReader::setColorPropsFromJsonDictionary(gui::Widget *widget, const rapidjson::Value &options) - { - bool op = DICTOOL->checkObjectExist_json(options, "opacity"); - if (op) - { - widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity")); - } - bool cr = DICTOOL->checkObjectExist_json(options, "colorR"); - bool cg = DICTOOL->checkObjectExist_json(options, "colorG"); - bool cb = DICTOOL->checkObjectExist_json(options, "colorB"); - int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255; - int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; - int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; - widget->setColor(Color3B(colorR, colorG, colorB)); - bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX"); - float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f); - bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY"); - float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f); - widget->setAnchorPoint(Point(apxf, apyf)); - bool flipX = DICTOOL->getBooleanValue_json(options, "flipX"); - bool flipY = DICTOOL->getBooleanValue_json(options, "flipY"); - widget->setFlipX(flipX); - widget->setFlipY(flipY); - } -} diff --git a/cocos/gui/WidgetReader/WidgetReader.h b/cocos/gui/WidgetReader/WidgetReader.h deleted file mode 100644 index 9c9e994d66..0000000000 --- a/cocos/gui/WidgetReader/WidgetReader.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__WidgetReader__ -#define __TestCpp__WidgetReader__ - -#include "WidgetReaderProtocol.h" -#include "../CCSGUIReader.h" -#include "gui/GUIDefine.h" -#include "gui/UIWidget.h" - -namespace cocostudio -{ - class WidgetReader : public Object, public WidgetReaderProtocol - { - public: - DECLARE_CLASS_WIDGET_READER_INFO - - WidgetReader(); - virtual ~WidgetReader(); - - static WidgetReader* getInstance(); - static void purge(); - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - virtual void setColorPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); - }; -} - -#endif /* defined(__TestCpp__WidgetReader__) */ diff --git a/cocos/gui/WidgetReader/WidgetReaderProtocol.h b/cocos/gui/WidgetReader/WidgetReaderProtocol.h deleted file mode 100644 index e910bb1827..0000000000 --- a/cocos/gui/WidgetReader/WidgetReaderProtocol.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 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__WidgetReaderProtocol__ -#define __TestCpp__WidgetReaderProtocol__ - -#include "cocos2d.h" -#include "cocostudio/DictionaryHelper.h" - -namespace cocos2d -{ - namespace gui - { - class Widget; - } -} - -USING_NS_CC; -using namespace cocos2d::gui; - -namespace cocostudio -{ - class WidgetReaderProtocol - { - public: - virtual ~WidgetReaderProtocol() {}; - - virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options) = 0; - }; -} - -#endif /* defined(__TestCpp__WidgetReaderProtocol__) */ diff --git a/cocos/gui/proj.win32/libGUI.vcxproj b/cocos/gui/proj.win32/libGUI.vcxproj deleted file mode 100644 index 3dad252cfe..0000000000 --- a/cocos/gui/proj.win32/libGUI.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {7E06E92C-537A-442B-9E4A-4761C84F8A1A} - libGUI - - - - StaticLibrary - true - v100 - v110 - v110_xp - Unicode - - - StaticLibrary - false - v100 - v110 - v110_xp - true - Unicode - - - - - - - - - - - - - - - $(SolutionDir)$(Configuration).win32\ - $(Configuration).win32\ - - - $(SolutionDir)$(Configuration).win32\ - $(Configuration).win32\ - - - - Level3 - Disabled - - - $(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support;$(EngineRoot)external;$(EngineRoot)extensions;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - 4267;4251;4244;%(DisableSpecificWarnings) - false - OldStyle - - - true - - - - - Level3 - MaxSpeed - true - true - - - WIN32;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - $(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support;$(EngineRoot)external;$(EngineRoot)extensions;%(AdditionalIncludeDirectories) - - - true - true - true - - - - - - \ No newline at end of file diff --git a/cocos/gui/proj.win32/libGUI.vcxproj.filters b/cocos/gui/proj.win32/libGUI.vcxproj.filters deleted file mode 100644 index d79c8a4a8d..0000000000 --- a/cocos/gui/proj.win32/libGUI.vcxproj.filters +++ /dev/null @@ -1,141 +0,0 @@ - - - - - {e31ab7d3-b8b2-467f-9e08-fd5fe168b491} - - - {f9d13563-9e5e-4b35-b0e7-d41f587efa42} - - - {ed8a2ae0-5690-4d0d-829b-7c07164c0597} - - - {5f6e9e52-fbe7-4073-ac71-98632f9e6781} - - - {b59b178a-b7e0-4826-ba07-44c46cd29a10} - - - - - UIWidgets\ScrollWidget - - - UIWidgets\ScrollWidget - - - UIWidgets\ScrollWidget - - - UIWidgets\ScrollWidget - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - System - - - System - - - Layouts - - - BaseClasses - - - Layouts - - - Layouts - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - - - UIWidgets\ScrollWidget - - - UIWidgets\ScrollWidget - - - UIWidgets\ScrollWidget - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - System - - - System - - - Layouts - - - BaseClasses - - - Layouts - - - Layouts - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - UIWidgets - - - \ No newline at end of file diff --git a/cocos/gui/proj.win32/libGUI.vcxproj.user b/cocos/gui/proj.win32/libGUI.vcxproj.user deleted file mode 100644 index a375ae3527..0000000000 --- a/cocos/gui/proj.win32/libGUI.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From cbcc1bbbcfc8831f94c63c2e4e3a7188f4637737 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 17:13:54 +0800 Subject: [PATCH 02/17] let ios project compile correct --- .../project.pbxproj.REMOVED.git-id | 2 +- .../cocostudio/CCActionNode.cpp | 4 +- .../cocostudio/CCSGUIReader.cpp | 2 +- .../editor-support/cocostudio/CCSGUIReader.h | 2 +- .../cocostudio/CCSSceneReader.cpp | 2 +- .../cocostudio/ObjectFactory.cpp | 4 +- .../ButtonReader/ButtonReader.cpp | 2 +- .../CheckBoxReader/CheckBoxReader.cpp | 2 +- .../ImageViewReader/ImageViewReader.cpp | 2 +- .../LayoutReader/LayoutReader.cpp | 2 +- .../ListViewReader/ListViewReader.cpp | 2 +- .../LoadingBarReader/LoadingBarReader.cpp | 2 +- .../PageViewReader/PageViewReader.cpp | 2 +- .../ScrollViewReader/ScrollViewReader.cpp | 2 +- .../SliderReader/SliderReader.cpp | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 2 +- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- .../TextFieldReader/TextFieldReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 2 +- .../cocostudio/WidgetReader/WidgetReader.h | 4 +- cocos/ui/Android.mk | 48 + cocos/ui/CMakeLists.txt | 31 + cocos/ui/CocosGUI.cpp | 37 + cocos/ui/CocosGUI.h | 54 + cocos/ui/GUIDefine.h | 79 + cocos/ui/UIButton.cpp | 714 +++++++ cocos/ui/UIButton.h | 226 +++ cocos/ui/UICheckBox.cpp | 540 ++++++ cocos/ui/UICheckBox.h | 211 ++ cocos/ui/UIHelper.cpp | 123 ++ cocos/ui/UIHelper.h | 81 + cocos/ui/UIImageView.cpp | 316 +++ cocos/ui/UIImageView.h | 130 ++ cocos/ui/UILayout.cpp | 1404 ++++++++++++++ cocos/ui/UILayout.h | 358 ++++ cocos/ui/UILayoutDefine.cpp | 64 + cocos/ui/UILayoutDefine.h | 96 + cocos/ui/UILayoutParameter.cpp | 175 ++ cocos/ui/UILayoutParameter.h | 226 +++ cocos/ui/UIListView.cpp | 480 +++++ cocos/ui/UIListView.h | 213 ++ cocos/ui/UILoadingBar.cpp | 370 ++++ cocos/ui/UILoadingBar.h | 161 ++ cocos/ui/UIPageView.cpp | 631 ++++++ cocos/ui/UIPageView.h | 222 +++ cocos/ui/UIRichText.cpp | 442 +++++ cocos/ui/UIRichText.h | 133 ++ cocos/ui/UIScrollInterface.h | 49 + cocos/ui/UIScrollView.cpp | 1719 +++++++++++++++++ cocos/ui/UIScrollView.h | 430 +++++ cocos/ui/UISlider.cpp | 600 ++++++ cocos/ui/UISlider.h | 249 +++ cocos/ui/UIText.cpp | 287 +++ cocos/ui/UIText.h | 167 ++ cocos/ui/UITextAtlas.cpp | 171 ++ cocos/ui/UITextAtlas.h | 103 + cocos/ui/UITextBMFont.cpp | 181 ++ cocos/ui/UITextBMFont.h | 93 + cocos/ui/UITextField.cpp | 772 ++++++++ cocos/ui/UITextField.h | 192 ++ cocos/ui/UIWidget.cpp | 1139 +++++++++++ cocos/ui/UIWidget.h | 723 +++++++ .../ButtonReader/ButtonReader.cpp | 158 ++ .../WidgetReader/ButtonReader/ButtonReader.h | 47 + .../CheckBoxReader/CheckBoxReader.cpp | 153 ++ .../CheckBoxReader/CheckBoxReader.h | 47 + .../ImageViewReader/ImageViewReader.cpp | 98 + .../ImageViewReader/ImageViewReader.h | 47 + .../LayoutReader/LayoutReader.cpp | 119 ++ .../WidgetReader/LayoutReader/LayoutReader.h | 47 + .../ListViewReader/ListViewReader.cpp | 48 + .../ListViewReader/ListViewReader.h | 47 + .../LoadingBarReader/LoadingBarReader.cpp | 91 + .../LoadingBarReader/LoadingBarReader.h | 47 + .../PageViewReader/PageViewReader.cpp | 35 + .../PageViewReader/PageViewReader.h | 47 + .../ScrollViewReader/ScrollViewReader.cpp | 47 + .../ScrollViewReader/ScrollViewReader.h | 47 + .../SliderReader/SliderReader.cpp | 192 ++ .../WidgetReader/SliderReader/SliderReader.h | 47 + .../TextAtlasReader/TextAtlasReader.cpp | 69 + .../TextAtlasReader/TextAtlasReader.h | 46 + .../TextBMFontReader/TextBMFontReader.cpp | 65 + .../TextBMFontReader/TextBMFontReader.h | 47 + .../TextFieldReader/TextFieldReader.cpp | 84 + .../TextFieldReader/TextFieldReader.h | 47 + .../ui/WidgetReader/TextReader/TextReader.cpp | 74 + cocos/ui/WidgetReader/TextReader/TextReader.h | 47 + cocos/ui/WidgetReader/WidgetReader.cpp | 173 ++ cocos/ui/WidgetReader/WidgetReader.h | 51 + cocos/ui/WidgetReader/WidgetReaderProtocol.h | 53 + cocos/ui/proj.win32/libGUI.vcxproj | 135 ++ cocos/ui/proj.win32/libGUI.vcxproj.filters | 141 ++ cocos/ui/proj.win32/libGUI.vcxproj.user | 4 + .../CocoStudioGUITest/CocosGUIScene.h | 2 +- .../CocoStudioGUITest/CustomGUIScene.h | 2 +- .../CustomImageTest/CustomImageTest.cpp | 2 +- .../CustomWidget/CustomImageView.h | 2 +- .../CustomWidget/CustomImageViewReader.h | 2 +- .../CustomWidget/CustomParticleWidget.h | 2 +- .../CustomWidget/CustomParticleWidgetReader.h | 2 +- .../CustomWidget/CustomReader.h | 2 +- .../UIButtonTest/UIButtonTest.cpp | 10 +- .../UIButtonTest/UIButtonTest_Editor.cpp | 2 +- .../UICheckBoxTest/UICheckBoxTest.cpp | 12 +- .../UICheckBoxTest/UICheckBoxTest_Editor.cpp | 2 +- .../UIImageViewTest/UIImageViewTest.cpp | 12 +- .../UIImageViewTest_Editor.cpp | 2 +- .../UILayoutTest/UILayoutTest.cpp | 76 +- .../UILayoutTest/UILayoutTest_Editor.cpp | 18 +- .../UIListViewTest/UIListViewTest.cpp | 18 +- .../UIListViewTest/UIListViewTest_Editor.cpp | 6 +- .../UILoadingBarTest/UILoadingBarTest.cpp | 10 +- .../UILoadingBarTest_Editor.cpp | 4 +- .../UIPageViewTest/UIPageViewTest.cpp | 2 +- .../UIPageViewTest/UIPageViewTest_Editor.cpp | 4 +- .../UIRichTextTest/UIRichTextTest.cpp | 8 +- .../CocoStudioGUITest/UIScene.cpp | 2 +- .../CocoStudioGUITest/UIScene.h | 2 +- .../CocoStudioGUITest/UIScene_Editor.cpp | 2 +- .../CocoStudioGUITest/UIScene_Editor.h | 2 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 22 +- .../UIScrollViewTest_Editor.cpp | 10 +- .../UISliderTest/UISliderTest.cpp | 26 +- .../UISliderTest/UISliderTest_Editor.cpp | 2 +- .../UITextAtlasTest/UITextAtlasTest.cpp | 4 +- .../UITextAtlasTest_Editor.cpp | 2 +- .../UITextBMFontTest/UITextBMFontTest.cpp | 4 +- .../UITextBMFontTest_Editor.cpp | 4 +- .../UITextFieldTest_Editor.cpp | 2 +- .../UITextTest/UITextTest_Editor.cpp | 6 +- .../UIWidgetAddNodeTest.cpp | 4 +- .../UIWidgetAddNodeTest_Editor.cpp | 4 +- .../CocoStudioSceneTest/SceneEditorTest.cpp | 2 +- .../Classes/LabelTest/LabelTestNew.cpp | 12 +- .../Classes/LabelTest/LabelTestNew.h | 2 +- 136 files changed, 17021 insertions(+), 181 deletions(-) create mode 100644 cocos/ui/Android.mk create mode 100644 cocos/ui/CMakeLists.txt create mode 100644 cocos/ui/CocosGUI.cpp create mode 100644 cocos/ui/CocosGUI.h create mode 100644 cocos/ui/GUIDefine.h create mode 100644 cocos/ui/UIButton.cpp create mode 100644 cocos/ui/UIButton.h create mode 100644 cocos/ui/UICheckBox.cpp create mode 100644 cocos/ui/UICheckBox.h create mode 100644 cocos/ui/UIHelper.cpp create mode 100644 cocos/ui/UIHelper.h create mode 100644 cocos/ui/UIImageView.cpp create mode 100644 cocos/ui/UIImageView.h create mode 100644 cocos/ui/UILayout.cpp create mode 100644 cocos/ui/UILayout.h create mode 100644 cocos/ui/UILayoutDefine.cpp create mode 100644 cocos/ui/UILayoutDefine.h create mode 100644 cocos/ui/UILayoutParameter.cpp create mode 100644 cocos/ui/UILayoutParameter.h create mode 100644 cocos/ui/UIListView.cpp create mode 100644 cocos/ui/UIListView.h create mode 100644 cocos/ui/UILoadingBar.cpp create mode 100644 cocos/ui/UILoadingBar.h create mode 100644 cocos/ui/UIPageView.cpp create mode 100644 cocos/ui/UIPageView.h create mode 100644 cocos/ui/UIRichText.cpp create mode 100644 cocos/ui/UIRichText.h create mode 100644 cocos/ui/UIScrollInterface.h create mode 100644 cocos/ui/UIScrollView.cpp create mode 100644 cocos/ui/UIScrollView.h create mode 100644 cocos/ui/UISlider.cpp create mode 100644 cocos/ui/UISlider.h create mode 100644 cocos/ui/UIText.cpp create mode 100644 cocos/ui/UIText.h create mode 100644 cocos/ui/UITextAtlas.cpp create mode 100644 cocos/ui/UITextAtlas.h create mode 100644 cocos/ui/UITextBMFont.cpp create mode 100644 cocos/ui/UITextBMFont.h create mode 100644 cocos/ui/UITextField.cpp create mode 100644 cocos/ui/UITextField.h create mode 100644 cocos/ui/UIWidget.cpp create mode 100644 cocos/ui/UIWidget.h create mode 100644 cocos/ui/WidgetReader/ButtonReader/ButtonReader.cpp create mode 100644 cocos/ui/WidgetReader/ButtonReader/ButtonReader.h create mode 100644 cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp create mode 100644 cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.h create mode 100644 cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.cpp create mode 100644 cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.h create mode 100644 cocos/ui/WidgetReader/LayoutReader/LayoutReader.cpp create mode 100644 cocos/ui/WidgetReader/LayoutReader/LayoutReader.h create mode 100644 cocos/ui/WidgetReader/ListViewReader/ListViewReader.cpp create mode 100644 cocos/ui/WidgetReader/ListViewReader/ListViewReader.h create mode 100644 cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp create mode 100644 cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.h create mode 100644 cocos/ui/WidgetReader/PageViewReader/PageViewReader.cpp create mode 100644 cocos/ui/WidgetReader/PageViewReader/PageViewReader.h create mode 100644 cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp create mode 100644 cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.h create mode 100644 cocos/ui/WidgetReader/SliderReader/SliderReader.cpp create mode 100644 cocos/ui/WidgetReader/SliderReader/SliderReader.h create mode 100644 cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp create mode 100644 cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.h create mode 100644 cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp create mode 100644 cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.h create mode 100644 cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.cpp create mode 100644 cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.h create mode 100644 cocos/ui/WidgetReader/TextReader/TextReader.cpp create mode 100644 cocos/ui/WidgetReader/TextReader/TextReader.h create mode 100644 cocos/ui/WidgetReader/WidgetReader.cpp create mode 100644 cocos/ui/WidgetReader/WidgetReader.h create mode 100644 cocos/ui/WidgetReader/WidgetReaderProtocol.h create mode 100644 cocos/ui/proj.win32/libGUI.vcxproj create mode 100644 cocos/ui/proj.win32/libGUI.vcxproj.filters create mode 100644 cocos/ui/proj.win32/libGUI.vcxproj.user diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 8f1f1fd4dc..85fc17c725 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -b8671f5532fbc91d62fd7acbae8b054fbc9816af \ No newline at end of file +be9729478e98eeb340d839d3cc4c2c2dc9c46b65 \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/CCActionNode.cpp b/cocos/editor-support/cocostudio/CCActionNode.cpp index ff4969566c..d615b11c46 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.cpp +++ b/cocos/editor-support/cocostudio/CCActionNode.cpp @@ -25,8 +25,8 @@ THE SOFTWARE. #include "cocostudio/CCActionNode.h" #include "cocostudio/CCActionFrameEasing.h" #include "cocostudio/DictionaryHelper.h" -#include "gui/UIWidget.h" -#include "gui/UIHelper.h" +#include "ui/UIWidget.h" +#include "ui/UIHelper.h" using namespace cocos2d; using namespace ui; diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 1787772d07..740598b2dc 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #include "cocostudio/CCSGUIReader.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" #include "cocostudio/CCActionManagerEx.h" #include #include diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.h b/cocos/editor-support/cocostudio/CCSGUIReader.h index 50e569049a..737126f85b 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.h +++ b/cocos/editor-support/cocostudio/CCSGUIReader.h @@ -25,7 +25,7 @@ THE SOFTWARE. #ifndef __CCSGUIREADER_H__ #define __CCSGUIREADER_H__ -#include "gui/UIWidget.h" +#include "ui/UIWidget.h" #include "cocostudio/DictionaryHelper.h" #include "WidgetReader/WidgetReaderProtocol.h" #include "ObjectFactory.h" diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index aa7f514101..9d92d25e5d 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "cocostudio/CocoStudio.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" #include "SimpleAudioEngine.h" #include "ObjectFactory.h" diff --git a/cocos/editor-support/cocostudio/ObjectFactory.cpp b/cocos/editor-support/cocostudio/ObjectFactory.cpp index 9f5978c0d3..87b724b984 100644 --- a/cocos/editor-support/cocostudio/ObjectFactory.cpp +++ b/cocos/editor-support/cocostudio/ObjectFactory.cpp @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "ObjectFactory.h" -#include "gui/UIWidget.h" +#include "ui/UIWidget.h" #include "cocostudio/WidgetReader/WidgetReaderProtocol.h" using namespace cocos2d; @@ -199,4 +199,4 @@ void ObjectFactory::registerType(const TInfo &t) _typeMap.insert(std::make_pair(t._class, t)); } -} \ No newline at end of file +} diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index bf3edc9dc5..96f7f96ebe 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -1,7 +1,7 @@ #include "ButtonReader.h" -#include "gui/UIButton.h" +#include "ui/UIButton.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 3b34767867..8bd0898f8b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -1,7 +1,7 @@ #include "CheckBoxReader.h" -#include "gui/UICheckBox.h" +#include "ui/UICheckBox.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 0ccd858240..ea2755c8fc 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -1,7 +1,7 @@ #include "ImageViewReader.h" -#include "gui/UIImageView.h" +#include "ui/UIImageView.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index b8c86cbf38..3bb361d7e0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -1,7 +1,7 @@ #include "LayoutReader.h" -#include "gui/UILayout.h" +#include "ui/UILayout.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index bbbdb9b14a..42444720dd 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -1,7 +1,7 @@ #include "ListViewReader.h" -#include "gui/UIListView.h" +#include "ui/UIListView.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index 97720ed9b2..db62cc4cac 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -1,7 +1,7 @@ #include "LoadingBarReader.h" -#include "gui/UILoadingBar.h" +#include "ui/UILoadingBar.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp index 30ae81de31..a5111906be 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -1,7 +1,7 @@ #include "PageViewReader.h" -#include "gui/UIPageView.h" +#include "ui/UIPageView.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index 8df1963597..436eb8b981 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -1,7 +1,7 @@ #include "ScrollViewReader.h" -#include "gui/UIScrollView.h" +#include "ui/UIScrollView.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index 616dad40d3..6d3793a226 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -1,7 +1,7 @@ #include "SliderReader.h" -#include "gui/UISlider.h" +#include "ui/UISlider.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index 731b8c1a48..c7ef7ebcd2 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -1,7 +1,7 @@ #include "TextAtlasReader.h" -#include "gui/UITextAtlas.h" +#include "ui/UITextAtlas.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index c95d0cd778..cd5ca3d85b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -1,7 +1,7 @@ #include "TextBMFontReader.h" -#include "gui/UITextBMFont.h" +#include "ui/UITextBMFont.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 483b13d35d..634c34c1c8 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -1,7 +1,7 @@ #include "TextFieldReader.h" -#include "gui/UITextField.h" +#include "ui/UITextField.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index d9406425c1..76db3ff6f1 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -1,7 +1,7 @@ #include "TextReader.h" -#include "gui/UIText.h" +#include "ui/UIText.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h index 346739b3fc..fbd2c28411 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h @@ -27,8 +27,8 @@ #include "WidgetReaderProtocol.h" #include "../CCSGUIReader.h" -#include "gui/GUIDefine.h" -#include "gui/UIWidget.h" +#include "ui/GUIDefine.h" +#include "ui/UIWidget.h" namespace cocostudio { diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk new file mode 100644 index 0000000000..ba8a3dcf17 --- /dev/null +++ b/cocos/ui/Android.mk @@ -0,0 +1,48 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE := cocos_gui_static + +LOCAL_MODULE_FILENAME := libgui + +LOCAL_SRC_FILES := \ +UIWidget.cpp \ +UILayout.cpp \ +UILayoutParameter.cpp \ +UILayoutDefine.cpp \ +CocosGUI.cpp \ +UIHelper.cpp \ +UIListView.cpp \ +UIPageView.cpp \ +UIScrollView.cpp \ +UIButton.cpp \ +UICheckBox.cpp \ +UIImageView.cpp \ +UIText.cpp \ +UITextAtlas.cpp \ +UITextBMFont.cpp \ +UILoadingBar.cpp \ +UISlider.cpp \ +UITextField.cpp \ +UIRichText.cpp + + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \ +$(LOCAL_PATH)/../editor-support + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../2d \ +$(LOCAL_PATH)/../../external \ +$(LOCAL_PATH)/.. \ +$(LOCAL_PATH)/../.. \ +$(LOCAL_PATH)/../editor-support + +LOCAL_CFLAGS += -Wno-psabi +LOCAL_EXPORT_CFLAGS += -Wno-psabi + +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static +LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static + +include $(BUILD_STATIC_LIBRARY) + +$(call import-module,extensions) +$(call import-module,2d) diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt new file mode 100644 index 0000000000..4b78830596 --- /dev/null +++ b/cocos/ui/CMakeLists.txt @@ -0,0 +1,31 @@ +set(GUI_SRC + UIWidget.cpp + UILayout.cpp + UILayoutParameter.cpp + UILayoutDefine.cpp + CocosGUI.cpp + UIHelper.cpp + UIListView.cpp + UIPageView.cpp + UIScrollView.cpp + UIButton.cpp + UICheckBox.cpp + UIImageView.cpp + UIText.cpp + UITextAtlas.cpp + UITextBMFont.cpp + UILoadingBar.cpp + UISlider.cpp + UITextField.cpp + UIRichText.cpp +) + +add_library(gui STATIC + ${GUI_SRC} +) + +set_target_properties(gui + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" +) diff --git a/cocos/ui/CocosGUI.cpp b/cocos/ui/CocosGUI.cpp new file mode 100644 index 0000000000..efcd0e017e --- /dev/null +++ b/cocos/ui/CocosGUI.cpp @@ -0,0 +1,37 @@ +/**************************************************************************** +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/CocosGUI.h" + +NS_CC_BEGIN + +namespace ui { + +const char* CocosGUIVersion() +{ + return "CocosGUI v1.0.0.0"; +} + +} +NS_CC_END diff --git a/cocos/ui/CocosGUI.h b/cocos/ui/CocosGUI.h new file mode 100644 index 0000000000..a4e6ac7ce8 --- /dev/null +++ b/cocos/ui/CocosGUI.h @@ -0,0 +1,54 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __COCOSGUI_H__ +#define __COCOSGUI_H__ + + +#include "ui/UIWidget.h" +#include "ui/UILayout.h" +#include "ui/UIButton.h" +#include "ui/UICheckBox.h" +#include "ui/UIImageView.h" +#include "ui/UIText.h" +#include "ui/UITextAtlas.h" +#include "ui/UILoadingBar.h" +#include "ui/UIScrollView.h" +#include "ui/UIListView.h" +#include "ui/UISlider.h" +#include "ui/UITextField.h" +#include "ui/UITextBMFont.h" +#include "ui/UIPageView.h" +#include "ui/UIHelper.h" +#include "ui/UIRichText.h" + +NS_CC_BEGIN +namespace ui { + +const char* CocosGUIVersion(); + +} +NS_CC_END + +#endif /* defined(__CocosGUITest__Cocos__) */ diff --git a/cocos/ui/GUIDefine.h b/cocos/ui/GUIDefine.h new file mode 100644 index 0000000000..8cd44b664a --- /dev/null +++ b/cocos/ui/GUIDefine.h @@ -0,0 +1,79 @@ +/**************************************************************************** + Copyright (c) 2014 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__GUIDefine__ +#define __TestCpp__GUIDefine__ + +#include "cocos2d.h" +#include "../../extensions/ExtensionMacros.h" +#include +#include "cocostudio/ObjectFactory.h" + +#pragma mark - +#pragma mark Widget macro +#pragma mark - + +#define DECLARE_CLASS_GUI_INFO \ + public: \ + static cocostudio::ObjectFactory::TInfo Type; \ + static cocos2d::Ref* createInstance(void); \ + +#define IMPLEMENT_CLASS_GUI_INFO(className) \ + cocos2d::Ref* className::createInstance(void) \ + { \ + return className::create(); \ + } \ + cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \ + +#define CREATE_CLASS_GUI_INFO(className) \ + cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \ + + +#pragma mark - +#pragma mark Reader macro +#pragma mark - + +#define DECLARE_CLASS_WIDGET_READER_INFO \ + public: \ + static cocostudio::ObjectFactory::TInfo Type; \ + static cocos2d::Ref* createInstance(void); \ + +#define IMPLEMENT_CLASS_WIDGET_READER_INFO(className) \ + cocos2d::Ref* className::createInstance(void) \ + { \ + return className::getInstance(); \ + } \ + cocostudio::ObjectFactory::TInfo className::Type(#className, &className::createInstance); \ + +#define CREATE_CLASS_WIDGET_READER_INFO(className) \ + cocostudio::ObjectFactory::TInfo(#className, &className::createInstance) \ + + + + + +//#define CUSTOM_GUI_PARSE_FUNCTION(className, functionName) \ +// className::functionName \ + +#endif /* defined(__TestCpp__GUIDefine__) */ diff --git a/cocos/ui/UIButton.cpp b/cocos/ui/UIButton.cpp new file mode 100644 index 0000000000..941bdf0b46 --- /dev/null +++ b/cocos/ui/UIButton.cpp @@ -0,0 +1,714 @@ +/**************************************************************************** +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/UIButton.h" +#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" + +NS_CC_BEGIN + +namespace ui { + +static const int NORMAL_RENDERER_Z = (-2); +static const int PRESSED_RENDERER_Z = (-2); +static const int DISABLED_RENDERER_Z = (-2); +static const int TITLE_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(Button) + +Button::Button(): +_buttonNormalRenderer(nullptr), +_buttonClickedRenderer(nullptr), +_buttonDisableRenderer(nullptr), +_titleRenderer(nullptr), +_normalFileName(""), +_clickedFileName(""), +_disabledFileName(""), +_prevIgnoreSize(true), +_scale9Enabled(false), +_capInsetsNormal(Rect::ZERO), +_capInsetsPressed(Rect::ZERO), +_capInsetsDisabled(Rect::ZERO), +_normalTexType(UI_TEX_TYPE_LOCAL), +_pressedTexType(UI_TEX_TYPE_LOCAL), +_disabledTexType(UI_TEX_TYPE_LOCAL), +_normalTextureSize(_size), +_pressedTextureSize(_size), +_disabledTextureSize(_size), +_pressedActionEnabled(false), +_titleColor(Color3B::WHITE), +_normalTextureScaleXInSize(1.0f), +_normalTextureScaleYInSize(1.0f), +_pressedTextureScaleXInSize(1.0f), +_pressedTextureScaleYInSize(1.0f), +_normalTextureLoaded(false), +_pressedTextureLoaded(false), +_disabledTextureLoaded(false) +{ + +} + +Button::~Button() +{ +} + +Button* Button::create() +{ + Button* widget = new Button(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +bool Button::init() +{ + if (Widget::init()) + { + setTouchEnabled(true); + return true; + } + return false; +} + +void Button::initRenderer() +{ + _buttonNormalRenderer = Sprite::create(); + _buttonClickedRenderer = Sprite::create(); + _buttonDisableRenderer = Sprite::create(); + _titleRenderer = LabelTTF::create(); + + Node::addChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1); + Node::addChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1); + Node::addChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1); + Node::addChild(_titleRenderer, TITLE_RENDERER_Z, -1); +} + +void Button::setScale9Enabled(bool able) +{ + if (_scale9Enabled == able) + { + return; + } + _brightStyle = BRIGHT_NONE; + _scale9Enabled = able; + Node::removeChild(_buttonNormalRenderer); + Node::removeChild(_buttonClickedRenderer); + Node::removeChild(_buttonDisableRenderer); + _buttonNormalRenderer = nullptr; + _buttonClickedRenderer = nullptr; + _buttonDisableRenderer = nullptr; + if (_scale9Enabled) + { + _buttonNormalRenderer = extension::Scale9Sprite::create(); + _buttonClickedRenderer = extension::Scale9Sprite::create(); + _buttonDisableRenderer = extension::Scale9Sprite::create(); + } + else + { + _buttonNormalRenderer = Sprite::create(); + _buttonClickedRenderer = Sprite::create(); + _buttonDisableRenderer = Sprite::create(); + } + + loadTextureNormal(_normalFileName.c_str(), _normalTexType); + loadTexturePressed(_clickedFileName.c_str(), _pressedTexType); + loadTextureDisabled(_disabledFileName.c_str(), _disabledTexType); + Node::addChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1); + Node::addChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1); + Node::addChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1); + if (_scale9Enabled) + { + bool ignoreBefore = _ignoreSize; + ignoreContentAdaptWithSize(false); + _prevIgnoreSize = ignoreBefore; + } + else + { + ignoreContentAdaptWithSize(_prevIgnoreSize); + } + setCapInsetsNormalRenderer(_capInsetsNormal); + setCapInsetsPressedRenderer(_capInsetsPressed); + setCapInsetsDisabledRenderer(_capInsetsDisabled); + setBright(_bright); +} + +bool Button::isScale9Enabled() +{ + return _scale9Enabled; +} + +void Button::ignoreContentAdaptWithSize(bool ignore) +{ + if (!_scale9Enabled || (_scale9Enabled && !ignore)) + { + Widget::ignoreContentAdaptWithSize(ignore); + _prevIgnoreSize = ignore; + } +} + +void Button::loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType) +{ + loadTextureNormal(normal,texType); + loadTexturePressed(selected,texType); + loadTextureDisabled(disabled,texType); +} + +void Button::loadTextureNormal(const char* normal,TextureResType texType) +{ + if (!normal || strcmp(normal, "") == 0) + { + return; + } + _normalFileName = normal; + _normalTexType = texType; + if (_scale9Enabled) + { + extension::Scale9Sprite* normalRendererScale9 = static_cast(_buttonNormalRenderer); + switch (_normalTexType) + { + case UI_TEX_TYPE_LOCAL: + normalRendererScale9->initWithFile(normal); + break; + case UI_TEX_TYPE_PLIST: + normalRendererScale9->initWithSpriteFrameName(normal); + break; + default: + break; + } + normalRendererScale9->setCapInsets(_capInsetsNormal); + } + else + { + Sprite* normalRenderer = static_cast(_buttonNormalRenderer); + switch (_normalTexType) + { + case UI_TEX_TYPE_LOCAL: + normalRenderer->setTexture(normal); + break; + case UI_TEX_TYPE_PLIST: + normalRenderer->setSpriteFrame(normal); + break; + default: + break; + } + } + _normalTextureSize = _buttonNormalRenderer->getContentSize(); + normalTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_buttonNormalRenderer); + _normalTextureLoaded = true; +} + +void Button::loadTexturePressed(const char* selected,TextureResType texType) +{ + if (!selected || strcmp(selected, "") == 0) + { + return; + } + _clickedFileName = selected; + _pressedTexType = texType; + if (_scale9Enabled) + { + extension::Scale9Sprite* clickedRendererScale9 = static_cast(_buttonClickedRenderer); + switch (_pressedTexType) + { + case UI_TEX_TYPE_LOCAL: + clickedRendererScale9->initWithFile(selected); + break; + case UI_TEX_TYPE_PLIST: + clickedRendererScale9->initWithSpriteFrameName(selected); + break; + default: + break; + } + clickedRendererScale9->setCapInsets(_capInsetsPressed); + } + else + { + Sprite* clickedRenderer = static_cast(_buttonClickedRenderer); + switch (_pressedTexType) + { + case UI_TEX_TYPE_LOCAL: + clickedRenderer->setTexture(selected); + break; + case UI_TEX_TYPE_PLIST: + clickedRenderer->setSpriteFrame(selected); + break; + default: + break; + } + } + _pressedTextureSize = _buttonClickedRenderer->getContentSize(); + pressedTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_buttonDisableRenderer); + _pressedTextureLoaded = true; +} + +void Button::loadTextureDisabled(const char* disabled,TextureResType texType) +{ + if (!disabled || strcmp(disabled, "") == 0) + { + return; + } + _disabledFileName = disabled; + _disabledTexType = texType; + if (_scale9Enabled) + { + extension::Scale9Sprite* disabledScale9 = static_cast(_buttonDisableRenderer); + switch (_disabledTexType) + { + case UI_TEX_TYPE_LOCAL: + disabledScale9->initWithFile(disabled); + break; + case UI_TEX_TYPE_PLIST: + disabledScale9->initWithSpriteFrameName(disabled); + break; + default: + break; + } + disabledScale9->setCapInsets(_capInsetsDisabled); + } + else + { + Sprite* disabledRenderer = static_cast(_buttonDisableRenderer); + switch (_disabledTexType) + { + case UI_TEX_TYPE_LOCAL: + disabledRenderer->setTexture(disabled); + break; + case UI_TEX_TYPE_PLIST: + disabledRenderer->setSpriteFrame(disabled); + break; + default: + break; + } + } + _disabledTextureSize = _buttonDisableRenderer->getContentSize(); + disabledTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_buttonDisableRenderer); + _disabledTextureLoaded = true; +} + +void Button::setCapInsets(const Rect &capInsets) +{ + setCapInsetsNormalRenderer(capInsets); + setCapInsetsPressedRenderer(capInsets); + setCapInsetsDisabledRenderer(capInsets); +} + +void Button::setCapInsetsNormalRenderer(const Rect &capInsets) +{ + _capInsetsNormal = capInsets; + if (!_scale9Enabled) + { + return; + } + static_cast(_buttonNormalRenderer)->setCapInsets(capInsets); +} + +const Rect& Button::getCapInsetsNormalRenderer() +{ + return _capInsetsNormal; +} + +void Button::setCapInsetsPressedRenderer(const Rect &capInsets) +{ + _capInsetsPressed = capInsets; + if (!_scale9Enabled) + { + return; + } + static_cast(_buttonClickedRenderer)->setCapInsets(capInsets); +} + +const Rect& Button::getCapInsetsPressedRenderer() +{ + return _capInsetsPressed; +} + +void Button::setCapInsetsDisabledRenderer(const Rect &capInsets) +{ + _capInsetsDisabled = capInsets; + if (!_scale9Enabled) + { + return; + } + static_cast(_buttonDisableRenderer)->setCapInsets(capInsets); +} + +const Rect& Button::getCapInsetsDisabledRenderer() +{ + return _capInsetsDisabled; +} + +void Button::onPressStateChangedToNormal() +{ + _buttonNormalRenderer->setVisible(true); + _buttonClickedRenderer->setVisible(false); + _buttonDisableRenderer->setVisible(false); + if (_pressedTextureLoaded) + { + if (_pressedActionEnabled) + { + _buttonNormalRenderer->stopAllActions(); + _buttonClickedRenderer->stopAllActions(); + Action *zoomAction = ScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize); + _buttonNormalRenderer->runAction(zoomAction); + _buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize); + } + } + else + { + _buttonNormalRenderer->stopAllActions(); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); + } +} + +void Button::onPressStateChangedToPressed() +{ + if (_pressedTextureLoaded) + { + _buttonNormalRenderer->setVisible(false); + _buttonClickedRenderer->setVisible(true); + _buttonDisableRenderer->setVisible(false); + if (_pressedActionEnabled) + { + _buttonNormalRenderer->stopAllActions(); + _buttonClickedRenderer->stopAllActions(); + Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); + _buttonClickedRenderer->runAction(zoomAction); + _buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + 0.1f, _pressedTextureScaleYInSize + 0.1f); + } + } + else + { + _buttonNormalRenderer->setVisible(true); + _buttonClickedRenderer->setVisible(true); + _buttonDisableRenderer->setVisible(false); + _buttonNormalRenderer->stopAllActions(); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize + 0.1f, _normalTextureScaleYInSize + 0.1f); + } +} + +void Button::onPressStateChangedToDisabled() +{ + _buttonNormalRenderer->setVisible(false); + _buttonClickedRenderer->setVisible(false); + _buttonDisableRenderer->setVisible(true); + _buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize); + _buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize); +} + +void Button::updateFlippedX() +{ + _titleRenderer->setFlippedX(_flippedX); + if (_scale9Enabled) + { + int flip = _flippedX ? -1 : 1; + _buttonNormalRenderer->setScaleX(flip); + _buttonClickedRenderer->setScaleX(flip); + _buttonDisableRenderer->setScaleX(flip); + } + else + { + static_cast(_buttonNormalRenderer)->setFlippedX(_flippedX); + static_cast(_buttonClickedRenderer)->setFlippedX(_flippedX); + static_cast(_buttonDisableRenderer)->setFlippedX(_flippedX); + } +} + +void Button::updateFlippedY() +{ + _titleRenderer->setFlippedY(_flippedY); + if (_scale9Enabled) + { + int flip = _flippedY ? -1 : 1; + _buttonNormalRenderer->setScaleY(flip); + _buttonClickedRenderer->setScaleY(flip); + _buttonDisableRenderer->setScaleY(flip); + } + else + { + static_cast(_buttonNormalRenderer)->setFlippedY(_flippedY); + static_cast(_buttonClickedRenderer)->setFlippedY(_flippedY); + static_cast(_buttonDisableRenderer)->setFlippedY(_flippedY); + } +} + +void Button::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _buttonNormalRenderer->setAnchorPoint(pt); + _buttonClickedRenderer->setAnchorPoint(pt); + _buttonDisableRenderer->setAnchorPoint(pt); + _titleRenderer->setPosition(Point(_size.width*(0.5f-_anchorPoint.x), _size.height*(0.5f-_anchorPoint.y))); +} + +void Button::onSizeChanged() +{ + Widget::onSizeChanged(); + normalTextureScaleChangedWithSize(); + pressedTextureScaleChangedWithSize(); + disabledTextureScaleChangedWithSize(); +} + +const Size& Button::getContentSize() const +{ + return _normalTextureSize; +} + +Node* Button::getVirtualRenderer() +{ + if (_bright) + { + switch (_brightStyle) + { + case BRIGHT_NORMAL: + return _buttonNormalRenderer; + case BRIGHT_HIGHLIGHT: + return _buttonClickedRenderer; + default: + return nullptr; + } + } + else + { + return _buttonDisableRenderer; + } +} + +void Button::normalTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + if (!_scale9Enabled) + { + _buttonNormalRenderer->setScale(1.0f); + _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; + _size = _normalTextureSize; + } + } + else + { + if (_scale9Enabled) + { + static_cast(_buttonNormalRenderer)->setPreferredSize(_size); + _normalTextureScaleXInSize = _normalTextureScaleYInSize = 1.0f; + } + else + { + Size textureSize = _normalTextureSize; + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _buttonNormalRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _buttonNormalRenderer->setScaleX(scaleX); + _buttonNormalRenderer->setScaleY(scaleY); + _normalTextureScaleXInSize = scaleX; + _normalTextureScaleYInSize = scaleY; + } + } +} + +void Button::pressedTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + if (!_scale9Enabled) + { + _buttonClickedRenderer->setScale(1.0f); + _pressedTextureScaleXInSize = _pressedTextureScaleYInSize = 1.0f; + } + } + else + { + if (_scale9Enabled) + { + static_cast(_buttonClickedRenderer)->setPreferredSize(_size); + _pressedTextureScaleXInSize = _pressedTextureScaleYInSize = 1.0f; + } + else + { + Size textureSize = _pressedTextureSize; + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _buttonClickedRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / _pressedTextureSize.width; + float scaleY = _size.height / _pressedTextureSize.height; + _buttonClickedRenderer->setScaleX(scaleX); + _buttonClickedRenderer->setScaleY(scaleY); + _pressedTextureScaleXInSize = scaleX; + _pressedTextureScaleYInSize = scaleY; + } + } +} + +void Button::disabledTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + if (!_scale9Enabled) + { + _buttonDisableRenderer->setScale(1.0f); + } + } + else + { + if (_scale9Enabled) + { + static_cast(_buttonDisableRenderer)->setPreferredSize(_size); + } + else + { + Size textureSize = _disabledTextureSize; + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _buttonDisableRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / _disabledTextureSize.width; + float scaleY = _size.height / _disabledTextureSize.height; + _buttonDisableRenderer->setScaleX(scaleX); + _buttonDisableRenderer->setScaleY(scaleY); + } + } +} + +void Button::setPressedActionEnabled(bool enabled) +{ + _pressedActionEnabled = enabled; +} + +void Button::setTitleText(const std::string& text) +{ + _titleRenderer->setString(text); +} + +const std::string& Button::getTitleText() const +{ + return _titleRenderer->getString(); +} + +void Button::setTitleColor(const Color3B& color) +{ + _titleColor = color; + _titleRenderer->updateDisplayedColor(color); +} + +const Color3B& Button::getTitleColor() const +{ + return _titleRenderer->getColor(); +} + +void Button::setTitleFontSize(float size) +{ + _titleRenderer->setFontSize(size); +} + +float Button::getTitleFontSize() const +{ + return _titleRenderer->getFontSize(); +} + +void Button::setTitleFontName(const char* fontName) +{ + _titleRenderer->setFontName(fontName); +} + +const char* Button::getTitleFontName() const +{ + return _titleRenderer->getFontName().c_str(); +} + +std::string Button::getDescription() const +{ + return "Button"; +} + +void Button::updateTextureColor() +{ + updateColorToRenderer(_buttonNormalRenderer); + updateColorToRenderer(_buttonClickedRenderer); + updateColorToRenderer(_buttonDisableRenderer); +} + +void Button::updateTextureOpacity() +{ + updateOpacityToRenderer(_buttonNormalRenderer); + updateOpacityToRenderer(_buttonClickedRenderer); + updateOpacityToRenderer(_buttonDisableRenderer); +} + +void Button::updateTextureRGBA() +{ + updateRGBAToRenderer(_buttonNormalRenderer); + updateRGBAToRenderer(_buttonClickedRenderer); + updateRGBAToRenderer(_buttonDisableRenderer); +} + +Widget* Button::createCloneInstance() +{ + return Button::create(); +} + +void Button::copySpecialProperties(Widget *widget) +{ + Button* button = dynamic_cast(widget); + if (button) + { + _prevIgnoreSize = button->_prevIgnoreSize; + setScale9Enabled(button->_scale9Enabled); + loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType); + loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType); + loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType); + setCapInsetsNormalRenderer(button->_capInsetsNormal); + setCapInsetsPressedRenderer(button->_capInsetsPressed); + setCapInsetsDisabledRenderer(button->_capInsetsDisabled); + setTitleText(button->getTitleText()); + setTitleFontName(button->getTitleFontName()); + setTitleFontSize(button->getTitleFontSize()); + setTitleColor(button->getTitleColor()); + setPressedActionEnabled(button->_pressedActionEnabled); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h new file mode 100644 index 0000000000..7e4dc758e1 --- /dev/null +++ b/cocos/ui/UIButton.h @@ -0,0 +1,226 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UIBUTTON_H__ +#define __UIBUTTON_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui{ + +/** +* @js NA +* @lua NA +*/ +class Button : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + Button(); + + /** + * Default destructor + */ + virtual ~Button(); + + /** + * Allocates and initializes. + */ + static Button* create(); + + /** + * Load textures for button. + * + * @param normal normal state texture. + * + * @param selected selected state texture. + * + * @param disabled dark state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load normal state texture for button. + * + * @param normal normal state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureNormal(const char* normal, TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load selected state texture for button. + * + * @param selected selected state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTexturePressed(const char* selected, TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load dark state texture for button. + * + * @param disabled dark state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureDisabled(const char* disabled, TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Sets capinsets for button, if button is using scale9 renderer. + * + * @param capInsets capinsets for button + */ + void setCapInsets(const Rect &capInsets); + + /** + * Sets capinsets for button, if button is using scale9 renderer. + * + * @param capInsets capinsets for button + */ + void setCapInsetsNormalRenderer(const Rect &capInsets); + + const Rect& getCapInsetsNormalRenderer(); + + /** + * Sets capinsets for button, if button is using scale9 renderer. + * + * @param capInsets capinsets for button + */ + void setCapInsetsPressedRenderer(const Rect &capInsets); + + const Rect& getCapInsetsPressedRenderer(); + + /** + * Sets capinsets for button, if button is using scale9 renderer. + * + * @param capInsets capinsets for button + */ + void setCapInsetsDisabledRenderer(const Rect &capInsets); + + const Rect& getCapInsetsDisabledRenderer(); + + //override "setAnchorPoint" of widget. + virtual void setAnchorPoint(const Point &pt) override; + + /** + * Sets if button is using scale9 renderer. + * + * @param true that using scale9 renderer, false otherwise. + */ + virtual void setScale9Enabled(bool able); + + bool isScale9Enabled(); + + /** + * Changes if button can be clicked zoom effect. + * + * @param true that can be clicked zoom effect, false otherwise. + */ + void setPressedActionEnabled(bool enabled); + + //override "ignoreContentAdaptWithSize" method of widget. + virtual void ignoreContentAdaptWithSize(bool ignore) override; + + //override "getContentSize" method of widget. + virtual const Size& getContentSize() const override; + + //override "getVirtualRenderer" method of widget. + virtual Node* getVirtualRenderer() override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + void setTitleText(const std::string& text); + const std::string& getTitleText() const; + void setTitleColor(const Color3B& color); + const Color3B& getTitleColor() const; + void setTitleFontSize(float size); + float getTitleFontSize() const; + void setTitleFontName(const char* fontName); + const char* getTitleFontName() const; + +protected: + virtual bool init() override; + virtual void initRenderer() override; + virtual void onPressStateChangedToNormal() override; + virtual void onPressStateChangedToPressed() override; + virtual void onPressStateChangedToDisabled() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + virtual void updateFlippedX() override; + virtual void updateFlippedY() override; + void normalTextureScaleChangedWithSize(); + void pressedTextureScaleChangedWithSize(); + void disabledTextureScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + Node* _buttonNormalRenderer; + Node* _buttonClickedRenderer; + Node* _buttonDisableRenderer; + LabelTTF* _titleRenderer; + std::string _normalFileName; + std::string _clickedFileName; + std::string _disabledFileName; + bool _prevIgnoreSize; + bool _scale9Enabled; + Rect _capInsetsNormal; + Rect _capInsetsPressed; + Rect _capInsetsDisabled; + TextureResType _normalTexType; + TextureResType _pressedTexType; + TextureResType _disabledTexType; + Size _normalTextureSize; + Size _pressedTextureSize; + Size _disabledTextureSize; + bool _pressedActionEnabled; + Color3B _titleColor; + float _normalTextureScaleXInSize; + float _normalTextureScaleYInSize; + float _pressedTextureScaleXInSize; + float _pressedTextureScaleYInSize; + bool _normalTextureLoaded; + bool _pressedTextureLoaded; + bool _disabledTextureLoaded; +}; + +} + +NS_CC_END + +#endif /* defined(__CocoGUI__Button__) */ diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp new file mode 100644 index 0000000000..86cf8ed815 --- /dev/null +++ b/cocos/ui/UICheckBox.cpp @@ -0,0 +1,540 @@ +/**************************************************************************** +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/UICheckBox.h" + +NS_CC_BEGIN + +namespace ui { + +static const int BACKGROUNDBOX_RENDERER_Z = (-1); +static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1); +static const int FRONTCROSS_RENDERER_Z = (-1); +static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1); +static const int FRONTCROSSDISABLED_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(CheckBox) + +CheckBox::CheckBox(): +_backGroundBoxRenderer(nullptr), +_backGroundSelectedBoxRenderer(nullptr), +_frontCrossRenderer(nullptr), +_backGroundBoxDisabledRenderer(nullptr), +_frontCrossDisabledRenderer(nullptr), +_isSelected(true), +_checkBoxEventListener(nullptr), +_checkBoxEventSelector(nullptr), +_backGroundTexType(UI_TEX_TYPE_LOCAL), +_backGroundSelectedTexType(UI_TEX_TYPE_LOCAL), +_frontCrossTexType(UI_TEX_TYPE_LOCAL), +_backGroundDisabledTexType(UI_TEX_TYPE_LOCAL), +_frontCrossDisabledTexType(UI_TEX_TYPE_LOCAL), +_backGroundFileName(""), +_backGroundSelectedFileName(""), +_frontCrossFileName(""), +_backGroundDisabledFileName(""), +_frontCrossDisabledFileName("") +{ +} + +CheckBox::~CheckBox() +{ + _checkBoxEventListener = nullptr; + _checkBoxEventSelector = nullptr; +} + +CheckBox* CheckBox::create() +{ + CheckBox* widget = new CheckBox(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +bool CheckBox::init() +{ + if (Widget::init()) + { + setSelectedState(false); + setTouchEnabled(true); + return true; + } + return false; +} + +void CheckBox::initRenderer() +{ + _backGroundBoxRenderer = Sprite::create(); + _backGroundSelectedBoxRenderer = Sprite::create(); + _frontCrossRenderer = Sprite::create(); + _backGroundBoxDisabledRenderer = Sprite::create(); + _frontCrossDisabledRenderer = Sprite::create(); + + Node::addChild(_backGroundBoxRenderer, BACKGROUNDBOX_RENDERER_Z, -1); + Node::addChild(_backGroundSelectedBoxRenderer, BACKGROUNDSELECTEDBOX_RENDERER_Z, -1); + Node::addChild(_frontCrossRenderer, FRONTCROSS_RENDERER_Z, -1); + Node::addChild(_backGroundBoxDisabledRenderer, BACKGROUNDBOXDISABLED_RENDERER_Z, -1); + Node::addChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1); +} + +void CheckBox::loadTextures(const char *backGround, const char *backGroundSelected, const char *cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType) +{ + loadTextureBackGround(backGround,texType); + loadTextureBackGroundSelected(backGroundSelected,texType); + loadTextureFrontCross(cross,texType); + loadTextureBackGroundDisabled(backGroundDisabled,texType); + loadTextureFrontCrossDisabled(frontCrossDisabled,texType); +} + +void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texType) +{ + if (!backGround || strcmp(backGround, "") == 0) + { + return; + } + _backGroundFileName = backGround; + _backGroundTexType = texType; + switch (_backGroundTexType) + { + case UI_TEX_TYPE_LOCAL: + _backGroundBoxRenderer->setTexture(backGround); + break; + case UI_TEX_TYPE_PLIST: + _backGroundBoxRenderer->setSpriteFrame(backGround); + break; + default: + break; + } + backGroundTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_backGroundBoxRenderer); +} + +void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,TextureResType texType) +{ + if (!backGroundSelected || strcmp(backGroundSelected, "") == 0) + { + return; + } + _backGroundSelectedFileName = backGroundSelected; + _backGroundSelectedTexType = texType; + switch (_backGroundSelectedTexType) + { + case UI_TEX_TYPE_LOCAL: + _backGroundSelectedBoxRenderer->setTexture(backGroundSelected); + break; + case UI_TEX_TYPE_PLIST: + _backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected); + break; + default: + break; + } + backGroundSelectedTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_backGroundSelectedBoxRenderer); +} + +void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType) +{ + if (!cross || strcmp(cross, "") == 0) + { + return; + } + _frontCrossFileName = cross; + _frontCrossTexType = texType; + switch (_frontCrossTexType) + { + case UI_TEX_TYPE_LOCAL: + _frontCrossRenderer->setTexture(cross); + break; + case UI_TEX_TYPE_PLIST: + _frontCrossRenderer->setSpriteFrame(cross); + break; + default: + break; + } + frontCrossTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_frontCrossRenderer); +} + +void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,TextureResType texType) +{ + if (!backGroundDisabled || strcmp(backGroundDisabled, "") == 0) + { + return; + } + _backGroundDisabledFileName = backGroundDisabled; + _backGroundDisabledTexType = texType; + switch (_backGroundDisabledTexType) + { + case UI_TEX_TYPE_LOCAL: + _backGroundBoxDisabledRenderer->setTexture(backGroundDisabled); + break; + case UI_TEX_TYPE_PLIST: + _backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled); + break; + default: + break; + } + backGroundDisabledTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_backGroundBoxDisabledRenderer); +} + +void CheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,TextureResType texType) +{ + if (!frontCrossDisabled || strcmp(frontCrossDisabled, "") == 0) + { + return; + } + _frontCrossDisabledFileName = frontCrossDisabled; + _frontCrossDisabledTexType = texType; + switch (_frontCrossDisabledTexType) + { + case UI_TEX_TYPE_LOCAL: + _frontCrossDisabledRenderer->setTexture(frontCrossDisabled); + break; + case UI_TEX_TYPE_PLIST: + _frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled); + break; + default: + break; + } + frontCrossDisabledTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_frontCrossDisabledRenderer); +} + +void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent) +{ + _touchEndPos = touch->getLocation(); + if (_focus) + { + releaseUpEvent(); + if (_isSelected){ + setSelectedState(false); + unSelectedEvent(); + } + else + { + setSelectedState(true); + selectedEvent(); + } + } + setFocused(false); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + widgetParent->checkChildInfo(2,this,_touchEndPos); + } +} + +void CheckBox::onPressStateChangedToNormal() +{ + _backGroundBoxRenderer->setVisible(true); + _backGroundSelectedBoxRenderer->setVisible(false); + _backGroundBoxDisabledRenderer->setVisible(false); + _frontCrossDisabledRenderer->setVisible(false); +} + +void CheckBox::onPressStateChangedToPressed() +{ + _backGroundBoxRenderer->setVisible(false); + _backGroundSelectedBoxRenderer->setVisible(true); + _backGroundBoxDisabledRenderer->setVisible(false); + _frontCrossDisabledRenderer->setVisible(false); +} + +void CheckBox::onPressStateChangedToDisabled() +{ + _backGroundBoxRenderer->setVisible(false); + _backGroundSelectedBoxRenderer->setVisible(false); + _backGroundBoxDisabledRenderer->setVisible(true); + _frontCrossRenderer->setVisible(false); + if (_isSelected) + { + _frontCrossDisabledRenderer->setVisible(true); + } +} + +void CheckBox::setSelectedState(bool selected) +{ + if (selected == _isSelected) + { + return; + } + _isSelected = selected; + _frontCrossRenderer->setVisible(_isSelected); +} + +bool CheckBox::getSelectedState() +{ + return _isSelected; +} + +void CheckBox::selectedEvent() +{ + if (_checkBoxEventListener && _checkBoxEventSelector) + { + (_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_SELECTED); + } +} + +void CheckBox::unSelectedEvent() +{ + if (_checkBoxEventListener && _checkBoxEventSelector) + { + (_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_UNSELECTED); + } +} + +void CheckBox::addEventListenerCheckBox(Ref *target, SEL_SelectedStateEvent selector) +{ + _checkBoxEventListener = target; + _checkBoxEventSelector = selector; +} + +void CheckBox::updateFlippedX() +{ + _backGroundBoxRenderer->setFlippedX(_flippedX); + _backGroundSelectedBoxRenderer->setFlippedX(_flippedX); + _frontCrossRenderer->setFlippedX(_flippedX); + _backGroundBoxDisabledRenderer->setFlippedX(_flippedX); + _frontCrossDisabledRenderer->setFlippedX(_flippedX); +} + +void CheckBox::updateFlippedY() +{ + _backGroundBoxRenderer->setFlippedY(_flippedY); + _backGroundSelectedBoxRenderer->setFlippedY(_flippedY); + _frontCrossRenderer->setFlippedY(_flippedY); + _backGroundBoxDisabledRenderer->setFlippedY(_flippedY); + _frontCrossDisabledRenderer->setFlippedY(_flippedY); +} + +void CheckBox::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _backGroundBoxRenderer->setAnchorPoint(pt); + _backGroundSelectedBoxRenderer->setAnchorPoint(pt); + _backGroundBoxDisabledRenderer->setAnchorPoint(pt); + _frontCrossRenderer->setAnchorPoint(pt); + _frontCrossDisabledRenderer->setAnchorPoint(pt); +} + +void CheckBox::onSizeChanged() +{ + Widget::onSizeChanged(); + backGroundTextureScaleChangedWithSize(); + backGroundSelectedTextureScaleChangedWithSize(); + frontCrossTextureScaleChangedWithSize(); + backGroundDisabledTextureScaleChangedWithSize(); + frontCrossDisabledTextureScaleChangedWithSize(); +} + +const Size& CheckBox::getContentSize() const +{ + return _backGroundBoxRenderer->getContentSize(); +} + +Node* CheckBox::getVirtualRenderer() +{ + return _backGroundBoxRenderer; +} + +void CheckBox::backGroundTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _backGroundBoxRenderer->setScale(1.0f); + _size = _backGroundBoxRenderer->getContentSize(); + } + else + { + Size textureSize = _backGroundBoxRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _backGroundBoxRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _backGroundBoxRenderer->setScaleX(scaleX); + _backGroundBoxRenderer->setScaleY(scaleY); + } +} + +void CheckBox::backGroundSelectedTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _backGroundSelectedBoxRenderer->setScale(1.0f); + } + else + { + Size textureSize = _backGroundSelectedBoxRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _backGroundSelectedBoxRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _backGroundSelectedBoxRenderer->setScaleX(scaleX); + _backGroundSelectedBoxRenderer->setScaleY(scaleY); + } +} + +void CheckBox::frontCrossTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _frontCrossRenderer->setScale(1.0f); + } + else + { + Size textureSize = _frontCrossRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _frontCrossRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _frontCrossRenderer->setScaleX(scaleX); + _frontCrossRenderer->setScaleY(scaleY); + } +} + +void CheckBox::backGroundDisabledTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _backGroundBoxDisabledRenderer->setScale(1.0f); + } + else + { + Size textureSize = _backGroundBoxDisabledRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _backGroundBoxDisabledRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _backGroundBoxDisabledRenderer->setScaleX(scaleX); + _backGroundBoxDisabledRenderer->setScaleY(scaleY); + } +} + +void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _frontCrossDisabledRenderer->setScale(1.0f); + } + else + { + Size textureSize = _frontCrossDisabledRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _frontCrossDisabledRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _frontCrossDisabledRenderer->setScaleX(scaleX); + _frontCrossDisabledRenderer->setScaleY(scaleY); + } +} + +std::string CheckBox::getDescription() const +{ + return "CheckBox"; +} + +void CheckBox::updateTextureColor() +{ + updateColorToRenderer(_backGroundBoxRenderer); + updateColorToRenderer(_backGroundSelectedBoxRenderer); + updateColorToRenderer(_frontCrossRenderer); + updateColorToRenderer(_backGroundBoxDisabledRenderer); + updateColorToRenderer(_frontCrossDisabledRenderer); +} + +void CheckBox::updateTextureOpacity() +{ + updateOpacityToRenderer(_backGroundBoxRenderer); + updateOpacityToRenderer(_backGroundSelectedBoxRenderer); + updateOpacityToRenderer(_frontCrossRenderer); + updateOpacityToRenderer(_backGroundBoxDisabledRenderer); + updateOpacityToRenderer(_frontCrossDisabledRenderer); +} + +void CheckBox::updateTextureRGBA() +{ + updateRGBAToRenderer(_backGroundBoxRenderer); + updateRGBAToRenderer(_backGroundSelectedBoxRenderer); + updateRGBAToRenderer(_frontCrossRenderer); + updateRGBAToRenderer(_backGroundBoxDisabledRenderer); + updateRGBAToRenderer(_frontCrossDisabledRenderer); +} + +Widget* CheckBox::createCloneInstance() +{ + return CheckBox::create(); +} + +void CheckBox::copySpecialProperties(Widget *widget) +{ + CheckBox* checkBox = dynamic_cast(widget); + if (checkBox) + { + loadTextureBackGround(checkBox->_backGroundFileName.c_str(), checkBox->_backGroundTexType); + loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName.c_str(), checkBox->_backGroundSelectedTexType); + loadTextureFrontCross(checkBox->_frontCrossFileName.c_str(), checkBox->_frontCrossTexType); + loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName.c_str(), checkBox->_backGroundDisabledTexType); + loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName.c_str(), checkBox->_frontCrossDisabledTexType); + setSelectedState(checkBox->_isSelected); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h new file mode 100644 index 0000000000..0ee94c6eaf --- /dev/null +++ b/cocos/ui/UICheckBox.h @@ -0,0 +1,211 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UICHECKBOX_H__ +#define __UICHECKBOX_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + CHECKBOX_STATE_EVENT_SELECTED, + CHECKBOX_STATE_EVENT_UNSELECTED +}CheckBoxEventType; + +typedef void (Ref::*SEL_SelectedStateEvent)(Ref*,CheckBoxEventType); +#define checkboxselectedeventselector(_SELECTOR) (SEL_SelectedStateEvent)(&_SELECTOR) + +/** +* @js NA +* @lua NA +*/ +class CheckBox : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + CheckBox(); + + /** + * Default destructor + */ + virtual ~CheckBox(); + + /** + * Allocates and initializes. + */ + static CheckBox* create(); + + /** + * Load textures for checkbox. + * + * @param backGround backGround texture. + * + * @param backGroundSelected backGround selected state texture. + * + * @param cross cross texture. + * + * @param frontCrossDisabled cross dark state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextures(const char* backGround,const char* backGroundSelected,const char* cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load backGround texture for checkbox. + * + * @param backGround backGround texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureBackGround(const char* backGround,TextureResType type = UI_TEX_TYPE_LOCAL); + + /** + * Load backGroundSelected texture for checkbox. + * + * @param backGroundSelected backGround selected state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureBackGroundSelected(const char* backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load cross texture for checkbox. + * + * @param cross cross texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureFrontCross(const char* cross,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load backGroundDisabled texture for checkbox. + * + * @param backGroundDisabled backGroundDisabled texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureBackGroundDisabled(const char* backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load frontCrossDisabled texture for checkbox. + * + * @param frontCrossDisabled frontCrossDisabled texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTextureFrontCrossDisabled(const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Sets selcted state for checkbox. + * + * @param selected true that checkbox is selected, false otherwise. + */ + void setSelectedState(bool selected); + + /** + * Gets selcted state of checkbox. + * + * @return selected true that checkbox is selected, false otherwise. + */ + bool getSelectedState(); + + //override "setAnchorPoint" method of widget. + virtual void setAnchorPoint(const Point &pt) override; + + //add a call back function would called when checkbox is selected or unselected. + void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector); + + //override "onTouchEnded" method of widget. + virtual void onTouchEnded(Touch *touch, Event *unusedEvent); + + //override "getContentSize" method of widget. + virtual const Size& getContentSize() const override; + + //override "getVirtualRenderer" method of widget. + virtual Node* getVirtualRenderer() override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + +protected: + virtual bool init() override; + virtual void initRenderer() override; + virtual void onPressStateChangedToNormal() override; + virtual void onPressStateChangedToPressed() override; + virtual void onPressStateChangedToDisabled() override; + void selectedEvent(); + void unSelectedEvent(); + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + virtual void updateFlippedX() override; + virtual void updateFlippedY() override; + void backGroundTextureScaleChangedWithSize(); + void backGroundSelectedTextureScaleChangedWithSize(); + void frontCrossTextureScaleChangedWithSize(); + void backGroundDisabledTextureScaleChangedWithSize(); + void frontCrossDisabledTextureScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + Sprite* _backGroundBoxRenderer; + Sprite* _backGroundSelectedBoxRenderer; + Sprite* _frontCrossRenderer; + Sprite* _backGroundBoxDisabledRenderer; + Sprite* _frontCrossDisabledRenderer; + bool _isSelected; + + Ref* _checkBoxEventListener; + SEL_SelectedStateEvent _checkBoxEventSelector; + + TextureResType _backGroundTexType; + TextureResType _backGroundSelectedTexType; + TextureResType _frontCrossTexType; + TextureResType _backGroundDisabledTexType; + TextureResType _frontCrossDisabledTexType; + + std::string _backGroundFileName; + std::string _backGroundSelectedFileName; + std::string _frontCrossFileName; + std::string _backGroundDisabledFileName; + std::string _frontCrossDisabledFileName; +}; + +} + +NS_CC_END + +#endif /* defined(__CocoGUI__CheckBox__) */ diff --git a/cocos/ui/UIHelper.cpp b/cocos/ui/UIHelper.cpp new file mode 100644 index 0000000000..4bb3d4ee8b --- /dev/null +++ b/cocos/ui/UIHelper.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +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 "CocosGUI.h" + +NS_CC_BEGIN + +namespace ui { + +Widget* Helper::seekWidgetByTag(Widget* root, int tag) +{ + if (!root) + { + return nullptr; + } + if (root->getTag() == tag) + { + return root; + } + const auto& arrayRootChildren = root->getChildren(); + ssize_t length = arrayRootChildren.size(); + for (ssize_t i=0;i(arrayRootChildren.at(i)); + Widget* res = seekWidgetByTag(child,tag); + if (res != nullptr) + { + return res; + } + } + return nullptr; +} + +Widget* Helper::seekWidgetByName(Widget* root, const char *name) +{ + if (!root) + { + return nullptr; + } + if (strcmp(root->getName(), name) == 0) + { + return root; + } + const auto& arrayRootChildren = root->getChildren(); + for (auto& subWidget : arrayRootChildren) + { + Widget* child = static_cast(subWidget); + Widget* res = seekWidgetByName(child,name); + if (res != nullptr) + { + return res; + } + } + return nullptr; +} + +Widget* Helper::seekWidgetByRelativeName(Widget *root, const char *name) +{ + if (!root) + { + return nullptr; + } + const auto& arrayRootChildren = root->getChildren(); + for (auto& subWidget : arrayRootChildren) + { + Widget* child = static_cast(subWidget); + RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); + if (layoutParameter && strcmp(layoutParameter->getRelativeName(), name) == 0) + { + return child; + } + } + return nullptr; +} + +/*temp action*/ +Widget* Helper::seekActionWidgetByActionTag(Widget* root, int tag) +{ + if (!root) + { + return nullptr; + } + if (root->getActionTag() == tag) + { + return root; + } + const auto& arrayRootChildren = root->getChildren(); + for (auto& subWidget : arrayRootChildren) + { + Widget* child = static_cast(subWidget); + Widget* res = seekActionWidgetByActionTag(child,tag); + if (res != nullptr) + { + return res; + } + } + return nullptr; +} + +} + +NS_CC_END diff --git a/cocos/ui/UIHelper.h b/cocos/ui/UIHelper.h new file mode 100644 index 0000000000..035df13cdb --- /dev/null +++ b/cocos/ui/UIHelper.h @@ -0,0 +1,81 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UIHELPER_H__ +#define __UIHELPER_H__ + +NS_CC_BEGIN + +namespace ui { + +/** +* @js NA +* @lua NA +*/ +class Helper +{ +public: + /** + * Finds a widget whose tag equals to param tag from root widget. + * + * @param root widget which will be seeked. + * + * @tag tag value. + * + * @return finded result. + */ + static Widget* seekWidgetByTag(Widget* root, int tag); + + /** + * Finds a widget whose name equals to param name from root widget. + * + * @param root widget which will be seeked. + * + * @name name value. + * + * @return finded result. + */ + static Widget* seekWidgetByName(Widget* root, const char* name); + + /** + * Finds a widget whose name equals to param name from root widget. + * + * RelativeLayout will call this method to find the widget witch is needed. + * + * @param root widget which will be seeked. + * + * @name name value. + * + * @return finded result. + */ + static Widget* seekWidgetByRelativeName(Widget* root, const char* name); + + /*temp action*/ + static Widget* seekActionWidgetByActionTag(Widget* root, int tag); +}; +} + +NS_CC_END + +#endif /* defined(__CocoGUI__UISystem__) */ diff --git a/cocos/ui/UIImageView.cpp b/cocos/ui/UIImageView.cpp new file mode 100644 index 0000000000..83d93b06b3 --- /dev/null +++ b/cocos/ui/UIImageView.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +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/UIImageView.h" +#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" + +NS_CC_BEGIN + +namespace ui { + + +#define STATIC_CAST_CCSPRITE static_cast(_imageRenderer) +#define STATIC_CAST_SCALE9SPRITE static_cast(_imageRenderer) + +static const int IMAGE_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(ImageView) + +ImageView::ImageView(): +_scale9Enabled(false), +_prevIgnoreSize(true), +_capInsets(Rect::ZERO), +_imageRenderer(nullptr), +_textureFile(""), +_imageTexType(UI_TEX_TYPE_LOCAL), +_imageTextureSize(_size) +{ + +} + +ImageView::~ImageView() +{ + +} + +ImageView* ImageView::create() +{ + ImageView* widget = new ImageView(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void ImageView::initRenderer() +{ + _imageRenderer = Sprite::create(); + Node::addChild(_imageRenderer, IMAGE_RENDERER_Z, -1); +} + +void ImageView::loadTexture(const char *fileName, TextureResType texType) +{ + if (!fileName || strcmp(fileName, "") == 0) + { + return; + } + _textureFile = fileName; + _imageTexType = texType; + switch (_imageTexType) + { + case UI_TEX_TYPE_LOCAL: + if (_scale9Enabled) + { + extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; + imageRendererScale9->initWithFile(fileName); + imageRendererScale9->setCapInsets(_capInsets); + } + else + { + Sprite* imageRenderer = STATIC_CAST_CCSPRITE; + imageRenderer->setTexture(fileName); + } + break; + case UI_TEX_TYPE_PLIST: + if (_scale9Enabled) + { + extension::Scale9Sprite* imageRendererScale9 = STATIC_CAST_SCALE9SPRITE; + imageRendererScale9->initWithSpriteFrameName(fileName); + imageRendererScale9->setCapInsets(_capInsets); + } + else + { + Sprite* imageRenderer = STATIC_CAST_CCSPRITE; + imageRenderer->setSpriteFrame(fileName); + } + break; + default: + break; + } + _imageTextureSize = _imageRenderer->getContentSize(); + imageTextureScaleChangedWithSize(); + updateAnchorPoint(); + updateFlippedX(); + updateFlippedY(); + updateRGBAToRenderer(_imageRenderer); +} + +void ImageView::setTextureRect(const Rect &rect) +{ + if (_scale9Enabled) + { + } + else + { + STATIC_CAST_CCSPRITE->setTextureRect(rect); + } +} + +void ImageView::updateFlippedX() +{ + if (_scale9Enabled) + { + int flip = _flippedX ? -1 : 1; + STATIC_CAST_SCALE9SPRITE->setScaleX(flip); + } + else + { + STATIC_CAST_CCSPRITE->setFlippedX(_flippedX); + } +} + +void ImageView::updateFlippedY() +{ + if (_scale9Enabled) + { + int flip = _flippedY ? -1 : 1; + STATIC_CAST_SCALE9SPRITE->setScaleY(flip); + } + else + { + STATIC_CAST_CCSPRITE->setFlippedY(_flippedY); + } + +} + +void ImageView::setScale9Enabled(bool able) +{ + if (_scale9Enabled == able) + { + return; + } + + + _scale9Enabled = able; + Node::removeChild(_imageRenderer); + _imageRenderer = nullptr; + if (_scale9Enabled) + { + _imageRenderer = extension::Scale9Sprite::create(); + } + else + { + _imageRenderer = Sprite::create(); + } + loadTexture(_textureFile.c_str(),_imageTexType); + Node::addChild(_imageRenderer, IMAGE_RENDERER_Z, -1); + if (_scale9Enabled) + { + bool ignoreBefore = _ignoreSize; + ignoreContentAdaptWithSize(false); + _prevIgnoreSize = ignoreBefore; + } + else + { + ignoreContentAdaptWithSize(_prevIgnoreSize); + } + setCapInsets(_capInsets); +} + +bool ImageView::isScale9Enabled() +{ + return _scale9Enabled; +} + +void ImageView::ignoreContentAdaptWithSize(bool ignore) +{ + if (!_scale9Enabled || (_scale9Enabled && !ignore)) + { + Widget::ignoreContentAdaptWithSize(ignore); + _prevIgnoreSize = ignore; + } +} + +void ImageView::setCapInsets(const Rect &capInsets) +{ + _capInsets = capInsets; + if (!_scale9Enabled) + { + return; + } + STATIC_CAST_SCALE9SPRITE->setCapInsets(capInsets); +} + +const Rect& ImageView::getCapInsets() +{ + return _capInsets; +} + +void ImageView::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _imageRenderer->setAnchorPoint(pt); +} + +void ImageView::onSizeChanged() +{ + Widget::onSizeChanged(); + imageTextureScaleChangedWithSize(); +} + +const Size& ImageView::getContentSize() const +{ + return _imageTextureSize; +} + +Node* ImageView::getVirtualRenderer() +{ + return _imageRenderer; +} + +void ImageView::imageTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + if (!_scale9Enabled) + { + _imageRenderer->setScale(1.0f); + _size = _imageTextureSize; + } + } + else + { + if (_scale9Enabled) + { + static_cast(_imageRenderer)->setPreferredSize(_size); + } + else + { + Size textureSize = _imageRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _imageRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _imageRenderer->setScaleX(scaleX); + _imageRenderer->setScaleY(scaleY); + } + } +} + +std::string ImageView::getDescription() const +{ + return "ImageView"; +} + +void ImageView::updateTextureColor() +{ + updateColorToRenderer(_imageRenderer); +} + +void ImageView::updateTextureOpacity() +{ + updateOpacityToRenderer(_imageRenderer); +} + +void ImageView::updateTextureRGBA() +{ + updateRGBAToRenderer(_imageRenderer); +} + +Widget* ImageView::createCloneInstance() +{ + return ImageView::create(); +} + +void ImageView::copySpecialProperties(Widget *widget) +{ + ImageView* imageView = dynamic_cast(widget); + if (imageView) + { + _prevIgnoreSize = imageView->_prevIgnoreSize; + setScale9Enabled(imageView->_scale9Enabled); + loadTexture(imageView->_textureFile.c_str(), imageView->_imageTexType); + setCapInsets(imageView->_capInsets); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UIImageView.h b/cocos/ui/UIImageView.h new file mode 100644 index 0000000000..24d0d481a3 --- /dev/null +++ b/cocos/ui/UIImageView.h @@ -0,0 +1,130 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UIIMAGEVIEW_H__ +#define __UIIMAGEVIEW_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +/** +* @js NA +* @lua NA +*/ +class ImageView : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + ImageView(); + + /** + * Default destructor + */ + virtual ~ImageView(); + + /** + * Allocates and initializes. + */ + static ImageView* create(); + + /** + * Load texture for imageview. + * + * @param fileName file name of texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Updates the texture rect of the ImageView in points. + * It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size. + */ + void setTextureRect(const Rect& rect); + + /** + * Sets if imageview is using scale9 renderer. + * + * @param true that using scale9 renderer, false otherwise. + */ + void setScale9Enabled(bool able); + + bool isScale9Enabled(); + + /** + * Sets capinsets for imageview, if imageview is using scale9 renderer. + * + * @param capInsets capinsets for imageview + */ + void setCapInsets(const Rect &capInsets); + + const Rect& getCapInsets(); + + //override "setAnchorPoint" method of widget. + virtual void setAnchorPoint(const Point &pt) override; + + //override "ignoreContentAdaptWithSize" method of widget. + virtual void ignoreContentAdaptWithSize(bool ignore) override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + virtual const Size& getContentSize() const override; + virtual Node* getVirtualRenderer() override; +protected: + virtual void initRenderer() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + virtual void updateFlippedX() override; + virtual void updateFlippedY() override; + void imageTextureScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + bool _scale9Enabled; + bool _prevIgnoreSize; + Rect _capInsets; + Node* _imageRenderer; + std::string _textureFile; + TextureResType _imageTexType; + Size _imageTextureSize; +}; + +} + +NS_CC_END + +#endif /* defined(__CocoGUI__ImageView__) */ diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp new file mode 100644 index 0000000000..1c488618d4 --- /dev/null +++ b/cocos/ui/UILayout.cpp @@ -0,0 +1,1404 @@ +/**************************************************************************** +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/UILayout.h" +#include "ui/UIHelper.h" +#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" +#include "kazmath/GL/matrix.h" +#include "CCGLProgram.h" +#include "CCShaderCache.h" +#include "CCDirector.h" +#include "CCDrawingPrimitives.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" + +NS_CC_BEGIN + +namespace ui { + +static const int BACKGROUNDIMAGE_Z = (-1); +static const int BCAKGROUNDCOLORRENDERER_Z = (-2); + +static GLint g_sStencilBits = -1; +static GLint s_layer = -1; + +IMPLEMENT_CLASS_GUI_INFO(Layout) + +Layout::Layout(): +_clippingEnabled(false), +_backGroundScale9Enabled(false), +_backGroundImage(nullptr), +_backGroundImageFileName(""), +_backGroundImageCapInsets(Rect::ZERO), +_colorType(LAYOUT_COLOR_NONE), +_bgImageTexType(UI_TEX_TYPE_LOCAL), +_colorRender(nullptr), +_gradientRender(nullptr), +_cColor(Color3B::WHITE), +_gStartColor(Color3B::WHITE), +_gEndColor(Color3B::WHITE), +_alongVector(Point(0.0f, -1.0f)), +_cOpacity(255), +_backGroundImageTextureSize(Size::ZERO), +_layoutType(LAYOUT_ABSOLUTE), +_clippingType(LAYOUT_CLIPPING_STENCIL), +_clippingStencil(nullptr), +_scissorRectDirty(false), +_clippingRect(Rect::ZERO), +_clippingParent(nullptr), +_doLayoutDirty(true), +_clippingRectDirty(true), +_currentStencilEnabled(GL_FALSE), +_currentStencilWriteMask(~0), +_currentStencilFunc(GL_ALWAYS), +_currentStencilRef(0), +_currentStencilValueMask(~0), +_currentStencilFail(GL_KEEP), +_currentStencilPassDepthFail(GL_KEEP), +_currentStencilPassDepthPass(GL_KEEP), +_currentDepthWriteMask(GL_TRUE), +_currentAlphaTestEnabled(GL_FALSE), +_currentAlphaTestFunc(GL_ALWAYS), +_currentAlphaTestRef(1), +_backGroundImageColor(Color3B::WHITE), +_backGroundImageOpacity(255) +{ + _widgetType = WidgetTypeContainer; +} + +Layout::~Layout() +{ + CC_SAFE_RELEASE(_clippingStencil); +} + +void Layout::onEnter() +{ + Widget::onEnter(); + if (_clippingStencil) + { + _clippingStencil->onEnter(); + } + _doLayoutDirty = true; + _clippingRectDirty = true; +} + +void Layout::onExit() +{ + Widget::onExit(); + if (_clippingStencil) + { + _clippingStencil->onExit(); + } +} + +Layout* Layout::create() +{ + Layout* layout = new Layout(); + if (layout && layout->init()) + { + layout->autorelease(); + return layout; + } + CC_SAFE_DELETE(layout); + return nullptr; +} + +bool Layout::init() +{ + if (Node::init()) + { + initRenderer(); + setBright(true); + ignoreContentAdaptWithSize(false); + setSize(Size::ZERO); + setAnchorPoint(Point::ZERO); + return true; + } + return false; +} + +void Layout::addChild(Node *child) +{ + Widget::addChild(child); +} + +void Layout::addChild(Node * child, int zOrder) +{ + Widget::addChild(child, zOrder); +} + +void Layout::addChild(Node *child, int zOrder, int tag) +{ + supplyTheLayoutParameterLackToChild(static_cast(child)); + Widget::addChild(child, zOrder, tag); + _doLayoutDirty = true; +} + +void Layout::removeChild(Node *child, bool cleanup) +{ + Widget::removeChild(child, cleanup); + _doLayoutDirty = true; +} + +void Layout::removeAllChildren() +{ + Widget::removeAllChildren(); +} + +void Layout::removeAllChildrenWithCleanup(bool cleanup) +{ + Widget::removeAllChildrenWithCleanup(cleanup); + _doLayoutDirty = true; +} + +bool Layout::isClippingEnabled() +{ + return _clippingEnabled; +} + +bool Layout::hitTest(const Point &pt) +{ + Point nsp = convertToNodeSpace(pt); + Rect bb = Rect(0.0f, 0.0f, _size.width, _size.height); + if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) + { + return true; + } + return false; +} + +void Layout::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) +{ + if (!_enabled) + { + return; + } + if (_clippingEnabled) + { + switch (_clippingType) + { + case LAYOUT_CLIPPING_STENCIL: + stencilClippingVisit(renderer, parentTransform, parentTransformUpdated); + break; + case LAYOUT_CLIPPING_SCISSOR: + scissorClippingVisit(renderer, parentTransform, parentTransformUpdated); + break; + default: + break; + } + } + else + { + Node::visit(renderer, parentTransform, parentTransformUpdated); + } +} + +void Layout::sortAllChildren() +{ + Widget::sortAllChildren(); + doLayout(); +} + +void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) +{ + if(!_visible) + return; + + bool dirty = parentTransformUpdated || _transformUpdated; + if(dirty) + _modelViewTransform = transform(parentTransform); + _transformUpdated = false; + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); + + //Add group command + + _groupCommand.init(_globalZOrder); + renderer->addCommand(&_groupCommand); + + renderer->pushGroup(_groupCommand.getRenderQueueID()); + + _beforeVisitCmdStencil.init(_globalZOrder); + _beforeVisitCmdStencil.func = CC_CALLBACK_0(Layout::onBeforeVisitStencil, this); + renderer->addCommand(&_beforeVisitCmdStencil); + + _clippingStencil->visit(renderer, _modelViewTransform, dirty); + + _afterDrawStencilCmd.init(_globalZOrder); + _afterDrawStencilCmd.func = CC_CALLBACK_0(Layout::onAfterDrawStencil, this); + renderer->addCommand(&_afterDrawStencilCmd); + + int i = 0; + + if(!_children.empty()) + { + sortAllChildren(); + // draw children zOrder < 0 + for( ; i < _children.size(); i++ ) + { + auto node = _children.at(i); + + if ( node && node->getLocalZOrder() < 0 ) + node->visit(renderer, _modelViewTransform, dirty); + else + break; + } + // self draw + this->draw(renderer, _modelViewTransform, dirty); + + for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) + (*it)->visit(renderer, _modelViewTransform, dirty); + } + else + { + this->draw(renderer, _modelViewTransform, dirty); + } + + _afterVisitCmdStencil.init(_globalZOrder); + _afterVisitCmdStencil.func = CC_CALLBACK_0(Layout::onAfterVisitStencil, this); + renderer->addCommand(&_afterVisitCmdStencil); + + renderer->popGroup(); + + kmGLPopMatrix(); +} + +void Layout::onBeforeVisitStencil() +{ + s_layer++; + GLint mask_layer = 0x1 << s_layer; + GLint mask_layer_l = mask_layer - 1; + _mask_layer_le = mask_layer | mask_layer_l; + _currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST); + glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)&_currentStencilWriteMask); + glGetIntegerv(GL_STENCIL_FUNC, (GLint *)&_currentStencilFunc); + glGetIntegerv(GL_STENCIL_REF, &_currentStencilRef); + glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)&_currentStencilValueMask); + glGetIntegerv(GL_STENCIL_FAIL, (GLint *)&_currentStencilFail); + glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)&_currentStencilPassDepthFail); + glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)&_currentStencilPassDepthPass); + + glEnable(GL_STENCIL_TEST); + CHECK_GL_ERROR_DEBUG(); + glStencilMask(mask_layer); + glGetBooleanv(GL_DEPTH_WRITEMASK, &_currentDepthWriteMask); + glDepthMask(GL_FALSE); + glStencilFunc(GL_NEVER, mask_layer, mask_layer); + glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); + kmGLMatrixMode(KM_GL_MODELVIEW); + kmGLPushMatrix(); + kmGLLoadIdentity(); + + kmGLMatrixMode(KM_GL_PROJECTION); + kmGLPushMatrix(); + kmGLLoadIdentity(); + + DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1)); + + kmGLMatrixMode(KM_GL_PROJECTION); + kmGLPopMatrix(); + kmGLMatrixMode(KM_GL_MODELVIEW); + kmGLPopMatrix(); + glStencilFunc(GL_NEVER, mask_layer, mask_layer); + glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP); +} + +void Layout::onAfterDrawStencil() +{ + glDepthMask(_currentDepthWriteMask); + glStencilFunc(GL_EQUAL, _mask_layer_le, _mask_layer_le); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +} + + +void Layout::onAfterVisitStencil() +{ + glStencilFunc(_currentStencilFunc, _currentStencilRef, _currentStencilValueMask); + glStencilOp(_currentStencilFail, _currentStencilPassDepthFail, _currentStencilPassDepthPass); + glStencilMask(_currentStencilWriteMask); + if (!_currentStencilEnabled) + { + glDisable(GL_STENCIL_TEST); + } + s_layer--; +} + +void Layout::onBeforeVisitScissor() +{ + Rect clippingRect = getClippingRect(); + glEnable(GL_SCISSOR_TEST); + auto glview = Director::getInstance()->getOpenGLView(); + glview->setScissorInPoints(clippingRect.origin.x, clippingRect.origin.y, clippingRect.size.width, clippingRect.size.height); +} + +void Layout::onAfterVisitScissor() +{ + glDisable(GL_SCISSOR_TEST); +} + +void Layout::scissorClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated) +{ + _beforeVisitCmdScissor.init(_globalZOrder); + _beforeVisitCmdScissor.func = CC_CALLBACK_0(Layout::onBeforeVisitScissor, this); + renderer->addCommand(&_beforeVisitCmdScissor); + + Node::visit(renderer, parentTransform, parentTransformUpdated); + + _afterVisitCmdScissor.init(_globalZOrder); + _afterVisitCmdScissor.func = CC_CALLBACK_0(Layout::onAfterVisitScissor, this); + renderer->addCommand(&_afterVisitCmdScissor); +} + +void Layout::setClippingEnabled(bool able) +{ + if (able == _clippingEnabled) + { + return; + } + _clippingEnabled = able; + switch (_clippingType) + { + case LAYOUT_CLIPPING_STENCIL: + if (able) + { + static bool once = true; + if (once) + { + glGetIntegerv(GL_STENCIL_BITS, &g_sStencilBits); + if (g_sStencilBits <= 0) + { + CCLOG("Stencil buffer is not enabled."); + } + once = false; + } + _clippingStencil = DrawNode::create(); + if (_running) + { + _clippingStencil->onEnter(); + } + _clippingStencil->retain(); + setStencilClippingSize(_size); + } + else + { + if (_running) + { + _clippingStencil->onExit(); + } + _clippingStencil->release(); + _clippingStencil = nullptr; + } + break; + default: + break; + } +} + +void Layout::setClippingType(LayoutClippingType type) +{ + if (type == _clippingType) + { + return; + } + bool clippingEnabled = isClippingEnabled(); + setClippingEnabled(false); + _clippingType = type; + setClippingEnabled(clippingEnabled); +} + +LayoutClippingType Layout::getClippingType() +{ + return _clippingType; +} + +void Layout::setStencilClippingSize(const Size &size) +{ + if (_clippingEnabled && _clippingType == LAYOUT_CLIPPING_STENCIL) + { + Point rect[4]; + rect[0] = Point::ZERO; + rect[1] = Point(_size.width, 0); + rect[2] = Point(_size.width, _size.height); + rect[3] = Point(0, _size.height); + Color4F green(0, 1, 0, 1); + _clippingStencil->clear(); + _clippingStencil->drawPolygon(rect, 4, green, 0, green); + } +} + +const Rect& Layout::getClippingRect() +{ + if (_clippingRectDirty) + { + Point worldPos = convertToWorldSpace(Point::ZERO); + AffineTransform t = getNodeToWorldAffineTransform(); + float scissorWidth = _size.width*t.a; + float scissorHeight = _size.height*t.d; + Rect parentClippingRect; + Layout* parent = this; + bool firstClippingParentFounded = false; + while (parent) + { + parent = dynamic_cast(parent->getParent()); + if(parent) + { + if (parent->isClippingEnabled()) + { + if (!firstClippingParentFounded) + { + _clippingParent = parent; + firstClippingParentFounded = true; + break; + } + } + } + } + + if (_clippingParent) + { + parentClippingRect = _clippingParent->getClippingRect(); + float finalX = worldPos.x - (scissorWidth * _anchorPoint.x); + float finalY = worldPos.y - (scissorHeight * _anchorPoint.y); + float finalWidth = scissorWidth; + float finalHeight = scissorHeight; + + float leftOffset = worldPos.x - parentClippingRect.origin.x; + if (leftOffset < 0.0f) + { + finalX = parentClippingRect.origin.x; + finalWidth += leftOffset; + } + float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width); + if (rightOffset > 0.0f) + { + finalWidth -= rightOffset; + } + float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height); + if (topOffset > 0.0f) + { + finalHeight -= topOffset; + } + float bottomOffset = worldPos.y - parentClippingRect.origin.y; + if (bottomOffset < 0.0f) + { + finalY = parentClippingRect.origin.x; + finalHeight += bottomOffset; + } + if (finalWidth < 0.0f) + { + finalWidth = 0.0f; + } + if (finalHeight < 0.0f) + { + finalHeight = 0.0f; + } + _clippingRect.origin.x = finalX; + _clippingRect.origin.y = finalY; + _clippingRect.size.width = finalWidth; + _clippingRect.size.height = finalHeight; + } + else + { + _clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x); + _clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y); + _clippingRect.size.width = scissorWidth; + _clippingRect.size.height = scissorHeight; + } + _clippingRectDirty = false; + } + return _clippingRect; +} + +void Layout::onSizeChanged() +{ + Widget::onSizeChanged(); + setContentSize(_size); + setStencilClippingSize(_size); + _doLayoutDirty = true; + _clippingRectDirty = true; + if (_backGroundImage) + { + _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); + if (_backGroundScale9Enabled && _backGroundImage) + { + static_cast(_backGroundImage)->setPreferredSize(_size); + } + } + if (_colorRender) + { + _colorRender->setContentSize(_size); + } + if (_gradientRender) + { + _gradientRender->setContentSize(_size); + } +} + +void Layout::setBackGroundImageScale9Enabled(bool able) +{ + if (_backGroundScale9Enabled == able) + { + return; + } + Node::removeChild(_backGroundImage); + _backGroundImage = nullptr; + _backGroundScale9Enabled = able; + if (_backGroundScale9Enabled) + { + _backGroundImage = extension::Scale9Sprite::create(); + Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); + } + else + { + _backGroundImage = Sprite::create(); + Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); + } + setBackGroundImage(_backGroundImageFileName.c_str(),_bgImageTexType); + setBackGroundImageCapInsets(_backGroundImageCapInsets); +} + +bool Layout::isBackGroundImageScale9Enabled() +{ + return _backGroundScale9Enabled; +} + +void Layout::setBackGroundImage(const char* fileName,TextureResType texType) +{ + if (!fileName || strcmp(fileName, "") == 0) + { + return; + } + if (_backGroundImage == nullptr) + { + addBackGroundImage(); + } + _backGroundImageFileName = fileName; + _bgImageTexType = texType; + if (_backGroundScale9Enabled) + { + extension::Scale9Sprite* bgiScale9 = static_cast(_backGroundImage); + switch (_bgImageTexType) + { + case UI_TEX_TYPE_LOCAL: + bgiScale9->initWithFile(fileName); + break; + case UI_TEX_TYPE_PLIST: + bgiScale9->initWithSpriteFrameName(fileName); + break; + default: + break; + } + bgiScale9->setPreferredSize(_size); + } + else + { + switch (_bgImageTexType) + { + case UI_TEX_TYPE_LOCAL: + static_cast(_backGroundImage)->setTexture(fileName); + break; + case UI_TEX_TYPE_PLIST: + static_cast(_backGroundImage)->setSpriteFrame(fileName); + break; + default: + break; + } + } + _backGroundImageTextureSize = _backGroundImage->getContentSize(); + _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); + updateBackGroundImageRGBA(); +} + +void Layout::setBackGroundImageCapInsets(const Rect &capInsets) +{ + _backGroundImageCapInsets = capInsets; + if (_backGroundScale9Enabled && _backGroundImage) + { + static_cast(_backGroundImage)->setCapInsets(capInsets); + } +} + +const Rect& Layout::getBackGroundImageCapInsets() +{ + return _backGroundImageCapInsets; +} + +void Layout::supplyTheLayoutParameterLackToChild(Widget *child) +{ + if (!child) + { + return; + } + switch (_layoutType) + { + case LAYOUT_ABSOLUTE: + break; + case LAYOUT_LINEAR_HORIZONTAL: + case LAYOUT_LINEAR_VERTICAL: + { + LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); + if (!layoutParameter) + { + child->setLayoutParameter(LinearLayoutParameter::create()); + } + break; + } + case LAYOUT_RELATIVE: + { + RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); + if (!layoutParameter) + { + child->setLayoutParameter(RelativeLayoutParameter::create()); + } + break; + } + default: + break; + } +} + +void Layout::addBackGroundImage() +{ + if (_backGroundScale9Enabled) + { + _backGroundImage = extension::Scale9Sprite::create(); + _backGroundImage->setLocalZOrder(-1); + Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); + static_cast(_backGroundImage)->setPreferredSize(_size); + } + else + { + _backGroundImage = Sprite::create(); + _backGroundImage->setLocalZOrder(-1); + Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); + } + _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); +} + +void Layout::removeBackGroundImage() +{ + if (!_backGroundImage) + { + return; + } + Node::removeChild(_backGroundImage); + _backGroundImage = nullptr; + _backGroundImageFileName = ""; + _backGroundImageTextureSize = Size::ZERO; +} + +void Layout::setBackGroundColorType(LayoutBackGroundColorType type) +{ + if (_colorType == type) + { + return; + } + switch (_colorType) + { + case LAYOUT_COLOR_NONE: + if (_colorRender) + { + Node::removeChild(_colorRender); + _colorRender = nullptr; + } + if (_gradientRender) + { + Node::removeChild(_gradientRender); + _gradientRender = nullptr; + } + break; + case LAYOUT_COLOR_SOLID: + if (_colorRender) + { + Node::removeChild(_colorRender); + _colorRender = nullptr; + } + break; + case LAYOUT_COLOR_GRADIENT: + if (_gradientRender) + { + Node::removeChild(_gradientRender); + _gradientRender = nullptr; + } + break; + default: + break; + } + _colorType = type; + switch (_colorType) + { + case LAYOUT_COLOR_NONE: + break; + case LAYOUT_COLOR_SOLID: + _colorRender = LayerColor::create(); + _colorRender->setContentSize(_size); + _colorRender->setOpacity(_cOpacity); + _colorRender->setColor(_cColor); + Node::addChild(_colorRender, BCAKGROUNDCOLORRENDERER_Z, -1); + break; + case LAYOUT_COLOR_GRADIENT: + _gradientRender = LayerGradient::create(); + _gradientRender->setContentSize(_size); + _gradientRender->setOpacity(_cOpacity); + _gradientRender->setStartColor(_gStartColor); + _gradientRender->setEndColor(_gEndColor); + _gradientRender->setVector(_alongVector); + Node::addChild(_gradientRender, BCAKGROUNDCOLORRENDERER_Z, -1); + break; + default: + break; + } +} + +LayoutBackGroundColorType Layout::getBackGroundColorType() +{ + return _colorType; +} + +void Layout::setBackGroundColor(const Color3B &color) +{ + _cColor = color; + if (_colorRender) + { + _colorRender->setColor(color); + } +} + +const Color3B& Layout::getBackGroundColor() +{ + return _cColor; +} + +void Layout::setBackGroundColor(const Color3B &startColor, const Color3B &endColor) +{ + _gStartColor = startColor; + if (_gradientRender) + { + _gradientRender->setStartColor(startColor); + } + _gEndColor = endColor; + if (_gradientRender) + { + _gradientRender->setEndColor(endColor); + } +} + +const Color3B& Layout::getBackGroundStartColor() +{ + return _gStartColor; +} + +const Color3B& Layout::getBackGroundEndColor() +{ + return _gEndColor; +} + +void Layout::setBackGroundColorOpacity(GLubyte opacity) +{ + _cOpacity = opacity; + switch (_colorType) + { + case LAYOUT_COLOR_NONE: + break; + case LAYOUT_COLOR_SOLID: + _colorRender->setOpacity(opacity); + break; + case LAYOUT_COLOR_GRADIENT: + _gradientRender->setOpacity(opacity); + break; + default: + break; + } +} + +GLubyte Layout::getBackGroundColorOpacity() +{ + return _cOpacity; +} + +void Layout::setBackGroundColorVector(const Point &vector) +{ + _alongVector = vector; + if (_gradientRender) + { + _gradientRender->setVector(vector); + } +} + +const Point& Layout::getBackGroundColorVector() +{ + return _alongVector; +} + +void Layout::setBackGroundImageColor(const Color3B &color) +{ + _backGroundImageColor = color; + updateBackGroundImageColor(); +} + +void Layout::setBackGroundImageOpacity(GLubyte opacity) +{ + _backGroundImageOpacity = opacity; + updateBackGroundImageOpacity(); +} + +const Color3B& Layout::getBackGroundImageColor() +{ + return _backGroundImageColor; +} + +GLubyte Layout::getBackGroundImageOpacity() +{ + return _backGroundImageOpacity; +} + +void Layout::updateBackGroundImageColor() +{ + if (_backGroundImage) + { + _backGroundImage->setColor(_backGroundImageColor); + } +} + +void Layout::updateBackGroundImageOpacity() +{ + if (_backGroundImage) + { + _backGroundImage->setOpacity(_backGroundImageOpacity); + } +} + +void Layout::updateBackGroundImageRGBA() +{ + if (_backGroundImage) + { + _backGroundImage->setColor(_backGroundImageColor); + _backGroundImage->setOpacity(_backGroundImageOpacity); + } +} + +const Size& Layout::getBackGroundImageTextureSize() const +{ + return _backGroundImageTextureSize; +} + +void Layout::setLayoutType(LayoutType type) +{ + _layoutType = type; + for (auto& child : _widgetChildren) + { + if (child) + { + supplyTheLayoutParameterLackToChild(static_cast(child)); + } + } + _doLayoutDirty = true; +} + +LayoutType Layout::getLayoutType() const +{ + return _layoutType; +} + +void Layout::requestDoLayout() +{ + _doLayoutDirty = true; +} + +void Layout::doLayout() +{ + if (!_doLayoutDirty) + { + return; + } + switch (_layoutType) + { + case LAYOUT_ABSOLUTE: + break; + case LAYOUT_LINEAR_VERTICAL: + { + Size layoutSize = getSize(); + float topBoundary = layoutSize.height; + + for (auto& subWidget : _widgetChildren) + { + Widget* child = static_cast(subWidget); + LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); + + if (layoutParameter) + { + LinearGravity childGravity = layoutParameter->getGravity(); + Point ap = child->getAnchorPoint(); + Size cs = child->getSize(); + float finalPosX = ap.x * cs.width; + float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height); + switch (childGravity) + { + case LINEAR_GRAVITY_NONE: + case LINEAR_GRAVITY_LEFT: + break; + case LINEAR_GRAVITY_RIGHT: + finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); + break; + case LINEAR_GRAVITY_CENTER_HORIZONTAL: + finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x); + break; + default: + break; + } + Margin mg = layoutParameter->getMargin(); + finalPosX += mg.left; + finalPosY -= mg.top; + child->setPosition(Point(finalPosX, finalPosY)); + topBoundary = child->getBottomInParent() - mg.bottom; + } + } + break; + } + case LAYOUT_LINEAR_HORIZONTAL: + { + Size layoutSize = getSize(); + float leftBoundary = 0.0f; + for (auto& subWidget : _widgetChildren) + { + Widget* child = static_cast(subWidget); + LinearLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); + + if (layoutParameter) + { + LinearGravity childGravity = layoutParameter->getGravity(); + Point ap = child->getAnchorPoint(); + Size cs = child->getSize(); + float finalPosX = leftBoundary + (ap.x * cs.width); + float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height; + switch (childGravity) + { + case LINEAR_GRAVITY_NONE: + case LINEAR_GRAVITY_TOP: + break; + case LINEAR_GRAVITY_BOTTOM: + finalPosY = ap.y * cs.height; + break; + case LINEAR_GRAVITY_CENTER_VERTICAL: + finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y); + break; + default: + break; + } + Margin mg = layoutParameter->getMargin(); + finalPosX += mg.left; + finalPosY -= mg.top; + child->setPosition(Point(finalPosX, finalPosY)); + leftBoundary = child->getRightInParent() + mg.right; + } + } + break; + } + case LAYOUT_RELATIVE: + { + ssize_t unlayoutChildCount = _widgetChildren.size(); + Size layoutSize = getSize(); + for (auto& subWidget : _widgetChildren) + { + Widget* child = static_cast(subWidget); + RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); + layoutParameter->_put = false; + } + while (unlayoutChildCount > 0) + { + for (auto& subWidget : _widgetChildren) + { + Widget* child = static_cast(subWidget); + RelativeLayoutParameter* layoutParameter = dynamic_cast(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); + + if (layoutParameter) + { + if (layoutParameter->_put) + { + continue; + } + Point ap = child->getAnchorPoint(); + Size cs = child->getSize(); + RelativeAlign align = layoutParameter->getAlign(); + const char* relativeName = layoutParameter->getRelativeToWidgetName(); + Widget* relativeWidget = nullptr; + RelativeLayoutParameter* relativeWidgetLP = nullptr; + float finalPosX = 0.0f; + float finalPosY = 0.0f; + if (relativeName && strcmp(relativeName, "")) + { + relativeWidget = Helper::seekWidgetByRelativeName(this, relativeName); + if (relativeWidget) + { + relativeWidgetLP = dynamic_cast(relativeWidget->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE)); + } + } + switch (align) + { + case RELATIVE_ALIGN_NONE: + case RELATIVE_ALIGN_PARENT_TOP_LEFT: + finalPosX = ap.x * cs.width; + finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height); + break; + case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL: + finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x); + finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height); + break; + case RELATIVE_ALIGN_PARENT_TOP_RIGHT: + finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); + finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height); + break; + case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL: + finalPosX = ap.x * cs.width; + finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y); + break; + case RELATIVE_CENTER_IN_PARENT: + finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x); + finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y); + break; + case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL: + finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); + finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y); + break; + case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM: + finalPosX = ap.x * cs.width; + finalPosY = ap.y * cs.height; + break; + case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL: + finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x); + finalPosY = ap.y * cs.height; + break; + case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM: + finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width); + finalPosY = ap.y * cs.height; + break; + + case RELATIVE_LOCATION_ABOVE_LEFTALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationBottom = relativeWidget->getTopInParent(); + float locationLeft = relativeWidget->getLeftInParent(); + finalPosY = locationBottom + ap.y * cs.height; + finalPosX = locationLeft + ap.x * cs.width; + } + break; + case RELATIVE_LOCATION_ABOVE_CENTER: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + Size rbs = relativeWidget->getSize(); + float locationBottom = relativeWidget->getTopInParent(); + + finalPosY = locationBottom + ap.y * cs.height; + finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f; + } + break; + case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationBottom = relativeWidget->getTopInParent(); + float locationRight = relativeWidget->getRightInParent(); + finalPosY = locationBottom + ap.y * cs.height; + finalPosX = locationRight - (1.0f - ap.x) * cs.width; + } + break; + case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationTop = relativeWidget->getTopInParent(); + float locationRight = relativeWidget->getLeftInParent(); + finalPosY = locationTop - (1.0f - ap.y) * cs.height; + finalPosX = locationRight - (1.0f - ap.x) * cs.width; + } + break; + case RELATIVE_LOCATION_LEFT_OF_CENTER: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + Size rbs = relativeWidget->getSize(); + float locationRight = relativeWidget->getLeftInParent(); + finalPosX = locationRight - (1.0f - ap.x) * cs.width; + + finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f; + } + break; + case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationBottom = relativeWidget->getBottomInParent(); + float locationRight = relativeWidget->getLeftInParent(); + finalPosY = locationBottom + ap.y * cs.height; + finalPosX = locationRight - (1.0f - ap.x) * cs.width; + } + break; + case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationTop = relativeWidget->getTopInParent(); + float locationLeft = relativeWidget->getRightInParent(); + finalPosY = locationTop - (1.0f - ap.y) * cs.height; + finalPosX = locationLeft + ap.x * cs.width; + } + break; + case RELATIVE_LOCATION_RIGHT_OF_CENTER: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + Size rbs = relativeWidget->getSize(); + float locationLeft = relativeWidget->getRightInParent(); + finalPosX = locationLeft + ap.x * cs.width; + + finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f; + } + break; + case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationBottom = relativeWidget->getBottomInParent(); + float locationLeft = relativeWidget->getRightInParent(); + finalPosY = locationBottom + ap.y * cs.height; + finalPosX = locationLeft + ap.x * cs.width; + } + break; + case RELATIVE_LOCATION_BELOW_LEFTALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationTop = relativeWidget->getBottomInParent(); + float locationLeft = relativeWidget->getLeftInParent(); + finalPosY = locationTop - (1.0f - ap.y) * cs.height; + finalPosX = locationLeft + ap.x * cs.width; + } + break; + case RELATIVE_LOCATION_BELOW_CENTER: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + Size rbs = relativeWidget->getSize(); + float locationTop = relativeWidget->getBottomInParent(); + + finalPosY = locationTop - (1.0f - ap.y) * cs.height; + finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f; + } + break; + case RELATIVE_LOCATION_BELOW_RIGHTALIGN: + if (relativeWidget) + { + if (relativeWidgetLP && !relativeWidgetLP->_put) + { + continue; + } + float locationTop = relativeWidget->getBottomInParent(); + float locationRight = relativeWidget->getRightInParent(); + finalPosY = locationTop - (1.0f - ap.y) * cs.height; + finalPosX = locationRight - (1.0f - ap.x) * cs.width; + } + break; + default: + break; + } + Margin relativeWidgetMargin; + Margin mg = layoutParameter->getMargin(); + if (relativeWidgetLP) + { + relativeWidgetMargin = relativeWidgetLP->getMargin(); + } + //handle margin + switch (align) + { + case RELATIVE_ALIGN_NONE: + case RELATIVE_ALIGN_PARENT_TOP_LEFT: + finalPosX += mg.left; + finalPosY -= mg.top; + break; + case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL: + finalPosY -= mg.top; + break; + case RELATIVE_ALIGN_PARENT_TOP_RIGHT: + finalPosX -= mg.right; + finalPosY -= mg.top; + break; + case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL: + finalPosX += mg.left; + break; + case RELATIVE_CENTER_IN_PARENT: + break; + case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL: + finalPosX -= mg.right; + break; + case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM: + finalPosX += mg.left; + finalPosY += mg.bottom; + break; + case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL: + finalPosY += mg.bottom; + break; + case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM: + finalPosX -= mg.right; + finalPosY += mg.bottom; + break; + + case RELATIVE_LOCATION_ABOVE_LEFTALIGN: + finalPosY += mg.bottom; + finalPosX += mg.left; + break; + case RELATIVE_LOCATION_ABOVE_RIGHTALIGN: + finalPosY += mg.bottom; + finalPosX -= mg.right; + break; + case RELATIVE_LOCATION_ABOVE_CENTER: + finalPosY += mg.bottom; + break; + + case RELATIVE_LOCATION_LEFT_OF_TOPALIGN: + finalPosX -= mg.right; + finalPosY -= mg.top; + break; + case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN: + finalPosX -= mg.right; + finalPosY += mg.bottom; + break; + case RELATIVE_LOCATION_LEFT_OF_CENTER: + finalPosX -= mg.right; + break; + + case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN: + finalPosX += mg.left; + finalPosY -= mg.top; + break; + case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN: + finalPosX += mg.left; + finalPosY += mg.bottom; + break; + case RELATIVE_LOCATION_RIGHT_OF_CENTER: + finalPosX += mg.left; + break; + + case RELATIVE_LOCATION_BELOW_LEFTALIGN: + finalPosY -= mg.top; + finalPosX += mg.left; + break; + case RELATIVE_LOCATION_BELOW_RIGHTALIGN: + finalPosY -= mg.top; + finalPosX -= mg.right; + break; + case RELATIVE_LOCATION_BELOW_CENTER: + finalPosY -= mg.top; + break; + default: + break; + } + child->setPosition(Point(finalPosX, finalPosY)); + layoutParameter->_put = true; + unlayoutChildCount--; + } + } + } + break; + } + default: + break; + } + _doLayoutDirty = false; +} + +std::string Layout::getDescription() const +{ + return "Layout"; +} + +Widget* Layout::createCloneInstance() +{ + return Layout::create(); +} + +void Layout::copyClonedWidgetChildren(Widget* model) +{ + Widget::copyClonedWidgetChildren(model); +} + +void Layout::copySpecialProperties(Widget *widget) +{ + Layout* layout = dynamic_cast(widget); + if (layout) + { + setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled); + setBackGroundImage(layout->_backGroundImageFileName.c_str(),layout->_bgImageTexType); + setBackGroundImageCapInsets(layout->_backGroundImageCapInsets); + setBackGroundColorType(layout->_colorType); + setBackGroundColor(layout->_cColor); + setBackGroundColor(layout->_gStartColor, layout->_gEndColor); + setBackGroundColorOpacity(layout->_cOpacity); + setBackGroundColorVector(layout->_alongVector); + setLayoutType(layout->_layoutType); + setClippingEnabled(layout->_clippingEnabled); + setClippingType(layout->_clippingType); + } +} +} +NS_CC_END diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h new file mode 100644 index 0000000000..f525ab870a --- /dev/null +++ b/cocos/ui/UILayout.h @@ -0,0 +1,358 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __LAYOUT_H__ +#define __LAYOUT_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + LAYOUT_COLOR_NONE, + LAYOUT_COLOR_SOLID, + LAYOUT_COLOR_GRADIENT +}LayoutBackGroundColorType; + +typedef enum +{ + LAYOUT_ABSOLUTE, + LAYOUT_LINEAR_VERTICAL, + LAYOUT_LINEAR_HORIZONTAL, + LAYOUT_RELATIVE +}LayoutType; + +typedef enum { + LAYOUT_CLIPPING_STENCIL, + LAYOUT_CLIPPING_SCISSOR +}LayoutClippingType; + +/** + * @js NA + * @lua NA + */ +class Layout : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + Layout(); + + /** + * Default destructor + */ + virtual ~Layout(); + + /** + * Allocates and initializes a layout. + */ + static Layout* create(); + + //background + /** + * Sets a background image for layout + * + * @param fileName image file path. + * + * @param texType @see TextureResType. UI_TEX_TYPE_LOCAL means local file, UI_TEX_TYPE_PLIST means sprite frame. + */ + void setBackGroundImage(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Sets a background image capinsets for layout, if the background image is a scale9 render. + * + * @param capinsets of background image. + * + */ + void setBackGroundImageCapInsets(const Rect& capInsets); + + const Rect& getBackGroundImageCapInsets(); + + /** + * Sets Color Type for layout. + * + * @param type @see LayoutBackGroundColorType. + */ + void setBackGroundColorType(LayoutBackGroundColorType type); + + LayoutBackGroundColorType getBackGroundColorType(); + + /** + * Sets background iamge use scale9 renderer. + * + * @param enabled true that use scale9 renderer, false otherwise. + */ + void setBackGroundImageScale9Enabled(bool enabled); + + bool isBackGroundImageScale9Enabled(); + + /** + * Sets background color for layout, if color type is LAYOUT_COLOR_SOLID + * + * @param color + */ + void setBackGroundColor(const Color3B &color); + + const Color3B& getBackGroundColor(); + + /** + * Sets background color for layout, if color type is LAYOUT_COLOR_GRADIENT + * + * @param start color + * + * @param end color + */ + void setBackGroundColor(const Color3B &startColor, const Color3B &endColor); + + const Color3B& getBackGroundStartColor(); + + const Color3B& getBackGroundEndColor(); + + /** + * Sets background opacity layout. + * + * @param opacity + */ + void setBackGroundColorOpacity(GLubyte opacity); + + GLubyte getBackGroundColorOpacity(); + + /** + * Sets background color vector for layout, if color type is LAYOUT_COLOR_GRADIENT + * + * @param vector + */ + void setBackGroundColorVector(const Point &vector); + + const Point& getBackGroundColorVector(); + + void setBackGroundImageColor(const ccColor3B& color); + + void setBackGroundImageOpacity(GLubyte opacity); + + const ccColor3B& getBackGroundImageColor(); + + GLubyte getBackGroundImageOpacity(); + + /** + * Remove the background image of layout. + */ + void removeBackGroundImage(); + + /** + * Gets background image texture size. + * + * @return background image texture size. + */ + const Size& getBackGroundImageTextureSize() const; + + /** + * Changes if layout can clip it's content and child. + * + * If you really need this, please enable it. But it would reduce the rendering efficiency. + * + * @param clipping enabled. + */ + virtual void setClippingEnabled(bool enabled); + + void setClippingType(LayoutClippingType type); + + LayoutClippingType getClippingType(); + + /** + * Gets if layout is clipping enabled. + * + * @return if layout is clipping enabled. + */ + virtual bool isClippingEnabled(); + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + /** + * Sets LayoutType. + * + * @see LayoutType + * + * @param LayoutType + */ + virtual void setLayoutType(LayoutType type); + + /** + * Gets LayoutType. + * + * @see LayoutType + * + * @return LayoutType + */ + virtual LayoutType getLayoutType() const; + + virtual void addChild(Node * child) override; + /** + * Adds a child to the container with a z-order + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) + */ + virtual void addChild(Node * child, int zOrder) override; + /** + * Adds a child to the container with z order and tag + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) + * @param tag A interger to identify the node easily. Please refer to setTag(int) + */ + virtual void addChild(Node* child, int zOrder, int tag) override; + + virtual void visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; + + virtual void removeChild(Node* child, bool cleanup = true) override; + + /** + * Removes all children from the container with a cleanup. + * + * @see `removeAllChildrenWithCleanup(bool)` + */ + virtual void removeAllChildren() override; + /** + * Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. + * + * @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise. + * @js removeAllChildren + * @lua removeAllChildren + */ + virtual void removeAllChildrenWithCleanup(bool cleanup) override; + + virtual void sortAllChildren() override; + + void requestDoLayout(); + + virtual void onEnter() override; + virtual void onExit() override; + + virtual bool hitTest(const Point &pt); +protected: + //override "init" method of widget. + virtual bool init() override; + + //override "onSizeChanged" method of widget. + virtual void onSizeChanged() override; + + //init background image renderer. + void addBackGroundImage(); + + void supplyTheLayoutParameterLackToChild(Widget* child); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; + virtual void copyClonedWidgetChildren(Widget* model) override; + + void stencilClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated); + void scissorClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated); + + void setStencilClippingSize(const Size& size); + const Rect& getClippingRect(); + virtual void doLayout(); + + //clipping + void onBeforeVisitStencil(); + void onAfterDrawStencil(); + void onAfterVisitStencil(); + + void onBeforeVisitScissor(); + void onAfterVisitScissor(); + void updateBackGroundImageColor(); + void updateBackGroundImageOpacity(); + void updateBackGroundImageRGBA(); +protected: + bool _clippingEnabled; + + //background + bool _backGroundScale9Enabled; + Node* _backGroundImage; + std::string _backGroundImageFileName; + Rect _backGroundImageCapInsets; + LayoutBackGroundColorType _colorType; + TextureResType _bgImageTexType; + LayerColor* _colorRender; + LayerGradient* _gradientRender; + Color3B _cColor; + Color3B _gStartColor; + Color3B _gEndColor; + Point _alongVector; + GLubyte _cOpacity; + Size _backGroundImageTextureSize; + LayoutType _layoutType; + LayoutClippingType _clippingType; + DrawNode* _clippingStencil; + bool _scissorRectDirty; + Rect _clippingRect; + Layout* _clippingParent; + bool _doLayoutDirty; + bool _clippingRectDirty; + + //clipping + + GLboolean _currentStencilEnabled; + GLuint _currentStencilWriteMask; + GLenum _currentStencilFunc; + GLint _currentStencilRef; + GLuint _currentStencilValueMask; + GLenum _currentStencilFail; + GLenum _currentStencilPassDepthFail; + GLenum _currentStencilPassDepthPass; + GLboolean _currentDepthWriteMask; + + GLboolean _currentAlphaTestEnabled; + GLenum _currentAlphaTestFunc; + GLclampf _currentAlphaTestRef; + + + Color3B _backGroundImageColor; + GLubyte _backGroundImageOpacity; + + GLint _mask_layer_le; + GroupCommand _groupCommand; + CustomCommand _beforeVisitCmdStencil; + CustomCommand _afterDrawStencilCmd; + CustomCommand _afterVisitCmdStencil; + CustomCommand _beforeVisitCmdScissor; + CustomCommand _afterVisitCmdScissor; +}; + +} +NS_CC_END +#endif /* defined(__Layout__) */ diff --git a/cocos/ui/UILayoutDefine.cpp b/cocos/ui/UILayoutDefine.cpp new file mode 100644 index 0000000000..b1cc88d46b --- /dev/null +++ b/cocos/ui/UILayoutDefine.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +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 "UILayoutDefine.h" + +NS_CC_BEGIN + +namespace ui { + + +Margin::Margin(void) : left(0), top(0), right(0), bottom(0) +{ +} + +Margin::Margin(float l, float t, float r, float b) : left(l), top(t), right(r), bottom(b) +{ +} + +Margin::Margin(const Margin& other) : left(other.left), top(other.top), right(other.right), bottom(other.bottom) +{ +} + +Margin& Margin::operator= (const Margin& other) +{ + setMargin(other.left, other.top, other.right, other.bottom); + return *this; +} + +void Margin::setMargin(float l, float t, float r, float b) +{ + left = l; + top = t; + right = r; + bottom = b; +} + +bool Margin::equals(const Margin &target) const +{ + return (left == target.left && top == target.top && right == target.right && bottom == target.bottom); +} + +} + +NS_CC_END diff --git a/cocos/ui/UILayoutDefine.h b/cocos/ui/UILayoutDefine.h new file mode 100644 index 0000000000..dc1af74a65 --- /dev/null +++ b/cocos/ui/UILayoutDefine.h @@ -0,0 +1,96 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UILAYOUTDEFINE_H__ +#define __UILAYOUTDEFINE_H__ + +#include "cocos2d.h" + +NS_CC_BEGIN + +namespace ui { +/** +* @js NA +* @lua NA +*/ +class Margin +{ +public: + float left; + float top; + float right; + float bottom; + +public: + Margin(); + Margin(float l, float t, float r, float b); + Margin(const Margin& other); + Margin& operator= (const Margin& other); + void setMargin(float l, float t, float r, float b); + bool equals(const Margin& target) const; +}; + +const Margin MarginZero = Margin(); + +typedef enum +{ + LINEAR_GRAVITY_NONE, + LINEAR_GRAVITY_LEFT, + LINEAR_GRAVITY_TOP, + LINEAR_GRAVITY_RIGHT, + LINEAR_GRAVITY_BOTTOM, + LINEAR_GRAVITY_CENTER_VERTICAL, + LINEAR_GRAVITY_CENTER_HORIZONTAL +}LinearGravity; + +typedef enum +{ + RELATIVE_ALIGN_NONE, + RELATIVE_ALIGN_PARENT_TOP_LEFT, + RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL, + RELATIVE_ALIGN_PARENT_TOP_RIGHT, + RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL, + RELATIVE_CENTER_IN_PARENT, + RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL, + RELATIVE_ALIGN_PARENT_LEFT_BOTTOM, + RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL, + RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM, + + RELATIVE_LOCATION_ABOVE_LEFTALIGN, + RELATIVE_LOCATION_ABOVE_CENTER, + RELATIVE_LOCATION_ABOVE_RIGHTALIGN, + RELATIVE_LOCATION_LEFT_OF_TOPALIGN, + RELATIVE_LOCATION_LEFT_OF_CENTER, + RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN, + RELATIVE_LOCATION_RIGHT_OF_TOPALIGN, + RELATIVE_LOCATION_RIGHT_OF_CENTER, + RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN, + RELATIVE_LOCATION_BELOW_LEFTALIGN, + RELATIVE_LOCATION_BELOW_CENTER, + RELATIVE_LOCATION_BELOW_RIGHTALIGN +}RelativeAlign; + +} +NS_CC_END +#endif /* defined(__UILayoutDefine__) */ diff --git a/cocos/ui/UILayoutParameter.cpp b/cocos/ui/UILayoutParameter.cpp new file mode 100644 index 0000000000..0957980f74 --- /dev/null +++ b/cocos/ui/UILayoutParameter.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** + 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/UILayoutParameter.h" +#include "ui/UILayout.h" + +NS_CC_BEGIN + +namespace ui { + + +LayoutParameter* LayoutParameter::create() +{ + LayoutParameter* parameter = new LayoutParameter(); + if (parameter) + { + parameter->autorelease(); + return parameter; + } + CC_SAFE_DELETE(parameter); + return nullptr; +} + +void LayoutParameter::setMargin(const Margin &margin) +{ + _margin = margin; +} + +const Margin& LayoutParameter::getMargin() const +{ + return _margin; +} + +LayoutParameterType LayoutParameter::getLayoutType() const +{ + return _layoutParameterType; +} + +LayoutParameter* LayoutParameter::clone() +{ + LayoutParameter* clonedParameter = createCloneInstance(); + clonedParameter->copyProperties(this); + return clonedParameter; +} + +LayoutParameter* LayoutParameter::createCloneInstance() +{ + return LayoutParameter::create(); +} + +void LayoutParameter::copyProperties(LayoutParameter *model) +{ + _margin = model->_margin; +} + +LinearLayoutParameter* LinearLayoutParameter::create() +{ + LinearLayoutParameter* parameter = new LinearLayoutParameter(); + if (parameter) + { + parameter->autorelease(); + return parameter; + } + CC_SAFE_DELETE(parameter); + return nullptr; +} + +void LinearLayoutParameter::setGravity(LinearGravity gravity) +{ + _linearGravity = gravity; +} + +LinearGravity LinearLayoutParameter::getGravity() const +{ + return _linearGravity; +} + +LayoutParameter* LinearLayoutParameter::createCloneInstance() +{ + return LinearLayoutParameter::create(); +} + +void LinearLayoutParameter::copyProperties(LayoutParameter *model) +{ + LayoutParameter::copyProperties(model); + LinearLayoutParameter* parameter = dynamic_cast(model); + if (parameter) + { + setGravity(parameter->_linearGravity); + } +} + +RelativeLayoutParameter* RelativeLayoutParameter::create() +{ + RelativeLayoutParameter* parameter = new RelativeLayoutParameter(); + if (parameter) + { + parameter->autorelease(); + return parameter; + } + CC_SAFE_DELETE(parameter); + return nullptr; +} + +void RelativeLayoutParameter::setAlign(RelativeAlign align) +{ + _relativeAlign = align; +} + +RelativeAlign RelativeLayoutParameter::getAlign() const +{ + return _relativeAlign; +} + +void RelativeLayoutParameter::setRelativeToWidgetName(const char *name) +{ + _relativeWidgetName = name; +} + +const char* RelativeLayoutParameter::getRelativeToWidgetName() const +{ + return _relativeWidgetName.c_str(); +} + +void RelativeLayoutParameter::setRelativeName(const char* name) +{ + _relativeLayoutName = name; +} + +const char* RelativeLayoutParameter::getRelativeName() const +{ + return _relativeLayoutName.c_str(); +} + +LayoutParameter* RelativeLayoutParameter::createCloneInstance() +{ + return RelativeLayoutParameter::create(); +} + +void RelativeLayoutParameter::copyProperties(LayoutParameter *model) +{ + LayoutParameter::copyProperties(model); + RelativeLayoutParameter* parameter = dynamic_cast(model); + if (parameter) + { + setAlign(parameter->_relativeAlign); + setRelativeName(parameter->_relativeLayoutName.c_str()); + setRelativeToWidgetName(parameter->_relativeWidgetName.c_str()); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UILayoutParameter.h b/cocos/ui/UILayoutParameter.h new file mode 100644 index 0000000000..c0f0f5dea6 --- /dev/null +++ b/cocos/ui/UILayoutParameter.h @@ -0,0 +1,226 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + +#ifndef __LAYOUTPARMETER_H__ +#define __LAYOUTPARMETER_H__ + +#include "ui/UILayoutDefine.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + LAYOUT_PARAMETER_NONE, + LAYOUT_PARAMETER_LINEAR, + LAYOUT_PARAMETER_RELATIVE +}LayoutParameterType; +/** +* @js NA +* @lua NA +*/ +class LayoutParameter : public Ref +{ +public: + /** + * Default constructor + */ + LayoutParameter() : _margin(Margin()){_layoutParameterType = LAYOUT_PARAMETER_NONE;}; + + /** + * Default destructor + */ + virtual ~LayoutParameter(){}; + + /** + * Allocates and initializes. + * @return A initialized LayoutParameter which is marked as "autorelease". + */ + static LayoutParameter* create(); + + /** + * Sets Margin parameter for LayoutParameter. + * + * @see Margin + * + * @param margin + */ + void setMargin(const Margin& margin); + + /** + * Gets Margin parameter of LayoutParameter. + * + * @see Margin + * + * @return const Margin& + */ + const Margin& getMargin() const; + + /** + * Gets LayoutParameterType of LayoutParameter. + * + * @see LayoutParameterType + * + * @return LayoutParameterType + */ + LayoutParameterType getLayoutType() const; + + LayoutParameter* clone(); + virtual LayoutParameter* createCloneInstance(); + virtual void copyProperties(LayoutParameter* model); +protected: + Margin _margin; + LayoutParameterType _layoutParameterType; +}; +/** +* @js NA +* @lua NA +*/ +class LinearLayoutParameter : public LayoutParameter +{ +public: + /** + * Default constructor + */ + LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE){_layoutParameterType = LAYOUT_PARAMETER_LINEAR;}; + + /** + * Default destructor + */ + virtual ~LinearLayoutParameter(){}; + + /** + * Allocates and initializes. + * @return A initialized LayoutParameter which is marked as "autorelease". + */ + static LinearLayoutParameter* create(); + + /** + * Sets LinearGravity parameter for LayoutParameter. + * + * @see LinearGravity + * + * @param LinearGravity + */ + void setGravity(LinearGravity gravity); + + /** + * Gets LinearGravity parameter for LayoutParameter. + * + * @see LinearGravity + * + * @return LinearGravity + */ + LinearGravity getGravity() const; + virtual LayoutParameter* createCloneInstance() override; + virtual void copyProperties(LayoutParameter* model) override; +protected: + LinearGravity _linearGravity; +}; +/** +* @js NA +* @lua NA +*/ + +class RelativeLayoutParameter : public LayoutParameter +{ +public: + /** + * Default constructor + */ + RelativeLayoutParameter() : _relativeAlign(RELATIVE_ALIGN_NONE),_relativeWidgetName(""),_relativeLayoutName(""),_put(false){_layoutParameterType = LAYOUT_PARAMETER_RELATIVE;}; + + /** + * Default destructor + */ + virtual ~RelativeLayoutParameter(){}; + + /** + * Allocates and initializes. + * @return A initialized LayoutParameter which is marked as "autorelease". + */ + static RelativeLayoutParameter* create(); + + /** + * Sets RelativeAlign parameter for LayoutParameter. + * + * @see RelativeAlign + * + * @param RelativeAlign + */ + void setAlign(RelativeAlign align); + + /** + * Gets RelativeAlign parameter for LayoutParameter. + * + * @see RelativeAlign + * + * @return RelativeAlign + */ + RelativeAlign getAlign() const; + + /** + * Sets a key for LayoutParameter. Witch widget named this is relative to. + * + * @param name + */ + void setRelativeToWidgetName(const char* name); + + /** + * Gets the key of LayoutParameter. Witch widget named this is relative to. + * + * @return name + */ + const char* getRelativeToWidgetName() const; + + /** + * Sets a name in Relative Layout for LayoutParameter. + * + * @param name + */ + void setRelativeName(const char* name); + + /** + * Gets a name in Relative Layout of LayoutParameter. + * + * @return name + */ + const char* getRelativeName() const; + + virtual LayoutParameter* createCloneInstance() override; + virtual void copyProperties(LayoutParameter* model) override; +protected: + RelativeAlign _relativeAlign; + std::string _relativeWidgetName; + std::string _relativeLayoutName; + bool _put; + friend class Layout; +}; + +} + +NS_CC_END + +#endif /* defined(__LayoutParameter__) */ diff --git a/cocos/ui/UIListView.cpp b/cocos/ui/UIListView.cpp new file mode 100644 index 0000000000..c58f3592db --- /dev/null +++ b/cocos/ui/UIListView.cpp @@ -0,0 +1,480 @@ +/**************************************************************************** +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/UIListView.h" +#include "ui/UIHelper.h" +#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" + +NS_CC_BEGIN + +namespace ui { + +IMPLEMENT_CLASS_GUI_INFO(ListView) + +ListView::ListView(): +_model(nullptr), +_gravity(LISTVIEW_GRAVITY_CENTER_HORIZONTAL), +_itemsMargin(0.0f), +_listViewEventListener(nullptr), +_listViewEventSelector(nullptr), +_curSelectedIndex(0), +_refreshViewDirty(true) +{ + +} + +ListView::~ListView() +{ + _listViewEventListener = nullptr; + _listViewEventSelector = nullptr; + _items.clear(); +} + +ListView* ListView::create() +{ + ListView* widget = new ListView(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +bool ListView::init() +{ + if (ScrollView::init()) + { + setLayoutType(LAYOUT_LINEAR_VERTICAL); + return true; + } + return false; +} + +void ListView::setItemModel(Widget *model) +{ + if (!model) + { + return; + } + CC_SAFE_RELEASE_NULL(_model); + _model = model; + CC_SAFE_RETAIN(_model); +} + +void ListView::updateInnerContainerSize() +{ + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: + { + size_t length = _items.size(); + float totalHeight = (length - 1) * _itemsMargin; + for (auto& item : _items) + { + totalHeight += item->getSize().height; + } + float finalWidth = _size.width; + float finalHeight = totalHeight; + setInnerContainerSize(Size(finalWidth, finalHeight)); + break; + } + case SCROLLVIEW_DIR_HORIZONTAL: + { + size_t length = _items.size(); + float totalWidth = (length - 1) * _itemsMargin; + for (auto& item : _items) + { + totalWidth += item->getSize().width; + } + float finalWidth = totalWidth; + float finalHeight = _size.height; + setInnerContainerSize(Size(finalWidth, finalHeight)); + break; + } + default: + break; + } +} + +void ListView::remedyLayoutParameter(Widget *item) +{ + if (!item) + { + return; + } + switch (_direction) { + case SCROLLVIEW_DIR_VERTICAL: + { + LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); + if (!llp) + { + LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); + switch (_gravity) { + case LISTVIEW_GRAVITY_LEFT: + defaultLp->setGravity(LINEAR_GRAVITY_LEFT); + break; + case LISTVIEW_GRAVITY_RIGHT: + defaultLp->setGravity(LINEAR_GRAVITY_RIGHT); + break; + case LISTVIEW_GRAVITY_CENTER_HORIZONTAL: + defaultLp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); + break; + default: + break; + } + if (getIndex(item) == 0) + { + defaultLp->setMargin(MarginZero); + } + else + { + defaultLp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); + } + item->setLayoutParameter(defaultLp); + } + else + { + if (getIndex(item) == 0) + { + llp->setMargin(MarginZero); + } + else + { + llp->setMargin(Margin(0.0f, _itemsMargin, 0.0f, 0.0f)); + } + switch (_gravity) { + case LISTVIEW_GRAVITY_LEFT: + llp->setGravity(LINEAR_GRAVITY_LEFT); + break; + case LISTVIEW_GRAVITY_RIGHT: + llp->setGravity(LINEAR_GRAVITY_RIGHT); + break; + case LISTVIEW_GRAVITY_CENTER_HORIZONTAL: + llp->setGravity(LINEAR_GRAVITY_CENTER_HORIZONTAL); + break; + default: + break; + } + } + break; + } + case SCROLLVIEW_DIR_HORIZONTAL: + { + LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)); + if (!llp) + { + LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); + switch (_gravity) { + case LISTVIEW_GRAVITY_TOP: + defaultLp->setGravity(LINEAR_GRAVITY_TOP); + break; + case LISTVIEW_GRAVITY_BOTTOM: + defaultLp->setGravity(LINEAR_GRAVITY_BOTTOM); + break; + case LISTVIEW_GRAVITY_CENTER_VERTICAL: + defaultLp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL); + break; + default: + break; + } + if (getIndex(item) == 0) + { + defaultLp->setMargin(MarginZero); + } + else + { + defaultLp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); + } + item->setLayoutParameter(defaultLp); + } + else + { + if (getIndex(item) == 0) + { + llp->setMargin(MarginZero); + } + else + { + llp->setMargin(Margin(_itemsMargin, 0.0f, 0.0f, 0.0f)); + } + switch (_gravity) { + case LISTVIEW_GRAVITY_TOP: + llp->setGravity(LINEAR_GRAVITY_TOP); + break; + case LISTVIEW_GRAVITY_BOTTOM: + llp->setGravity(LINEAR_GRAVITY_BOTTOM); + break; + case LISTVIEW_GRAVITY_CENTER_VERTICAL: + llp->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL); + break; + default: + break; + } + } + break; + } + default: + break; + } + +} + +void ListView::pushBackDefaultItem() +{ + if (!_model) + { + return; + } + Widget* newItem = _model->clone(); + _items.pushBack(newItem); + remedyLayoutParameter(newItem); + addChild(newItem); + _refreshViewDirty = true; +} + +void ListView::insertDefaultItem(ssize_t index) +{ + if (!_model) + { + return; + } + Widget* newItem = _model->clone(); + _items.insert(index, newItem); + remedyLayoutParameter(newItem); + addChild(newItem); + _refreshViewDirty = true; +} + +void ListView::pushBackCustomItem(Widget* item) +{ + _items.pushBack(item); + remedyLayoutParameter(item); + addChild(item); + _refreshViewDirty = true; +} + +void ListView::insertCustomItem(Widget* item, ssize_t index) +{ + _items.insert(index, item); + remedyLayoutParameter(item); + addChild(item); + _refreshViewDirty = true; +} + +void ListView::removeItem(ssize_t index) +{ + Widget* item = getItem(index); + if (!item) + { + return; + } + _items.eraseObject(item); + removeChild(item); + _refreshViewDirty = true; +} + +void ListView::removeLastItem() +{ + removeItem(_items.size() -1); +} + +void ListView::removeAllItems() +{ + _items.clear(); + removeAllChildren(); +} + +Widget* ListView::getItem(ssize_t index) +{ + if (index < 0 || index >= _items.size()) + { + return nullptr; + } + return _items.at(index); +} + +Vector& ListView::getItems() +{ + return _items; +} + +ssize_t ListView::getIndex(Widget *item) const +{ + if (!item) + { + return -1; + } + return _items.getIndex(item); +} + +void ListView::setGravity(ListViewGravity gravity) +{ + if (_gravity == gravity) + { + return; + } + _gravity = gravity; + _refreshViewDirty = true; +} + +void ListView::setItemsMargin(float margin) +{ + if (_itemsMargin == margin) + { + return; + } + _itemsMargin = margin; + _refreshViewDirty = true; +} + +float ListView::getItemsMargin() +{ + return _itemsMargin; +} + +void ListView::setDirection(SCROLLVIEW_DIR dir) +{ + switch (dir) + { + case SCROLLVIEW_DIR_VERTICAL: + setLayoutType(LAYOUT_LINEAR_VERTICAL); + break; + case SCROLLVIEW_DIR_HORIZONTAL: + setLayoutType(LAYOUT_LINEAR_HORIZONTAL); + break; + case SCROLLVIEW_DIR_BOTH: + return; + default: + return; + break; + } + ScrollView::setDirection(dir); +} + +void ListView::requestRefreshView() +{ + _refreshViewDirty = true; +} + +void ListView::refreshView() +{ + ssize_t length = _items.size(); + for (int i=0; isetLocalZOrder(i); + remedyLayoutParameter(item); + } + updateInnerContainerSize(); +} + +void ListView::sortAllChildren() +{ + ScrollView::sortAllChildren(); + if (_refreshViewDirty) + { + refreshView(); + _refreshViewDirty = false; + } +} + +void ListView::addEventListenerListView(Ref *target, SEL_ListViewEvent selector) +{ + _listViewEventListener = target; + _listViewEventSelector = selector; +} + +void ListView::selectedItemEvent() +{ + if (_listViewEventListener && _listViewEventSelector) + { + (_listViewEventListener->*_listViewEventSelector)(this, LISTVIEW_ONSELECTEDITEM); + } +} + +void ListView::interceptTouchEvent(int handleState, Widget *sender, const Point &touchPoint) +{ + ScrollView::interceptTouchEvent(handleState, sender, touchPoint); + if (handleState != 1) + { + Widget* parent = sender; + while (parent) + { + if (parent && parent->getParent() == _innerContainer) + { + _curSelectedIndex = getIndex(parent); + break; + } + parent = dynamic_cast(parent->getParent()); + } + selectedItemEvent(); + } +} + +ssize_t ListView::getCurSelectedIndex() const +{ + return _curSelectedIndex; +} + +void ListView::onSizeChanged() +{ + ScrollView::onSizeChanged(); + _refreshViewDirty = true; +} + +std::string ListView::getDescription() const +{ + return "ListView"; +} + +Widget* ListView::createCloneInstance() +{ + return ListView::create(); +} + +void ListView::copyClonedWidgetChildren(Widget* model) +{ + auto& arrayItems = static_cast(model)->getItems(); + for (auto& item : arrayItems) + { + pushBackCustomItem(item->clone()); + } +} + +void ListView::copySpecialProperties(Widget *widget) +{ + ListView* listViewEx = dynamic_cast(widget); + if (listViewEx) + { + ScrollView::copySpecialProperties(widget); + setItemModel(listViewEx->_model); + setItemsMargin(listViewEx->_itemsMargin); + setGravity(listViewEx->_gravity); + } +} + +} +NS_CC_END diff --git a/cocos/ui/UIListView.h b/cocos/ui/UIListView.h new file mode 100644 index 0000000000..bcc2682e23 --- /dev/null +++ b/cocos/ui/UIListView.h @@ -0,0 +1,213 @@ +/**************************************************************************** +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. +****************************************************************************/ + + +#ifndef __UILISTVIEW_H__ +#define __UILISTVIEW_H__ + +#include "ui/UIScrollView.h" + +NS_CC_BEGIN + +namespace ui{ + +typedef enum +{ + LISTVIEW_GRAVITY_LEFT, + LISTVIEW_GRAVITY_RIGHT, + LISTVIEW_GRAVITY_CENTER_HORIZONTAL, + + LISTVIEW_GRAVITY_TOP, + LISTVIEW_GRAVITY_BOTTOM, + LISTVIEW_GRAVITY_CENTER_VERTICAL, +}ListViewGravity; + +typedef enum +{ + LISTVIEW_ONSELECTEDITEM +}ListViewEventType; + +typedef void (Ref::*SEL_ListViewEvent)(Ref*,ListViewEventType); +#define listvieweventselector(_SELECTOR) (SEL_ListViewEvent)(&_SELECTOR) + +class ListView : public ScrollView +{ + + DECLARE_CLASS_GUI_INFO + +public: + + /** + * Default constructor + */ + ListView(); + + /** + * Default destructor + */ + virtual ~ListView(); + + /** + * Allocates and initializes. + */ + static ListView* create(); + + /** + * Sets a item model for listview + * + * A model will be cloned for adding default item. + * + * @param model item model for listview + */ + void setItemModel(Widget* model); + + /** + * Push back a default item(create by a cloned model) into listview. + */ + void pushBackDefaultItem(); + + /** + * Insert a default item(create by a cloned model) into listview. + */ + void insertDefaultItem(ssize_t index); + + /** + * Push back custom item into listview. + */ + void pushBackCustomItem(Widget* item); + + /** + * Insert custom item into listview. + */ + void insertCustomItem(Widget* item, ssize_t index); + + /** + * Removes the last item of listview. + */ + void removeLastItem(); + + /** + * Removes a item whose index is same as the parameter. + * + * @param index of item. + */ + void removeItem(ssize_t index); + + void removeAllItems(); + + /** + * Returns a item whose index is same as the parameter. + * + * @param index of item. + * + * @return the item widget. + */ + Widget* getItem(ssize_t index); + + /** + * Returns the item container. + */ + Vector& getItems(); + + /** + * Returns the index of item. + * + * @param item the item which need to be checked. + * + * @return the index of item. + */ + ssize_t getIndex(Widget* item) const; + + /** + * Changes the gravity of listview. + * @see ListViewGravity + */ + void setGravity(ListViewGravity gravity); + + /** + * Changes the margin between each item. + * + * @param margin + */ + void setItemsMargin(float margin); + + float getItemsMargin(); + + virtual void sortAllChildren() override; + + ssize_t getCurSelectedIndex() const; + + void addEventListenerListView(Ref* target, SEL_ListViewEvent selector); + + /** + * Changes scroll direction of scrollview. + * + * @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll + * + * @param SCROLLVIEW_DIR + */ + virtual void setDirection(SCROLLVIEW_DIR dir) override; + + virtual std::string getDescription() const override; + + void requestRefreshView(); + void refreshView(); +protected: + virtual void addChild(Node* child) override{ScrollView::addChild(child);}; + virtual void addChild(Node * child, int zOrder) override{ScrollView::addChild(child, zOrder);}; + virtual void addChild(Node* child, int zOrder, int tag) override{ScrollView::addChild(child, zOrder, tag);}; + virtual void removeChild(Node* widget, bool cleanup = true) override{ScrollView::removeChild(widget, cleanup);}; + + virtual void removeAllChildren() override{removeAllChildrenWithCleanup(true);}; + virtual void removeAllChildrenWithCleanup(bool cleanup) override {ScrollView::removeAllChildrenWithCleanup(cleanup);}; + virtual Vector& getChildren() override{return ScrollView::getChildren();}; + virtual const Vector& getChildren() const override{return ScrollView::getChildren();}; + virtual ssize_t getChildrenCount() const override {return ScrollView::getChildrenCount();}; + virtual Node * getChildByTag(int tag) override {return ScrollView::getChildByTag(tag);}; + virtual Widget* getChildByName(const char* name) override {return ScrollView::getChildByName(name);}; + virtual bool init() override; + void updateInnerContainerSize(); + void remedyLayoutParameter(Widget* item); + virtual void onSizeChanged() override; + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; + virtual void copyClonedWidgetChildren(Widget* model) override; + void selectedItemEvent(); + virtual void interceptTouchEvent(int handleState,Widget* sender,const Point &touchPoint) override; +protected: + + Widget* _model; + Vector _items; + ListViewGravity _gravity; + float _itemsMargin; + Ref* _listViewEventListener; + SEL_ListViewEvent _listViewEventSelector; + ssize_t _curSelectedIndex; + bool _refreshViewDirty; +}; + +} +NS_CC_END + +#endif /* defined(__ListView__) */ diff --git a/cocos/ui/UILoadingBar.cpp b/cocos/ui/UILoadingBar.cpp new file mode 100644 index 0000000000..643ff18a47 --- /dev/null +++ b/cocos/ui/UILoadingBar.cpp @@ -0,0 +1,370 @@ +/**************************************************************************** +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/UILoadingBar.h" +#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" + +NS_CC_BEGIN + +namespace ui { + +static const int BAR_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(LoadingBar) + +LoadingBar::LoadingBar(): +_barType(LoadingBarTypeLeft), +_percent(100), +_totalLength(0), +_barRenderer(nullptr), +_renderBarTexType(UI_TEX_TYPE_LOCAL), +_barRendererTextureSize(Size::ZERO), +_scale9Enabled(false), +_prevIgnoreSize(true), +_capInsets(Rect::ZERO), +_textureFile("") +{ +} + +LoadingBar::~LoadingBar() +{ + +} + +LoadingBar* LoadingBar::create() +{ + LoadingBar* widget = new LoadingBar(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void LoadingBar::initRenderer() +{ + _barRenderer = Sprite::create(); + Node::addChild(_barRenderer, BAR_RENDERER_Z, -1); + _barRenderer->setAnchorPoint(Point(0.0,0.5)); +} + +void LoadingBar::setDirection(LoadingBarType dir) +{ + if (_barType == dir) + { + return; + } + _barType = dir; + + switch (_barType) + { + case LoadingBarTypeLeft: + _barRenderer->setAnchorPoint(Point(0.0f,0.5f)); + _barRenderer->setPosition(Point(-_totalLength*0.5f,0.0f)); + if (!_scale9Enabled) + { + static_cast(_barRenderer)->setFlippedX(false); + } + break; + case LoadingBarTypeRight: + _barRenderer->setAnchorPoint(Point(1.0f,0.5f)); + _barRenderer->setPosition(Point(_totalLength*0.5f,0.0f)); + if (!_scale9Enabled) + { + static_cast(_barRenderer)->setFlippedX(true); + } + break; + } +} + +int LoadingBar::getDirection() +{ + return _barType; +} + +void LoadingBar::loadTexture(const char* texture,TextureResType texType) +{ + if (!texture || strcmp(texture, "") == 0) + { + return; + } + _renderBarTexType = texType; + _textureFile = texture; + switch (_renderBarTexType) + { + case UI_TEX_TYPE_LOCAL: + if (_scale9Enabled) + { + extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); + barRendererScale9->initWithFile(texture); + barRendererScale9->setCapInsets(_capInsets); + } + else + { + static_cast(_barRenderer)->setTexture(texture); + } + break; + case UI_TEX_TYPE_PLIST: + if (_scale9Enabled) + { + extension::Scale9Sprite* barRendererScale9 = static_cast(_barRenderer); + barRendererScale9->initWithSpriteFrameName(texture); + barRendererScale9->setCapInsets(_capInsets); + } + else + { + static_cast(_barRenderer)->setSpriteFrame(texture); + } + break; + default: + break; + } + updateRGBAToRenderer(_barRenderer); + _barRendererTextureSize = _barRenderer->getContentSize(); + + switch (_barType) + { + case LoadingBarTypeLeft: + _barRenderer->setAnchorPoint(Point(0.0f,0.5f)); + if (!_scale9Enabled) + { + static_cast(_barRenderer)->setFlippedX(false); + } + break; + case LoadingBarTypeRight: + _barRenderer->setAnchorPoint(Point(1.0f,0.5f)); + if (!_scale9Enabled) + { + static_cast(_barRenderer)->setFlippedX(true); + } + break; + } + barRendererScaleChangedWithSize(); +} + +void LoadingBar::setScale9Enabled(bool enabled) +{ + if (_scale9Enabled == enabled) + { + return; + } + _scale9Enabled = enabled; + Node::removeChild(_barRenderer); + _barRenderer = nullptr; + if (_scale9Enabled) + { + _barRenderer = extension::Scale9Sprite::create(); + } + else + { + _barRenderer = Sprite::create(); + } + loadTexture(_textureFile.c_str(),_renderBarTexType); + Node::addChild(_barRenderer, BAR_RENDERER_Z, -1); + if (_scale9Enabled) + { + bool ignoreBefore = _ignoreSize; + ignoreContentAdaptWithSize(false); + _prevIgnoreSize = ignoreBefore; + } + else + { + ignoreContentAdaptWithSize(_prevIgnoreSize); + } + setCapInsets(_capInsets); + setPercent(_percent); +} + +bool LoadingBar::isScale9Enabled() +{ + return _scale9Enabled; +} + +void LoadingBar::setCapInsets(const Rect &capInsets) +{ + _capInsets = capInsets; + if (!_scale9Enabled) + { + return; + } + static_cast(_barRenderer)->setCapInsets(capInsets); +} + +const Rect& LoadingBar::getCapInsets() +{ + return _capInsets; +} + +void LoadingBar::setPercent(int percent) +{ + if ( percent < 0 || percent > 100) + { + return; + } + if (_totalLength <= 0) + { + return; + } + _percent = percent; + float res = _percent / 100.0f; + + if (_scale9Enabled) + { + setScale9Scale(); + } + else + { + Sprite* spriteRenderer = static_cast(_barRenderer); + Rect rect = spriteRenderer->getTextureRect(); + rect.size.width = _barRendererTextureSize.width * res; + spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size); + } +} + +int LoadingBar::getPercent() +{ + return _percent; +} + +void LoadingBar::onSizeChanged() +{ + Widget::onSizeChanged(); + barRendererScaleChangedWithSize(); +} + +void LoadingBar::ignoreContentAdaptWithSize(bool ignore) +{ + if (!_scale9Enabled || (_scale9Enabled && !ignore)) + { + Widget::ignoreContentAdaptWithSize(ignore); + _prevIgnoreSize = ignore; + } +} + +const Size& LoadingBar::getContentSize() const +{ + return _barRendererTextureSize; +} + +Node* LoadingBar::getVirtualRenderer() +{ + return _barRenderer; +} + +void LoadingBar::barRendererScaleChangedWithSize() +{ + if (_ignoreSize) + { + if (!_scale9Enabled) + { + _totalLength = _barRendererTextureSize.width; + _barRenderer->setScale(1.0f); + _size = _barRendererTextureSize; + } + } + else + { + _totalLength = _size.width; + if (_scale9Enabled) + { + setScale9Scale(); + } + else + { + + Size textureSize = _barRendererTextureSize; + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _barRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _barRenderer->setScaleX(scaleX); + _barRenderer->setScaleY(scaleY); + } + } + switch (_barType) + { + case LoadingBarTypeLeft: + _barRenderer->setPosition(Point(-_totalLength * 0.5f, 0.0f)); + break; + case LoadingBarTypeRight: + _barRenderer->setPosition(Point(_totalLength * 0.5f, 0.0f)); + break; + default: + break; + } +} + +void LoadingBar::setScale9Scale() +{ + float width = (float)(_percent) / 100.0f * _totalLength; + static_cast(_barRenderer)->setPreferredSize(Size(width, _size.height)); +} + +std::string LoadingBar::getDescription() const +{ + return "LoadingBar"; +} + +void LoadingBar::updateTextureColor() +{ + updateColorToRenderer(_barRenderer); +} + +void LoadingBar::updateTextureOpacity() +{ + updateOpacityToRenderer(_barRenderer); +} + +void LoadingBar::updateTextureRGBA() +{ + updateRGBAToRenderer(_barRenderer); +} + +Widget* LoadingBar::createCloneInstance() +{ + return LoadingBar::create(); +} + +void LoadingBar::copySpecialProperties(Widget *widget) +{ + LoadingBar* loadingBar = dynamic_cast(widget); + if (loadingBar) + { + _prevIgnoreSize = loadingBar->_prevIgnoreSize; + setScale9Enabled(loadingBar->_scale9Enabled); + loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType); + setCapInsets(loadingBar->_capInsets); + setPercent(loadingBar->_percent); + setDirection(loadingBar->_barType); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UILoadingBar.h b/cocos/ui/UILoadingBar.h new file mode 100644 index 0000000000..b6eaeed234 --- /dev/null +++ b/cocos/ui/UILoadingBar.h @@ -0,0 +1,161 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UILOADINGBAR_H__ +#define __UILOADINGBAR_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + LoadingBarTypeLeft, + LoadingBarTypeRight +}LoadingBarType; +/** +* @js NA +* @lua NA +*/ +class LoadingBar : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + LoadingBar(); + + /** + * Default destructor + */ + virtual ~LoadingBar(); + + /** + * Allocates and initializes. + */ + static LoadingBar* create(); + + /** + * Changes the progress direction of loadingbar. + * + * @see LoadingBarType LoadingBarTypeLeft means progress left to right, LoadingBarTypeRight otherwise. + * + * @param LoadingBarType + */ + void setDirection(LoadingBarType dir); + + /** + * Gets the progress direction of loadingbar. + * + * @see LoadingBarType LoadingBarTypeLeft means progress left to right, LoadingBarTypeRight otherwise. + * + * @param LoadingBarType + */ + int getDirection(); + + /** + * Load texture for loadingbar. + * + * @param fileName file name of texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadTexture(const char* texture,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Changes the progress direction of loadingbar. + * + * @param percent percent value from 1 to 100. + */ + void setPercent(int percent); + + /** + * Gets the progress direction of loadingbar. + * + * @return percent percent value from 1 to 100. + */ + int getPercent(); + + /** + * Sets if loadingbar is using scale9 renderer. + * + * @param true that using scale9 renderer, false otherwise. + */ + void setScale9Enabled(bool enabled); + + bool isScale9Enabled(); + + /** + * Sets capinsets for loadingbar, if loadingbar is using scale9 renderer. + * + * @param capInsets capinsets for loadingbar + */ + void setCapInsets(const Rect &capInsets); + + const Rect& getCapInsets(); + + //override "ignoreContentAdaptWithSize" method of widget. + virtual void ignoreContentAdaptWithSize(bool ignore) override; + + //override "getContentSize" method of widget. + virtual const Size& getContentSize() const override; + + //override "getVirtualRenderer" method of widget. + virtual Node* getVirtualRenderer() override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; +protected: + virtual void initRenderer() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + void setScale9Scale(); + void barRendererScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + LoadingBarType _barType; + int _percent; + float _totalLength; + Node* _barRenderer; + TextureResType _renderBarTexType; + Size _barRendererTextureSize; + bool _scale9Enabled; + bool _prevIgnoreSize; + Rect _capInsets; + std::string _textureFile; +}; + +} +NS_CC_END +#endif /* defined(__CocoGUI__LoadingBar__) */ diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp new file mode 100644 index 0000000000..6ca5b60cac --- /dev/null +++ b/cocos/ui/UIPageView.cpp @@ -0,0 +1,631 @@ +/**************************************************************************** +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/UIPageView.h" + +NS_CC_BEGIN + +namespace ui { + +IMPLEMENT_CLASS_GUI_INFO(PageView) + +PageView::PageView(): +_curPageIdx(0), +_touchMoveDir(PAGEVIEW_TOUCHLEFT), +_touchStartLocation(0.0f), +_touchMoveStartLocation(0.0f), +_movePagePoint(Point::ZERO), +_leftChild(nullptr), +_rightChild(nullptr), +_leftBoundary(0.0f), +_rightBoundary(0.0f), +_isAutoScrolling(false), +_autoScrollDistance(0.0f), +_autoScrollSpeed(0.0f), +_autoScrollDir(0), +_childFocusCancelOffset(5.0f), +_pageViewEventListener(nullptr), +_pageViewEventSelector(nullptr) +{ +} + +PageView::~PageView() +{ + _pages.clear(); + _pageViewEventListener = nullptr; + _pageViewEventSelector = nullptr; +} + +PageView* PageView::create() +{ + PageView* widget = new PageView(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void PageView::onEnter() +{ + Layout::onEnter(); + scheduleUpdate(); +} + +bool PageView::init() +{ + if (Layout::init()) + { + setClippingEnabled(true); + setTouchEnabled(true); + return true; + } + return false; +} + +void PageView::addWidgetToPage(Widget *widget, ssize_t pageIdx, bool forceCreate) +{ + if (!widget) + { + return; + } + if (pageIdx < 0) + { + return; + } + ssize_t pageCount = _pages.size(); + if (pageIdx < 0 || pageIdx >= pageCount) + { + if (forceCreate) + { + if (pageIdx > pageCount) + { + CCLOG("pageIdx is %d, it will be added as page id [%d]",static_cast(pageIdx),static_cast(pageCount)); + } + Layout* newPage = createPage(); + newPage->addChild(widget); + addPage(newPage); + } + } + else + { + Layout * page = _pages.at(pageIdx); + page->addChild(widget); + } +} + +Layout* PageView::createPage() +{ + Layout* newPage = Layout::create(); + newPage->setSize(getSize()); + return newPage; +} + +void PageView::addPage(Layout* page) +{ + if (!page) + { + return; + } + if (page->getWidgetType() != WidgetTypeContainer) + { + return; + } + if (_pages.contains(page)) + { + return; + } + Size pSize = page->getSize(); + Size pvSize = getSize(); + if (!pSize.equals(pvSize)) + { + CCLOG("page size does not match pageview size, it will be force sized!"); + page->setSize(pvSize); + } + page->setPosition(Point(getPositionXByIndex(_pages.size()), 0)); + _pages.pushBack(page); + addChild(page); + updateBoundaryPages(); +} + +void PageView::insertPage(Layout* page, int idx) +{ + if (idx < 0) + { + return; + } + if (!page) + { + return; + } + if (page->getWidgetType() != WidgetTypeContainer) + { + return; + } + if (_pages.contains(page)) + { + return; + } + + ssize_t pageCount = _pages.size(); + if (idx >= pageCount) + { + addPage(page); + } + else + { + _pages.insert(idx, page); + page->setPosition(Point(getPositionXByIndex(idx), 0)); + addChild(page); + Size pSize = page->getSize(); + Size pvSize = getSize(); + if (!pSize.equals(pvSize)) + { + CCLOG("page size does not match pageview size, it will be force sized!"); + page->setSize(pvSize); + } + ssize_t length = _pages.size(); + for (ssize_t i=(idx+1); igetPosition(); + behindPage->setPosition(Point(formerPos.x+getSize().width, 0)); + } + updateBoundaryPages(); + } +} + +void PageView::removePage(Layout* page) +{ + if (!page) + { + return; + } + removeChild(page); + updateChildrenPosition(); + updateBoundaryPages(); +} + +void PageView::removePageAtIndex(ssize_t index) +{ + if (index < 0 || index >= _pages.size()) + { + return; + } + Layout* page = _pages.at(index); + removePage(page); +} + +void PageView::removeAllPages() +{ + removeAllChildren(); +} + +void PageView::updateBoundaryPages() +{ + if (_pages.size() <= 0) + { + _leftChild = nullptr; + _rightChild = nullptr; + return; + } + _leftChild = _pages.at(0); + _rightChild = _pages.at(_pages.size()-1); +} + +float PageView::getPositionXByIndex(ssize_t idx) +{ + return (getSize().width*(idx-_curPageIdx)); +} + +void PageView::addChild(Node *child) +{ + Layout::addChild(child); +} + +void PageView::addChild(Node * child, int zOrder) +{ + Layout::addChild(child, zOrder); +} + +void PageView::addChild(Node *child, int zOrder, int tag) +{ + Layout::addChild(child, zOrder, tag); +} + +void PageView::removeChild(Node *child, bool cleanup) +{ + if (_pages.contains(static_cast(child))) + { + _pages.eraseObject(static_cast(child)); + } + Layout::removeChild(child, cleanup); +} + +void PageView::onSizeChanged() +{ + Layout::onSizeChanged(); + _rightBoundary = getSize().width; + updateChildrenSize(); + updateChildrenPosition(); +} + +void PageView::updateChildrenSize() +{ + Size selfSize = getSize(); + for (auto& page : _pages) + { + page->setSize(selfSize); + } +} + +void PageView::updateChildrenPosition() +{ + ssize_t pageCount = _pages.size(); + if (pageCount <= 0) + { + _curPageIdx = 0; + return; + } + if (_curPageIdx >= pageCount) + { + _curPageIdx = pageCount-1; + } + float pageWidth = getSize().width; + for (int i=0; isetPosition(Point((i-_curPageIdx)*pageWidth, 0)); + } +} + +void PageView::removeAllChildren() +{ + removeAllChildrenWithCleanup(true); +} + +void PageView::removeAllChildrenWithCleanup(bool cleanup) +{ + _pages.clear(); + Layout::removeAllChildrenWithCleanup(cleanup); +} + +void PageView::scrollToPage(ssize_t idx) +{ + if (idx < 0 || idx >= _pages.size()) + { + return; + } + _curPageIdx = idx; + Widget* curPage = _pages.at(idx); + _autoScrollDistance = -(curPage->getPosition().x); + _autoScrollSpeed = fabs(_autoScrollDistance)/0.2f; + _autoScrollDir = _autoScrollDistance > 0 ? 1 : 0; + _isAutoScrolling = true; +} + +void PageView::update(float dt) +{ + if (_isAutoScrolling) + { + switch (_autoScrollDir) + { + case 0: + { + float step = _autoScrollSpeed*dt; + if (_autoScrollDistance + step >= 0.0f) + { + step = -_autoScrollDistance; + _autoScrollDistance = 0.0f; + _isAutoScrolling = false; + } + else + { + _autoScrollDistance += step; + } + scrollPages(-step); + if (!_isAutoScrolling) + { + pageTurningEvent(); + } + break; + } + break; + case 1: + { + float step = _autoScrollSpeed*dt; + if (_autoScrollDistance - step <= 0.0f) + { + step = _autoScrollDistance; + _autoScrollDistance = 0.0f; + _isAutoScrolling = false; + } + else + { + _autoScrollDistance -= step; + } + scrollPages(step); + if (!_isAutoScrolling) + { + pageTurningEvent(); + } + break; + } + default: + break; + } + } +} + +bool PageView::onTouchBegan(Touch *touch, Event *unusedEvent) +{ + bool pass = Layout::onTouchBegan(touch, unusedEvent); + if (_hitted) + { + handlePressLogic(touch->getLocation()); + } + return pass; +} + +void PageView::onTouchMoved(Touch *touch, Event *unusedEvent) +{ + _touchMovePos = touch->getLocation(); + handleMoveLogic(_touchMovePos); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + widgetParent->checkChildInfo(1,this,_touchMovePos); + } + moveEvent(); +} + +void PageView::onTouchEnded(Touch *touch, Event *unusedEvent) +{ + Layout::onTouchEnded(touch, unusedEvent); + handleReleaseLogic(_touchEndPos); +} + +void PageView::onTouchCancelled(Touch *touch, Event *unusedEvent) +{ + Layout::onTouchCancelled(touch, unusedEvent); + handleReleaseLogic(touch->getLocation()); +} + +void PageView::movePages(float offset) +{ + for (auto& page : _pages) + { + _movePagePoint.x = page->getPosition().x + offset; + _movePagePoint.y = page->getPosition().y; + page->setPosition(_movePagePoint); + } +} + +bool PageView::scrollPages(float touchOffset) +{ + if (_pages.size() <= 0) + { + return false; + } + + if (!_leftChild || !_rightChild) + { + return false; + } + + float realOffset = touchOffset; + + switch (_touchMoveDir) + { + case PAGEVIEW_TOUCHLEFT: // left + if (_rightChild->getRightInParent() + touchOffset <= _rightBoundary) + { + realOffset = _rightBoundary - _rightChild->getRightInParent(); + movePages(realOffset); + return false; + } + break; + + case PAGEVIEW_TOUCHRIGHT: // right + if (_leftChild->getLeftInParent() + touchOffset >= _leftBoundary) + { + realOffset = _leftBoundary - _leftChild->getLeftInParent(); + movePages(realOffset); + return false; + } + break; + default: + break; + } + + movePages(realOffset); + return true; +} + +void PageView::handlePressLogic(const Point &touchPoint) +{ + Point nsp = convertToNodeSpace(touchPoint); + _touchMoveStartLocation = nsp.x; + _touchStartLocation = nsp.x; +} + +void PageView::handleMoveLogic(const Point &touchPoint) +{ + Point nsp = convertToNodeSpace(touchPoint); + float offset = 0.0; + float moveX = nsp.x; + offset = moveX - _touchMoveStartLocation; + _touchMoveStartLocation = moveX; + if (offset < 0) + { + _touchMoveDir = PAGEVIEW_TOUCHLEFT; + } + else if (offset > 0) + { + _touchMoveDir = PAGEVIEW_TOUCHRIGHT; + } + scrollPages(offset); +} + +void PageView::handleReleaseLogic(const Point &touchPoint) +{ + if (_pages.size() <= 0) + { + return; + } + Widget* curPage = _pages.at(_curPageIdx); + if (curPage) + { + Point curPagePos = curPage->getPosition(); + ssize_t pageCount = _pages.size(); + float curPageLocation = curPagePos.x; + float pageWidth = getSize().width; + float boundary = pageWidth/2.0f; + if (curPageLocation <= -boundary) + { + if (_curPageIdx >= pageCount-1) + { + scrollPages(-curPageLocation); + } + else + { + scrollToPage(_curPageIdx+1); + } + } + else if (curPageLocation >= boundary) + { + if (_curPageIdx <= 0) + { + scrollPages(-curPageLocation); + } + else + { + scrollToPage(_curPageIdx-1); + } + } + else + { + scrollToPage(_curPageIdx); + } + } +} + +void PageView::checkChildInfo(int handleState,Widget* sender, const Point &touchPoint) +{ + interceptTouchEvent(handleState, sender, touchPoint); +} + +void PageView::interceptTouchEvent(int handleState, Widget *sender, const Point &touchPoint) +{ + switch (handleState) + { + case 0: + handlePressLogic(touchPoint); + break; + case 1: + { + float offset = 0; + offset = fabs(sender->getTouchStartPos().x - touchPoint.x); + if (offset > _childFocusCancelOffset) + { + sender->setFocused(false); + handleMoveLogic(touchPoint); + } + } + break; + case 2: + handleReleaseLogic(touchPoint); + break; + + case 3: + handleReleaseLogic(touchPoint); + break; + } +} + +void PageView::pageTurningEvent() +{ + if (_pageViewEventListener && _pageViewEventSelector) + { + (_pageViewEventListener->*_pageViewEventSelector)(this, PAGEVIEW_EVENT_TURNING); + } +} + +void PageView::addEventListenerPageView(Ref *target, SEL_PageViewEvent selector) +{ + _pageViewEventListener = target; + _pageViewEventSelector = selector; +} + +ssize_t PageView::getCurPageIndex() const +{ + return _curPageIdx; +} + +Vector& PageView::getPages() +{ + return _pages; +} + +Layout* PageView::getPage(ssize_t index) +{ + if (index < 0 || index >= _pages.size()) + { + return nullptr; + } + return _pages.at(index); +} + +std::string PageView::getDescription() const +{ + return "PageView"; +} + +Widget* PageView::createCloneInstance() +{ + return PageView::create(); +} + +void PageView::copyClonedWidgetChildren(Widget* model) +{ + auto& modelPages = static_cast(model)->getPages(); + for (auto& page : modelPages) + { + addPage(dynamic_cast(page->clone())); + } +} + +void PageView::copySpecialProperties(Widget *widget) +{ + PageView* pageView = dynamic_cast(widget); + if (pageView) + { + Layout::copySpecialProperties(widget); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UIPageView.h b/cocos/ui/UIPageView.h new file mode 100644 index 0000000000..80b1274719 --- /dev/null +++ b/cocos/ui/UIPageView.h @@ -0,0 +1,222 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UIPAGEVIEW_H__ +#define __UIPAGEVIEW_H__ + +#include "ui/UILayout.h" +#include "ui/UIScrollInterface.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + PAGEVIEW_EVENT_TURNING, +}PageViewEventType; + +typedef void (Ref::*SEL_PageViewEvent)(Ref*, PageViewEventType); +#define pagevieweventselector(_SELECTOR)(SEL_PageViewEvent)(&_SELECTOR) + +typedef enum { + PAGEVIEW_TOUCHLEFT, + PAGEVIEW_TOUCHRIGHT +}PVTouchDir; + +class PageView : public Layout , public UIScrollInterface +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + PageView(); + + /** + * Default destructor + */ + virtual ~PageView(); + + /** + * Allocates and initializes. + */ + static PageView* create(); + + /** + * Add a widget to a page of pageview. + * + * @param widget widget to be added to pageview. + * + * @param pageIdx index of page. + * + * @param forceCreate if force create and there is no page exsit, pageview would create a default page for adding widget. + */ + void addWidgetToPage(Widget* widget, ssize_t pageIdx, bool forceCreate); + + /** + * Push back a page to pageview. + * + * @param page page to be added to pageview. + */ + void addPage(Layout* page); + + /** + * Inert a page to pageview. + * + * @param page page to be added to pageview. + */ + void insertPage(Layout* page, int idx); + + /** + * Remove a page of pageview. + * + * @param page page which will be removed. + */ + void removePage(Layout* page); + + /** + * Remove a page at index of pageview. + * + * @param index index of page. + */ + void removePageAtIndex(ssize_t index); + + void removeAllPages(); + + /** + * scroll pageview to index. + * + * @param idx index of page. + */ + void scrollToPage(ssize_t idx); + + /** + * Gets current page index. + * + * @return current page index. + */ + ssize_t getCurPageIndex() const; + + Vector& getPages(); + + Layout* getPage(ssize_t index); + + // event + void addEventListenerPageView(Ref *target, SEL_PageViewEvent selector); + + + + + virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; + virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; + virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; + virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; + + //override "update" method of widget. + virtual void update(float dt) override; + /** + * Sets LayoutType. + * + * @see LayoutType + * + * @param LayoutType + */ + virtual void setLayoutType(LayoutType type) override{}; + + /** + * Gets LayoutType. + * + * @see LayoutType + * + * @return LayoutType + */ + virtual LayoutType getLayoutType() const override{return LAYOUT_ABSOLUTE;}; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + virtual void onEnter() override; + +protected: + virtual void addChild(Node * child) override; + virtual void addChild(Node * child, int zOrder) override; + virtual void addChild(Node* child, int zOrder, int tag) override; + virtual void removeChild(Node* widget, bool cleanup = true) override; + virtual void removeAllChildren() override; + virtual void removeAllChildrenWithCleanup(bool cleanup) override; + virtual Vector& getChildren() override{return Widget::getChildren();}; + virtual const Vector& getChildren() const override{return Widget::getChildren();}; + virtual ssize_t getChildrenCount() const override {return Widget::getChildrenCount();}; + virtual Node * getChildByTag(int tag) override {return Widget::getChildByTag(tag);}; + virtual Widget* getChildByName(const char* name) override {return Widget::getChildByName(name);}; + virtual bool init() override; + Layout* createPage(); + float getPositionXByIndex(ssize_t idx); + void updateBoundaryPages(); + virtual void handlePressLogic(const Point &touchPoint) override; + virtual void handleMoveLogic(const Point &touchPoint) override; + virtual void handleReleaseLogic(const Point &touchPoint) override; + virtual void interceptTouchEvent(int handleState, Widget* sender, const Point &touchPoint) override; + virtual void checkChildInfo(int handleState, Widget* sender, const Point &touchPoint) override; + virtual bool scrollPages(float touchOffset); + void movePages(float offset); + void pageTurningEvent(); + void updateChildrenSize(); + void updateChildrenPosition(); + virtual void onSizeChanged() override; + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; + virtual void copyClonedWidgetChildren(Widget* model) override; + virtual void setClippingEnabled(bool enabled) override {Layout::setClippingEnabled(enabled);}; + virtual void doLayout() override{if (!_doLayoutDirty){return;} _doLayoutDirty = false;}; +protected: + ssize_t _curPageIdx; + Vector _pages; + PVTouchDir _touchMoveDir; + float _touchStartLocation; + float _touchMoveStartLocation; + Point _movePagePoint; + Widget* _leftChild; + Widget* _rightChild; + float _leftBoundary; + float _rightBoundary; + bool _isAutoScrolling; + float _autoScrollDistance; + float _autoScrollSpeed; + int _autoScrollDir; + float _childFocusCancelOffset; + Ref* _pageViewEventListener; + SEL_PageViewEvent _pageViewEventSelector; + +}; + +} +NS_CC_END + +#endif /* defined(__PageView__) */ diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp new file mode 100644 index 0000000000..8e153ec123 --- /dev/null +++ b/cocos/ui/UIRichText.cpp @@ -0,0 +1,442 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + +#include "UIRichText.h" + + +NS_CC_BEGIN + +namespace ui { + +bool RichElement::init(int tag, const Color3B &color, GLubyte opacity) +{ + _tag = tag; + _color = color; + _opacity = opacity; + return true; +} + + +RichElementText* RichElementText::create(int tag, const Color3B &color, GLubyte opacity, const char *text, const char *fontName, float fontSize) +{ + RichElementText* element = new RichElementText(); + if (element && element->init(tag, color, opacity, text, fontName, fontSize)) + { + element->autorelease(); + return element; + } + CC_SAFE_DELETE(element); + return NULL; +} + +bool RichElementText::init(int tag, const Color3B &color, GLubyte opacity, const char *text, const char *fontName, float fontSize) +{ + if (RichElement::init(tag, color, opacity)) + { + _text = text; + _fontName = fontName; + _fontSize = fontSize; + return true; + } + return false; +} + +RichElementImage* RichElementImage::create(int tag, const Color3B &color, GLubyte opacity, const char *filePath) +{ + RichElementImage* element = new RichElementImage(); + if (element && element->init(tag, color, opacity, filePath)) + { + element->autorelease(); + return element; + } + CC_SAFE_DELETE(element); + return NULL; +} + +bool RichElementImage::init(int tag, const Color3B &color, GLubyte opacity, const char *filePath) +{ + if (RichElement::init(tag, color, opacity)) + { + _filePath = filePath; + return true; + } + return false; +} + +RichElementCustomNode* RichElementCustomNode::create(int tag, const Color3B &color, GLubyte opacity, cocos2d::Node *customNode) +{ + RichElementCustomNode* element = new RichElementCustomNode(); + if (element && element->init(tag, color, opacity, customNode)) + { + element->autorelease(); + return element; + } + CC_SAFE_DELETE(element); + return NULL; +} + +bool RichElementCustomNode::init(int tag, const Color3B &color, GLubyte opacity, cocos2d::Node *customNode) +{ + if (RichElement::init(tag, color, opacity)) + { + _customNode = customNode; + _customNode->retain(); + return true; + } + return false; +} + +RichText::RichText(): +_formatTextDirty(true), +_richElements(NULL), +_elementRenders(NULL), +_leftSpaceWidth(0.0f), +_verticalSpace(0.0f), +_elementRenderersContainer(NULL) +{ + +} + +RichText::~RichText() +{ + _richElements.clear(); +} + +RichText* RichText::create() +{ + RichText* widget = new RichText(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return NULL; +} + +bool RichText::init() +{ + if (Widget::init()) + { + return true; + } + return false; +} + +void RichText::initRenderer() +{ + _elementRenderersContainer = Node::create(); + _elementRenderersContainer->setAnchorPoint(Point(0.5f, 0.5f)); + Node::addChild(_elementRenderersContainer, 0, -1); +} + +void RichText::insertElement(RichElement *element, int index) +{ + _richElements.insert(index, element); + _formatTextDirty = true; +} + +void RichText::pushBackElement(RichElement *element) +{ + _richElements.pushBack(element); + _formatTextDirty = true; +} + +void RichText::removeElement(int index) +{ + _richElements.erase(index); + _formatTextDirty = true; +} + +void RichText::removeElement(RichElement *element) +{ + _richElements.eraseObject(element); + _formatTextDirty = true; +} + +void RichText::formatText() +{ + if (_formatTextDirty) + { + _elementRenderersContainer->removeAllChildren(); + _elementRenders.clear(); + if (_ignoreSize) + { + addNewLine(); + for (int i=0; i<_richElements.size(); i++) + { + RichElement* element = _richElements.at(i); + Node* elementRenderer = NULL; + switch (element->_type) + { + case RICH_TEXT: + { + RichElementText* elmtText = static_cast(element); + elementRenderer = LabelTTF::create(elmtText->_text.c_str(), elmtText->_fontName.c_str(), elmtText->_fontSize); + break; + } + case RICH_IMAGE: + { + RichElementImage* elmtImage = static_cast(element); + elementRenderer = Sprite::create(elmtImage->_filePath.c_str()); + break; + } + case RICH_CUSTOM: + { + RichElementCustomNode* elmtCustom = static_cast(element); + elementRenderer = elmtCustom->_customNode; + break; + } + default: + break; + } + elementRenderer->setColor(element->_color); + elementRenderer->setOpacity(element->_opacity); + pushToContainer(elementRenderer); + } + } + else + { + addNewLine(); + for (int i=0; i<_richElements.size(); i++) + { + + RichElement* element = static_cast(_richElements.at(i)); + switch (element->_type) + { + case RICH_TEXT: + { + RichElementText* elmtText = static_cast(element); + handleTextRenderer(elmtText->_text.c_str(), elmtText->_fontName.c_str(), elmtText->_fontSize, elmtText->_color, elmtText->_opacity); + break; + } + case RICH_IMAGE: + { + RichElementImage* elmtImage = static_cast(element); + handleImageRenderer(elmtImage->_filePath.c_str(), elmtImage->_color, elmtImage->_opacity); + break; + } + case RICH_CUSTOM: + { + RichElementCustomNode* elmtCustom = static_cast(element); + handleCustomRenderer(elmtCustom->_customNode); + break; + } + default: + break; + } + } + } + formarRenderers(); + _formatTextDirty = false; + } +} + +void RichText::handleTextRenderer(const char *text, const char *fontName, float fontSize, const Color3B &color, GLubyte opacity) +{ + LabelTTF* textRenderer = LabelTTF::create(text, fontName, fontSize); + float textRendererWidth = textRenderer->getContentSize().width; + _leftSpaceWidth -= textRendererWidth; + if (_leftSpaceWidth < 0.0f) + { + float overstepPercent = (-_leftSpaceWidth) / textRendererWidth; + std::string curText = text; + int stringLength = curText.length(); + int leftLength = stringLength * (1.0f - overstepPercent); + std::string leftWords = curText.substr(0, leftLength); + std::string cutWords = curText.substr(leftLength, curText.length()-1); + if (leftLength > 0) + { + LabelTTF* leftRenderer = LabelTTF::create(leftWords.substr(0, leftLength).c_str(), fontName, fontSize); + leftRenderer->setColor(color); + leftRenderer->setOpacity(opacity); + pushToContainer(leftRenderer); + } + + addNewLine(); + handleTextRenderer(cutWords.c_str(), fontName, fontSize, color, opacity); + } + else + { + textRenderer->setColor(color); + textRenderer->setOpacity(opacity); + pushToContainer(textRenderer); + } +} + +void RichText::handleImageRenderer(const char *fileParh, const Color3B &color, GLubyte opacity) +{ + Sprite* imageRenderer = Sprite::create(fileParh); + handleCustomRenderer(imageRenderer); +} + +void RichText::handleCustomRenderer(cocos2d::Node *renderer) +{ + Size imgSize = renderer->getContentSize(); + _leftSpaceWidth -= imgSize.width; + if (_leftSpaceWidth < 0.0f) + { + addNewLine(); + pushToContainer(renderer); + _leftSpaceWidth -= imgSize.width; + } + else + { + pushToContainer(renderer); + } +} + +void RichText::addNewLine() +{ + _leftSpaceWidth = _customSize.width; + _elementRenders.push_back(new Vector()); +} + +void RichText::formarRenderers() +{ + if (_ignoreSize) + { + float newContentSizeWidth = 0.0f; + float newContentSizeHeight = 0.0f; + + Vector* row = (_elementRenders[0]); + float nextPosX = 0.0f; + for (int j=0; jsize(); j++) + { + Node* l = row->at(j); + l->setAnchorPoint(Point::ZERO); + l->setPosition(Point(nextPosX, 0.0f)); + _elementRenderersContainer->addChild(l, 1, j); + Size iSize = l->getContentSize(); + newContentSizeWidth += iSize.width; + newContentSizeHeight = MAX(newContentSizeHeight, iSize.height); + nextPosX += iSize.width; + } + _elementRenderersContainer->setContentSize(Size(newContentSizeWidth, newContentSizeHeight)); + } + else + { + float newContentSizeHeight = 0.0f; + float *maxHeights = new float[_elementRenders.size()]; + + for (int i=0; i<_elementRenders.size(); i++) + { + Vector* row = (_elementRenders[i]); + float maxHeight = 0.0f; + for (int j=0; jsize(); j++) + { + Node* l = row->at(j); + maxHeight = MAX(l->getContentSize().height, maxHeight); + } + maxHeights[i] = maxHeight; + newContentSizeHeight += maxHeights[i]; + } + + + float nextPosY = _customSize.height; + for (int i=0; i<_elementRenders.size(); i++) + { + Vector* row = (_elementRenders[i]); + float nextPosX = 0.0f; + nextPosY -= (maxHeights[i] + _verticalSpace); + + for (int j=0; jsize(); j++) + { + Node* l = row->at(j); + l->setAnchorPoint(Point::ZERO); + l->setPosition(Point(nextPosX, nextPosY)); + _elementRenderersContainer->addChild(l, 1, i*10 + j); + nextPosX += l->getContentSize().width; + } + } + _elementRenderersContainer->setContentSize(_size); + delete [] maxHeights; + } + + int length = _elementRenders.size(); + for (size_t i = 0; i* l = _elementRenders[i]; + l->clear(); + delete l; + } + _elementRenders.clear(); + + if (_ignoreSize) + { + Size s = getContentSize(); + _size = s; + } + else + { + _size = _customSize; + } +} + +void RichText::pushToContainer(cocos2d::Node *renderer) +{ + if (_elementRenders.size() <= 0) + { + return; + } + _elementRenders[_elementRenders.size()-1]->pushBack(renderer); +} + +void RichText::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) +{ + if (_enabled) + { + formatText(); + Widget::visit(renderer, parentTransform, parentTransformUpdated); + } +} + +void RichText::setVerticalSpace(float space) +{ + _verticalSpace = space; +} + +void RichText::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _elementRenderersContainer->setAnchorPoint(pt); +} + +const Size& RichText::getContentSize() const +{ + return _elementRenderersContainer->getContentSize(); +} + +void RichText::ignoreContentAdaptWithSize(bool ignore) +{ + if (_ignoreSize != ignore) + { + _formatTextDirty = true; + Widget::ignoreContentAdaptWithSize(ignore); + } +} + +} + +NS_CC_END \ No newline at end of file diff --git a/cocos/ui/UIRichText.h b/cocos/ui/UIRichText.h new file mode 100644 index 0000000000..6958c07cbc --- /dev/null +++ b/cocos/ui/UIRichText.h @@ -0,0 +1,133 @@ +/**************************************************************************** + 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 __UIRICHTEXT_H__ +#define __UIRICHTEXT_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum { + RICH_TEXT, + RICH_IMAGE, + RICH_CUSTOM +}RichElementType; + +class RichElement : public Ref +{ +public: + RichElement(){}; + virtual ~RichElement(){}; + bool init(int tag, const Color3B& color, GLubyte opacity); +protected: + RichElementType _type; + int _tag; + Color3B _color; + GLubyte _opacity; + friend class RichText; +}; + +class RichElementText : public RichElement +{ +public: + RichElementText(){_type = RICH_TEXT;}; + virtual ~RichElementText(){}; + bool init(int tag, const Color3B& color, GLubyte opacity, const char* text, const char* fontName, float fontSize); + static RichElementText* create(int tag, const Color3B& color, GLubyte opacity, const char* text, const char* fontName, float fontSize); +protected: + std::string _text; + std::string _fontName; + float _fontSize; + friend class RichText; + +}; + +class RichElementImage : public RichElement +{ +public: + RichElementImage(){_type = RICH_IMAGE;}; + virtual ~RichElementImage(){}; + bool init(int tag, const Color3B& color, GLubyte opacity, const char* filePath); + static RichElementImage* create(int tag, const Color3B& color, GLubyte opacity, const char* filePath); +protected: + std::string _filePath; + Rect _textureRect; + int _textureType; + friend class RichText; +}; + +class RichElementCustomNode : public RichElement +{ +public: + RichElementCustomNode(){_type = RICH_CUSTOM;}; + virtual ~RichElementCustomNode(){CC_SAFE_RELEASE(_customNode);}; + bool init(int tag, const Color3B& color, GLubyte opacity, Node* customNode); + static RichElementCustomNode* create(int tag, const Color3B& color, GLubyte opacity, Node* customNode); +protected: + Node* _customNode; + friend class RichText; +}; + +class RichText : public Widget +{ +public: + RichText(); + virtual ~RichText(); + static RichText* create(); + void insertElement(RichElement* element, int index); + void pushBackElement(RichElement* element); + void removeElement(int index); + void removeElement(RichElement* element); + virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; + void setVerticalSpace(float space); + virtual void setAnchorPoint(const Point &pt); + virtual const Size& getContentSize() const; + void formatText(); + virtual void ignoreContentAdaptWithSize(bool ignore); +protected: + virtual bool init(); + virtual void initRenderer(); + void pushToContainer(Node* renderer); + void handleTextRenderer(const char* text, const char* fontName, float fontSize, const Color3B& color, GLubyte opacity); + void handleImageRenderer(const char* fileParh, const Color3B& color, GLubyte opacity); + void handleCustomRenderer(Node* renderer); + void formarRenderers(); + void addNewLine(); +protected: + bool _formatTextDirty; + Vector _richElements; + std::vector*> _elementRenders; + float _leftSpaceWidth; + float _verticalSpace; + Node* _elementRenderersContainer; +}; + +} + +NS_CC_END + +#endif /* defined(__UIRichText__) */ diff --git a/cocos/ui/UIScrollInterface.h b/cocos/ui/UIScrollInterface.h new file mode 100644 index 0000000000..2acaab5759 --- /dev/null +++ b/cocos/ui/UIScrollInterface.h @@ -0,0 +1,49 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UISCROLLDELEGATE_H__ +#define __UISCROLLDELEGATE_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +class UIScrollInterface +{ +public: + virtual ~UIScrollInterface() {} + +protected: + virtual void handlePressLogic(const Point &touchPoint) = 0; + virtual void handleMoveLogic(const Point &touchPoint) = 0; + virtual void handleReleaseLogic(const Point &touchPoint) = 0; + virtual void interceptTouchEvent(int handleState, Widget* sender, const Point &touchPoint) = 0; +}; + +} +NS_CC_END + +#endif /* defined(__UIScrollDelegate__) */ diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp new file mode 100644 index 0000000000..f286c9ba29 --- /dev/null +++ b/cocos/ui/UIScrollView.cpp @@ -0,0 +1,1719 @@ +/**************************************************************************** +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/UIScrollView.h" + +NS_CC_BEGIN + +namespace ui { + +static const float AUTOSCROLLMAXSPEED = 1000.0f; + +const Point SCROLLDIR_UP = Point(0.0f, 1.0f); +const Point SCROLLDIR_DOWN = Point(0.0f, -1.0f); +const Point SCROLLDIR_LEFT = Point(-1.0f, 0.0f); +const Point SCROLLDIR_RIGHT = Point(1.0f, 0.0f); + +IMPLEMENT_CLASS_GUI_INFO(ScrollView) + +ScrollView::ScrollView(): +_innerContainer(nullptr), +_direction(SCROLLVIEW_DIR_VERTICAL), +_touchBeganPoint(Point::ZERO), +_touchMovedPoint(Point::ZERO), +_touchEndedPoint(Point::ZERO), +_touchMovingPoint(Point::ZERO), +_autoScrollDir(Point::ZERO), +_topBoundary(0.0f), +_bottomBoundary(0.0f), +_leftBoundary(0.0f), +_rightBoundary(0.0f), +_bounceTopBoundary(0.0f), +_bounceBottomBoundary(0.0f), +_bounceLeftBoundary(0.0f), +_bounceRightBoundary(0.0f), +_autoScroll(false), +_autoScrollAddUpTime(0.0f), +_autoScrollOriginalSpeed(0.0f), +_autoScrollAcceleration(-1000.0f), +_isAutoScrollSpeedAttenuated(false), +_needCheckAutoScrollDestination(false), +_autoScrollDestination(Point::ZERO), +_bePressed(false), +_slidTime(0.0f), +_moveChildPoint(Point::ZERO), +_childFocusCancelOffset(5.0f), +_leftBounceNeeded(false), +_topBounceNeeded(false), +_rightBounceNeeded(false), +_bottomBounceNeeded(false), +_bounceEnabled(false), +_bouncing(false), +_bounceDir(Point::ZERO), +_bounceOriginalSpeed(0.0f), +_inertiaScrollEnabled(true), +_scrollViewEventListener(nullptr), +_scrollViewEventSelector(nullptr) +{ +} + +ScrollView::~ScrollView() +{ + _scrollViewEventListener = nullptr; + _scrollViewEventSelector = nullptr; +} + +ScrollView* ScrollView::create() +{ + ScrollView* widget = new ScrollView(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void ScrollView::onEnter() +{ + Layout::onEnter(); + scheduleUpdate(); +} + +bool ScrollView::init() +{ + if (Layout::init()) + { + setTouchEnabled(true); + setClippingEnabled(true); + _innerContainer->setTouchEnabled(false); + return true; + } + return false; +} + +void ScrollView::initRenderer() +{ + Layout::initRenderer(); + _innerContainer = Layout::create(); + Layout::addChild(_innerContainer,1,1); +} + +void ScrollView::onSizeChanged() +{ + Layout::onSizeChanged(); + _topBoundary = _size.height; + _rightBoundary = _size.width; + float bounceBoundaryParameterX = _size.width / 3.0f; + float bounceBoundaryParameterY = _size.height / 3.0f; + _bounceTopBoundary = _size.height - bounceBoundaryParameterY; + _bounceBottomBoundary = bounceBoundaryParameterY; + _bounceLeftBoundary = bounceBoundaryParameterX; + _bounceRightBoundary = _size.width - bounceBoundaryParameterX; + Size innerSize = _innerContainer->getSize(); + float orginInnerSizeWidth = innerSize.width; + float orginInnerSizeHeight = innerSize.height; + float innerSizeWidth = MAX(orginInnerSizeWidth, _size.width); + float innerSizeHeight = MAX(orginInnerSizeHeight, _size.height); + _innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight)); + _innerContainer->setPosition(Point(0, _size.height - _innerContainer->getSize().height)); +} + +void ScrollView::setInnerContainerSize(const Size &size) +{ + float innerSizeWidth = _size.width; + float innerSizeHeight = _size.height; + Size originalInnerSize = _innerContainer->getSize(); + if (size.width < _size.width) + { + CCLOG("Inner width <= scrollview width, it will be force sized!"); + } + else + { + innerSizeWidth = size.width; + } + if (size.height < _size.height) + { + CCLOG("Inner height <= scrollview height, it will be force sized!"); + } + else + { + innerSizeHeight = size.height; + } + _innerContainer->setSize(Size(innerSizeWidth, innerSizeHeight)); + + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: + { + Size newInnerSize = _innerContainer->getSize(); + float offset = originalInnerSize.height - newInnerSize.height; + scrollChildren(0.0f, offset); + break; + } + case SCROLLVIEW_DIR_HORIZONTAL: + { + if (_innerContainer->getRightInParent() <= _size.width) + { + Size newInnerSize = _innerContainer->getSize(); + float offset = originalInnerSize.width - newInnerSize.width; + scrollChildren(offset, 0.0f); + } + break; + } + case SCROLLVIEW_DIR_BOTH: + { + Size newInnerSize = _innerContainer->getSize(); + float offsetY = originalInnerSize.height - newInnerSize.height; + float offsetX = 0.0f; + if (_innerContainer->getRightInParent() <= _size.width) + { + offsetX = originalInnerSize.width - newInnerSize.width; + } + scrollChildren(offsetX, offsetY); + break; + } + default: + break; + } + if (_innerContainer->getLeftInParent() > 0.0f) + { + _innerContainer->setPosition(Point(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, _innerContainer->getPosition().y)); + } + if (_innerContainer->getRightInParent() < _size.width) + { + _innerContainer->setPosition(Point(_size.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), _innerContainer->getPosition().y)); + } + if (_innerContainer->getPosition().y > 0.0f) + { + _innerContainer->setPosition(Point(_innerContainer->getPosition().x, _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height)); + } + if (_innerContainer->getTopInParent() < _size.height) + { + _innerContainer->setPosition(Point(_innerContainer->getPosition().x, _size.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height)); + } +} + +const Size& ScrollView::getInnerContainerSize() const +{ + return _innerContainer->getSize(); +} + +void ScrollView::addChild(Node *child) +{ + Layout::addChild(child); +} + +void ScrollView::addChild(Node * child, int zOrder) +{ + Layout::addChild(child, zOrder); +} + +void ScrollView::addChild(Node *child, int zOrder, int tag) +{ + return _innerContainer->addChild(child, zOrder, tag); +} + +void ScrollView::removeAllChildren() +{ + removeAllChildrenWithCleanup(true); +} + +void ScrollView::removeAllChildrenWithCleanup(bool cleanup) +{ + _innerContainer->removeAllChildrenWithCleanup(cleanup); +} + +void ScrollView::removeChild(Node* child, bool cleanup) +{ + return _innerContainer->removeChild(child, cleanup); +} + +Vector& ScrollView::getChildren() +{ + return _innerContainer->getChildren(); +} + +const Vector& ScrollView::getChildren() const +{ + return _innerContainer->getChildren(); +} + +ssize_t ScrollView::getChildrenCount() const +{ + return _innerContainer->getChildrenCount(); +} + +Node* ScrollView::getChildByTag(int tag) +{ + return _innerContainer->getChildByTag(tag); +} + +Widget* ScrollView::getChildByName(const char *name) +{ + return _innerContainer->getChildByName(name); +} + +void ScrollView::addNode(Node* node) +{ + Layout::addNode(node); +} + +void ScrollView::addNode(Node * node, int zOrder) +{ + Layout::addNode(node, zOrder); +} + +void ScrollView::addNode(Node* node, int zOrder, int tag) +{ + _innerContainer->addNode(node, zOrder, tag); +} + +Node* ScrollView::getNodeByTag(int tag) +{ + return _innerContainer->getNodeByTag(tag); +} + +Vector& ScrollView::getNodes() +{ + return _innerContainer->getNodes(); +} + +void ScrollView::removeNode(Node* node) +{ + _innerContainer->removeNode(node); +} + +void ScrollView::removeNodeByTag(int tag) +{ + _innerContainer->removeNodeByTag(tag); +} + +void ScrollView::removeAllNodes() +{ + _innerContainer->removeAllNodes(); +} + +void ScrollView::moveChildren(float offsetX, float offsetY) +{ + _moveChildPoint = _innerContainer->getPosition() + Point(offsetX, offsetY); + _innerContainer->setPosition(_moveChildPoint); +} + +void ScrollView::autoScrollChildren(float dt) +{ + float lastTime = _autoScrollAddUpTime; + _autoScrollAddUpTime += dt; + if (_isAutoScrollSpeedAttenuated) + { + float nowSpeed = _autoScrollOriginalSpeed + _autoScrollAcceleration * _autoScrollAddUpTime; + if (nowSpeed <= 0.0f) + { + stopAutoScrollChildren(); + checkNeedBounce(); + } + else + { + float timeParam = lastTime * 2 + dt; + float offset = (_autoScrollOriginalSpeed + _autoScrollAcceleration * timeParam * 0.5f) * dt; + float offsetX = offset * _autoScrollDir.x; + float offsetY = offset * _autoScrollDir.y; + if (!scrollChildren(offsetX, offsetY)) + { + stopAutoScrollChildren(); + checkNeedBounce(); + } + } + } + else + { + if (_needCheckAutoScrollDestination) + { + float xOffset = _autoScrollDir.x * dt * _autoScrollOriginalSpeed; + float yOffset = _autoScrollDir.y * dt * _autoScrollOriginalSpeed; + bool notDone = checkCustomScrollDestination(&xOffset, &yOffset); + bool scrollCheck = scrollChildren(xOffset, yOffset); + if (!notDone || !scrollCheck) + { + stopAutoScrollChildren(); + checkNeedBounce(); + } + } + else + { + if (!scrollChildren(_autoScrollDir.x * dt * _autoScrollOriginalSpeed, _autoScrollDir.y * dt * _autoScrollOriginalSpeed)) + { + stopAutoScrollChildren(); + checkNeedBounce(); + } + } + } +} + +void ScrollView::bounceChildren(float dt) +{ + if (_bounceOriginalSpeed <= 0.0f) + { + stopBounceChildren(); + } + if (!bounceScrollChildren(_bounceDir.x * dt * _bounceOriginalSpeed, _bounceDir.y * dt * _bounceOriginalSpeed)) + { + stopBounceChildren(); + } +} + +bool ScrollView::checkNeedBounce() +{ + if (!_bounceEnabled) + { + return false; + } + checkBounceBoundary(); + if (_topBounceNeeded || _bottomBounceNeeded || _leftBounceNeeded || _rightBounceNeeded) + { + if (_topBounceNeeded && _leftBounceNeeded) + { + Point scrollVector = Point(0.0f, _size.height) - Point(_innerContainer->getLeftInParent(), _innerContainer->getTopInParent()); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_topBounceNeeded && _rightBounceNeeded) + { + Point scrollVector = Point(_size.width, _size.height) - Point(_innerContainer->getRightInParent(), _innerContainer->getTopInParent()); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_bottomBounceNeeded && _leftBounceNeeded) + { + Point scrollVector = Point::ZERO - Point(_innerContainer->getLeftInParent(), _innerContainer->getBottomInParent()); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_bottomBounceNeeded && _rightBounceNeeded) + { + Point scrollVector = Point(_size.width, 0.0f) - Point(_innerContainer->getRightInParent(), _innerContainer->getBottomInParent()); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_topBounceNeeded) + { + Point scrollVector = Point(0.0f, _size.height) - Point(0.0f, _innerContainer->getTopInParent()); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_bottomBounceNeeded) + { + Point scrollVector = Point::ZERO - Point(0.0f, _innerContainer->getBottomInParent()); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_leftBounceNeeded) + { + Point scrollVector = Point::ZERO - Point(_innerContainer->getLeftInParent(), 0.0f); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + else if (_rightBounceNeeded) + { + Point scrollVector = Point(_size.width, 0.0f) - Point(_innerContainer->getRightInParent(), 0.0f); + float orSpeed = scrollVector.getLength()/(0.2f); + _bounceDir = scrollVector.normalize(); + startBounceChildren(orSpeed); + } + return true; + } + return false; +} + +void ScrollView::checkBounceBoundary() +{ + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos > _bottomBoundary) + { + scrollToBottomEvent(); + _bottomBounceNeeded = true; + } + else + { + _bottomBounceNeeded = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos < _topBoundary) + { + scrollToTopEvent(); + _topBounceNeeded = true; + } + else + { + _topBounceNeeded = false; + } + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos < _rightBoundary) + { + scrollToRightEvent(); + _rightBounceNeeded = true; + } + else + { + _rightBounceNeeded = false; + } + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos > _leftBoundary) + { + scrollToLeftEvent(); + _leftBounceNeeded = true; + } + else + { + _leftBounceNeeded = false; + } +} + +void ScrollView::startBounceChildren(float v) +{ + _bounceOriginalSpeed = v; + _bouncing = true; +} + +void ScrollView::stopBounceChildren() +{ + _bouncing = false; + _bounceOriginalSpeed = 0.0f; + _leftBounceNeeded = false; + _rightBounceNeeded = false; + _topBounceNeeded = false; + _bottomBounceNeeded = false; +} + +void ScrollView::startAutoScrollChildrenWithOriginalSpeed(const Point& dir, float v, bool attenuated, float acceleration) +{ + stopAutoScrollChildren(); + _autoScrollDir = dir; + _isAutoScrollSpeedAttenuated = attenuated; + _autoScrollOriginalSpeed = v; + _autoScroll = true; + _autoScrollAcceleration = acceleration; +} + +void ScrollView::startAutoScrollChildrenWithDestination(const Point& des, float time, bool attenuated) +{ + _needCheckAutoScrollDestination = false; + _autoScrollDestination = des; + Point dis = des - _innerContainer->getPosition(); + Point dir = dis.normalize(); + float orSpeed = 0.0f; + float acceleration = -1000.0f; + if (attenuated) + { + acceleration = (-(2 * dis.getLength())) / (time * time); + orSpeed = 2 * dis.getLength() / time; + } + else + { + _needCheckAutoScrollDestination = true; + orSpeed = dis.getLength() / time; + } + startAutoScrollChildrenWithOriginalSpeed(dir, orSpeed, attenuated, acceleration); +} + +void ScrollView::jumpToDestination(const Point &des) +{ + float finalOffsetX = des.x; + float finalOffsetY = des.y; + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: + if (des.y <= 0) + { + finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height); + } + break; + case SCROLLVIEW_DIR_HORIZONTAL: + if (des.x <= 0) + { + finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width); + } + break; + case SCROLLVIEW_DIR_BOTH: + if (des.y <= 0) + { + finalOffsetY = MAX(des.y, _size.height - _innerContainer->getSize().height); + } + if (des.x <= 0) + { + finalOffsetX = MAX(des.x, _size.width - _innerContainer->getSize().width); + } + break; + default: + break; + } + _innerContainer->setPosition(Point(finalOffsetX, finalOffsetY)); +} + +void ScrollView::stopAutoScrollChildren() +{ + _autoScroll = false; + _autoScrollOriginalSpeed = 0.0f; + _autoScrollAddUpTime = 0.0f; +} + +bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY) +{ + bool scrollenabled = true; + if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) //first quadrant //bounce to top-right + { + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + realOffsetX >= _rightBoundary) + { + realOffsetX = _rightBoundary - icRightPos; + bounceRightEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY >= _topBoundary) + { + realOffsetY = _topBoundary - icTopPos; + bounceTopEvent(); + scrollenabled = false; + } + moveChildren(realOffsetX, realOffsetY); + } + else if(touchOffsetX < 0.0f && touchOffsetY > 0.0f) //second quadrant //bounce to top-left + { + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + float icLefrPos = _innerContainer->getLeftInParent(); + if (icLefrPos + realOffsetX <= _leftBoundary) + { + realOffsetX = _leftBoundary - icLefrPos; + bounceLeftEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY >= _topBoundary) + { + realOffsetY = _topBoundary - icTopPos; + bounceTopEvent(); + scrollenabled = false; + } + moveChildren(realOffsetX, realOffsetY); + } + else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) //third quadrant //bounce to bottom-left + { + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + float icLefrPos = _innerContainer->getLeftInParent(); + if (icLefrPos + realOffsetX <= _leftBoundary) + { + realOffsetX = _leftBoundary - icLefrPos; + bounceLeftEvent(); + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY <= _bottomBoundary) + { + realOffsetY = _bottomBoundary - icBottomPos; + bounceBottomEvent(); + scrollenabled = false; + } + moveChildren(realOffsetX, realOffsetY); + } + else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) //forth quadrant //bounce to bottom-right + { + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + realOffsetX >= _rightBoundary) + { + realOffsetX = _rightBoundary - icRightPos; + bounceRightEvent(); + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY <= _bottomBoundary) + { + realOffsetY = _bottomBoundary - icBottomPos; + bounceBottomEvent(); + scrollenabled = false; + } + moveChildren(realOffsetX, realOffsetY); + } + else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // bounce to top + { + float realOffsetY = touchOffsetY; + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY >= _topBoundary) + { + realOffsetY = _topBoundary - icTopPos; + bounceTopEvent(); + scrollenabled = false; + } + moveChildren(0.0f, realOffsetY); + } + else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) //bounce to bottom + { + float realOffsetY = touchOffsetY; + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY <= _bottomBoundary) + { + realOffsetY = _bottomBoundary - icBottomPos; + bounceBottomEvent(); + scrollenabled = false; + } + moveChildren(0.0f, realOffsetY); + } + else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) //bounce to right + { + float realOffsetX = touchOffsetX; + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + realOffsetX >= _rightBoundary) + { + realOffsetX = _rightBoundary - icRightPos; + bounceRightEvent(); + scrollenabled = false; + } + moveChildren(realOffsetX, 0.0f); + } + else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) //bounce to left + { + float realOffsetX = touchOffsetX; + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + realOffsetX <= _leftBoundary) + { + realOffsetX = _leftBoundary - icLeftPos; + bounceLeftEvent(); + scrollenabled = false; + } + moveChildren(realOffsetX, 0.0f); + } + return scrollenabled; +} + +bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY) +{ + bool scrollenabled = true; + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: // vertical + { + if (_autoScrollDir.y > 0) + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icBottomPos; + scrollenabled = false; + } + } + else + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + *touchOffsetY <= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icBottomPos; + scrollenabled = false; + } + } + break; + } + case SCROLLVIEW_DIR_HORIZONTAL: // horizontal + { + if (_autoScrollDir.x > 0) + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icLeftPos; + scrollenabled = false; + } + } + else + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + *touchOffsetX <= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icLeftPos; + scrollenabled = false; + } + } + break; + } + case SCROLLVIEW_DIR_BOTH: + { + if (*touchOffsetX > 0.0f && *touchOffsetY > 0.0f) // up right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icLeftPos; + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icBottomPos; + scrollenabled = false; + } + } + else if (*touchOffsetX < 0.0f && *touchOffsetY > 0.0f) // up left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icRightPos; + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icBottomPos; + scrollenabled = false; + } + } + else if (*touchOffsetX < 0.0f && *touchOffsetY < 0.0f) // down left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icRightPos; + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icTopPos; + scrollenabled = false; + } + } + else if (*touchOffsetX > 0.0f && *touchOffsetY < 0.0f) // down right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icLeftPos; + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icTopPos; + scrollenabled = false; + } + } + else if (*touchOffsetX == 0.0f && *touchOffsetY > 0.0f) // up + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icBottomPos; + scrollenabled = false; + } + } + else if (*touchOffsetX < 0.0f && *touchOffsetY == 0.0f) // left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icRightPos; + scrollenabled = false; + } + } + else if (*touchOffsetX == 0.0f && *touchOffsetY < 0.0f) // down + { + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) + { + *touchOffsetY = _autoScrollDestination.y - icTopPos; + scrollenabled = false; + } + } + else if (*touchOffsetX > 0.0f && *touchOffsetY == 0.0f) // right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) + { + *touchOffsetX = _autoScrollDestination.x - icLeftPos; + scrollenabled = false; + } + } + break; + } + default: + break; + } + return scrollenabled; +} + +bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) +{ + bool scrollenabled = true; + scrollingEvent(); + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: // vertical + { + float realOffset = touchOffsetY; + if (_bounceEnabled) + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) + { + realOffset = _bounceBottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _bounceTopBoundary) + { + realOffset = _bounceTopBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bottomBoundary) + { + realOffset = _bottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _topBoundary) + { + realOffset = _topBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + moveChildren(0.0f, realOffset); + break; + } + case SCROLLVIEW_DIR_HORIZONTAL: // horizontal + { + float realOffset = touchOffsetX; + if (_bounceEnabled) + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _bounceRightBoundary) + { + realOffset = _bounceRightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) + { + realOffset = _bounceLeftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + } + else + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _rightBoundary) + { + realOffset = _rightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _leftBoundary) + { + realOffset = _leftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + } + moveChildren(realOffset, 0.0f); + break; + } + case SCROLLVIEW_DIR_BOTH: + { + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + if (_bounceEnabled) + { + if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) + { + realOffsetX = _bounceLeftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) + { + realOffsetY = _bounceBottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _bounceRightBoundary) + { + realOffsetX = _bounceRightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) + { + realOffsetY = _bounceBottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _bounceRightBoundary) + { + realOffsetX = _bounceRightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _bounceTopBoundary) + { + realOffsetY = _bounceTopBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) + { + realOffsetX = _bounceLeftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _bounceTopBoundary) + { + realOffsetY = _bounceTopBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) + { + realOffsetY = _bounceBottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _bounceRightBoundary) + { + realOffsetX = _bounceRightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down + { + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _bounceTopBoundary) + { + realOffsetY = _bounceTopBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) + { + realOffsetX = _bounceLeftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + } + } + else + { + if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _leftBoundary) + { + realOffsetX = _leftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bottomBoundary) + { + realOffsetY = _bottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _rightBoundary) + { + realOffsetX = _rightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bottomBoundary) + { + realOffsetY = _bottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _rightBoundary) + { + realOffsetX = _rightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _topBoundary) + { + realOffsetY = _topBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _leftBoundary) + { + realOffsetX = _leftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _topBoundary) + { + realOffsetY = _topBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up + { + float icBottomPos = _innerContainer->getBottomInParent(); + if (icBottomPos + touchOffsetY >= _bottomBoundary) + { + realOffsetY = _bottomBoundary - icBottomPos; + scrollToBottomEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left + { + float icRightPos = _innerContainer->getRightInParent(); + if (icRightPos + touchOffsetX <= _rightBoundary) + { + realOffsetX = _rightBoundary - icRightPos; + scrollToRightEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down + { + float icTopPos = _innerContainer->getTopInParent(); + if (icTopPos + touchOffsetY <= _topBoundary) + { + realOffsetY = _topBoundary - icTopPos; + scrollToTopEvent(); + scrollenabled = false; + } + } + else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right + { + float icLeftPos = _innerContainer->getLeftInParent(); + if (icLeftPos + touchOffsetX >= _leftBoundary) + { + realOffsetX = _leftBoundary - icLeftPos; + scrollToLeftEvent(); + scrollenabled = false; + } + } + } + moveChildren(realOffsetX, realOffsetY); + break; + } + default: + break; + } + return scrollenabled; +} + +void ScrollView::scrollToBottom(float time, bool attenuated) +{ + startAutoScrollChildrenWithDestination(Point(_innerContainer->getPosition().x, 0.0f), time, attenuated); +} + +void ScrollView::scrollToTop(float time, bool attenuated) +{ + startAutoScrollChildrenWithDestination(Point(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height), time, attenuated); +} + +void ScrollView::scrollToLeft(float time, bool attenuated) +{ + startAutoScrollChildrenWithDestination(Point(0.0f, _innerContainer->getPosition().y), time, attenuated); +} + +void ScrollView::scrollToRight(float time, bool attenuated) +{ + startAutoScrollChildrenWithDestination(Point(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y), time, attenuated); +} + +void ScrollView::scrollToTopLeft(float time, bool attenuated) +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + startAutoScrollChildrenWithDestination(Point(0.0f, _size.height - _innerContainer->getSize().height), time, attenuated); +} + +void ScrollView::scrollToTopRight(float time, bool attenuated) +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + startAutoScrollChildrenWithDestination(Point(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height), time, attenuated); +} + +void ScrollView::scrollToBottomLeft(float time, bool attenuated) +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + startAutoScrollChildrenWithDestination(Point::ZERO, time, attenuated); +} + +void ScrollView::scrollToBottomRight(float time, bool attenuated) +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + startAutoScrollChildrenWithDestination(Point(_size.width - _innerContainer->getSize().width, 0.0f), time, attenuated); +} + +void ScrollView::scrollToPercentVertical(float percent, float time, bool attenuated) +{ + float minY = _size.height - _innerContainer->getSize().height; + float h = - minY; + startAutoScrollChildrenWithDestination(Point(_innerContainer->getPosition().x, minY + percent * h / 100.0f), time, attenuated); +} + +void ScrollView::scrollToPercentHorizontal(float percent, float time, bool attenuated) +{ + float w = _innerContainer->getSize().width - _size.width; + startAutoScrollChildrenWithDestination(Point(-(percent * w / 100.0f), _innerContainer->getPosition().y), time, attenuated); +} + +void ScrollView::scrollToPercentBothDirection(const Point& percent, float time, bool attenuated) +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + return; + } + float minY = _size.height - _innerContainer->getSize().height; + float h = - minY; + float w = _innerContainer->getSize().width - _size.width; + startAutoScrollChildrenWithDestination(Point(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), time, attenuated); +} + +void ScrollView::jumpToBottom() +{ + jumpToDestination(Point(_innerContainer->getPosition().x, 0.0f)); +} + +void ScrollView::jumpToTop() +{ + jumpToDestination(Point(_innerContainer->getPosition().x, _size.height - _innerContainer->getSize().height)); +} + +void ScrollView::jumpToLeft() +{ + jumpToDestination(Point(0.0f, _innerContainer->getPosition().y)); +} + +void ScrollView::jumpToRight() +{ + jumpToDestination(Point(_size.width - _innerContainer->getSize().width, _innerContainer->getPosition().y)); +} + +void ScrollView::jumpToTopLeft() +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + jumpToDestination(Point(0.0f, _size.height - _innerContainer->getSize().height)); +} + +void ScrollView::jumpToTopRight() +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + jumpToDestination(Point(_size.width - _innerContainer->getSize().width, _size.height - _innerContainer->getSize().height)); +} + +void ScrollView::jumpToBottomLeft() +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + jumpToDestination(Point::ZERO); +} + +void ScrollView::jumpToBottomRight() +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + CCLOG("Scroll diretion is not both!"); + return; + } + jumpToDestination(Point(_size.width - _innerContainer->getSize().width, 0.0f)); +} + +void ScrollView::jumpToPercentVertical(float percent) +{ + float minY = _size.height - _innerContainer->getSize().height; + float h = - minY; + jumpToDestination(Point(_innerContainer->getPosition().x, minY + percent * h / 100.0f)); +} + +void ScrollView::jumpToPercentHorizontal(float percent) +{ + float w = _innerContainer->getSize().width - _size.width; + jumpToDestination(Point(-(percent * w / 100.0f), _innerContainer->getPosition().y)); +} + +void ScrollView::jumpToPercentBothDirection(const Point& percent) +{ + if (_direction != SCROLLVIEW_DIR_BOTH) + { + return; + } + float minY = _size.height - _innerContainer->getSize().height; + float h = - minY; + float w = _innerContainer->getSize().width - _size.width; + jumpToDestination(Point(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f)); +} + +void ScrollView::startRecordSlidAction() +{ + if (_autoScroll) + { + stopAutoScrollChildren(); + } + if (_bouncing) + { + stopBounceChildren(); + } + _slidTime = 0.0f; +} + +void ScrollView::endRecordSlidAction() +{ + if (!checkNeedBounce() && _inertiaScrollEnabled) + { + if (_slidTime <= 0.016f) + { + return; + } + float totalDis = 0.0f; + Point dir; + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: + totalDis = _touchEndedPoint.y - _touchBeganPoint.y; + if (totalDis < 0.0f) + { + dir = SCROLLDIR_DOWN; + } + else + { + dir = SCROLLDIR_UP; + } + break; + case SCROLLVIEW_DIR_HORIZONTAL: + totalDis = _touchEndedPoint.x - _touchBeganPoint.x; + if (totalDis < 0.0f) + { + dir = SCROLLDIR_LEFT; + } + else + { + dir = SCROLLDIR_RIGHT; + } + break; + case SCROLLVIEW_DIR_BOTH: + { + Point subVector = _touchEndedPoint - _touchBeganPoint; + totalDis = subVector.getLength(); + dir = subVector.normalize(); + break; + } + default: + break; + } + float orSpeed = MIN(fabs(totalDis)/(_slidTime), AUTOSCROLLMAXSPEED); + startAutoScrollChildrenWithOriginalSpeed(dir, orSpeed, true, -1000); + _slidTime = 0.0f; + } +} + +void ScrollView::handlePressLogic(const Point &touchPoint) +{ + _touchBeganPoint = convertToNodeSpace(touchPoint); + _touchMovingPoint = _touchBeganPoint; + startRecordSlidAction(); + _bePressed = true; +} + +void ScrollView::handleMoveLogic(const Point &touchPoint) +{ + _touchMovedPoint = convertToNodeSpace(touchPoint); + Point delta = _touchMovedPoint - _touchMovingPoint; + _touchMovingPoint = _touchMovedPoint; + switch (_direction) + { + case SCROLLVIEW_DIR_VERTICAL: // vertical + { + scrollChildren(0.0f, delta.y); + break; + } + case SCROLLVIEW_DIR_HORIZONTAL: // horizontal + { + scrollChildren(delta.x, 0.0f); + break; + } + case SCROLLVIEW_DIR_BOTH: // both + { + scrollChildren(delta.x, delta.y); + break; + } + default: + break; + } +} + +void ScrollView::handleReleaseLogic(const Point &touchPoint) +{ + _touchEndedPoint = convertToNodeSpace(touchPoint); + endRecordSlidAction(); + _bePressed = false; +} + +bool ScrollView::onTouchBegan(Touch *touch, Event *unusedEvent) +{ + bool pass = Layout::onTouchBegan(touch, unusedEvent); + if (_hitted) + { + handlePressLogic(_touchStartPos); + } + return pass; +} + +void ScrollView::onTouchMoved(Touch *touch, Event *unusedEvent) +{ + Layout::onTouchMoved(touch, unusedEvent); + handleMoveLogic(_touchMovePos); +} + +void ScrollView::onTouchEnded(Touch *touch, Event *unusedEvent) +{ + Layout::onTouchEnded(touch, unusedEvent); + handleReleaseLogic(_touchEndPos); +} + +void ScrollView::onTouchCancelled(Touch *touch, Event *unusedEvent) +{ + Layout::onTouchCancelled(touch, unusedEvent); + handleReleaseLogic(touch->getLocation()); +} + +void ScrollView::update(float dt) +{ + if (_autoScroll) + { + autoScrollChildren(dt); + } + if (_bouncing) + { + bounceChildren(dt); + } + recordSlidTime(dt); +} + +void ScrollView::recordSlidTime(float dt) +{ + if (_bePressed) + { + _slidTime += dt; + } +} + +void ScrollView::interceptTouchEvent(int handleState, Widget *sender, const Point &touchPoint) +{ + switch (handleState) + { + case 0: + handlePressLogic(touchPoint); + break; + + case 1: + { + float offset = (sender->getTouchStartPos() - touchPoint).getLength(); + if (offset > _childFocusCancelOffset) + { + sender->setFocused(false); + handleMoveLogic(touchPoint); + } + } + break; + + case 2: + handleReleaseLogic(touchPoint); + break; + + case 3: + handleReleaseLogic(touchPoint); + break; + } +} + +void ScrollView::checkChildInfo(int handleState,Widget* sender,const Point &touchPoint) +{ + interceptTouchEvent(handleState, sender, touchPoint); +} + +void ScrollView::scrollToTopEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP); + } +} + +void ScrollView::scrollToBottomEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM); + } +} + +void ScrollView::scrollToLeftEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT); + } +} + +void ScrollView::scrollToRightEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_RIGHT); + } +} + +void ScrollView::scrollingEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLLING); + } +} + +void ScrollView::bounceTopEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_TOP); + } +} + +void ScrollView::bounceBottomEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_BOTTOM); + } +} + +void ScrollView::bounceLeftEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_LEFT); + } +} + +void ScrollView::bounceRightEvent() +{ + if (_scrollViewEventListener && _scrollViewEventSelector) + { + (_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_RIGHT); + } +} + +void ScrollView::addEventListenerScrollView(Ref *target, SEL_ScrollViewEvent selector) +{ + _scrollViewEventListener = target; + _scrollViewEventSelector = selector; +} + +void ScrollView::setDirection(SCROLLVIEW_DIR dir) +{ + _direction = dir; +} + +SCROLLVIEW_DIR ScrollView::getDirection() +{ + return _direction; +} + +void ScrollView::setBounceEnabled(bool enabled) +{ + _bounceEnabled = enabled; +} + +bool ScrollView::isBounceEnabled() const +{ + return _bounceEnabled; +} + +void ScrollView::setInertiaScrollEnabled(bool enabled) +{ + _inertiaScrollEnabled = enabled; +} + +bool ScrollView::isInertiaScrollEnabled() const +{ + return _inertiaScrollEnabled; +} + +Layout* ScrollView::getInnerContainer() +{ + return _innerContainer; +} + +void ScrollView::setLayoutType(LayoutType type) +{ + _innerContainer->setLayoutType(type); +} + +LayoutType ScrollView::getLayoutType() const +{ + return _innerContainer->getLayoutType(); +} + +void ScrollView::doLayout() +{ + if (!_doLayoutDirty) + { + return; + } + _doLayoutDirty = false; +} + +std::string ScrollView::getDescription() const +{ + return "ScrollView"; +} + +Widget* ScrollView::createCloneInstance() +{ + return ScrollView::create(); +} + +void ScrollView::copyClonedWidgetChildren(Widget* model) +{ + Layout::copyClonedWidgetChildren(model); +} + +void ScrollView::copySpecialProperties(Widget *widget) +{ + ScrollView* scrollView = dynamic_cast(widget); + if (scrollView) + { + Layout::copySpecialProperties(widget); + setInnerContainerSize(scrollView->getInnerContainerSize()); + setDirection(scrollView->_direction); + setBounceEnabled(scrollView->_bounceEnabled); + setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h new file mode 100644 index 0000000000..1f0150e2ea --- /dev/null +++ b/cocos/ui/UIScrollView.h @@ -0,0 +1,430 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UISCROLLVIEW_H__ +#define __UISCROLLVIEW_H__ + +#include "ui/UILayout.h" +#include "ui/UIScrollInterface.h" + +NS_CC_BEGIN + +namespace ui { + +enum SCROLLVIEW_DIR +{ + SCROLLVIEW_DIR_NONE, + SCROLLVIEW_DIR_VERTICAL, + SCROLLVIEW_DIR_HORIZONTAL, + SCROLLVIEW_DIR_BOTH +}; + +typedef enum +{ + SCROLLVIEW_EVENT_SCROLL_TO_TOP, + SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM, + SCROLLVIEW_EVENT_SCROLL_TO_LEFT, + SCROLLVIEW_EVENT_SCROLL_TO_RIGHT, + SCROLLVIEW_EVENT_SCROLLING, + SCROLLVIEW_EVENT_BOUNCE_TOP, + SCROLLVIEW_EVENT_BOUNCE_BOTTOM, + SCROLLVIEW_EVENT_BOUNCE_LEFT, + SCROLLVIEW_EVENT_BOUNCE_RIGHT +}ScrollviewEventType; + +typedef void (Ref::*SEL_ScrollViewEvent)(Ref*, ScrollviewEventType); +#define scrollvieweventselector(_SELECTOR) (SEL_ScrollViewEvent)(&_SELECTOR) + + +class ScrollView : public Layout , public UIScrollInterface +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + ScrollView(); + + /** + * Default destructor + */ + virtual ~ScrollView(); + + /** + * Allocates and initializes. + */ + static ScrollView* create(); + + /** + * Changes scroll direction of scrollview. + * + * @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll + * + * @param SCROLLVIEW_DIR + */ + virtual void setDirection(SCROLLVIEW_DIR dir); + + /** + * Gets scroll direction of scrollview. + * + * @see SCROLLVIEW_DIR SCROLLVIEW_DIR_VERTICAL means vertical scroll, SCROLLVIEW_DIR_HORIZONTAL means horizontal scroll + * + * @return SCROLLVIEW_DIR + */ + SCROLLVIEW_DIR getDirection(); + + /** + * Gets inner container of scrollview. + * + * Inner container is the container of scrollview's children. + * + * @return inner container. + */ + Layout* getInnerContainer(); + + /** + * Scroll inner container to bottom boundary of scrollview. + */ + void scrollToBottom(float time, bool attenuated); + + /** + * Scroll inner container to top boundary of scrollview. + */ + void scrollToTop(float time, bool attenuated); + + /** + * Scroll inner container to left boundary of scrollview. + */ + void scrollToLeft(float time, bool attenuated); + + /** + * Scroll inner container to right boundary of scrollview. + */ + void scrollToRight(float time, bool attenuated); + + /** + * Scroll inner container to top and left boundary of scrollview. + */ + void scrollToTopLeft(float time, bool attenuated); + + /** + * Scroll inner container to top and right boundary of scrollview. + */ + void scrollToTopRight(float time, bool attenuated); + + /** + * Scroll inner container to bottom and left boundary of scrollview. + */ + void scrollToBottomLeft(float time, bool attenuated); + + /** + * Scroll inner container to bottom and right boundary of scrollview. + */ + void scrollToBottomRight(float time, bool attenuated); + + /** + * Scroll inner container to vertical percent position of scrollview. + */ + void scrollToPercentVertical(float percent, float time, bool attenuated); + + /** + * Scroll inner container to horizontal percent position of scrollview. + */ + void scrollToPercentHorizontal(float percent, float time, bool attenuated); + + /** + * Scroll inner container to both direction percent position of scrollview. + */ + void scrollToPercentBothDirection(const Point& percent, float time, bool attenuated); + + /** + * Move inner container to bottom boundary of scrollview. + */ + void jumpToBottom(); + + /** + * Move inner container to top boundary of scrollview. + */ + void jumpToTop(); + + /** + * Move inner container to left boundary of scrollview. + */ + void jumpToLeft(); + + /** + * Move inner container to right boundary of scrollview. + */ + void jumpToRight(); + + /** + * Move inner container to top and left boundary of scrollview. + */ + void jumpToTopLeft(); + + /** + * Move inner container to top and right boundary of scrollview. + */ + void jumpToTopRight(); + + /** + * Move inner container to bottom and left boundary of scrollview. + */ + void jumpToBottomLeft(); + + /** + * Move inner container to bottom and right boundary of scrollview. + */ + void jumpToBottomRight(); + + /** + * Move inner container to vertical percent position of scrollview. + */ + void jumpToPercentVertical(float percent); + + /** + * Move inner container to horizontal percent position of scrollview. + */ + void jumpToPercentHorizontal(float percent); + + /** + * Move inner container to both direction percent position of scrollview. + */ + void jumpToPercentBothDirection(const Point& percent); + + /** + * Changes inner container size of scrollview. + * + * Inner container size must be larger than or equal scrollview's size. + * + * @param inner container size. + */ + void setInnerContainerSize(const Size &size); + + /** + * Gets inner container size of scrollview. + * + * Inner container size must be larger than or equal scrollview's size. + * + * @return inner container size. + */ + const Size& getInnerContainerSize() const; + + /** + * Add call back function called scrollview event triggered + */ + void addEventListenerScrollView(Ref* target, SEL_ScrollViewEvent selector); + + virtual void addChild(Node * child) override; + /** + * Adds a child to the container with a z-order + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) + */ + virtual void addChild(Node * child, int zOrder) override; + /** + * Adds a child to the container with z order and tag + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) + * @param tag A interger to identify the node easily. Please refer to setTag(int) + */ + virtual void addChild(Node* child, int zOrder, int tag) override; + + //override "removeAllChildrenAndCleanUp" method of widget. + virtual void removeAllChildren() override; + + virtual void removeAllChildrenWithCleanup(bool cleanup) override; + + //override "removeChild" method of widget. + virtual void removeChild(Node* child, bool cleaup = true) override; + + //override "getChildren" method of widget. + virtual Vector& getChildren() override; + virtual const Vector& getChildren() const override; + + virtual ssize_t getChildrenCount() const override; + + virtual Node * getChildByTag(int tag) override; + + virtual Widget* getChildByName(const char* name) override; + + virtual void addNode(Node* node) override; + + virtual void addNode(Node * node, int zOrder) override; + + virtual void addNode(Node* node, int zOrder, int tag) override; + + virtual Node * getNodeByTag(int tag) override; + + virtual Vector& getNodes() override; + + virtual void removeNode(Node* node) override; + + virtual void removeNodeByTag(int tag) override; + + virtual void removeAllNodes() override; + + virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; + virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; + virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; + virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; + + virtual void update(float dt) override; + + void setBounceEnabled(bool enabled); + + bool isBounceEnabled() const; + + void setInertiaScrollEnabled(bool enabled); + + bool isInertiaScrollEnabled() const; + + /** + * Sets LayoutType. + * + * @see LayoutType + * + * @param LayoutType + */ + virtual void setLayoutType(LayoutType type) override; + + /** + * Gets LayoutType. + * + * @see LayoutType + * + * @return LayoutType + */ + virtual LayoutType getLayoutType() const override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + virtual void onEnter() override; +protected: + virtual bool init() override; + virtual void initRenderer() override; + void moveChildren(float offsetX, float offsetY); + void autoScrollChildren(float dt); + void bounceChildren(float dt); + void checkBounceBoundary(); + bool checkNeedBounce(); + void startAutoScrollChildrenWithOriginalSpeed(const Point& dir, float v, bool attenuated, float acceleration); + void startAutoScrollChildrenWithDestination(const Point& des, float time, bool attenuated); + void jumpToDestination(const Point& des); + void stopAutoScrollChildren(); + void startBounceChildren(float v); + void stopBounceChildren(); + bool checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY); + virtual bool scrollChildren(float touchOffsetX, float touchOffsetY); + bool bounceScrollChildren(float touchOffsetX, float touchOffsetY); + void startRecordSlidAction(); + virtual void endRecordSlidAction(); + virtual void handlePressLogic(const Point &touchPoint) override; + virtual void handleMoveLogic(const Point &touchPoint) override; + virtual void handleReleaseLogic(const Point &touchPoint) override; + virtual void interceptTouchEvent(int handleState,Widget* sender,const Point &touchPoint) override; + virtual void checkChildInfo(int handleState,Widget* sender,const Point &touchPoint) override; + void recordSlidTime(float dt); + void scrollToTopEvent(); + void scrollToBottomEvent(); + void scrollToLeftEvent(); + void scrollToRightEvent(); + void scrollingEvent(); + void bounceTopEvent(); + void bounceBottomEvent(); + void bounceLeftEvent(); + void bounceRightEvent(); + virtual void onSizeChanged() override; + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; + virtual void copyClonedWidgetChildren(Widget* model) override; + virtual void setClippingEnabled(bool able) override{Layout::setClippingEnabled(able);}; + virtual void doLayout() override; +protected: + Layout* _innerContainer; + + SCROLLVIEW_DIR _direction; + + Point _touchBeganPoint; + Point _touchMovedPoint; + Point _touchEndedPoint; + Point _touchMovingPoint; + Point _autoScrollDir; + + float _topBoundary; + float _bottomBoundary; + float _leftBoundary; + float _rightBoundary; + + float _bounceTopBoundary; + float _bounceBottomBoundary; + float _bounceLeftBoundary; + float _bounceRightBoundary; + + + bool _autoScroll; + float _autoScrollAddUpTime; + + float _autoScrollOriginalSpeed; + float _autoScrollAcceleration; + bool _isAutoScrollSpeedAttenuated; + bool _needCheckAutoScrollDestination; + Point _autoScrollDestination; + + bool _bePressed; + float _slidTime; + Point _moveChildPoint; + float _childFocusCancelOffset; + + bool _leftBounceNeeded; + bool _topBounceNeeded; + bool _rightBounceNeeded; + bool _bottomBounceNeeded; + + bool _bounceEnabled; + bool _bouncing; + Point _bounceDir; + float _bounceOriginalSpeed; + bool _inertiaScrollEnabled; + + + + Ref* _scrollViewEventListener; + SEL_ScrollViewEvent _scrollViewEventSelector; +}; + +} +NS_CC_END +#endif /* defined(__CocoGUI__ScrollView__) */ diff --git a/cocos/ui/UISlider.cpp b/cocos/ui/UISlider.cpp new file mode 100644 index 0000000000..3b0737ef0e --- /dev/null +++ b/cocos/ui/UISlider.cpp @@ -0,0 +1,600 @@ +/**************************************************************************** +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" + +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(UI_TEX_TYPE_LOCAL), +_progressBarTexType(UI_TEX_TYPE_LOCAL), +_ballNTexType(UI_TEX_TYPE_LOCAL), +_ballPTexType(UI_TEX_TYPE_LOCAL), +_ballDTexType(UI_TEX_TYPE_LOCAL) +{ +} + +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()) + { + setTouchEnabled(true); + return true; + } + return false; +} + +void Slider::initRenderer() +{ + _barRenderer = Sprite::create(); + _progressBarRenderer = Sprite::create(); + _progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f)); + Node::addChild(_barRenderer, BASEBAR_RENDERER_Z, -1); + Node::addChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1); + _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); + Node::addChild(_slidBallRenderer, SLIDBALL_RENDERER_Z, -1); +} + +void Slider::loadBarTexture(const char* fileName, TextureResType texType) +{ + if (!fileName || strcmp(fileName, "") == 0) + { + return; + } + _textureFile = fileName; + _barTexType = texType; + switch (_barTexType) + { + case UI_TEX_TYPE_LOCAL: + if (_scale9Enabled) + { + static_cast(_barRenderer)->initWithFile(fileName); + } + else + { + static_cast(_barRenderer)->setTexture(fileName); + } + break; + case UI_TEX_TYPE_PLIST: + if (_scale9Enabled) + { + static_cast(_barRenderer)->initWithSpriteFrameName(fileName); + } + else + { + static_cast(_barRenderer)->setSpriteFrame(fileName); + } + break; + default: + break; + } + updateRGBAToRenderer(_barRenderer); + barRendererScaleChangedWithSize(); + progressBarRendererScaleChangedWithSize(); +} + +void Slider::loadProgressBarTexture(const char *fileName, TextureResType texType) +{ + if (!fileName || strcmp(fileName, "") == 0) + { + return; + } + _progressBarTextureFile = fileName; + _progressBarTexType = texType; + switch (_progressBarTexType) + { + case UI_TEX_TYPE_LOCAL: + if (_scale9Enabled) + { + static_cast(_progressBarRenderer)->initWithFile(fileName); + } + else + { + static_cast(_progressBarRenderer)->setTexture(fileName); + } + break; + case UI_TEX_TYPE_PLIST: + if (_scale9Enabled) + { + static_cast(_progressBarRenderer)->initWithSpriteFrameName(fileName); + } + else + { + static_cast(_progressBarRenderer)->setSpriteFrame(fileName); + } + break; + default: + break; + } + updateRGBAToRenderer(_progressBarRenderer); + _progressBarRenderer->setAnchorPoint(Point(0.0f, 0.5f)); + _progressBarTextureSize = _progressBarRenderer->getContentSize(); + progressBarRendererScaleChangedWithSize(); +} + +void Slider::setScale9Enabled(bool able) +{ + if (_scale9Enabled == able) + { + return; + } + + _scale9Enabled = able; + Node::removeChild(_barRenderer); + Node::removeChild(_progressBarRenderer); + _barRenderer = nullptr; + _progressBarRenderer = nullptr; + if (_scale9Enabled) + { + _barRenderer = extension::Scale9Sprite::create(); + _progressBarRenderer = extension::Scale9Sprite::create(); + } + else + { + _barRenderer = Sprite::create(); + _progressBarRenderer = Sprite::create(); + } + loadBarTexture(_textureFile.c_str(), _barTexType); + loadProgressBarTexture(_progressBarTextureFile.c_str(), _progressBarTexType); + Node::addChild(_barRenderer, BASEBAR_RENDERER_Z, -1); + Node::addChild(_progressBarRenderer, PROGRESSBAR_RENDERER_Z, -1); + if (_scale9Enabled) + { + bool ignoreBefore = _ignoreSize; + ignoreContentAdaptWithSize(false); + _prevIgnoreSize = ignoreBefore; + } + else + { + ignoreContentAdaptWithSize(_prevIgnoreSize); + } + setCapInsetsBarRenderer(_capInsetsBarRenderer); + setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer); +} + +bool Slider::isScale9Enabled() +{ + 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(_barRenderer)->setCapInsets(capInsets); +} + +const Rect& Slider::getCapInsetsBarRenderer() +{ + return _capInsetsBarRenderer; +} + +void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets) +{ + _capInsetsProgressBarRenderer = capInsets; + if (!_scale9Enabled) + { + return; + } + static_cast(_progressBarRenderer)->setCapInsets(capInsets); +} + +const Rect& Slider::getCapInsetsProgressBarRebderer() +{ + return _capInsetsProgressBarRenderer; +} + +void Slider::loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType) +{ + loadSlidBallTextureNormal(normal, texType); + loadSlidBallTexturePressed(pressed,texType); + loadSlidBallTextureDisabled(disabled,texType); +} + +void Slider::loadSlidBallTextureNormal(const char* normal,TextureResType texType) +{ + if (!normal || strcmp(normal, "") == 0) + { + return; + } + _slidBallNormalTextureFile = normal; + _ballNTexType = texType; + switch (_ballNTexType) + { + case UI_TEX_TYPE_LOCAL: + _slidBallNormalRenderer->setTexture(normal); + break; + case UI_TEX_TYPE_PLIST: + _slidBallNormalRenderer->setSpriteFrame(normal); + break; + default: + break; + } + updateRGBAToRenderer(_slidBallNormalRenderer); +} + +void Slider::loadSlidBallTexturePressed(const char* pressed,TextureResType texType) +{ + if (!pressed || strcmp(pressed, "") == 0) + { + return; + } + _slidBallPressedTextureFile = pressed; + _ballPTexType = texType; + switch (_ballPTexType) + { + case UI_TEX_TYPE_LOCAL: + _slidBallPressedRenderer->setTexture(pressed); + break; + case UI_TEX_TYPE_PLIST: + _slidBallPressedRenderer->setSpriteFrame(pressed); + break; + default: + break; + } + updateRGBAToRenderer(_slidBallPressedRenderer); +} + +void Slider::loadSlidBallTextureDisabled(const char* disabled,TextureResType texType) +{ + if (!disabled || strcmp(disabled, "") == 0) + { + return; + } + _slidBallDisabledTextureFile = disabled; + _ballDTexType = texType; + switch (_ballDTexType) + { + case UI_TEX_TYPE_LOCAL: + _slidBallDisabledRenderer->setTexture(disabled); + break; + case UI_TEX_TYPE_PLIST: + _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; + _slidBallRenderer->setPosition(Point(-_barLength/2.0f + dis, 0.0f)); + if (_scale9Enabled) + { + static_cast(_progressBarRenderer)->setPreferredSize(Size(dis,_progressBarTextureSize.height)); + } + else + { + Sprite* spriteRenderer = static_cast(_progressBarRenderer); + Rect rect = spriteRenderer->getTextureRect(); + rect.size.width = _progressBarTextureSize.width * res; + spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size); + } +} + +bool Slider::onTouchBegan(Touch *touch, Event *unusedEvent) +{ + bool pass = Widget::onTouchBegan(touch, unusedEvent); + if (_hitted) + { + Point nsp = convertToNodeSpace(_touchStartPos); + setPercent(getPercentWithBallPos(nsp.x)); + percentChangedEvent(); + } + return pass; +} + +void Slider::onTouchMoved(Touch *touch, Event *unusedEvent) +{ + _touchMovePos = touch->getLocation(); + Point nsp = convertToNodeSpace(_touchMovePos); + _slidBallRenderer->setPosition(Point(nsp.x,0)); + 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); +} + +float Slider::getPercentWithBallPos(float px) +{ + return (((px-(-_barLength/2.0f))/_barLength)*100.0f); +} + +void Slider::addEventListenerSlider(Ref *target, SEL_SlidPercentChangedEvent selector) +{ + _sliderEventListener = target; + _sliderEventSelector = selector; +} + +void Slider::percentChangedEvent() +{ + if (_sliderEventListener && _sliderEventSelector) + { + (_sliderEventListener->*_sliderEventSelector)(this,SLIDER_PERCENTCHANGED); + } +} + +int Slider::getPercent() +{ + return _percent; +} + +void Slider::onSizeChanged() +{ + Widget::onSizeChanged(); + barRendererScaleChangedWithSize(); + progressBarRendererScaleChangedWithSize(); +} + +const Size& Slider::getContentSize() const +{ + return _barRenderer->getContentSize(); +} + +Node* Slider::getVirtualRenderer() +{ + return _barRenderer; +} + +void Slider::barRendererScaleChangedWithSize() +{ + if (_ignoreSize) + { + + _barRenderer->setScale(1.0f); + _size = _barRenderer->getContentSize(); + _barLength = _size.width; + } + else + { + _barLength = _size.width; + if (_scale9Enabled) + { + static_cast(_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); + } + } + 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(_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); + } + } + _progressBarRenderer->setPosition(Point(-_barLength * 0.5f, 0.0f)); + 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(widget); + if (slider) + { + _prevIgnoreSize = slider->_prevIgnoreSize; + setScale9Enabled(slider->_scale9Enabled); + loadBarTexture(slider->_textureFile.c_str(), slider->_barTexType); + loadProgressBarTexture(slider->_progressBarTextureFile.c_str(), slider->_progressBarTexType); + loadSlidBallTextureNormal(slider->_slidBallNormalTextureFile.c_str(), slider->_ballNTexType); + loadSlidBallTexturePressed(slider->_slidBallPressedTextureFile.c_str(), slider->_ballPTexType); + loadSlidBallTextureDisabled(slider->_slidBallDisabledTextureFile.c_str(), slider->_ballDTexType); + setPercent(slider->getPercent()); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UISlider.h b/cocos/ui/UISlider.h new file mode 100644 index 0000000000..267120b3fc --- /dev/null +++ b/cocos/ui/UISlider.h @@ -0,0 +1,249 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UISLIDER_H__ +#define __UISLIDER_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + SLIDER_PERCENTCHANGED +}SliderEventType; + +typedef void (Ref::*SEL_SlidPercentChangedEvent)(Ref*,SliderEventType); +#define sliderpercentchangedselector(_SELECTOR) (SEL_SlidPercentChangedEvent)(&_SELECTOR) + +/** +* @js NA +* @lua NA +*/ +class Slider : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + Slider(); + + /** + * Default destructor + */ + virtual ~Slider(); + + /** + * Allocates and initializes. + */ + static Slider* create(); + + /** + * Load texture for slider bar. + * + * @param fileName file name of texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadBarTexture(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Sets if slider is using scale9 renderer. + * + * @param true that using scale9 renderer, false otherwise. + */ + void setScale9Enabled(bool able); + + bool isScale9Enabled(); + + /** + * Sets capinsets for slider, if slider is using scale9 renderer. + * + * @param capInsets capinsets for slider + */ + void setCapInsets(const Rect &capInsets); + + /** + * Sets capinsets for slider, if slider is using scale9 renderer. + * + * @param capInsets capinsets for slider + */ + void setCapInsetsBarRenderer(const Rect &capInsets); + + const Rect& getCapInsetsBarRenderer(); + + /** + * Sets capinsets for slider, if slider is using scale9 renderer. + * + * @param capInsets capinsets for slider + */ + void setCapInsetProgressBarRebderer(const Rect &capInsets); + + const Rect& getCapInsetsProgressBarRebderer(); + + /** + * Load textures for slider ball. + * + * @param slider ball normal normal state texture. + * + * @param slider ball selected selected state texture. + * + * @param slider ball disabled dark state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadSlidBallTextures(const char* normal,const char* pressed,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load normal state texture for slider ball. + * + * @param normal normal state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadSlidBallTextureNormal(const char* normal,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load selected state texture for slider ball. + * + * @param selected selected state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadSlidBallTexturePressed(const char* pressed,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load dark state texture for slider ball. + * + * @param disabled dark state texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadSlidBallTextureDisabled(const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Load dark state texture for slider progress bar. + * + * @param fileName file path of texture. + * + * @param texType @see UI_TEX_TYPE_LOCAL + */ + void loadProgressBarTexture(const char* fileName, TextureResType texType = UI_TEX_TYPE_LOCAL); + + /** + * Changes the progress direction of slider. + * + * @param percent percent value from 1 to 100. + */ + void setPercent(int percent); + + /** + * Gets the progress direction of slider. + * + * @return percent percent value from 1 to 100. + */ + int getPercent(); + + /** + * Add call back function called when slider's percent has changed to slider. + */ + void addEventListenerSlider(Ref* target,SEL_SlidPercentChangedEvent selector); + + virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; + virtual void onTouchMoved(Touch *touch, Event *unusedEvent) override; + virtual void onTouchEnded(Touch *touch, Event *unusedEvent) override; + virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override; + + //override "getContentSize" method of widget. + virtual const Size& getContentSize() const override; + + //override "getVirtualRenderer" method of widget. + virtual Node* getVirtualRenderer() override; + + //override "ignoreContentAdaptWithSize" method of widget. + virtual void ignoreContentAdaptWithSize(bool ignore) override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + +protected: + virtual bool init() override; + virtual void initRenderer() override; + float getPercentWithBallPos(float location); + void percentChangedEvent(); + virtual void onPressStateChangedToNormal() override; + virtual void onPressStateChangedToPressed() override; + virtual void onPressStateChangedToDisabled() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + void barRendererScaleChangedWithSize(); + void progressBarRendererScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + Node* _barRenderer; + Node* _progressBarRenderer; + Size _progressBarTextureSize; + + Sprite* _slidBallNormalRenderer; + Sprite* _slidBallPressedRenderer; + Sprite* _slidBallDisabledRenderer; + Node* _slidBallRenderer; + + float _barLength; + int _percent; + + bool _scale9Enabled; + bool _prevIgnoreSize; + std::string _textureFile; + std::string _progressBarTextureFile; + std::string _slidBallNormalTextureFile; + std::string _slidBallPressedTextureFile; + std::string _slidBallDisabledTextureFile; + + Rect _capInsetsBarRenderer; + Rect _capInsetsProgressBarRenderer; + + Ref* _sliderEventListener; + SEL_SlidPercentChangedEvent _sliderEventSelector; + TextureResType _barTexType; + TextureResType _progressBarTexType; + TextureResType _ballNTexType; + TextureResType _ballPTexType; + TextureResType _ballDTexType; +}; + +} +NS_CC_END + +#endif /* defined(__CocoGUI__Slider__) */ diff --git a/cocos/ui/UIText.cpp b/cocos/ui/UIText.cpp new file mode 100644 index 0000000000..be67c99905 --- /dev/null +++ b/cocos/ui/UIText.cpp @@ -0,0 +1,287 @@ +/**************************************************************************** +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/UIText.h" + +NS_CC_BEGIN + +namespace ui { + +static const int LABEL_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(Text) + +Text::Text(): +_touchScaleChangeEnabled(false), +_normalScaleValueX(1.0f), +_normalScaleValueY(1.0f), +_fontName("Thonburi"), +_fontSize(10), +_onSelectedScaleOffset(0.5), +_labelRenderer(nullptr) +{ +} + +Text::~Text() +{ + +} + +Text* Text::create() +{ + Text* widget = new Text(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +bool Text::init() +{ + if (Widget::init()) + { + return true; + } + return false; +} + +void Text::initRenderer() +{ + _labelRenderer = LabelTTF::create(); + Node::addChild(_labelRenderer, LABEL_RENDERER_Z, -1); +} + +void Text::setText(const std::string& text) +{ + _labelRenderer->setString(text); + labelScaleChangedWithSize(); +} + +const std::string& Text::getStringValue() +{ + return _labelRenderer->getString(); +} + +ssize_t Text::getStringLength() +{ + return _labelRenderer->getString().size(); +} + +void Text::setFontSize(int size) +{ + _fontSize = size; + _labelRenderer->setFontSize(size); + labelScaleChangedWithSize(); +} + +int Text::getFontSize() +{ + return _fontSize; +} + +void Text::setFontName(const std::string& name) +{ + _fontName = name; + _labelRenderer->setFontName(name); + labelScaleChangedWithSize(); +} + +const std::string& Text::getFontName() +{ + return _fontName; +} + +void Text::setTextAreaSize(const Size &size) +{ + _labelRenderer->setDimensions(size); + labelScaleChangedWithSize(); +} + +const Size& Text::getTextAreaSize() +{ + return _labelRenderer->getDimensions(); +} + +void Text::setTextHorizontalAlignment(TextHAlignment alignment) +{ + _labelRenderer->setHorizontalAlignment(alignment); + labelScaleChangedWithSize(); +} + +TextHAlignment Text::getTextHorizontalAlignment() +{ + return _labelRenderer->getHorizontalAlignment(); +} + +void Text::setTextVerticalAlignment(TextVAlignment alignment) +{ + _labelRenderer->setVerticalAlignment(alignment); + labelScaleChangedWithSize(); +} + +TextVAlignment Text::getTextVerticalAlignment() +{ + return _labelRenderer->getVerticalAlignment(); +} + +void Text::setTouchScaleChangeEnabled(bool enable) +{ + _touchScaleChangeEnabled = enable; +} + +bool Text::isTouchScaleChangeEnabled() +{ + return _touchScaleChangeEnabled; +} + +void Text::onPressStateChangedToNormal() +{ + if (!_touchScaleChangeEnabled) + { + return; + } + _labelRenderer->setScale(_normalScaleValueX, _normalScaleValueY); +} + +void Text::onPressStateChangedToPressed() +{ + if (!_touchScaleChangeEnabled) + { + return; + } + _labelRenderer->setScale(_normalScaleValueX + _onSelectedScaleOffset, _normalScaleValueY + _onSelectedScaleOffset); +} + +void Text::onPressStateChangedToDisabled() +{ + +} + +void Text::updateFlippedX() +{ + _labelRenderer->setFlippedX(_flippedX); + +} + +void Text::updateFlippedY() +{ + _labelRenderer->setFlippedY(_flippedY); +} + +void Text::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _labelRenderer->setAnchorPoint(pt); +} + +void Text::onSizeChanged() +{ + Widget::onSizeChanged(); + labelScaleChangedWithSize(); +} + +const Size& Text::getContentSize() const +{ + return _labelRenderer->getContentSize(); +} + +Node* Text::getVirtualRenderer() +{ + return _labelRenderer; +} + +void Text::labelScaleChangedWithSize() +{ + if (_ignoreSize) + { + _labelRenderer->setDimensions(Size::ZERO); + _labelRenderer->setScale(1.0f); + _size = _labelRenderer->getContentSize(); + _normalScaleValueX = _normalScaleValueY = 1.0f; + } + else + { + _labelRenderer->setDimensions(_size); + Size textureSize = _labelRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _labelRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _labelRenderer->setScaleX(scaleX); + _labelRenderer->setScaleY(scaleY); + _normalScaleValueX = scaleX; + _normalScaleValueY = scaleY; + } + +} + +std::string Text::getDescription() const +{ + return "Label"; +} + +void Text::updateTextureColor() +{ + updateColorToRenderer(_labelRenderer); +} + +void Text::updateTextureOpacity() +{ + updateOpacityToRenderer(_labelRenderer); +} + +void Text::updateTextureRGBA() +{ + updateRGBAToRenderer(_labelRenderer); +} + +Widget* Text::createCloneInstance() +{ + return Text::create(); +} + +void Text::copySpecialProperties(Widget *widget) +{ + Text* label = dynamic_cast(widget); + if (label) + { + setFontName(label->_fontName.c_str()); + setFontSize(label->_labelRenderer->getFontSize()); + setText(label->getStringValue()); + setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled); + setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment()); + setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment()); + setTextAreaSize(label->_labelRenderer->getDimensions()); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UIText.h b/cocos/ui/UIText.h new file mode 100644 index 0000000000..46faa4d183 --- /dev/null +++ b/cocos/ui/UIText.h @@ -0,0 +1,167 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UILABEL_H__ +#define __UILABEL_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +/** +* @js NA +* @lua NA +*/ +class Text : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + Text(); + + /** + * Default destructor + */ + virtual ~Text(); + + /** + * Allocates and initializes. + */ + static Text* create(); + + /** + * Changes the string value of label. + * + * @param text string value. + */ + void setText(const std::string& text); + + /** + * Gets the string value of label. + * + * @return text string value. + */ + const std::string& getStringValue(); + + /** + * Gets the string length of label. + * + * @return string length. + */ + ssize_t getStringLength(); + + /** + * Sets the font size of label. + * + * @param font size. + */ + void setFontSize(int size); + + int getFontSize(); + + /** + * Sets the font name of label. + * + * @param font name. + */ + void setFontName(const std::string& name); + + const std::string& getFontName(); + + /** + * Sets the touch scale enabled of label. + * + * @param touch scale enabled of label. + */ + void setTouchScaleChangeEnabled(bool enabled); + + /** + * Gets the touch scale enabled of label. + * + * @return touch scale enabled of label. + */ + bool isTouchScaleChangeEnabled(); + + //override "setAnchorPoint" method of widget. + virtual void setAnchorPoint(const Point &pt) override; + + //override "getContentSize" method of widget. + virtual const Size& getContentSize() const override; + + //override "getVirtualRenderer" method of widget. + virtual Node* getVirtualRenderer() override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + void setTextAreaSize(const Size &size); + + const Size& getTextAreaSize(); + + void setTextHorizontalAlignment(TextHAlignment alignment); + + TextHAlignment getTextHorizontalAlignment(); + + void setTextVerticalAlignment(TextVAlignment alignment); + + TextVAlignment getTextVerticalAlignment(); + +protected: + virtual bool init() override; + virtual void initRenderer() override; + virtual void onPressStateChangedToNormal() override; + virtual void onPressStateChangedToPressed() override; + virtual void onPressStateChangedToDisabled() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + virtual void updateFlippedX() override; + virtual void updateFlippedY() override; + void labelScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + bool _touchScaleChangeEnabled; + float _normalScaleValueX; + float _normalScaleValueY; + std::string _fontName; + int _fontSize; + float _onSelectedScaleOffset; + LabelTTF* _labelRenderer; +}; + +} + +NS_CC_END + +#endif /* defined(__CocoGUI__Label__) */ diff --git a/cocos/ui/UITextAtlas.cpp b/cocos/ui/UITextAtlas.cpp new file mode 100644 index 0000000000..2258be841a --- /dev/null +++ b/cocos/ui/UITextAtlas.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** +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/UITextAtlas.h" + +NS_CC_BEGIN + +namespace ui { + +static const int LABELATLAS_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(TextAtlas) + +TextAtlas::TextAtlas(): +_labelAtlasRenderer(nullptr), +_stringValue(""), +_charMapFileName(""), +_itemWidth(0), +_itemHeight(0), +_startCharMap("") +{ +} + +TextAtlas::~TextAtlas() +{ + +} + +TextAtlas* TextAtlas::create() +{ + TextAtlas* widget = new TextAtlas(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void TextAtlas::initRenderer() +{ + _labelAtlasRenderer = LabelAtlas::create(); + Node::addChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1); +} + +void TextAtlas::setProperty(const std::string& stringValue, const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap) +{ + _stringValue = stringValue; + _charMapFileName = charMapFile; + _itemWidth = itemWidth; + _itemHeight = itemHeight; + _startCharMap = startCharMap; + _labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0])); + updateAnchorPoint(); + labelAtlasScaleChangedWithSize(); +} + +void TextAtlas::setStringValue(const std::string& value) +{ + _stringValue = value; + _labelAtlasRenderer->setString(value); + labelAtlasScaleChangedWithSize(); +} + +const std::string& TextAtlas::getStringValue() const +{ + return _labelAtlasRenderer->getString(); +} + +void TextAtlas::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _labelAtlasRenderer->setAnchorPoint(Point(pt.x, pt.y)); +} + +void TextAtlas::onSizeChanged() +{ + Widget::onSizeChanged(); + labelAtlasScaleChangedWithSize(); +} + +const Size& TextAtlas::getContentSize() const +{ + return _labelAtlasRenderer->getContentSize(); +} + +Node* TextAtlas::getVirtualRenderer() +{ + return _labelAtlasRenderer; +} + +void TextAtlas::labelAtlasScaleChangedWithSize() +{ + if (_ignoreSize) + { + _labelAtlasRenderer->setScale(1.0f); + _size = _labelAtlasRenderer->getContentSize(); + } + else + { + Size textureSize = _labelAtlasRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _labelAtlasRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _labelAtlasRenderer->setScaleX(scaleX); + _labelAtlasRenderer->setScaleY(scaleY); + } +} + +std::string TextAtlas::getDescription() const +{ + return "TextAtlas"; +} + +void TextAtlas::updateTextureColor() +{ + updateColorToRenderer(_labelAtlasRenderer); +} + +void TextAtlas::updateTextureOpacity() +{ + updateOpacityToRenderer(_labelAtlasRenderer); +} + +void TextAtlas::updateTextureRGBA() +{ + updateRGBAToRenderer(_labelAtlasRenderer); +} + +Widget* TextAtlas::createCloneInstance() +{ + return TextAtlas::create(); +} + +void TextAtlas::copySpecialProperties(Widget *widget) +{ + TextAtlas* labelAtlas = dynamic_cast(widget); + if (labelAtlas) + { + setProperty(labelAtlas->_stringValue, labelAtlas->_charMapFileName, labelAtlas->_itemWidth, labelAtlas->_itemHeight, labelAtlas->_startCharMap); + } +} + +} +NS_CC_END diff --git a/cocos/ui/UITextAtlas.h b/cocos/ui/UITextAtlas.h new file mode 100644 index 0000000000..f6530c315f --- /dev/null +++ b/cocos/ui/UITextAtlas.h @@ -0,0 +1,103 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UILABELATLAS_H__ +#define __UILABELATLAS_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +/** + * @js NA + * @lua NA + */ +class TextAtlas : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + TextAtlas(); + + /** + * Default destructor + */ + virtual ~TextAtlas(); + + /** + * Allocates and initializes. + */ + static TextAtlas* create(); + + /** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ + void setProperty(const std::string& stringValue,const std::string& charMapFile, int itemWidth, int itemHeight, const std::string& startCharMap); + + //set string value for labelatlas. + void setStringValue(const std::string& value); + + //get string value for labelatlas. + const std::string& getStringValue() const; + + //override "setAnchorPoint" method of widget. + virtual void setAnchorPoint(const Point &pt) override; + + //override "getContentSize" method of widget. + virtual const Size& getContentSize() const override; + + //override "getVirtualRenderer" method of widget. + virtual Node* getVirtualRenderer() override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + +protected: + virtual void initRenderer() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + void labelAtlasScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + LabelAtlas* _labelAtlasRenderer; + std::string _stringValue; + std::string _charMapFileName; + int _itemWidth; + int _itemHeight; + std::string _startCharMap; +}; + +} +NS_CC_END + +#endif /* defined(__CocoGUI__LabelAtlas__) */ diff --git a/cocos/ui/UITextBMFont.cpp b/cocos/ui/UITextBMFont.cpp new file mode 100644 index 0000000000..80906e85d2 --- /dev/null +++ b/cocos/ui/UITextBMFont.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +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/UITextBMFont.h" + +NS_CC_BEGIN + +namespace ui { + +static const int LABELBMFONT_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(TextBMFont) + +TextBMFont::TextBMFont(): +_labelBMFontRenderer(nullptr), +_fntFileHasInit(false), +_fntFileName(""), +_stringValue("") +{ +} + +TextBMFont::~TextBMFont() +{ + +} + +TextBMFont* TextBMFont::create() +{ + TextBMFont* widget = new TextBMFont(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void TextBMFont::initRenderer() +{ + _labelBMFontRenderer = cocos2d::LabelBMFont::create(); + Node::addChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1); +} + +void TextBMFont::setFntFile(const char *fileName) +{ + if (!fileName || strcmp(fileName, "") == 0) + { + return; + } + _fntFileName = fileName; + _labelBMFontRenderer->initWithString("", fileName); + updateAnchorPoint(); + labelBMFontScaleChangedWithSize(); + _fntFileHasInit = true; + setText(_stringValue.c_str()); +} + +void TextBMFont::setText(const char* value) +{ + if (!value) + { + return; + } + _stringValue = value; + if (!_fntFileHasInit) + { + return; + } + _labelBMFontRenderer->setString(value); + labelBMFontScaleChangedWithSize(); +} + +const char* TextBMFont::getStringValue() +{ + return _stringValue.c_str(); +} + +void TextBMFont::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _labelBMFontRenderer->setAnchorPoint(pt); +} + +void TextBMFont::onSizeChanged() +{ + Widget::onSizeChanged(); + labelBMFontScaleChangedWithSize(); +} + +const Size& TextBMFont::getContentSize() const +{ + return _labelBMFontRenderer->getContentSize(); +} + +Node* TextBMFont::getVirtualRenderer() +{ + return _labelBMFontRenderer; +} + +void TextBMFont::labelBMFontScaleChangedWithSize() +{ + if (_ignoreSize) + { + _labelBMFontRenderer->setScale(1.0f); + _size = _labelBMFontRenderer->getContentSize(); + } + else + { + Size textureSize = _labelBMFontRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _labelBMFontRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _labelBMFontRenderer->setScaleX(scaleX); + _labelBMFontRenderer->setScaleY(scaleY); + } +} + +std::string TextBMFont::getDescription() const +{ + return "TextBMFont"; +} + +void TextBMFont::updateTextureColor() +{ + updateColorToRenderer(_labelBMFontRenderer); +} + +void TextBMFont::updateTextureOpacity() +{ + updateOpacityToRenderer(_labelBMFontRenderer); +} + +void TextBMFont::updateTextureRGBA() +{ + updateRGBAToRenderer(_labelBMFontRenderer); +} + +Widget* TextBMFont::createCloneInstance() +{ + return TextBMFont::create(); +} + +void TextBMFont::copySpecialProperties(Widget *widget) +{ + TextBMFont* labelBMFont = dynamic_cast(widget); + if (labelBMFont) + { + setFntFile(labelBMFont->_fntFileName.c_str()); + setText(labelBMFont->_stringValue.c_str()); + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UITextBMFont.h b/cocos/ui/UITextBMFont.h new file mode 100644 index 0000000000..45c4355d30 --- /dev/null +++ b/cocos/ui/UITextBMFont.h @@ -0,0 +1,93 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UILABELBMFONT_H__ +#define __UILABELBMFONT_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +/** +* @js NA +* @lua NA +*/ +class TextBMFont : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + /** + * Default constructor + */ + TextBMFont(); + + /** + * Default destructor + */ + virtual ~TextBMFont(); + + /** + * Allocates and initializes. + */ + static TextBMFont* create(); + + /** init a bitmap font atlas with an initial string and the FNT file */ + void setFntFile(const char* fileName); + + /** set string value for labelbmfont*/ + void setText(const char* value); + + /** get string value for labelbmfont*/ + const char* getStringValue(); + virtual void setAnchorPoint(const Point &pt) override; + virtual const Size& getContentSize() const override; + virtual Node* getVirtualRenderer() override; + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; +protected: + virtual void initRenderer() override; + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + void labelBMFontScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + cocos2d::LabelBMFont* _labelBMFontRenderer; + bool _fntFileHasInit; + std::string _fntFileName; + std::string _stringValue; +}; + +} +NS_CC_END + +#endif /* defined(__LabelBMFont__) */ diff --git a/cocos/ui/UITextField.cpp b/cocos/ui/UITextField.cpp new file mode 100644 index 0000000000..30f633503c --- /dev/null +++ b/cocos/ui/UITextField.cpp @@ -0,0 +1,772 @@ +/**************************************************************************** +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/UITextField.h" + +NS_CC_BEGIN + +namespace ui { + +static int _calcCharCount(const char * pszText) +{ + int n = 0; + char ch = 0; + while ((ch = *pszText)) + { + CC_BREAK_IF(! ch); + + if (0x80 != (0xC0 & ch)) + { + ++n; + } + ++pszText; + } + return n; +} + +UICCTextField::UICCTextField() +: _maxLengthEnabled(false) +, _maxLength(0) +, _passwordEnabled(false) +, _passwordStyleText("*") +, _attachWithIME(false) +, _detachWithIME(false) +, _insertText(false) +, _deleteBackward(false) +{ +} + +UICCTextField::~UICCTextField() +{ +} + +UICCTextField * UICCTextField::create(const char *placeholder, const char *fontName, float fontSize) +{ + UICCTextField *pRet = new UICCTextField(); + + if(pRet && pRet->initWithString("", fontName, fontSize)) + { + pRet->autorelease(); + if (placeholder) + { + pRet->setPlaceHolder(placeholder); + } + return pRet; + } + CC_SAFE_DELETE(pRet); + + return nullptr; +} + +void UICCTextField::onEnter() +{ + TextFieldTTF::setDelegate(this); +} + + +bool UICCTextField::onTextFieldAttachWithIME(TextFieldTTF *pSender) +{ + setAttachWithIME(true); + return false; +} + +bool UICCTextField::onTextFieldInsertText(TextFieldTTF *pSender, const char *text, int nLen) +{ + if (nLen == 1 && strcmp(text, "\n") == 0) + { + return false; + } + setInsertText(true); + if (_maxLengthEnabled) + { + if (TextFieldTTF::getCharCount() >= _maxLength) + { + return true; + } + } + + return false; +} + +bool UICCTextField::onTextFieldDeleteBackward(TextFieldTTF *pSender, const char *delText, int nLen) +{ + setDeleteBackward(true); + return false; +} + +bool UICCTextField::onTextFieldDetachWithIME(TextFieldTTF *pSender) +{ + setDetachWithIME(true); + return false; +} + +void UICCTextField::insertText(const char * text, int len) +{ + std::string input_text = text; + + if (strcmp(text, "\n") != 0) + { + if (_maxLengthEnabled) + { + int text_count = _calcCharCount(getString().c_str()); + if (text_count >= _maxLength) + { + // password + if (_passwordEnabled) + { + setPasswordText(getString().c_str()); + } + return; + } + +#if ((CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)) + int input_count = _calcCharCount(text); + int total = total = text_count + input_count; + + if (total > _maxLength) + { + int end = 0; + int length = _maxLength - text_count; + + for (int i = 0; i < length; ++i) + { + char value = text[i]; + + if (value >= 0 && value <= 127) // ascii + { + end++; + } + else + { + end += 3; + } + } + input_text = input_text.substr(0, end); + len = end; + } +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + int input_count = _calcCharCount(text); + if (input_count > _maxLength) + { + int ascii = 0; + int unicode = 0; + int end = 0; + int count = 0; + + for (int i = 0; i < input_count * 3; ++i) + { + char value = text[i]; + + if (value >= 0 && value <= 127) // ascii + { + ascii++; + count++; + } + else + { + unicode++; + if (unicode % 3 == 0) + { + count++; + } + } + + if (count == _maxLength) + { + break; + } + } + end = ascii + unicode; + input_text = input_text.substr(0, end); + len = end; + } +#endif + } + } + TextFieldTTF::insertText(input_text.c_str(), len); + + // password + if (_passwordEnabled) + { + if (TextFieldTTF::getCharCount() > 0) + { + setPasswordText(getString().c_str()); + } + } +} + +void UICCTextField::deleteBackward() +{ + TextFieldTTF::deleteBackward(); + + if (TextFieldTTF::getCharCount() > 0) + { + // password + if (_passwordEnabled) + { + setPasswordText(_inputText.c_str()); + } + } +} + +void UICCTextField::openIME() +{ + TextFieldTTF::attachWithIME(); +} + +void UICCTextField::closeIME() +{ + TextFieldTTF::detachWithIME(); +} + +void UICCTextField::setMaxLengthEnabled(bool enable) +{ + _maxLengthEnabled = enable; +} + +bool UICCTextField::isMaxLengthEnabled() +{ + return _maxLengthEnabled; +} + +void UICCTextField::setMaxLength(int length) +{ + _maxLength = length; +} + +int UICCTextField::getMaxLength() +{ + return _maxLength; +} + +int UICCTextField::getCharCount() +{ + return TextFieldTTF::getCharCount(); +} + +void UICCTextField::setPasswordEnabled(bool enable) +{ + _passwordEnabled = enable; +} + +bool UICCTextField::isPasswordEnabled() +{ + return _passwordEnabled; +} + +void UICCTextField::setPasswordStyleText(const char* styleText) +{ + if (strlen(styleText) > 1) + { + return; + } + char value = styleText[0]; + if (value < 33 || value > 126) + { + return; + } + _passwordStyleText = styleText; +} + +void UICCTextField::setPasswordText(const char *text) +{ + std::string tempStr; + for (size_t i = 0; i < strlen(text); ++i) + { + tempStr.append(_passwordStyleText); + } + LabelTTF::setString(tempStr.c_str()); +} + +void UICCTextField::setAttachWithIME(bool attach) +{ + _attachWithIME = attach; +} + +bool UICCTextField::getAttachWithIME() +{ + return _attachWithIME; +} + +void UICCTextField::setDetachWithIME(bool detach) +{ + _detachWithIME = detach; +} + +bool UICCTextField::getDetachWithIME() +{ + return _detachWithIME; +} + +void UICCTextField::setInsertText(bool insert) +{ + _insertText = insert; +} + +bool UICCTextField::getInsertText() +{ + return _insertText; +} + +void UICCTextField::setDeleteBackward(bool deleteBackward) +{ + _deleteBackward = deleteBackward; +} + +bool UICCTextField::getDeleteBackward() +{ + return _deleteBackward; +} + +static const int TEXTFIELD_RENDERER_Z = (-1); + +IMPLEMENT_CLASS_GUI_INFO(TextField) + + +TextField::TextField(): +_textFieldRenderer(nullptr), +_touchWidth(0.0f), +_touchHeight(0.0f), +_useTouchArea(false), +_textFieldEventListener(nullptr), +_textFieldEventSelector(nullptr), +_passwordStyleText("") +{ +} + +TextField::~TextField() +{ + _textFieldEventListener = nullptr; + _textFieldEventSelector = nullptr; +} + +TextField* TextField::create() +{ + TextField* widget = new TextField(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +bool TextField::init() +{ + if (Widget::init()) + { + setTouchEnabled(true); + return true; + } + return false; +} + +void TextField::onEnter() +{ + Widget::onEnter(); + scheduleUpdate(); +} + +void TextField::initRenderer() +{ + _textFieldRenderer = UICCTextField::create("input words here", "Thonburi", 20); + Node::addChild(_textFieldRenderer, TEXTFIELD_RENDERER_Z, -1); +} + +void TextField::setTouchSize(const Size &size) +{ + _touchWidth = size.width; + _touchHeight = size.height; +} + +void TextField::setTouchAreaEnabled(bool enable) +{ + _useTouchArea = enable; +} + +bool TextField::hitTest(const Point &pt) +{ + if (_useTouchArea) + { + Point nsp = convertToNodeSpace(pt); + Rect bb = Rect(-_touchWidth * _anchorPoint.x, -_touchHeight * _anchorPoint.y, _touchWidth, _touchHeight); + if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) + { + return true; + } + } + else + { + return Widget::hitTest(pt); + } + + return false; +} + +Size TextField::getTouchSize() +{ + return Size(_touchWidth, _touchHeight); +} + +void TextField::setText(const std::string& text) +{ + std::string strText(text); + if (isMaxLengthEnabled()) + { + strText = strText.substr(0, getMaxLength()); + } + const char* content = strText.c_str(); + if (isPasswordEnabled()) + { + _textFieldRenderer->setPasswordText(content); + _textFieldRenderer->setString(""); + _textFieldRenderer->insertText(content, static_cast(strlen(content))); + } + else + { + _textFieldRenderer->setString(content); + } + textfieldRendererScaleChangedWithSize(); +} + +void TextField::setPlaceHolder(const std::string& value) +{ + _textFieldRenderer->setPlaceHolder(value); + textfieldRendererScaleChangedWithSize(); +} + +const std::string& TextField::getPlaceHolder() +{ + return _textFieldRenderer->getPlaceHolder(); +} + +void TextField::setFontSize(int size) +{ + _textFieldRenderer->setFontSize(size); + textfieldRendererScaleChangedWithSize(); +} + +int TextField::getFontSize() +{ + return _textFieldRenderer->getFontSize(); +} + +void TextField::setFontName(const std::string& name) +{ + _textFieldRenderer->setFontName(name); + textfieldRendererScaleChangedWithSize(); +} + +const std::string& TextField::getFontName() +{ + return _textFieldRenderer->getFontName(); +} + +void TextField::didNotSelectSelf() +{ + _textFieldRenderer->detachWithIME(); +} + +const std::string& TextField::getStringValue() +{ + return _textFieldRenderer->getString(); +} + +bool TextField::onTouchBegan(Touch *touch, Event *unusedEvent) +{ + bool pass = Widget::onTouchBegan(touch, unusedEvent); + if (_hitted) + { + _textFieldRenderer->attachWithIME(); + } + return pass; +} + +void TextField::setMaxLengthEnabled(bool enable) +{ + _textFieldRenderer->setMaxLengthEnabled(enable); +} + +bool TextField::isMaxLengthEnabled() +{ + return _textFieldRenderer->isMaxLengthEnabled(); +} + +void TextField::setMaxLength(int length) +{ + _textFieldRenderer->setMaxLength(length); + + setText(getStringValue()); +} + +int TextField::getMaxLength() +{ + return _textFieldRenderer->getMaxLength(); +} + +void TextField::setPasswordEnabled(bool enable) +{ + _textFieldRenderer->setPasswordEnabled(enable); +} + +bool TextField::isPasswordEnabled() +{ + return _textFieldRenderer->isPasswordEnabled(); +} + +void TextField::setPasswordStyleText(const char *styleText) +{ + _textFieldRenderer->setPasswordStyleText(styleText); + + _passwordStyleText = styleText; + + setText(getStringValue()); +} + +const char* TextField::getPasswordStyleText() +{ + return _passwordStyleText.c_str(); +} + +void TextField::update(float dt) +{ + if (getAttachWithIME()) + { + attachWithIMEEvent(); + setAttachWithIME(false); + } + if (getDetachWithIME()) + { + detachWithIMEEvent(); + setDetachWithIME(false); + } + if (getInsertText()) + { + insertTextEvent(); + setInsertText(false); + + textfieldRendererScaleChangedWithSize(); + } + if (getDeleteBackward()) + { + deleteBackwardEvent(); + setDeleteBackward(false); + + textfieldRendererScaleChangedWithSize(); + } +} + +bool TextField::getAttachWithIME() +{ + return _textFieldRenderer->getAttachWithIME(); +} + +void TextField::setAttachWithIME(bool attach) +{ + _textFieldRenderer->setAttachWithIME(attach); +} + +bool TextField::getDetachWithIME() +{ + return _textFieldRenderer->getDetachWithIME(); +} + +void TextField::setDetachWithIME(bool detach) +{ + _textFieldRenderer->setDetachWithIME(detach); +} + +bool TextField::getInsertText() +{ + return _textFieldRenderer->getInsertText(); +} + +void TextField::setInsertText(bool insertText) +{ + _textFieldRenderer->setInsertText(insertText); +} + +bool TextField::getDeleteBackward() +{ + return _textFieldRenderer->getDeleteBackward(); +} + +void TextField::setDeleteBackward(bool deleteBackward) +{ + _textFieldRenderer->setDeleteBackward(deleteBackward); +} + +void TextField::attachWithIMEEvent() +{ + if (_textFieldEventListener && _textFieldEventSelector) + { + (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_ATTACH_WITH_IME); + } +} + +void TextField::detachWithIMEEvent() +{ + if (_textFieldEventListener && _textFieldEventSelector) + { + (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_DETACH_WITH_IME); + } +} + +void TextField::insertTextEvent() +{ + if (_textFieldEventListener && _textFieldEventSelector) + { + (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_INSERT_TEXT); + } +} + +void TextField::deleteBackwardEvent() +{ + if (_textFieldEventListener && _textFieldEventSelector) + { + (_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_DELETE_BACKWARD); + } +} + +void TextField::addEventListenerTextField(Ref *target, SEL_TextFieldEvent selecor) +{ + _textFieldEventListener = target; + _textFieldEventSelector = selecor; +} + +void TextField::setAnchorPoint(const Point &pt) +{ + Widget::setAnchorPoint(pt); + _textFieldRenderer->setAnchorPoint(pt); +} + +void TextField::onSizeChanged() +{ + Widget::onSizeChanged(); + textfieldRendererScaleChangedWithSize(); +} + +void TextField::textfieldRendererScaleChangedWithSize() +{ + if (_ignoreSize) + { + _textFieldRenderer->setDimensions(Size::ZERO); + _textFieldRenderer->setScale(1.0f); + _size = getContentSize(); + } + else + { + _textFieldRenderer->setDimensions(_size); + Size textureSize = getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _textFieldRenderer->setScale(1.0f); + return; + } + float scaleX = _size.width / textureSize.width; + float scaleY = _size.height / textureSize.height; + _textFieldRenderer->setScaleX(scaleX); + _textFieldRenderer->setScaleY(scaleY); + } +} + +const Size& TextField::getContentSize() const +{ + return _textFieldRenderer->getContentSize(); +} + +Node* TextField::getVirtualRenderer() +{ + return _textFieldRenderer; +} + +std::string TextField::getDescription() const +{ + return "TextField"; +} + +void TextField::updateTextureColor() +{ + updateColorToRenderer(_textFieldRenderer); +} + +void TextField::updateTextureOpacity() +{ + updateOpacityToRenderer(_textFieldRenderer); +} + +void TextField::updateTextureRGBA() +{ + updateRGBAToRenderer(_textFieldRenderer); +} + +void TextField::attachWithIME() +{ + _textFieldRenderer->attachWithIME(); +} + +Widget* TextField::createCloneInstance() +{ + return TextField::create(); +} + +void TextField::copySpecialProperties(Widget *widget) +{ + TextField* textField = dynamic_cast(widget); + if (textField) + { + setText(textField->_textFieldRenderer->getString()); + setPlaceHolder(textField->getStringValue()); + setFontSize(textField->_textFieldRenderer->getFontSize()); + setFontName(textField->_textFieldRenderer->getFontName().c_str()); + setMaxLengthEnabled(textField->isMaxLengthEnabled()); + setMaxLength(textField->getMaxLength()); + setPasswordEnabled(textField->isPasswordEnabled()); + setPasswordStyleText(textField->_passwordStyleText.c_str()); + setAttachWithIME(textField->getAttachWithIME()); + setDetachWithIME(textField->getDetachWithIME()); + setInsertText(textField->getInsertText()); + setDeleteBackward(textField->getDeleteBackward()); + } +} + +void TextField::setTextAreaSize(const Size &size) +{ + _textFieldRenderer->setDimensions(size); +} + +void TextField::setTextHorizontalAlignment(TextHAlignment alignment) +{ + _textFieldRenderer->setHorizontalAlignment(alignment); +} + +void TextField::setTextVerticalAlignment(TextVAlignment alignment) +{ + _textFieldRenderer->setVerticalAlignment(alignment); +} + +} + +NS_CC_END diff --git a/cocos/ui/UITextField.h b/cocos/ui/UITextField.h new file mode 100644 index 0000000000..2c61d2724e --- /dev/null +++ b/cocos/ui/UITextField.h @@ -0,0 +1,192 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UITEXTFIELD_H__ +#define __UITEXTFIELD_H__ + +#include "ui/UIWidget.h" + +NS_CC_BEGIN + +namespace ui { + +/** + * @js NA + * @lua NA + */ +class UICCTextField: public TextFieldTTF, public TextFieldDelegate +{ +public: + UICCTextField(); + ~UICCTextField(); + + virtual void onEnter() override; + + // static + static UICCTextField* create(const char *placeholder, const char *fontName, float fontSize); + + // CCTextFieldDelegate + virtual bool onTextFieldAttachWithIME(TextFieldTTF *pSender) override; + virtual bool onTextFieldDetachWithIME(TextFieldTTF * pSender) override; + virtual bool onTextFieldInsertText(TextFieldTTF * pSender, const char * text, int nLen) override; + virtual bool onTextFieldDeleteBackward(TextFieldTTF * pSender, const char * delText, int nLen) override; + + void insertText(const char* text, int len); + void deleteBackward(); + + void openIME(); + void closeIME(); + + void setMaxLengthEnabled(bool enable); + bool isMaxLengthEnabled(); + void setMaxLength(int length); + int getMaxLength(); + int getCharCount(); + void setPasswordEnabled(bool enable); + bool isPasswordEnabled(); + void setPasswordStyleText(const char* styleText); + void setPasswordText(const char* text); + void setAttachWithIME(bool attach); + bool getAttachWithIME(); + void setDetachWithIME(bool detach); + bool getDetachWithIME(); + void setInsertText(bool insert); + bool getInsertText(); + void setDeleteBackward(bool deleteBackward); + bool getDeleteBackward(); +protected: + bool _maxLengthEnabled; + int _maxLength; + bool _passwordEnabled; + std::string _passwordStyleText; + bool _attachWithIME; + bool _detachWithIME; + bool _insertText; + bool _deleteBackward; +}; + +typedef enum +{ + TEXTFIELD_EVENT_ATTACH_WITH_IME, + TEXTFIELD_EVENT_DETACH_WITH_IME, + TEXTFIELD_EVENT_INSERT_TEXT, + TEXTFIELD_EVENT_DELETE_BACKWARD, +}TextFiledEventType; + +typedef void (Ref::*SEL_TextFieldEvent)(Ref*, TextFiledEventType); +#define textfieldeventselector(_SELECTOR) (SEL_TextFieldEvent)(&_SELECTOR) + +/** class UITextField : public Widget +* @js NA +* @lua NA +*/ +class TextField : public Widget +{ + + DECLARE_CLASS_GUI_INFO + +public: + TextField(); + virtual ~TextField(); + static TextField* create(); + void setTouchSize(const Size &size); + Size getTouchSize(); + void setTouchAreaEnabled(bool enable); + virtual bool hitTest(const Point &pt); + void setText(const std::string& text); + void setPlaceHolder(const std::string& value); + const std::string& getPlaceHolder(); + void setFontSize(int size); + int getFontSize(); + void setFontName(const std::string& name); + const std::string& getFontName(); + virtual void didNotSelectSelf(); + const std::string& getStringValue(); + virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override; + void setMaxLengthEnabled(bool enable); + bool isMaxLengthEnabled(); + void setMaxLength(int length); + int getMaxLength(); + void setPasswordEnabled(bool enable); + bool isPasswordEnabled(); + void setPasswordStyleText(const char* styleText); + const char* getPasswordStyleText(); + virtual void update(float dt) override; + bool getAttachWithIME(); + void setAttachWithIME(bool attach); + bool getDetachWithIME(); + void setDetachWithIME(bool detach); + bool getInsertText(); + void setInsertText(bool insertText); + bool getDeleteBackward(); + void setDeleteBackward(bool deleteBackward); + void addEventListenerTextField(Ref* target, SEL_TextFieldEvent selecor); + + virtual void setAnchorPoint(const Point &pt) override; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + virtual const Size& getContentSize() const override; + virtual Node* getVirtualRenderer() override; + void attachWithIME(); + virtual void onEnter() override; + + void setTextAreaSize(const Size &size); + void setTextHorizontalAlignment(TextHAlignment alignment); + void setTextVerticalAlignment(TextVAlignment alignment); +protected: + virtual bool init() override; + virtual void initRenderer() override; + void attachWithIMEEvent(); + void detachWithIMEEvent(); + void insertTextEvent(); + void deleteBackwardEvent(); + virtual void onSizeChanged() override; + virtual void updateTextureColor() override; + virtual void updateTextureOpacity() override; + virtual void updateTextureRGBA() override; + void textfieldRendererScaleChangedWithSize(); + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; +protected: + UICCTextField* _textFieldRenderer; + + float _touchWidth; + float _touchHeight; + bool _useTouchArea; + + Ref* _textFieldEventListener; + SEL_TextFieldEvent _textFieldEventSelector; + + std::string _passwordStyleText; +}; + +} + +NS_CC_END + +#endif /* defined(__TextField__) */ diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp new file mode 100644 index 0000000000..9b7f613a51 --- /dev/null +++ b/cocos/ui/UIWidget.cpp @@ -0,0 +1,1139 @@ +/**************************************************************************** +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/UIWidget.h" +#include "ui/UILayout.h" +#include "ui/UIHelper.h" + +NS_CC_BEGIN + +namespace ui { + +Widget::Widget(): +_enabled(true), +_bright(true), +_touchEnabled(false), +_touchPassedEnabled(false), +_focus(false), +_brightStyle(BRIGHT_NONE), +_touchStartPos(Point::ZERO), +_touchMovePos(Point::ZERO), +_touchEndPos(Point::ZERO), +_touchEventListener(nullptr), +_touchEventSelector(nullptr), +_name("default"), +_widgetType(WidgetTypeWidget), +_actionTag(0), +_size(Size::ZERO), +_customSize(Size::ZERO), +_ignoreSize(false), +_affectByClipping(false), +_sizeType(SIZE_ABSOLUTE), +_sizePercent(Point::ZERO), +_positionType(POSITION_ABSOLUTE), +_positionPercent(Point::ZERO), +_reorderWidgetChildDirty(true), +_hitted(false), +_touchListener(nullptr), +_nodes(NULL), +_color(Color3B::WHITE), +_opacity(255), +_flippedX(false), +_flippedY(false) +{ + +} + +Widget::~Widget() +{ + _touchEventListener = nullptr; + _touchEventSelector = nullptr; + _widgetChildren.clear(); + setTouchEnabled(false); + _nodes.clear(); +} + +Widget* Widget::create() +{ + Widget* widget = new Widget(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +bool Widget::init() +{ + if (Node::init()) + { + initRenderer(); + setBright(true); + ignoreContentAdaptWithSize(true); + setAnchorPoint(Point(0.5f, 0.5f)); + return true; + } + return false; +} + +void Widget::onEnter() +{ + updateSizeAndPosition(); + Node::onEnter(); +} + +void Widget::onExit() +{ + unscheduleUpdate(); + Node::onExit(); +} + +void Widget::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) +{ + if (_enabled) + { + Node::visit(renderer, parentTransform, parentTransformUpdated); + } +} + +void Widget::addChild(Node *child) +{ + Node::addChild(child); +} + +void Widget::addChild(Node * child, int zOrder) +{ + Node::addChild(child, zOrder); +} + +void Widget::addChild(Node* child, int zOrder, int tag) +{ + CCASSERT(dynamic_cast(child) != nullptr, "Widget only supports Widgets as children"); + Node::addChild(child, zOrder, tag); + _widgetChildren.pushBack(child); +} + +void Widget::sortAllChildren() +{ + _reorderWidgetChildDirty = _reorderChildDirty; + Node::sortAllChildren(); + if( _reorderWidgetChildDirty ) + { + std::sort( std::begin(_widgetChildren), std::end(_widgetChildren), nodeComparisonLess ); + _reorderWidgetChildDirty = false; + } +} + +Node* Widget::getChildByTag(int aTag) +{ + CCASSERT( aTag != Node::INVALID_TAG, "Invalid tag"); + + for (auto& child : _widgetChildren) + { + if(child && child->getTag() == aTag) + return child; + } + return nullptr; +} + +Vector& Widget::getChildren() +{ + return _widgetChildren; +} + +const Vector& Widget::getChildren() const +{ + return _widgetChildren; +} + +ssize_t Widget::getChildrenCount() const +{ + return _widgetChildren.size(); +} + +Widget* Widget::getWidgetParent() +{ + return dynamic_cast(getParent()); +} + +void Widget::removeFromParent() +{ + removeFromParentAndCleanup(true); +} + +void Widget::removeFromParentAndCleanup(bool cleanup) +{ + Node::removeFromParentAndCleanup(cleanup); +} + +void Widget::removeChild(Node *child, bool cleanup) +{ + Node::removeChild(child, cleanup); + _widgetChildren.eraseObject(child); +} + +void Widget::removeChildByTag(int tag, bool cleanup) +{ + CCASSERT( tag != Node::INVALID_TAG, "Invalid tag"); + + Node *child = getChildByTag(tag); + + if (child == nullptr) + { + CCLOG("cocos2d: removeChildByTag(tag = %d): child not found!", tag); + } + else + { + removeChild(child, cleanup); + } +} + +void Widget::removeAllChildren() +{ + removeAllChildrenWithCleanup(true); +} + +void Widget::removeAllChildrenWithCleanup(bool cleanup) +{ + for (auto& child : _widgetChildren) + { + if (child) + { + Node::removeChild(child); + } + } + _widgetChildren.clear(); +} + +void Widget::setEnabled(bool enabled) +{ + _enabled = enabled; + for (auto& child : _widgetChildren) + { + if (child) + { + static_cast(child)->setEnabled(enabled); + } + } +} + +Widget* Widget::getChildByName(const char *name) +{ + for (auto& child : _widgetChildren) + { + if (child) + { + Widget* widgetChild = static_cast(child); + if (strcmp(widgetChild->getName(), name) == 0) + { + return widgetChild; + } + } + } + return nullptr; +} + +void Widget::addNode(Node* node) +{ + addNode(node, node->getLocalZOrder(), node->getTag()); +} + +void Widget::addNode(Node * node, int zOrder) +{ + addNode(node, zOrder, node->getTag()); +} + +void Widget::addNode(Node* node, int zOrder, int tag) +{ + CCAssert(dynamic_cast(node) == nullptr, "Widget only supports Nodes as renderer"); + Node::addChild(node, zOrder, tag); + _nodes.pushBack(node); +} + +Node* Widget::getNodeByTag(int tag) +{ + CCAssert( tag != Node::INVALID_TAG, "Invalid tag"); + + for (auto& node : _nodes) + { + if(node && node->getTag() == tag) + return node; + } + return nullptr; +} + +Vector& Widget::getNodes() +{ + return _nodes; +} + +void Widget::removeNode(Node* node) +{ + Node::removeChild(node); + _nodes.eraseObject(node); +} + +void Widget::removeNodeByTag(int tag) +{ + CCAssert( tag != Node::INVALID_TAG, "Invalid tag"); + + Node *node = this->getNodeByTag(tag); + + if (node == nullptr) + { + CCLOG("cocos2d: removeNodeByTag(tag = %d): child not found!", tag); + } + else + { + this->removeNode(node); + } +} + +void Widget::removeAllNodes() +{ + for (auto& node : _nodes) + { + if (node) + { + Node::removeChild(node); + } + } + _nodes.clear(); +} + + +void Widget::initRenderer() +{ +} + +void Widget::setSize(const Size &size) +{ + _customSize = size; + if (_ignoreSize) + { + _size = getContentSize(); + } + else + { + _size = size; + } + if (_running) + { + Widget* widgetParent = getWidgetParent(); + Size pSize; + if (widgetParent) + { + pSize = widgetParent->getSize(); + } + else + { + pSize = _parent->getContentSize(); + } + float spx = 0.0f; + float spy = 0.0f; + if (pSize.width > 0.0f) + { + spx = _customSize.width / pSize.width; + } + if (pSize.height > 0.0f) + { + spy = _customSize.height / pSize.height; + } + _sizePercent = Point(spx, spy); + } + onSizeChanged(); +} + +void Widget::setSizePercent(const Point &percent) +{ + _sizePercent = percent; + Size cSize = _customSize; + if (_running) + { + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + cSize = Size(widgetParent->getSize().width * percent.x , widgetParent->getSize().height * percent.y); + } + else + { + cSize = Size(_parent->getContentSize().width * percent.x , _parent->getContentSize().height * percent.y); + } + } + if (_ignoreSize) + { + _size = getContentSize(); + } + else + { + _size = cSize; + } + _customSize = cSize; + onSizeChanged(); +} + +void Widget::updateSizeAndPosition() +{ + switch (_sizeType) + { + case SIZE_ABSOLUTE: + { + if (_ignoreSize) + { + _size = getContentSize(); + } + else + { + _size = _customSize; + } + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size pSize = widgetParent->getSize(); + float spx = 0.0f; + float spy = 0.0f; + if (pSize.width > 0.0f) + { + spx = _customSize.width / pSize.width; + } + if (pSize.height > 0.0f) + { + spy = _customSize.height / pSize.height; + } + _sizePercent = Point(spx, spy); + } + else + { + Size pSize = _parent->getContentSize(); + float spx = 0.0f; + float spy = 0.0f; + if (pSize.width > 0.0f) + { + spx = _customSize.width / pSize.width; + } + if (pSize.height > 0.0f) + { + spy = _customSize.height / pSize.height; + } + _sizePercent = Point(spx, spy); + } + break; + } + case SIZE_PERCENT: + { + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size cSize = Size(widgetParent->getSize().width * _sizePercent.x , widgetParent->getSize().height * _sizePercent.y); + if (_ignoreSize) + { + _size = getContentSize(); + } + else + { + _size = cSize; + } + _customSize = cSize; + } + else + { + Size cSize = Size(_parent->getContentSize().width * _sizePercent.x , _parent->getContentSize().height * _sizePercent.y); + if (_ignoreSize) + { + _size = getContentSize(); + } + else + { + _size = cSize; + } + _customSize = cSize; + } + } + break; + default: + break; + } + onSizeChanged(); + Point absPos = getPosition(); + switch (_positionType) + { + case POSITION_ABSOLUTE: + { + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size pSize = widgetParent->getSize(); + if (pSize.width <= 0.0f || pSize.height <= 0.0f) + { + _positionPercent = Point::ZERO; + } + else + { + _positionPercent = Point(absPos.x / pSize.width, absPos.y / pSize.height); + } + } + else + { + Size pSize = _parent->getContentSize(); + if (pSize.width <= 0.0f || pSize.height <= 0.0f) + { + _positionPercent = Point::ZERO; + } + else + { + _positionPercent = Point(absPos.x / pSize.width, absPos.y / pSize.height); + } + } + break; + } + case POSITION_PERCENT: + { + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size parentSize = widgetParent->getSize(); + absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); + } + else + { + Size parentSize = _parent->getContentSize(); + absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); + } + break; + } + default: + break; + } + setPosition(absPos); +} + +void Widget::setSizeType(SizeType type) +{ + _sizeType = type; +} + +SizeType Widget::getSizeType() const +{ + return _sizeType; +} + +void Widget::ignoreContentAdaptWithSize(bool ignore) +{ + if (_ignoreSize == ignore) + { + return; + } + _ignoreSize = ignore; + if (_ignoreSize) + { + Size s = getContentSize(); + _size = s; + } + else + { + _size = _customSize; + } + onSizeChanged(); +} + +bool Widget::isIgnoreContentAdaptWithSize() const +{ + return _ignoreSize; +} + +const Size& Widget::getSize() const +{ + return _size; +} + +const Size& Widget::getCustomSize() const +{ + return _customSize; +} + +const Point& Widget::getSizePercent() const +{ + return _sizePercent; +} + +Point Widget::getWorldPosition() +{ + return convertToWorldSpace(Point::ZERO); +} + +Node* Widget::getVirtualRenderer() +{ + return this; +} + +void Widget::onSizeChanged() +{ + for (auto& child : getChildren()) + { + if (child) + { + static_cast(child)->updateSizeAndPosition(); + } + } +} + +const Size& Widget::getContentSize() const +{ + return _size; +} + +void Widget::setTouchEnabled(bool enable) +{ + if (enable == _touchEnabled) + { + return; + } + _touchEnabled = enable; + if (_touchEnabled) + { + _touchListener = EventListenerTouchOneByOne::create(); + CC_SAFE_RETAIN(_touchListener); + _touchListener->setSwallowTouches(true); + _touchListener->onTouchBegan = CC_CALLBACK_2(Widget::onTouchBegan, this); + _touchListener->onTouchMoved = CC_CALLBACK_2(Widget::onTouchMoved, this); + _touchListener->onTouchEnded = CC_CALLBACK_2(Widget::onTouchEnded, this); + _touchListener->onTouchCancelled = CC_CALLBACK_2(Widget::onTouchCancelled, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this); + } + else + { + _eventDispatcher->removeEventListener(_touchListener); + CC_SAFE_RELEASE_NULL(_touchListener); + } +} + +bool Widget::isTouchEnabled() const +{ + return _touchEnabled; +} + +bool Widget::isFocused() const +{ + return _focus; +} + +void Widget::setFocused(bool fucos) +{ + if (fucos == _focus) + { + return; + } + _focus = fucos; + if (_bright) + { + if (_focus) + { + setBrightStyle(BRIGHT_HIGHLIGHT); + } + else + { + setBrightStyle(BRIGHT_NORMAL); + } + } + else + { + onPressStateChangedToDisabled(); + } +} + +void Widget::setBright(bool bright) +{ + _bright = bright; + if (_bright) + { + _brightStyle = BRIGHT_NONE; + setBrightStyle(BRIGHT_NORMAL); + } + else + { + onPressStateChangedToDisabled(); + } +} + +void Widget::setBrightStyle(BrightStyle style) +{ + if (_brightStyle == style) + { + return; + } + _brightStyle = style; + switch (_brightStyle) + { + case BRIGHT_NORMAL: + onPressStateChangedToNormal(); + break; + case BRIGHT_HIGHLIGHT: + onPressStateChangedToPressed(); + break; + default: + break; + } +} + +void Widget::onPressStateChangedToNormal() +{ + +} + +void Widget::onPressStateChangedToPressed() +{ + +} + +void Widget::onPressStateChangedToDisabled() +{ + +} + +void Widget::didNotSelectSelf() +{ + +} + +bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent) +{ + _hitted = false; + if (isEnabled() && isTouchEnabled()) + { + _touchStartPos = touch->getLocation(); + if(hitTest(_touchStartPos) && clippingParentAreaContainPoint(_touchStartPos)) + { + _hitted = true; + } + } + if (!_hitted) + { + return false; + } + setFocused(true); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + widgetParent->checkChildInfo(0,this,_touchStartPos); + } + pushDownEvent(); + return !_touchPassedEnabled; +} + +void Widget::onTouchMoved(Touch *touch, Event *unusedEvent) +{ + _touchMovePos = touch->getLocation(); + setFocused(hitTest(_touchMovePos)); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + widgetParent->checkChildInfo(1,this,_touchMovePos); + } + moveEvent(); +} + +void Widget::onTouchEnded(Touch *touch, Event *unusedEvent) +{ + _touchEndPos = touch->getLocation(); + bool focus = _focus; + setFocused(false); + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + widgetParent->checkChildInfo(2,this,_touchEndPos); + } + if (focus) + { + releaseUpEvent(); + } + else + { + cancelUpEvent(); + } +} + +void Widget::onTouchCancelled(Touch *touch, Event *unusedEvent) +{ + setFocused(false); + cancelUpEvent(); +} + +void Widget::pushDownEvent() +{ + if (_touchEventListener && _touchEventSelector) + { + (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_BEGAN); + } +} + +void Widget::moveEvent() +{ + if (_touchEventListener && _touchEventSelector) + { + (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_MOVED); + } +} + +void Widget::releaseUpEvent() +{ + if (_touchEventListener && _touchEventSelector) + { + (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_ENDED); + } +} + +void Widget::cancelUpEvent() +{ + if (_touchEventListener && _touchEventSelector) + { + (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_CANCELED); + } +} + +void Widget::addTouchEventListener(Ref *target, SEL_TouchEvent selector) +{ + _touchEventListener = target; + _touchEventSelector = selector; +} + +bool Widget::hitTest(const Point &pt) +{ + Point nsp = convertToNodeSpace(pt); + Rect bb = Rect(-_size.width * _anchorPoint.x, -_size.height * _anchorPoint.y, _size.width, _size.height); + if (nsp.x >= bb.origin.x && nsp.x <= bb.origin.x + bb.size.width && nsp.y >= bb.origin.y && nsp.y <= bb.origin.y + bb.size.height) + { + return true; + } + return false; +} + +bool Widget::clippingParentAreaContainPoint(const Point &pt) +{ + _affectByClipping = false; + Widget* parent = getWidgetParent(); + Widget* clippingParent = nullptr; + while (parent) + { + Layout* layoutParent = dynamic_cast(parent); + if (layoutParent) + { + if (layoutParent->isClippingEnabled()) + { + _affectByClipping = true; + clippingParent = layoutParent; + break; + } + } + parent = parent->getWidgetParent(); + } + + if (!_affectByClipping) + { + return true; + } + + + if (clippingParent) + { + bool bRet = false; + if (clippingParent->hitTest(pt)) + { + bRet = true; + } + if (bRet) + { + return clippingParent->clippingParentAreaContainPoint(pt); + } + return false; + } + return true; +} + +void Widget::checkChildInfo(int handleState, Widget *sender, const Point &touchPoint) +{ + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + widgetParent->checkChildInfo(handleState,sender,touchPoint); + } +} + +void Widget::setPosition(const Point &pos) +{ + if (_running) + { + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size pSize = widgetParent->getSize(); + if (pSize.width <= 0.0f || pSize.height <= 0.0f) + { + _positionPercent = Point::ZERO; + } + else + { + _positionPercent = Point(pos.x / pSize.width, pos.y / pSize.height); + } + } + } + Node::setPosition(pos); +} + +void Widget::setPositionPercent(const Point &percent) +{ + _positionPercent = percent; + if (_running) + { + Widget* widgetParent = getWidgetParent(); + if (widgetParent) + { + Size parentSize = widgetParent->getSize(); + Point absPos = Point(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); + setPosition(absPos); + } + } +} + +void Widget::updateAnchorPoint() +{ + setAnchorPoint(getAnchorPoint()); +} + +const Point& Widget::getPositionPercent() +{ + return _positionPercent; +} + +void Widget::setPositionType(PositionType type) +{ + _positionType = type; +} + +PositionType Widget::getPositionType() const +{ + return _positionType; +} + +bool Widget::isBright() const +{ + return _bright; +} + +bool Widget::isEnabled() const +{ + return _enabled; +} + +float Widget::getLeftInParent() +{ + return getPosition().x - getAnchorPoint().x * _size.width;; +} + +float Widget::getBottomInParent() +{ + return getPosition().y - getAnchorPoint().y * _size.height;; +} + +float Widget::getRightInParent() +{ + return getLeftInParent() + _size.width; +} + +float Widget::getTopInParent() +{ + return getBottomInParent() + _size.height; +} + +const Point& Widget::getTouchStartPos() +{ + return _touchStartPos; +} + +const Point& Widget::getTouchMovePos() +{ + return _touchMovePos; +} + +const Point& Widget::getTouchEndPos() +{ + return _touchEndPos; +} + +void Widget::setName(const char* name) +{ + _name = name; +} + +const char* Widget::getName() const +{ + return _name.c_str(); +} + +WidgetType Widget::getWidgetType() const +{ + return _widgetType; +} + +void Widget::setLayoutParameter(LayoutParameter *parameter) +{ + if (!parameter) + { + return; + } + _layoutParameterDictionary.insert(parameter->getLayoutType(), parameter); +} + +LayoutParameter* Widget::getLayoutParameter(LayoutParameterType type) +{ + return dynamic_cast(_layoutParameterDictionary.at(type)); +} + +std::string Widget::getDescription() const +{ + return "Widget"; +} + +Widget* Widget::clone() +{ + Widget* clonedWidget = createCloneInstance(); + clonedWidget->copyProperties(this); + clonedWidget->copyClonedWidgetChildren(this); + return clonedWidget; +} + +Widget* Widget::createCloneInstance() +{ + return Widget::create(); +} + +void Widget::copyClonedWidgetChildren(Widget* model) +{ + auto& modelChildren = model->getChildren(); + + for (auto& subWidget : modelChildren) + { + Widget* child = static_cast(subWidget); + addChild(child->clone()); + } +} + +void Widget::copySpecialProperties(Widget* model) +{ + +} + +void Widget::copyProperties(Widget *widget) +{ + setEnabled(widget->isEnabled()); + setVisible(widget->isVisible()); + setBright(widget->isBright()); + setTouchEnabled(widget->isTouchEnabled()); + _touchPassedEnabled = false; + setLocalZOrder(widget->getLocalZOrder()); + setTag(widget->getTag()); + setName(widget->getName()); + setActionTag(widget->getActionTag()); + _ignoreSize = widget->_ignoreSize; + _size = widget->_size; + _customSize = widget->_customSize; + copySpecialProperties(widget); + _sizeType = widget->getSizeType(); + _sizePercent = widget->_sizePercent; + _positionType = widget->_positionType; + _positionPercent = widget->_positionPercent; + setPosition(widget->getPosition()); + setAnchorPoint(widget->getAnchorPoint()); + setScaleX(widget->getScaleX()); + setScaleY(widget->getScaleY()); + setRotation(widget->getRotation()); + setRotationX(widget->getRotationX()); + setRotationY(widget->getRotationY()); + setFlippedX(widget->isFlippedX()); + setFlippedY(widget->isFlippedY()); + setColor(widget->getColor()); + setOpacity(widget->getOpacity()); + Map& layoutParameterDic = widget->_layoutParameterDictionary; + for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter) + { + setLayoutParameter(iter->second->clone()); + } + onSizeChanged(); +} + +void Widget::setColor(const Color3B& color) +{ + _color = color; + updateTextureColor(); +} + +void Widget::setOpacity(GLubyte opacity) +{ + _opacity = opacity; + updateTextureOpacity(); +} + +void Widget::setFlippedX(bool flippedX) +{ + _flippedX = flippedX; + updateFlippedX(); +} + +void Widget::setFlippedY(bool flippedY) +{ + _flippedY = flippedY; + updateFlippedY(); +} + +void Widget::updateColorToRenderer(Node* renderer) +{ + renderer->setColor(_color); +} + +void Widget::updateOpacityToRenderer(Node* renderer) +{ + renderer->setOpacity(_opacity); +} + +void Widget::updateRGBAToRenderer(Node* renderer) +{ + renderer->setColor(_color); + renderer->setOpacity(_opacity); +} + +/*temp action*/ +void Widget::setActionTag(int tag) +{ + _actionTag = tag; +} + +int Widget::getActionTag() +{ + return _actionTag; +} + +} + +NS_CC_END diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h new file mode 100644 index 0000000000..eaa4bb692e --- /dev/null +++ b/cocos/ui/UIWidget.h @@ -0,0 +1,723 @@ +/**************************************************************************** +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. +****************************************************************************/ + +#ifndef __UIWIDGET_H__ +#define __UIWIDGET_H__ + +#include "CCNode.h" +#include "ui/UILayoutDefine.h" +#include "ui/UILayoutParameter.h" +#include "ui/GUIDefine.h" + +NS_CC_BEGIN + +namespace ui { + +typedef enum +{ + BRIGHT_NONE = -1, + BRIGHT_NORMAL, + BRIGHT_HIGHLIGHT +}BrightStyle; + +typedef enum +{ + WidgetTypeWidget, //control + WidgetTypeContainer //container +}WidgetType; + +typedef enum +{ + UI_TEX_TYPE_LOCAL, + UI_TEX_TYPE_PLIST +}TextureResType; + +typedef enum +{ + TOUCH_EVENT_BEGAN, + TOUCH_EVENT_MOVED, + TOUCH_EVENT_ENDED, + TOUCH_EVENT_CANCELED +}TouchEventType; + +typedef enum +{ + SIZE_ABSOLUTE, + SIZE_PERCENT +}SizeType; + +typedef enum +{ + POSITION_ABSOLUTE, + POSITION_PERCENT +}PositionType; + +typedef void (Ref::*SEL_TouchEvent)(Ref*,TouchEventType); +#define toucheventselector(_SELECTOR) (SEL_TouchEvent)(&_SELECTOR) +/** +* @js NA +* @lua NA +*/ +class Widget : public Node +{ +public: + /** + * Default constructor + */ + Widget(void); + + /** + * Default destructor + */ + virtual ~Widget(); + + /** + * Allocates and initializes a widget. + */ + static Widget* create(); + + /** + * Sets whether the widget is enabled + * + * Highest control of widget. + * The default value is true, a widget is default to enabled + * + * @param enabled true if the widget is enabled, widget may be touched and visible, false if the widget is disabled, widget cannot be touched and hidden. + */ + virtual void setEnabled(bool enabled); + + /** + * Determines if the widget is enabled + * + * @return true if the widget is enabled, false if the widget is disabled. + */ + bool isEnabled() const; + + /** + * Sets whether the widget is bright + * + * The default value is true, a widget is default to bright + * + * @param visible true if the widget is bright, false if the widget is dark. + */ + void setBright(bool bright); + + /** + * Determines if the widget is bright + * + * @return true if the widget is bright, false if the widget is dark. + */ + bool isBright() const; + + /** + * Sets whether the widget is touch enabled + * + * The default value is false, a widget is default to touch disabled + * + * @param visible true if the widget is touch enabled, false if the widget is touch disabled. + */ + virtual void setTouchEnabled(bool enabled); + + /** + * To set the bright style of widget. + * + * @see BrightStyle + * + * @param style BRIGHT_NORMAL the widget is normal state, BRIGHT_HIGHLIGHT the widget is height light state. + */ + void setBrightStyle(BrightStyle style); + + /** + * Determines if the widget is touch enabled + * + * @return true if the widget is touch enabled, false if the widget is touch disabled. + */ + bool isTouchEnabled() const; + + /** + * Determines if the widget is on focused + * + * @return true if the widget is on focused, false if the widget is not on focused. + */ + bool isFocused() const; + + /** + * Sets whether the widget is on focused + * + * The default value is false, a widget is default to not on focused + * + * @param fucosed true if the widget is on focused, false if the widget is not on focused. + */ + void setFocused(bool fucosed); + + /** + * Gets the left boundary position of this widget. + * + * @return The left boundary position of this widget. + */ + float getLeftInParent(); + + /** + * Gets the bottom boundary position of this widget. + * + * @return The bottom boundary position of this widget. + */ + float getBottomInParent(); + + /** + * Gets the right boundary position of this widget. + * + * @return The right boundary position of this widget. + */ + float getRightInParent(); + + /** + * Gets the top boundary position of this widget. + * + * @return The top boundary position of this widget. + */ + float getTopInParent(); + + /** + * Adds a child to the container with z-order as 0. + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + */ + virtual void addChild(Node * child) override; + /** + * Adds a child to the container with a z-order + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) + */ + virtual void addChild(Node * child, int zOrder) override; + /** + * Adds a child to the container with z order and tag + * + * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. + * + * @param child A child node + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) + * @param tag A interger to identify the node easily. Please refer to setTag(int) + */ + virtual void addChild(Node* child, int zOrder, int tag) override; + /** + * Gets a child from the container with its tag + * + * @param tag An identifier to find the child node. + * + * @return a Node object whose tag equals to the input parameter + */ + virtual Node * getChildByTag(int tag) override; + + virtual void sortAllChildren() override; + /** + * Return an array of children + * + * Composing a "tree" structure is a very important feature of Node + * Here's a sample code of traversing children array: + @code + Node* node = NULL; + CCARRAY_FOREACH(parent->getChildren(), node) + { + node->setPosition(0,0); + } + @endcode + * This sample code traverses all children nodes, and set their position to (0,0) + * + * @return An array of children + */ + virtual Vector& getChildren() override; + virtual const Vector& getChildren() const override; + + /** + * Get the amount of children. + * + * @return The amount of children. + */ + virtual ssize_t getChildrenCount() const override; + + /** + * Removes this node itself from its parent node with a cleanup. + * If the node orphan, then nothing happens. + * @see `removeFromParentAndCleanup(bool)` + */ + virtual void removeFromParent() override; + /** + * Removes this node itself from its parent node. + * If the node orphan, then nothing happens. + * @param cleanup true if all actions and callbacks on this node should be removed, false otherwise. + * @js removeFromParent + * @lua removeFromParent + */ + virtual void removeFromParentAndCleanup(bool cleanup) override; + + /** + * Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter. + * + * @param child The child node which will be removed. + * @param cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise. + */ + virtual void removeChild(Node* child, bool cleanup = true) override; + + /** + * Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter + * + * @param tag An interger number that identifies a child node + * @param cleanup true if all running actions and callbacks on the child node will be cleanup, false otherwise. + */ + virtual void removeChildByTag(int tag, bool cleanup = true) override; + /** + * Removes all children from the container with a cleanup. + * + * @see `removeAllChildrenWithCleanup(bool)` + */ + virtual void removeAllChildren() override; + /** + * Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. + * + * @param cleanup true if all running actions on all children nodes should be cleanup, false oterwise. + * @js removeAllChildren + * @lua removeAllChildren + */ + virtual void removeAllChildrenWithCleanup(bool cleanup) override; + + /** + * Gets a child from the container with its name + * + * @param name An key to find the child widget. + * + * @return a Widget object whose name equals to the input parameter + */ + virtual Widget* getChildByName(const char* name); + + virtual void addNode(Node* node); + + virtual void addNode(Node * node, int zOrder); + + virtual void addNode(Node* node, int zOrder, int tag); + + virtual Node * getNodeByTag(int tag); + + virtual Vector& getNodes(); + + virtual void removeNode(Node* node); + + virtual void removeNodeByTag(int tag); + + virtual void removeAllNodes(); + + virtual void visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override; + + /** + * Sets the touch event target/selector of the menu item + */ + void addTouchEventListener(Ref* target,SEL_TouchEvent selector); + + + //cocos2d property + + /** + * Changes the position (x,y) of the widget in OpenGL coordinates + * + * Usually we use p(x,y) to compose Point object. + * The original point (0,0) is at the left-bottom corner of screen. + * + * @param position The position (x,y) of the widget in OpenGL coordinates + */ + virtual void setPosition(const Point &pos) override; + + /** + * Changes the position (x,y) of the widget in OpenGL coordinates + * + * Usually we use p(x,y) to compose Point object. + * The original point (0,0) is at the left-bottom corner of screen. + * + * @param percent The percent (x,y) of the widget in OpenGL coordinates + */ + void setPositionPercent(const Point &percent); + + /** + * Gets the percent (x,y) of the widget in OpenGL coordinates + * + * @see setPosition(const Point&) + * + * @return The percent (x,y) of the widget in OpenGL coordinates + */ + const Point& getPositionPercent(); + + /** + * Changes the position type of the widget + * + * @see PositionType + * + * @param type the position type of widget + */ + void setPositionType(PositionType type); + + /** + * Gets the position type of the widget + * + * @see PositionType + * + * @return type the position type of widget + */ + PositionType getPositionType() const; + + /** + * Sets whether the widget should be flipped horizontally or not. + * + * @param bFlippedX true if the widget should be flipped horizaontally, false otherwise. + */ + virtual void setFlippedX(bool flippedX); + + /** + * Returns the flag which indicates whether the widget is flipped horizontally or not. + * + * It only flips the texture of the widget, and not the texture of the widget's children. + * Also, flipping the texture doesn't alter the anchorPoint. + * If you want to flip the anchorPoint too, and/or to flip the children too use: + * widget->setScaleX(sprite->getScaleX() * -1); + * + * @return true if the widget is flipped horizaontally, false otherwise. + */ + virtual bool isFlippedX(){return _flippedX;}; + + /** + * Sets whether the widget should be flipped vertically or not. + * + * @param bFlippedY true if the widget should be flipped vertically, flase otherwise. + */ + virtual void setFlippedY(bool flippedY); + + /** + * Return the flag which indicates whether the widget is flipped vertically or not. + * + * It only flips the texture of the widget, and not the texture of the widget's children. + * Also, flipping the texture doesn't alter the anchorPoint. + * If you want to flip the anchorPoint too, and/or to flip the children too use: + * widget->setScaleY(widget->getScaleY() * -1); + * + * @return true if the widget is flipped vertically, flase otherwise. + */ + virtual bool isFlippedY(){return _flippedY;}; + + virtual void setColor(const Color3B& color) override; + + virtual void setOpacity(GLubyte opacity) override; + + const Color3B& getColor() const override {return _color;}; + + GLubyte getOpacity() const override {return _opacity;}; + + /** @deprecated Use isFlippedX() instead */ + CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); }; + /** @deprecated Use setFlippedX() instead */ + CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flipX) { setFlippedX(flipX); }; + /** @deprecated Use isFlippedY() instead */ + CC_DEPRECATED_ATTRIBUTE bool isFlipY() { return isFlippedY(); }; + /** @deprecated Use setFlippedY() instead */ + CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); }; + + /** + * A call back function when widget lost of focus. + */ + void didNotSelectSelf(); + + /* + * Checks a point if in parent's area. + * + * @param point + * + * @return true if the point is in parent's area, flase otherwise. + */ + bool clippingParentAreaContainPoint(const Point &pt); + + /* + * Sends the touch event to widget's parent + */ + virtual void checkChildInfo(int handleState,Widget* sender,const Point &touchPoint); + + /* + * Gets the touch began point of widget when widget is selected. + * + * @return the touch began point. + */ + const Point& getTouchStartPos(); + + /* + * Gets the touch move point of widget when widget is selected. + * + * @return the touch move point. + */ + const Point& getTouchMovePos(); + + /* + * Gets the touch end point of widget when widget is selected. + * + * @return the touch end point. + */ + const Point& getTouchEndPos(); + + /** + * Changes the name that is used to identify the widget easily. + * + * @param A const char* that indentifies the widget. + */ + void setName(const char* name); + + /** + * Returns a name that is used to identify the widget easily. + * + * You can set tags to widget then identify them easily. + * + * @return A const char* that identifies the widget. + */ + const char* getName() const; + + /** + * Returns a type that is widget's type + * + * @see WidgetType + * + * @return A WidgetType + */ + WidgetType getWidgetType() const; + + /** + * Changes the size that is widget's size + * + * @param size that is widget's size + */ + virtual void setSize(const Size &size); + + /** + * Changes the percent that is widget's percent size + * + * @param percent that is widget's percent size + */ + virtual void setSizePercent(const Point &percent); + + /** + * Changes the size type of widget. + * + * @see SizeType + * + * @param type that is widget's size type + */ + void setSizeType(SizeType type); + + /** + * Gets the size type of widget. + * + * @see SizeType + * + * @param type that is widget's size type + */ + SizeType getSizeType() const; + + /** + * Returns size of widget + * + * @return size + */ + const Size& getSize() const; + + const Size& getCustomSize() const; + + /** + * Returns size percent of widget + * + * @return size percent + */ + const Point& getSizePercent() const; + + /** + * Checks a point if is in widget's space + * + * @param point + * + * @return true if the point is in widget's space, flase otherwise. + */ + virtual bool hitTest(const Point &pt); + + virtual bool onTouchBegan(Touch *touch, Event *unusedEvent); + virtual void onTouchMoved(Touch *touch, Event *unusedEvent); + virtual void onTouchEnded(Touch *touch, Event *unusedEvent); + virtual void onTouchCancelled(Touch *touch, Event *unusedEvent); + + /** + * Sets a LayoutParameter to widget. + * + * @see LayoutParameter + * + * @param LayoutParameter pointer + * + * @param type Relative or Linear + */ + void setLayoutParameter(LayoutParameter* parameter); + + /** + * Gets LayoutParameter of widget. + * + * @see LayoutParameter + * + * @param type Relative or Linear + * + * @return LayoutParameter + */ + LayoutParameter* getLayoutParameter(LayoutParameterType type); + + /** + * Ignore the widget size + * + * @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true. + */ + virtual void ignoreContentAdaptWithSize(bool ignore); + + /** + * Gets the widget if is ignore it's size. + * + * @param ignore, true that widget will ignore it's size, use texture size, false otherwise. Default value is true. + */ + bool isIgnoreContentAdaptWithSize() const; + + /** + * Gets world position of widget. + * + * @return world position of widget. + */ + Point getWorldPosition(); + + /** + * Gets the Virtual Renderer of widget. + * + * For example, a button's Virtual Renderer is it's texture renderer. + * + * @return Node pointer. + */ + virtual Node* getVirtualRenderer(); + + /** + * Gets the content size of widget. + * + * Content size is widget's texture size. + */ + virtual const Size& getContentSize() const; + + /** + * Returns the "class name" of widget. + */ + virtual std::string getDescription() const override; + + Widget* clone(); + + virtual void onEnter() override; + virtual void onExit() override; + + void updateSizeAndPosition(); + + /*temp action*/ + void setActionTag(int tag); + int getActionTag(); +protected: + //call back function called when size changed. + virtual void onSizeChanged(); + + //initializes state of widget. + virtual bool init(); + + //initializes renderer of widget. + virtual void initRenderer(); + + //call back function called widget's state changed to normal. + virtual void onPressStateChangedToNormal(); + + //call back function called widget's state changed to selected. + virtual void onPressStateChangedToPressed(); + + //call back function called widget's state changed to dark. + virtual void onPressStateChangedToDisabled(); + void pushDownEvent(); + void moveEvent(); + void releaseUpEvent(); + void cancelUpEvent(); + void updateAnchorPoint(); + virtual void updateTextureColor(){}; + virtual void updateTextureOpacity(){}; + virtual void updateTextureRGBA(){}; + virtual void updateFlippedX(){}; + virtual void updateFlippedY(){}; + void updateColorToRenderer(Node* renderer); + void updateOpacityToRenderer(Node* renderer); + void updateRGBAToRenderer(Node* renderer); + void copyProperties(Widget* model); + virtual Widget* createCloneInstance(); + virtual void copySpecialProperties(Widget* model); + virtual void copyClonedWidgetChildren(Widget* model); + Widget* getWidgetParent(); +protected: + bool _enabled; ///< Highest control of widget + bool _bright; ///< is this widget bright + bool _touchEnabled; ///< is this widget touch endabled + bool _touchPassedEnabled; ///< is the touch event should be passed + bool _focus; ///< is the widget on focus + BrightStyle _brightStyle; ///< bright style + Point _touchStartPos; ///< touch began point + Point _touchMovePos; ///< touch moved point + Point _touchEndPos; ///< touch ended point + Ref* _touchEventListener; + SEL_TouchEvent _touchEventSelector; + std::string _name; + WidgetType _widgetType; + int _actionTag; + Size _size; + Size _customSize; + bool _ignoreSize; + bool _affectByClipping; + SizeType _sizeType; + Point _sizePercent; + PositionType _positionType; + Point _positionPercent; + bool _reorderWidgetChildDirty; + bool _hitted; + EventListenerTouchOneByOne* _touchListener; + Vector _nodes; + Color3B _color; + GLubyte _opacity; + bool _flippedX; + bool _flippedY; + Map _layoutParameterDictionary; + Vector _widgetChildren; + +}; +} + +NS_CC_END + +#endif /* defined(__Widget__) */ diff --git a/cocos/ui/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/ui/WidgetReader/ButtonReader/ButtonReader.cpp new file mode 100644 index 0000000000..5bf321dc84 --- /dev/null +++ b/cocos/ui/WidgetReader/ButtonReader/ButtonReader.cpp @@ -0,0 +1,158 @@ + + +#include "ButtonReader.h" +#include "ui/UIButton.h" + +namespace cocostudio +{ + static ButtonReader* instanceButtonReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader) + + ButtonReader::ButtonReader() + { + + } + + ButtonReader::~ButtonReader() + { + + } + + ButtonReader* ButtonReader::getInstance() + { + if (!instanceButtonReader) + { + instanceButtonReader = new ButtonReader(); + } + return instanceButtonReader; + } + + void ButtonReader::purge() + { + CC_SAFE_DELETE(instanceButtonReader); + } + + void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + Button* button = static_cast(widget); + bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + button->setScale9Enabled(scale9Enable); + + const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData"); + int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); + switch (normalType) + { + case 0: + { + std::string tp_n = jsonPath; + const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); + const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; + button->loadTextureNormal(normalFileName_tp); + break; + } + case 1: + { + const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); + button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData"); + int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); + switch (pressedType) + { + case 0: + { + std::string tp_p = jsonPath; + const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); + const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; + button->loadTexturePressed(pressedFileName_tp); + break; + } + case 1: + { + const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); + button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData"); + int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); + switch (disabledType) + { + case 0: + { + std::string tp_d = jsonPath; + const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); + const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; + button->loadTextureDisabled(disabledFileName_tp); + break; + } + case 1: + { + const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); + button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + if (scale9Enable) + { + float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); + float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); + float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); + float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + + button->setCapInsets(Rect(cx, cy, cw, ch)); + bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); + bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); + if (sw && sh) + { + float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); + float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); + button->setSize(Size(swf, shf)); + } + } + bool tt = DICTOOL->checkObjectExist_json(options, "text"); + if (tt) + { + const char* text = DICTOOL->getStringValue_json(options, "text"); + if (text) + { + button->setTitleText(text); + } + } + + bool cr = DICTOOL->checkObjectExist_json(options, "textColorR"); + bool cg = DICTOOL->checkObjectExist_json(options, "textColorG"); + bool cb = DICTOOL->checkObjectExist_json(options, "textColorB"); + int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255; + int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255; + int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255; + button->setTitleColor(Color3B(cri,cgi,cbi)); + bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); + if (fs) + { + button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize")); + } + bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); + if (fn) + { + button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName")); + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/ButtonReader/ButtonReader.h b/cocos/ui/WidgetReader/ButtonReader/ButtonReader.h new file mode 100644 index 0000000000..f3ec7b406a --- /dev/null +++ b/cocos/ui/WidgetReader/ButtonReader/ButtonReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__ButtonReader__ +#define __TestCpp__ButtonReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class ButtonReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + ButtonReader(); + virtual ~ButtonReader(); + + static ButtonReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__ButtonReader__) */ diff --git a/cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp new file mode 100644 index 0000000000..06ac1bc0a7 --- /dev/null +++ b/cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -0,0 +1,153 @@ + + +#include "CheckBoxReader.h" +#include "ui/UICheckBox.h" + +namespace cocostudio +{ + static CheckBoxReader* instanceCheckBoxReader = NULL; + using cocos2d::ui::CheckBox; + IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader) + + CheckBoxReader::CheckBoxReader() + { + + } + + CheckBoxReader::~CheckBoxReader() + { + + } + + CheckBoxReader* CheckBoxReader::getInstance() + { + if (!instanceCheckBoxReader) + { + instanceCheckBoxReader = new CheckBoxReader(); + } + return instanceCheckBoxReader; + } + + void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + CheckBox* checkBox = static_cast(widget); + + const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData"); + int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType"); + switch (backGroundType) + { + case 0: + { + std::string tp_b = jsonPath; + const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); + const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr; + checkBox->loadTextureBackGround(backGroundFileName_tp); + break; + } + case 1: + { + const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); + checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData"); + int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType"); + switch (backGroundSelectedType) + { + case 0: + { + std::string tp_bs = jsonPath; + const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); + const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr; + checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp); + break; + } + case 1: + { + const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); + checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData"); + int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType"); + switch (frontCrossType) + { + case 0: + { + std::string tp_c = jsonPath; + const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); + const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr; + checkBox->loadTextureFrontCross(frontCrossFileName_tp); + break; + } + case 1: + { + const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); + checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData"); + int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType"); + switch (backGroundDisabledType) + { + case 0: + { + std::string tp_bd = jsonPath; + const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); + const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr; + checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp); + break; + } + case 1: + { + const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); + checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData"); + int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType"); + switch (frontCrossDisabledType) + { + case 0: + { + std::string tp_cd = jsonPath; + const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); + const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr; + checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp); + break; + } + case 1: + { + const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); + checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.h b/cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.h new file mode 100644 index 0000000000..cbfed76584 --- /dev/null +++ b/cocos/ui/WidgetReader/CheckBoxReader/CheckBoxReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__CheckBoxReader__ +#define __TestCpp__CheckBoxReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class CheckBoxReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + CheckBoxReader(); + virtual ~CheckBoxReader(); + + static CheckBoxReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__CheckBoxReader__) */ diff --git a/cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.cpp new file mode 100644 index 0000000000..083d81f261 --- /dev/null +++ b/cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -0,0 +1,98 @@ + + +#include "ImageViewReader.h" +#include "ui/UIImageView.h" + +namespace cocostudio +{ + static ImageViewReader* instanceImageViewReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader) + + ImageViewReader::ImageViewReader() + { + + } + + ImageViewReader::~ImageViewReader() + { + + } + + ImageViewReader* ImageViewReader::getInstance() + { + if (!instanceImageViewReader) + { + instanceImageViewReader = new ImageViewReader(); + } + return instanceImageViewReader; + } + + void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + ImageView* imageView = static_cast(widget); + + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); + switch (imageFileNameType) + { + case 0: + { + std::string tp_i = jsonPath; + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileName_tp = nullptr; + if (imageFileName && (strcmp(imageFileName, "") != 0)) + { + imageFileName_tp = tp_i.append(imageFileName).c_str(); + imageView->loadTexture(imageFileName_tp); + } + break; + } + case 1: + { + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable"); + bool scale9Enable = false; + if (scale9EnableExist) + { + scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + } + imageView->setScale9Enabled(scale9Enable); + + + if (scale9Enable) + { + bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); + bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); + if (sw && sh) + { + float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); + float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); + imageView->setSize(Size(swf, shf)); + } + + float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); + float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); + float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); + float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + + imageView->setCapInsets(Rect(cx, cy, cw, ch)); + + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.h b/cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.h new file mode 100644 index 0000000000..09d4ae2b43 --- /dev/null +++ b/cocos/ui/WidgetReader/ImageViewReader/ImageViewReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__ImageViewReader__ +#define __TestCpp__ImageViewReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class ImageViewReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + ImageViewReader(); + virtual ~ImageViewReader(); + + static ImageViewReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__ImageViewReader__) */ diff --git a/cocos/ui/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/ui/WidgetReader/LayoutReader/LayoutReader.cpp new file mode 100644 index 0000000000..ec137e7ca4 --- /dev/null +++ b/cocos/ui/WidgetReader/LayoutReader/LayoutReader.cpp @@ -0,0 +1,119 @@ + + +#include "LayoutReader.h" +#include "ui/UILayout.h" + +namespace cocostudio +{ + static LayoutReader* instanceLayoutReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader) + + LayoutReader::LayoutReader() + { + + } + + LayoutReader::~LayoutReader() + { + + } + + LayoutReader* LayoutReader::getInstance() + { + if (!instanceLayoutReader) + { + instanceLayoutReader = new LayoutReader(); + } + return instanceLayoutReader; + } + + void LayoutReader::setPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + Layout* panel = static_cast(widget); + + /* adapt screen gui */ + float w = 0, h = 0; + bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); + if (adaptScrenn) + { + Size screenSize = CCDirector::getInstance()->getWinSize(); + w = screenSize.width; + h = screenSize.height; + } + else + { + w = DICTOOL->getFloatValue_json(options, "width"); + h = DICTOOL->getFloatValue_json(options, "height"); + } + panel->setSize(Size(w, h)); + /**/ + + bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable"); + panel->setBackGroundImageScale9Enabled(backGroundScale9Enable); + int cr = DICTOOL->getIntValue_json(options, "bgColorR"); + int cg = DICTOOL->getIntValue_json(options, "bgColorG"); + int cb = DICTOOL->getIntValue_json(options, "bgColorB"); + + int scr = DICTOOL->getIntValue_json(options, "bgStartColorR"); + int scg = DICTOOL->getIntValue_json(options, "bgStartColorG"); + int scb = DICTOOL->getIntValue_json(options, "bgStartColorB"); + + int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR"); + int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG"); + int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB"); + + float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX"); + float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY"); + panel->setBackGroundColorVector(Point(bgcv1, bgcv2)); + + int co = DICTOOL->getIntValue_json(options, "bgColorOpacity"); + + int colorType = DICTOOL->getIntValue_json(options, "colorType"); + panel->setBackGroundColorType(LayoutBackGroundColorType(colorType)); + panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb)); + panel->setBackGroundColor(Color3B(cr, cg, cb)); + panel->setBackGroundColorOpacity(co); + + + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData"); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); + switch (imageFileNameType) + { + case 0: + { + std::string tp_b = jsonPath; + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; + panel->setBackGroundImage(imageFileName_tp); + break; + } + case 1: + { + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + if (backGroundScale9Enable) + { + float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); + float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); + float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); + float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch)); + } + panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType")); + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/LayoutReader/LayoutReader.h b/cocos/ui/WidgetReader/LayoutReader/LayoutReader.h new file mode 100644 index 0000000000..e4d2f3b479 --- /dev/null +++ b/cocos/ui/WidgetReader/LayoutReader/LayoutReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__LayoutReader__ +#define __TestCpp__LayoutReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class LayoutReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + LayoutReader(); + virtual ~LayoutReader(); + + static LayoutReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__LayoutReader__) */ diff --git a/cocos/ui/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/ui/WidgetReader/ListViewReader/ListViewReader.cpp new file mode 100644 index 0000000000..44a58941b5 --- /dev/null +++ b/cocos/ui/WidgetReader/ListViewReader/ListViewReader.cpp @@ -0,0 +1,48 @@ + + +#include "ListViewReader.h" +#include "ui/UIListView.h" + +namespace cocostudio +{ + static ListViewReader* instanceListViewReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader) + + ListViewReader::ListViewReader() + { + + } + + ListViewReader::~ListViewReader() + { + + } + + ListViewReader* ListViewReader::getInstance() + { + if (!instanceListViewReader) + { + instanceListViewReader = new ListViewReader(); + } + return instanceListViewReader; + } + + void ListViewReader::setPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options) + { + ScrollViewReader::setPropsFromJsonDictionary(widget, options); + + + ListView* listView = static_cast(widget); + + int direction = DICTOOL->getFloatValue_json(options, "direction"); + listView->setDirection((SCROLLVIEW_DIR)direction); + + ListViewGravity gravity = (ListViewGravity)DICTOOL->getIntValue_json(options, "gravity"); + listView->setGravity(gravity); + + float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin"); + listView->setItemsMargin(itemMargin); + } +} + diff --git a/cocos/ui/WidgetReader/ListViewReader/ListViewReader.h b/cocos/ui/WidgetReader/ListViewReader/ListViewReader.h new file mode 100644 index 0000000000..6c10b2114b --- /dev/null +++ b/cocos/ui/WidgetReader/ListViewReader/ListViewReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__ListViewReader__ +#define __TestCpp__ListViewReader__ + +#include "../ScrollViewReader/ScrollViewReader.h" + +namespace cocostudio +{ + class ListViewReader : public ScrollViewReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + ListViewReader(); + virtual ~ListViewReader(); + + static ListViewReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__ListViewReader__) */ diff --git a/cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp new file mode 100644 index 0000000000..864e19a473 --- /dev/null +++ b/cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -0,0 +1,91 @@ + + +#include "LoadingBarReader.h" +#include "ui/UILoadingBar.h" + +namespace cocostudio +{ + static LoadingBarReader* instanceLoadingBar = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader) + + LoadingBarReader::LoadingBarReader() + { + + } + + LoadingBarReader::~LoadingBarReader() + { + + } + + LoadingBarReader* LoadingBarReader::getInstance() + { + if (!instanceLoadingBar) + { + instanceLoadingBar = new LoadingBarReader(); + } + return instanceLoadingBar; + } + + void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + LoadingBar* loadingBar = static_cast(widget); + + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData"); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); + switch (imageFileNameType) + { + case 0: + { + std::string tp_i = jsonPath; + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileName_tp = nullptr; + if (imageFileName && (strcmp(imageFileName, "") != 0)) + { + imageFileName_tp = tp_i.append(imageFileName).c_str(); + loadingBar->loadTexture(imageFileName_tp); + } + break; + } + case 1: + { + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + /* gui mark add load bar scale9 parse */ + bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + loadingBar->setScale9Enabled(scale9Enable); + + if (scale9Enable) + { + float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); + float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); + float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); + float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + + loadingBar->setCapInsets(Rect(cx, cy, cw, ch)); + + float width = DICTOOL->getFloatValue_json(options, "width"); + float height = DICTOOL->getFloatValue_json(options, "height"); + loadingBar->setSize(Size(width, height)); + } + /**/ + + loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction"))); + loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent")); + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.h b/cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.h new file mode 100644 index 0000000000..69d12e3f33 --- /dev/null +++ b/cocos/ui/WidgetReader/LoadingBarReader/LoadingBarReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__LoadingBarReader__ +#define __TestCpp__LoadingBarReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class LoadingBarReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + LoadingBarReader(); + virtual ~LoadingBarReader(); + + static LoadingBarReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__LoadingBarReader__) */ diff --git a/cocos/ui/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/ui/WidgetReader/PageViewReader/PageViewReader.cpp new file mode 100644 index 0000000000..c5692277e2 --- /dev/null +++ b/cocos/ui/WidgetReader/PageViewReader/PageViewReader.cpp @@ -0,0 +1,35 @@ + + +#include "PageViewReader.h" +#include "ui/UIPageView.h" + +namespace cocostudio +{ + static PageViewReader* instancePageViewReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader) + + PageViewReader::PageViewReader() + { + + } + + PageViewReader::~PageViewReader() + { + + } + + PageViewReader* PageViewReader::getInstance() + { + if (!instancePageViewReader) + { + instancePageViewReader = new PageViewReader(); + } + return instancePageViewReader; + } + + void PageViewReader::setPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options) + { + LayoutReader::setPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/PageViewReader/PageViewReader.h b/cocos/ui/WidgetReader/PageViewReader/PageViewReader.h new file mode 100644 index 0000000000..07b7719565 --- /dev/null +++ b/cocos/ui/WidgetReader/PageViewReader/PageViewReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__PageViewReader__ +#define __TestCpp__PageViewReader__ + +#include "../LayoutReader/LayoutReader.h" + +namespace cocostudio +{ + class PageViewReader : public LayoutReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + PageViewReader(); + virtual ~PageViewReader(); + + static PageViewReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(ui::Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__PageViewReader__) */ diff --git a/cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp new file mode 100644 index 0000000000..a09480d8e1 --- /dev/null +++ b/cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -0,0 +1,47 @@ + + +#include "ScrollViewReader.h" +#include "ui/UIScrollView.h" + +namespace cocostudio +{ + static ScrollViewReader* instanceScrollViewReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader) + + ScrollViewReader::ScrollViewReader() + { + + } + + ScrollViewReader::~ScrollViewReader() + { + + } + + ScrollViewReader* ScrollViewReader::getInstance() + { + if (!instanceScrollViewReader) + { + instanceScrollViewReader = new ScrollViewReader(); + } + return instanceScrollViewReader; + } + + void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + LayoutReader::setPropsFromJsonDictionary(widget, options); + + + ScrollView* scrollView = static_cast(widget); + float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth"); + float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight"); + scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); + int direction = DICTOOL->getFloatValue_json(options, "direction"); + scrollView->setDirection((SCROLLVIEW_DIR)direction); + scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable")); + + + LayoutReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.h b/cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.h new file mode 100644 index 0000000000..429a2ad9fe --- /dev/null +++ b/cocos/ui/WidgetReader/ScrollViewReader/ScrollViewReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__ScrollViewReader__ +#define __TestCpp__ScrollViewReader__ + +#include "../LayoutReader/LayoutReader.h" + +namespace cocostudio +{ + class ScrollViewReader : public LayoutReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + ScrollViewReader(); + virtual ~ScrollViewReader(); + + static ScrollViewReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__ScrollViewReader__) */ diff --git a/cocos/ui/WidgetReader/SliderReader/SliderReader.cpp b/cocos/ui/WidgetReader/SliderReader/SliderReader.cpp new file mode 100644 index 0000000000..9e290d28e3 --- /dev/null +++ b/cocos/ui/WidgetReader/SliderReader/SliderReader.cpp @@ -0,0 +1,192 @@ + + +#include "SliderReader.h" +#include "ui/UISlider.h" + +namespace cocostudio +{ + static SliderReader* instanceSliderReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader) + + SliderReader::SliderReader() + { + + } + + SliderReader::~SliderReader() + { + + } + + SliderReader* SliderReader::getInstance() + { + if (!instanceSliderReader) + { + instanceSliderReader = new SliderReader(); + } + return instanceSliderReader; + } + + void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + Slider* slider = static_cast(widget); + + bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable"); + slider->setScale9Enabled(barTextureScale9Enable); + bool bt = DICTOOL->checkObjectExist_json(options, "barFileName"); + float barLength = DICTOOL->getFloatValue_json(options, "length"); + if (bt) + { + if (barTextureScale9Enable) + { + + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); + int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); + switch (imageFileType) + { + case 0: + { + std::string tp_b = jsonPath; + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; + slider->loadBarTexture(imageFileName_tp); + break; + } + case 1: + { + const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + slider->setSize(Size(barLength, slider->getContentSize().height)); + } + else + { + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); + int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); + switch (imageFileType) + { + case 0: + { + std::string tp_b = jsonPath; + const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; + slider->loadBarTexture(imageFileName_tp); + break; + } + case 1: + { + const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); + slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + } + } + + const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData"); + int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); + switch (normalType) + { + case 0: + { + std::string tp_n = jsonPath; + const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); + const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; + slider->loadSlidBallTextureNormal(normalFileName_tp); + break; + } + case 1: + { + const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); + slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData"); + int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); + switch (pressedType) + { + case 0: + { + std::string tp_p = jsonPath; + const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); + const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; + slider->loadSlidBallTexturePressed(pressedFileName_tp); + break; + } + case 1: + { + const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); + slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData"); + int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); + switch (disabledType) + { + case 0: + { + std::string tp_d = jsonPath; + const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); + const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; + slider->loadSlidBallTextureDisabled(disabledFileName_tp); + break; + } + case 1: + { + const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); + slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + slider->setPercent(DICTOOL->getIntValue_json(options, "percent")); + + const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData"); + int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType"); + switch (progressBarType) + { + case 0: + { + std::string tp_b = jsonPath; + const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); + const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; + slider->loadProgressBarTexture(imageFileName_tp); + break; + } + case 1: + { + const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); + slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST); + break; + } + default: + break; + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/SliderReader/SliderReader.h b/cocos/ui/WidgetReader/SliderReader/SliderReader.h new file mode 100644 index 0000000000..1fa0390c07 --- /dev/null +++ b/cocos/ui/WidgetReader/SliderReader/SliderReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__SliderReader__ +#define __TestCpp__SliderReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class SliderReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + SliderReader(); + virtual ~SliderReader(); + + static SliderReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__SliderReader__) */ diff --git a/cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp new file mode 100644 index 0000000000..9fd20de2f2 --- /dev/null +++ b/cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -0,0 +1,69 @@ + + +#include "TextAtlasReader.h" +#include "ui/UITextAtlas.h" + +namespace cocostudio +{ + static TextAtlasReader* instanceTextAtalsReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader) + + TextAtlasReader::TextAtlasReader() + { + + } + + TextAtlasReader::~TextAtlasReader() + { + + } + + TextAtlasReader* TextAtlasReader::getInstance() + { + if (!instanceTextAtalsReader) + { + instanceTextAtalsReader = new TextAtlasReader(); + } + return instanceTextAtalsReader; + } + + void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + TextAtlas* labelAtlas = static_cast(widget); + bool sv = DICTOOL->checkObjectExist_json(options, "stringValue"); + bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile"); + bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth"); + bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight"); + bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap"); + if (sv && cmf && iw && ih && scm) + { + const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData"); + int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); + switch (cmfType) + { + case 0: + { + std::string tp_c = jsonPath; + const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); + const char* cmf_tp = tp_c.append(cmfPath).c_str(); + labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap")); + break; + } + case 1: + CCLOG("Wrong res type of LabelAtlas!"); + break; + default: + break; + } + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.h b/cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.h new file mode 100644 index 0000000000..a065162769 --- /dev/null +++ b/cocos/ui/WidgetReader/TextAtlasReader/TextAtlasReader.h @@ -0,0 +1,46 @@ +/**************************************************************************** + Copyright (c) 2014 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__TextAtlasReader__ +#define __TestCpp__TextAtlasReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class TextAtlasReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + TextAtlasReader(); + virtual ~TextAtlasReader(); + + static TextAtlasReader* getInstance(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__TextAtlasReader__) */ diff --git a/cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp new file mode 100644 index 0000000000..daec7016a0 --- /dev/null +++ b/cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -0,0 +1,65 @@ + + +#include "TextBMFontReader.h" +#include "ui/UITextBMFont.h" + +namespace cocostudio +{ + static TextBMFontReader* instanceTextBMFontReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader) + + TextBMFontReader::TextBMFontReader() + { + + } + + TextBMFontReader::~TextBMFontReader() + { + + } + + TextBMFontReader* TextBMFontReader::getInstance() + { + if (!instanceTextBMFontReader) + { + instanceTextBMFontReader = new TextBMFontReader(); + } + return instanceTextBMFontReader; + } + + void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + TextBMFont* labelBMFont = static_cast(widget); + + const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); + int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); + switch (cmfType) + { + case 0: + { + std::string tp_c = jsonPath; + const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); + const char* cmf_tp = tp_c.append(cmfPath).c_str(); + labelBMFont->setFntFile(cmf_tp); + break; + } + case 1: + CCLOG("Wrong res type of LabelAtlas!"); + break; + default: + break; + } + + const char* text = DICTOOL->getStringValue_json(options, "text"); + labelBMFont->setText(text); + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.h b/cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.h new file mode 100644 index 0000000000..bfba2f3cfc --- /dev/null +++ b/cocos/ui/WidgetReader/TextBMFontReader/TextBMFontReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__TextBMFontReader__ +#define __TestCpp__TextBMFontReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class TextBMFontReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + TextBMFontReader(); + virtual ~TextBMFontReader(); + + static TextBMFontReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__TextBMFontReader__) */ diff --git a/cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.cpp new file mode 100644 index 0000000000..0066e796fc --- /dev/null +++ b/cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -0,0 +1,84 @@ + + +#include "TextFieldReader.h" +#include "ui/UITextField.h" + +namespace cocostudio +{ + static TextFieldReader* instanceTextFieldReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader) + + TextFieldReader::TextFieldReader() + { + + } + + TextFieldReader::~TextFieldReader() + { + + } + + TextFieldReader* TextFieldReader::getInstance() + { + if (!instanceTextFieldReader) + { + instanceTextFieldReader = new TextFieldReader(); + } + return instanceTextFieldReader; + } + + void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + TextField* textField = static_cast(widget); + bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder"); + if (ph) + { + textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder")); + } + textField->setText(DICTOOL->getStringValue_json(options, "text")); + bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); + if (fs) + { + textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); + } + bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); + if (fn) + { + textField->setFontName(DICTOOL->getStringValue_json(options, "fontName")); + } + bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth"); + bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight"); + if (tsw && tsh) + { + textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight"))); + } + + float dw = DICTOOL->getFloatValue_json(options, "width"); + float dh = DICTOOL->getFloatValue_json(options, "height"); + if (dw > 0.0f || dh > 0.0f) + { + //textField->setSize(Size(dw, dh)); + } + bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable"); + textField->setMaxLengthEnabled(maxLengthEnable); + + if (maxLengthEnable) + { + int maxLength = DICTOOL->getIntValue_json(options, "maxLength"); + textField->setMaxLength(maxLength); + } + bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable"); + textField->setPasswordEnabled(passwordEnable); + if (passwordEnable) + { + textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText")); + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.h b/cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.h new file mode 100644 index 0000000000..30d467787a --- /dev/null +++ b/cocos/ui/WidgetReader/TextFieldReader/TextFieldReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__TextFieldReader__ +#define __TestCpp__TextFieldReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class TextFieldReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + TextFieldReader(); + virtual ~TextFieldReader(); + + static TextFieldReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__TextFieldReader__) */ diff --git a/cocos/ui/WidgetReader/TextReader/TextReader.cpp b/cocos/ui/WidgetReader/TextReader/TextReader.cpp new file mode 100644 index 0000000000..5910122767 --- /dev/null +++ b/cocos/ui/WidgetReader/TextReader/TextReader.cpp @@ -0,0 +1,74 @@ + + +#include "TextReader.h" +#include "ui/UIText.h" + +namespace cocostudio +{ + static TextReader* instanceTextReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(TextReader) + + TextReader::TextReader() + { + + } + + TextReader::~TextReader() + { + + } + + TextReader* TextReader::getInstance() + { + if (!instanceTextReader) + { + instanceTextReader = new TextReader(); + } + return instanceTextReader; + } + + void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) + { + WidgetReader::setPropsFromJsonDictionary(widget, options); + + + std::string jsonPath = GUIReader::getInstance()->getFilePath(); + + Text* label = static_cast(widget); + bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable"); + label->setTouchScaleChangeEnabled(touchScaleChangeAble); + const char* text = DICTOOL->getStringValue_json(options, "text"); + label->setText(text); + bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); + if (fs) + { + label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); + } + bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); + if (fn) + { + label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); + } + bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); + bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); + if (aw && ah) + { + Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); + label->setTextAreaSize(size); + } + bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); + if (ha) + { + label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment")); + } + bool va = DICTOOL->checkObjectExist_json(options, "vAlignment"); + if (va) + { + label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment")); + } + + + WidgetReader::setColorPropsFromJsonDictionary(widget, options); + } +} diff --git a/cocos/ui/WidgetReader/TextReader/TextReader.h b/cocos/ui/WidgetReader/TextReader/TextReader.h new file mode 100644 index 0000000000..18d15e6323 --- /dev/null +++ b/cocos/ui/WidgetReader/TextReader/TextReader.h @@ -0,0 +1,47 @@ +/**************************************************************************** + Copyright (c) 2014 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__TextReader__ +#define __TestCpp__TextReader__ + +#include "../WidgetReader.h" + +namespace cocostudio +{ + class TextReader : public WidgetReader + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + TextReader(); + virtual ~TextReader(); + + static TextReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__TextReader__) */ diff --git a/cocos/ui/WidgetReader/WidgetReader.cpp b/cocos/ui/WidgetReader/WidgetReader.cpp new file mode 100644 index 0000000000..29570ecff3 --- /dev/null +++ b/cocos/ui/WidgetReader/WidgetReader.cpp @@ -0,0 +1,173 @@ + + +#include "WidgetReader.h" + +namespace cocostudio +{ + using namespace cocos2d::ui; + static WidgetReader* instanceWidgetReader = NULL; + + IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader) + + WidgetReader::WidgetReader() + { + + } + + WidgetReader::~WidgetReader() + { + + } + + WidgetReader* WidgetReader::getInstance() + { + if (!instanceWidgetReader) + { + instanceWidgetReader = new WidgetReader(); + } + return instanceWidgetReader; + } + + void WidgetReader::purge() + { + CC_SAFE_DELETE(instanceWidgetReader); + } + + void WidgetReader::setPropsFromJsonDictionary(cocos2d::ui::Widget *widget, const rapidjson::Value &options) + { + bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); + if (ignoreSizeExsit) + { + widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); + } + + widget->setSizeType((SizeType)DICTOOL->getIntValue_json(options, "sizeType")); + widget->setPositionType((PositionType)DICTOOL->getIntValue_json(options, "positionType")); + + widget->setSizePercent(Point(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY"))); + widget->setPositionPercent(Point(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY"))); + + /* adapt screen */ + float w = 0, h = 0; + bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); + if (adaptScrenn) + { + Size screenSize = CCDirector::getInstance()->getWinSize(); + w = screenSize.width; + h = screenSize.height; + } + else + { + w = DICTOOL->getFloatValue_json(options, "width"); + h = DICTOOL->getFloatValue_json(options, "height"); + } + widget->setSize(Size(w, h)); + // before + /* + float w = DICTOOL->getFloatValue_json(options, "width"); + float h = DICTOOL->getFloatValue_json(options, "height"); + widget->setSize(CCSizeMake(w, h)); + */ + /**/ + + widget->setTag(DICTOOL->getIntValue_json(options, "tag")); + widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag")); + widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble")); + const char* name = DICTOOL->getStringValue_json(options, "name"); + const char* widgetName = name?name:"default"; + widget->setName(widgetName); + float x = DICTOOL->getFloatValue_json(options, "x"); + float y = DICTOOL->getFloatValue_json(options, "y"); + widget->setPosition(Point(x,y)); + bool sx = DICTOOL->checkObjectExist_json(options, "scaleX"); + if (sx) + { + widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX")); + } + bool sy = DICTOOL->checkObjectExist_json(options, "scaleY"); + if (sy) + { + widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY")); + } + bool rt = DICTOOL->checkObjectExist_json(options, "rotation"); + if (rt) + { + widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation")); + } + bool vb = DICTOOL->checkObjectExist_json(options, "visible"); + if (vb) + { + widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); + } + int z = DICTOOL->getIntValue_json(options, "ZOrder"); + widget->setLocalZOrder(z); + + bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter"); + if (layout) + { + const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter"); + int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type"); + LayoutParameter* parameter = nullptr; + switch (paramType) + { + case 0: + break; + case 1: + { + parameter = LinearLayoutParameter::create(); + int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity"); + ((LinearLayoutParameter*)parameter)->setGravity((LinearGravity)gravity); + break; + } + case 2: + { + parameter = RelativeLayoutParameter::create(); + RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter; + const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName"); + rParameter->setRelativeName(relativeName); + const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName"); + rParameter->setRelativeToWidgetName(relativeToName); + int align = DICTOOL->getIntValue_json(layoutParameterDic, "align"); + rParameter->setAlign((RelativeAlign)align); + break; + } + default: + break; + } + if (parameter) + { + float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft"); + float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop"); + float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight"); + float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown"); + parameter->setMargin(Margin(mgl, mgt, mgr, mgb)); + widget->setLayoutParameter(parameter); + } + } + } + + void WidgetReader::setColorPropsFromJsonDictionary(ui::Widget *widget, const rapidjson::Value &options) + { + bool op = DICTOOL->checkObjectExist_json(options, "opacity"); + if (op) + { + widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity")); + } + bool cr = DICTOOL->checkObjectExist_json(options, "colorR"); + bool cg = DICTOOL->checkObjectExist_json(options, "colorG"); + bool cb = DICTOOL->checkObjectExist_json(options, "colorB"); + int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255; + int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; + int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; + widget->setColor(Color3B(colorR, colorG, colorB)); + bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX"); + float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f); + bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY"); + float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f); + widget->setAnchorPoint(Point(apxf, apyf)); + bool flipX = DICTOOL->getBooleanValue_json(options, "flipX"); + bool flipY = DICTOOL->getBooleanValue_json(options, "flipY"); + widget->setFlipX(flipX); + widget->setFlipY(flipY); + } +} diff --git a/cocos/ui/WidgetReader/WidgetReader.h b/cocos/ui/WidgetReader/WidgetReader.h new file mode 100644 index 0000000000..7e10cfd8ef --- /dev/null +++ b/cocos/ui/WidgetReader/WidgetReader.h @@ -0,0 +1,51 @@ +/**************************************************************************** + Copyright (c) 2014 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__WidgetReader__ +#define __TestCpp__WidgetReader__ + +#include "WidgetReaderProtocol.h" +#include "CCSGUIReader.h" +#include "ui/GUIDefine.h" +#include "ui/UIWidget.h" + +namespace cocostudio +{ + class WidgetReader : public Object, public WidgetReaderProtocol + { + public: + DECLARE_CLASS_WIDGET_READER_INFO + + WidgetReader(); + virtual ~WidgetReader(); + + static WidgetReader* getInstance(); + static void purge(); + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + virtual void setColorPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options); + }; +} + +#endif /* defined(__TestCpp__WidgetReader__) */ diff --git a/cocos/ui/WidgetReader/WidgetReaderProtocol.h b/cocos/ui/WidgetReader/WidgetReaderProtocol.h new file mode 100644 index 0000000000..574262743a --- /dev/null +++ b/cocos/ui/WidgetReader/WidgetReaderProtocol.h @@ -0,0 +1,53 @@ +/**************************************************************************** + Copyright (c) 2014 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__WidgetReaderProtocol__ +#define __TestCpp__WidgetReaderProtocol__ + +#include "cocos2d.h" +#include "cocostudio/DictionaryHelper.h" + +namespace cocos2d +{ + namespace ui + { + class Widget; + } +} + +USING_NS_CC; +using namespace cocos2d::ui; + +namespace cocostudio +{ + class WidgetReaderProtocol + { + public: + virtual ~WidgetReaderProtocol() {}; + + virtual void setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options) = 0; + }; +} + +#endif /* defined(__TestCpp__WidgetReaderProtocol__) */ diff --git a/cocos/ui/proj.win32/libGUI.vcxproj b/cocos/ui/proj.win32/libGUI.vcxproj new file mode 100644 index 0000000000..3dad252cfe --- /dev/null +++ b/cocos/ui/proj.win32/libGUI.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {7E06E92C-537A-442B-9E4A-4761C84F8A1A} + libGUI + + + + StaticLibrary + true + v100 + v110 + v110_xp + Unicode + + + StaticLibrary + false + v100 + v110 + v110_xp + true + Unicode + + + + + + + + + + + + + + + $(SolutionDir)$(Configuration).win32\ + $(Configuration).win32\ + + + $(SolutionDir)$(Configuration).win32\ + $(Configuration).win32\ + + + + Level3 + Disabled + + + $(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support;$(EngineRoot)external;$(EngineRoot)extensions;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + 4267;4251;4244;%(DisableSpecificWarnings) + false + OldStyle + + + true + + + + + Level3 + MaxSpeed + true + true + + + WIN32;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + $(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support;$(EngineRoot)external;$(EngineRoot)extensions;%(AdditionalIncludeDirectories) + + + true + true + true + + + + + + \ No newline at end of file diff --git a/cocos/ui/proj.win32/libGUI.vcxproj.filters b/cocos/ui/proj.win32/libGUI.vcxproj.filters new file mode 100644 index 0000000000..d79c8a4a8d --- /dev/null +++ b/cocos/ui/proj.win32/libGUI.vcxproj.filters @@ -0,0 +1,141 @@ + + + + + {e31ab7d3-b8b2-467f-9e08-fd5fe168b491} + + + {f9d13563-9e5e-4b35-b0e7-d41f587efa42} + + + {ed8a2ae0-5690-4d0d-829b-7c07164c0597} + + + {5f6e9e52-fbe7-4073-ac71-98632f9e6781} + + + {b59b178a-b7e0-4826-ba07-44c46cd29a10} + + + + + UIWidgets\ScrollWidget + + + UIWidgets\ScrollWidget + + + UIWidgets\ScrollWidget + + + UIWidgets\ScrollWidget + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + System + + + System + + + Layouts + + + BaseClasses + + + Layouts + + + Layouts + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + + + UIWidgets\ScrollWidget + + + UIWidgets\ScrollWidget + + + UIWidgets\ScrollWidget + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + System + + + System + + + Layouts + + + BaseClasses + + + Layouts + + + Layouts + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + UIWidgets + + + \ No newline at end of file diff --git a/cocos/ui/proj.win32/libGUI.vcxproj.user b/cocos/ui/proj.win32/libGUI.vcxproj.user new file mode 100644 index 0000000000..a375ae3527 --- /dev/null +++ b/cocos/ui/proj.win32/libGUI.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.h index fdf27379ac..c85f123379 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.h @@ -28,7 +28,7 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "../../testBasic.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" USING_NS_CC; USING_NS_CC_EXT; diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomGUIScene.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomGUIScene.h index 5bd3d1ae25..140eee49de 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomGUIScene.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomGUIScene.h @@ -6,7 +6,7 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "../../testBasic.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" USING_NS_CC; USING_NS_CC_EXT; diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp index 467df7b239..4c65ddaae0 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp @@ -24,7 +24,7 @@ void CustomImageLayer::onEnter() CustomImageViewReader::getInstance(), parseselector(CustomImageViewReader::setProperties)); - Layout* layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/CustomImageViewTest/NewProject_2_1.ExportJson")); + Layout* layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/CustomImageViewTest/NewProject_2_1.ExportJson")); addChild(layout); } diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageView.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageView.h index 2e2630045e..f45c583413 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageView.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageView.h @@ -2,7 +2,7 @@ #ifndef __TestCpp__CustomImageView__ #define __TestCpp__CustomImageView__ -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" class CustomImageView : public cocos2d::ui::ImageView { diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.h index 94f6773494..b11c7ab39f 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.h @@ -5,7 +5,7 @@ #include "extensions/cocos-ext.h" #include "cocostudio/DictionaryHelper.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" class CustomImageViewReader : public cocos2d::Ref { diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.h index dee49860a8..acf68fbb91 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.h @@ -9,7 +9,7 @@ #ifndef __CustomUI__CustomParticleWidget__ #define __CustomUI__CustomParticleWidget__ -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" class CustomParticleWidget : public cocos2d::ui::Widget { diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidgetReader.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidgetReader.h index 04fa832189..8685271969 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidgetReader.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomParticleWidgetReader.h @@ -11,7 +11,7 @@ #include "extensions/cocos-ext.h" #include "cocostudio/DictionaryHelper.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" class CustomParticleWidgetReader : public cocos2d::Ref { diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomReader.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomReader.h index 7eb141d3cd..f788d0ab6f 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomReader.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/CustomWidget/CustomReader.h @@ -5,7 +5,7 @@ #include "extensions/cocos-ext.h" #include "cocostudio/DictionaryHelper.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" USING_NS_CC; USING_NS_CC_EXT; diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 44baad70af..bf98d36b3d 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -42,7 +42,7 @@ bool UIButtonTest::init() // Create the button Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent)); _uiLayer->addChild(button); @@ -119,7 +119,7 @@ bool UIButtonTest_Scale9::init() button->setTouchEnabled(true); // open scale9 render button->setScale9Enabled(true); - button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->setSize(Size(150, button->getContentSize().height * 1.5f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent)); @@ -194,7 +194,7 @@ bool UIButtonTest_PressedAction::init() Button* button = Button::create(); button->setTouchEnabled(true); button->setPressedActionEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_PressedAction::touchEvent)); _uiLayer->addChild(button); @@ -267,7 +267,7 @@ bool UIButtonTest_Title::init() // Create the button with title Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", ""); + button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", ""); button->setTitleText("Title Button"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(this, toucheventselector(UIButtonTest_Title::touchEvent)); @@ -302,4 +302,4 @@ void UIButtonTest_Title::touchEvent(Ref *pSender, TouchEventType type) default: break; } -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp index 4b35914424..bdc0d86570 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp @@ -20,7 +20,7 @@ bool UIButtonTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp index 58384998ea..c636efd573 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp @@ -41,11 +41,11 @@ bool UICheckBoxTest::init() // Create the checkbox CheckBox* checkBox = CheckBox::create(); checkBox->setTouchEnabled(true); - checkBox->loadTextures("cocosgui/check_box_normal.png", - "cocosgui/check_box_normal_press.png", - "cocosgui/check_box_active.png", - "cocosgui/check_box_normal_disable.png", - "cocosgui/check_box_active_disable.png"); + checkBox->loadTextures("cocosui/check_box_normal.png", + "cocosui/check_box_normal_press.png", + "cocosui/check_box_active.png", + "cocosui/check_box_normal_disable.png", + "cocosui/check_box_active_disable.png"); checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent)); @@ -72,4 +72,4 @@ void UICheckBoxTest::selectedEvent(Ref* pSender,CheckBoxEventType type) break; } -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp index cae646ed9f..345bbe0ebd 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp @@ -20,7 +20,7 @@ bool UICheckBoxTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 3a996e2d8e..6833df8b89 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -21,7 +21,7 @@ bool UIImageViewTest::init() // Create the imageview ImageView* imageView = ImageView::create(); - imageView->loadTexture("cocosgui/ccicon.png"); + imageView->loadTexture("cocosui/ccicon.png"); imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); // imageView->setOpacity(64); @@ -31,7 +31,7 @@ bool UIImageViewTest::init() NodeRGBA* root = NodeRGBA::create(); root->setCascadeOpacityEnabled(true); NodeRGBA* render = Sprite::create(); - static_cast(render)->setTexture("cocosgui/ccicon.png"); + static_cast(render)->setTexture("cocosui/ccicon.png"); root->addChild(render); // root->setOpacity(64); root->setPosition(Point(200, 180)); @@ -41,7 +41,7 @@ bool UIImageViewTest::init() /* NodeRGBA* nodergba = NodeRGBA::create(); Sprite* child = Sprite::create(); - child->setTexture("cocosgui/ccicon.png"); + child->setTexture("cocosui/ccicon.png"); nodergba->addChild(child); nodergba->setPosition(Point(120, 80)); nodergba->setOpacity(64); @@ -50,7 +50,7 @@ bool UIImageViewTest::init() /* Sprite* sprite = Sprite::create(); - sprite->setTexture("cocosgui/ccicon.png"); + sprite->setTexture("cocosui/ccicon.png"); sprite->setPosition(Point(200, 180)); // sprite->setOpacity(64); _uiLayer->addChild(sprite); @@ -83,7 +83,7 @@ bool UIImageViewTest_Scale9::init() // Create the imageview ImageView* imageView = ImageView::create(); imageView->setScale9Enabled(true); - imageView->loadTexture("cocosgui/buttonHighlighted.png"); + imageView->loadTexture("cocosui/buttonHighlighted.png"); imageView->setSize(Size(200, 85)); imageView->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + imageView->getSize().height / 4.0f)); _uiLayer->addChild(imageView); @@ -91,4 +91,4 @@ bool UIImageViewTest_Scale9::init() return true; } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp index b2d2fd0748..3243d913f5 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp @@ -9,7 +9,7 @@ bool UIImageViewTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index 0cc59d688f..afc6ac6543 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -44,20 +44,20 @@ bool UILayoutTest::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -112,20 +112,20 @@ bool UILayoutTest_Color::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -179,20 +179,20 @@ bool UILayoutTest_Gradient::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -235,7 +235,7 @@ bool UILayoutTest_BackGroundImage::init() // Create the layout with background image Layout* layout = Layout::create(); layout->setClippingEnabled(true); - layout->setBackGroundImage("cocosgui/Hello.png"); + layout->setBackGroundImage("cocosui/Hello.png"); layout->setSize(Size(280, 150)); Size backgroundSize = background->getContentSize(); layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -246,20 +246,20 @@ bool UILayoutTest_BackGroundImage::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -302,7 +302,7 @@ bool UILayoutTest_BackGroundImage_Scale9::init() // Create the layout with background image Layout* layout = Layout::create(); layout->setBackGroundImageScale9Enabled(true); - layout->setBackGroundImage("cocosgui/green_edit.png"); + layout->setBackGroundImage("cocosui/green_edit.png"); layout->setSize(Size(280, 150)); Size backgroundSize = background->getContentSize(); layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -313,20 +313,20 @@ bool UILayoutTest_BackGroundImage_Scale9::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(button->getSize().width / 2.0f, layout->getSize().height - button->getSize().height / 2.0f)); layout->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(titleButton); Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(layout->getSize().width - button_scale9->getSize().width / 2.0f, button_scale9->getSize().height / 2.0f)); @@ -380,7 +380,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button); LinearLayoutParameter* lp1 = LinearLayoutParameter::create(); @@ -391,7 +391,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); layout->addChild(titleButton); @@ -403,7 +403,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); layout->addChild(button_scale9); @@ -465,7 +465,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button); LinearLayoutParameter* lp1 = LinearLayoutParameter::create(); @@ -476,7 +476,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); layout->addChild(titleButton); @@ -488,7 +488,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setScale9Enabled(true); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); layout->addChild(button_scale9); @@ -552,7 +552,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top left Button* button_TopLeft = Button::create(); button_TopLeft->setTouchEnabled(true); - button_TopLeft->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_TopLeft->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_TopLeft); RelativeLayoutParameter* rp_TopLeft = RelativeLayoutParameter::create(); @@ -563,7 +563,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top center horizontal Button* button_TopCenter = Button::create(); button_TopCenter->setTouchEnabled(true); - button_TopCenter->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_TopCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_TopCenter); RelativeLayoutParameter* rp_TopCenter = RelativeLayoutParameter::create(); @@ -574,7 +574,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // top right Button* button_TopRight = Button::create(); button_TopRight->setTouchEnabled(true); - button_TopRight->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_TopRight->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_TopRight); RelativeLayoutParameter* rp_TopRight = RelativeLayoutParameter::create(); @@ -585,7 +585,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // left center Button* button_LeftCenter = Button::create(); button_LeftCenter->setTouchEnabled(true); - button_LeftCenter->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_LeftCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); @@ -596,7 +596,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // center Button* buttonCenter = Button::create(); buttonCenter->setTouchEnabled(true); - buttonCenter->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + buttonCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(buttonCenter); RelativeLayoutParameter* rpCenter = RelativeLayoutParameter::create(); @@ -607,7 +607,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // right center Button* button_RightCenter = Button::create(); button_RightCenter->setTouchEnabled(true); - button_RightCenter->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_RightCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); @@ -618,7 +618,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // left bottom Button* button_LeftBottom = Button::create(); button_LeftBottom->setTouchEnabled(true); - button_LeftBottom->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_LeftBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_LeftBottom); RelativeLayoutParameter* rp_LeftBottom = RelativeLayoutParameter::create(); @@ -629,7 +629,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // bottom center Button* button_BottomCenter = Button::create(); button_BottomCenter->setTouchEnabled(true); - button_BottomCenter->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_BottomCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_BottomCenter); RelativeLayoutParameter* rp_BottomCenter = RelativeLayoutParameter::create(); @@ -640,7 +640,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent::init() // right bottom Button* button_RightBottom = Button::create(); button_RightBottom->setTouchEnabled(true); - button_RightBottom->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button_RightBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); layout->addChild(button_RightBottom); RelativeLayoutParameter* rp_RightBottom = RelativeLayoutParameter::create(); @@ -698,7 +698,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // center ImageView* imageView_Center = ImageView::create(); - imageView_Center->loadTexture("cocosgui/scrollviewbg.png"); + imageView_Center->loadTexture("cocosui/scrollviewbg.png"); layout->addChild(imageView_Center); RelativeLayoutParameter* rp_Center = RelativeLayoutParameter::create(); @@ -709,7 +709,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // above center ImageView* imageView_AboveCenter = ImageView::create(); - imageView_AboveCenter->loadTexture("cocosgui/switch-mask.png"); + imageView_AboveCenter->loadTexture("cocosui/switch-mask.png"); layout->addChild(imageView_AboveCenter); RelativeLayoutParameter* rp_AboveCenter = RelativeLayoutParameter::create(); @@ -720,7 +720,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // below center ImageView* imageView_BelowCenter = ImageView::create(); - imageView_BelowCenter->loadTexture("cocosgui/switch-mask.png"); + imageView_BelowCenter->loadTexture("cocosui/switch-mask.png"); layout->addChild(imageView_BelowCenter); RelativeLayoutParameter* rp_BelowCenter = RelativeLayoutParameter::create(); @@ -731,7 +731,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // left center ImageView* imageView_LeftCenter = ImageView::create(); - imageView_LeftCenter->loadTexture("cocosgui/switch-mask.png"); + imageView_LeftCenter->loadTexture("cocosui/switch-mask.png"); layout->addChild(imageView_LeftCenter); RelativeLayoutParameter* rp_LeftCenter = RelativeLayoutParameter::create(); @@ -743,7 +743,7 @@ bool UILayoutTest_Layout_Relative_Location::init() // right center ImageView* imageView_RightCenter = ImageView::create(); - imageView_RightCenter->loadTexture("cocosgui/switch-mask.png"); + imageView_RightCenter->loadTexture("cocosui/switch-mask.png"); layout->addChild(imageView_RightCenter); RelativeLayoutParameter* rp_RightCenter = RelativeLayoutParameter::create(); @@ -807,7 +807,7 @@ bool UILayoutTest_Layout_Grid::init() Button* button = Button::create(); button->setName("TextButton"); button->setTouchEnabled(true); - button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button->setScale9Enabled(true); AffineTransform transform = AffineTransformMakeIdentity(); transform = AffineTransformScale(transform, 3.0f, 1.3f); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp index 147a25a794..5780b30a08 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp @@ -19,7 +19,7 @@ bool UILayoutTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -74,7 +74,7 @@ bool UILayoutTest_Color_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -129,7 +129,7 @@ bool UILayoutTest_Gradient_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -184,7 +184,7 @@ bool UILayoutTest_BackGroundImage_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -239,7 +239,7 @@ bool UILayoutTest_BackGroundImage_Scale9_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -294,7 +294,7 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -349,7 +349,7 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -405,7 +405,7 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -460,7 +460,7 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 3939de5b26..f8a61c82df 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -6,7 +6,7 @@ const char* font_UIListViewTest = #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) "Marker Felt"; #else -"cocosgui/Marker Felt.ttf"; +"cocosui/Marker Felt.ttf"; #endif // UIListViewTest_Vertical @@ -68,7 +68,7 @@ bool UIListViewTest_Vertical::init() listView->setDirection(SCROLLVIEW_DIR_VERTICAL); listView->setTouchEnabled(true); listView->setBounceEnabled(true); - listView->setBackGroundImage("cocosgui/green_edit.png"); + listView->setBackGroundImage("cocosui/green_edit.png"); listView->setBackGroundImageScale9Enabled(true); listView->setSize(Size(240, 130)); listView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -83,7 +83,7 @@ bool UIListViewTest_Vertical::init() Button* default_button = Button::create(); default_button->setName("Title Button"); default_button->setTouchEnabled(true); - default_button->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", ""); + default_button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", ""); Layout* default_item = Layout::create(); default_item->setTouchEnabled(true); @@ -112,7 +112,7 @@ bool UIListViewTest_Vertical::init() Button* custom_button = Button::create(); custom_button->setName("Title Button"); custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); @@ -131,7 +131,7 @@ bool UIListViewTest_Vertical::init() Button* custom_button = Button::create(); custom_button->setName("Title Button"); custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); @@ -246,7 +246,7 @@ bool UIListViewTest_Horizontal::init() listView->setDirection(SCROLLVIEW_DIR_HORIZONTAL); listView->setTouchEnabled(true); listView->setBounceEnabled(true); - listView->setBackGroundImage("cocosgui/green_edit.png"); + listView->setBackGroundImage("cocosui/green_edit.png"); listView->setBackGroundImageScale9Enabled(true); listView->setSize(Size(240, 130)); listView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -261,7 +261,7 @@ bool UIListViewTest_Horizontal::init() Button* default_button = Button::create(); default_button->setName("Title Button"); default_button->setTouchEnabled(true); - default_button->loadTextures("cocosgui/backtotoppressed.png", "cocosgui/backtotopnormal.png", ""); + default_button->loadTextures("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png", ""); Layout *default_item = Layout::create(); default_item->setTouchEnabled(true); @@ -290,7 +290,7 @@ bool UIListViewTest_Horizontal::init() Button* custom_button = Button::create(); custom_button->setName("Title Button"); custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); @@ -309,7 +309,7 @@ bool UIListViewTest_Horizontal::init() Button* custom_button = Button::create(); custom_button->setName("Title Button"); custom_button->setTouchEnabled(true); - custom_button->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + custom_button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); custom_button->setScale9Enabled(true); custom_button->setSize(default_button->getSize()); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp index c4fd8c603e..83cfeccd19 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp @@ -19,7 +19,7 @@ bool UIListViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -78,7 +78,7 @@ bool UIListViewTest_Horizontal_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -113,4 +113,4 @@ bool UIListViewTest_Horizontal_Editor::init() } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 09ae16aa62..044052ee99 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -36,7 +36,7 @@ bool UILoadingBarTest_Left::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create(); loadingBar->setTag(0); - loadingBar->loadTexture("cocosgui/sliderProgress.png"); + loadingBar->loadTexture("cocosui/sliderProgress.png"); loadingBar->setPercent(0); loadingBar->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f)); @@ -118,7 +118,7 @@ bool UILoadingBarTest_Right::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create(); loadingBar->setTag(0); - loadingBar->loadTexture("cocosgui/sliderProgress.png"); + loadingBar->loadTexture("cocosui/sliderProgress.png"); loadingBar->setDirection(LoadingBarTypeRight); loadingBar->setPercent(0); @@ -201,7 +201,7 @@ bool UILoadingBarTest_Left_Scale9::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create(); loadingBar->setTag(0); - loadingBar->loadTexture("cocosgui/slider_bar_active_9patch.png"); + loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png"); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); @@ -286,7 +286,7 @@ bool UILoadingBarTest_Right_Scale9::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create(); loadingBar->setTag(0); - loadingBar->loadTexture("cocosgui/slider_bar_active_9patch.png"); + loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png"); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setSize(Size(300, loadingBar->getContentSize().height)); @@ -337,4 +337,4 @@ void UILoadingBarTest_Right_Scale9::nextCallback(Ref* sender, TouchEventType typ unscheduleUpdate(); UIScene::nextCallback(sender, type); } -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp index 37a72a9209..d61602028f 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp @@ -21,7 +21,7 @@ bool UILoadingBarTest_Editor::init() { scheduleUpdate(); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -79,4 +79,4 @@ void UILoadingBarTest_Editor::toCocosGUITestScene(Ref *sender, TouchEventType ty default: break; } -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index dccf9ff599..d510ba32c2 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -60,7 +60,7 @@ bool UIPageViewTest::init() ImageView* imageView = ImageView::create(); imageView->setTouchEnabled(true); imageView->setScale9Enabled(true); - imageView->loadTexture("cocosgui/scrollviewbg.png"); + imageView->loadTexture("cocosui/scrollviewbg.png"); imageView->setSize(Size(240, 130)); imageView->setPosition(Point(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(imageView); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp index 1e56645d68..743b5fc1f7 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp @@ -20,7 +20,7 @@ bool UIPageViewTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -56,4 +56,4 @@ bool UIPageViewTest_Editor::init() } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index 27dbadffb7..afd0e47ba8 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -32,7 +32,7 @@ bool UIRichTextTest::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setTitleText("switch"); button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5)); button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent)); @@ -51,9 +51,9 @@ bool UIRichTextTest::init() RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green. ", "Helvetica", 10); RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10); - RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosgui/sliderballnormal.png"); + RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png"); - cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosgui/100/100.ExportJson"); + cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson"); cocostudio::Armature *pAr = cocostudio::Armature::create("100"); pAr->getAnimation()->play("Animation1"); @@ -100,4 +100,4 @@ void UIRichTextTest::touchEvent(Ref *pSender, TouchEventType type) default: break; } -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp index b11e03ff8b..464f7d955c 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp @@ -27,7 +27,7 @@ bool UIScene::init() _uiLayer = Layer::create(); addChild(_uiLayer); - _widget = dynamic_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UITest/UITest.json")); + _widget = dynamic_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); _uiLayer->addChild(_widget); Size screenSize = CCDirector::getInstance()->getWinSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.h index e24518bb82..99b0ae12ee 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.h @@ -27,7 +27,7 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" USING_NS_CC; USING_NS_CC_EXT; diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp index 1f1dc8f503..889a182c0e 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp @@ -2,7 +2,7 @@ #include "UIScene_Editor.h" #include "GUIEditorTest.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" #include "UISceneManager_Editor.h" diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.h b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.h index 03bfb76160..cf3ce97fab 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.h +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.h @@ -27,7 +27,7 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" #include "cocostudio/CocoStudio.h" USING_NS_CC; diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 5a6f73c66e..0ae7c15314 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -54,7 +54,7 @@ bool UIScrollViewTest_Vertical::init() _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create(); - imageView->loadTexture("cocosgui/ccicon.png"); + imageView->loadTexture("cocosui/ccicon.png"); float innerWidth = scrollView->getSize().width; float innerHeight = scrollView->getSize().height + imageView->getSize().height; @@ -63,13 +63,13 @@ bool UIScrollViewTest_Vertical::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f)); scrollView->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(innerWidth / 2.0f, button->getBottomInParent() - button->getSize().height)); scrollView->addChild(titleButton); @@ -77,7 +77,7 @@ bool UIScrollViewTest_Vertical::init() Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); button_scale9->setScale9Enabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height)); scrollView->addChild(button_scale9); @@ -144,7 +144,7 @@ bool UIScrollViewTest_Horizontal::init() _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create(); - imageView->loadTexture("cocosgui/ccicon.png"); + imageView->loadTexture("cocosui/ccicon.png"); float innerWidth = scrollView->getSize().width + imageView->getSize().width; float innerHeight = scrollView->getSize().height; @@ -153,14 +153,14 @@ bool UIScrollViewTest_Horizontal::init() Button* button = Button::create(); button->setTouchEnabled(true); - button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", ""); + button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", ""); button->setPosition(Point(button->getSize().width / 2.0f, scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f)); scrollView->addChild(button); Button* titleButton = Button::create(); titleButton->setTouchEnabled(true); - titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", ""); + titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", ""); titleButton->setTitleText("Title Button"); titleButton->setPosition(Point(button->getRightInParent() + button->getSize().width / 2.0f, button->getBottomInParent() - button->getSize().height / 2.0f)); @@ -169,7 +169,7 @@ bool UIScrollViewTest_Horizontal::init() Button* button_scale9 = Button::create(); button_scale9->setTouchEnabled(true); button_scale9->setScale9Enabled(true); - button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", ""); + button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", ""); button_scale9->setSize(Size(100.0f, button_scale9->getContentSize().height)); button_scale9->setPosition(Point(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f)); @@ -230,7 +230,7 @@ bool UIScrollViewTest_Both::init() scrollView->setTouchEnabled(true); scrollView->setBounceEnabled(true); scrollView->setBackGroundImageScale9Enabled(true); - scrollView->setBackGroundImage("cocosgui/green_edit.png"); + scrollView->setBackGroundImage("cocosui/green_edit.png"); scrollView->setSize(Size(210, 122.5)); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Point((widgetSize.width - backgroundSize.width) / 2.0f + @@ -306,7 +306,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() (backgroundSize.height - sc->getSize().height) / 2.0f)); sc->scrollToPercentBothDirection(Point(50, 50), 1, true); ImageView* iv = ImageView::create(); - iv->loadTexture("cocosgui/Hello.png"); + iv->loadTexture("cocosui/Hello.png"); iv->setPosition(Point(240, 160)); sc->addChild(iv); _uiLayer->addChild(sc); @@ -369,7 +369,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() (backgroundSize.height - sc->getSize().height) / 2.0f)); sc->scrollToPercentBothDirection(Point(50, 50), 1, true); ImageView* iv = ImageView::create(); - iv->loadTexture("cocosgui/Hello.png"); + iv->loadTexture("cocosui/Hello.png"); iv->setPosition(Point(240, 160)); sc->addChild(iv); _uiLayer->addChild(sc); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp index 1d1d9dde30..d9a0d53e55 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp @@ -19,7 +19,7 @@ bool UIScrollViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -74,7 +74,7 @@ bool UIScrollViewTest_Horizontal_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -129,7 +129,7 @@ bool UIScrollViewTest_Both_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -184,7 +184,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UITest/UITest.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -230,7 +230,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UITest/UITest.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index d740e1cf65..db7071f578 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -42,9 +42,9 @@ bool UISliderTest::init() // Create the slider Slider* slider = Slider::create(); slider->setTouchEnabled(true); - slider->loadBarTexture("cocosgui/sliderTrack.png"); - slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); - slider->loadProgressBarTexture("cocosgui/sliderProgress.png"); + slider->loadBarTexture("cocosui/sliderTrack.png"); + slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider->loadProgressBarTexture("cocosui/sliderProgress.png"); slider->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f/* + slider->getSize().height * 2.0f*/)); slider->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); _uiLayer->addChild(slider); @@ -55,9 +55,9 @@ bool UISliderTest::init() // sliderAllow->setMinAllowPercent(20); // sliderAllow->setMaxAllowPercent(80); sliderAllow->setTouchEnabled(true); - sliderAllow->loadBarTexture("cocosgui/sliderTrack.png"); - sliderAllow->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); - sliderAllow->loadProgressBarTexture("cocosgui/sliderProgress.png"); + sliderAllow->loadBarTexture("cocosui/sliderTrack.png"); + sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + sliderAllow->loadProgressBarTexture("cocosui/sliderProgress.png"); sliderAllow->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - sliderAllow->getSize().height * 2.0f)); sliderAllow->addEventListenerSlider(this, sliderpercentchangedselector(UISliderTest::sliderEvent)); _uiLayer->addChild(sliderAllow); @@ -117,9 +117,9 @@ bool UISliderTest_Scale9::init() // Create the slider Slider* slider = Slider::create(); slider->setTouchEnabled(true); - slider->loadBarTexture("cocosgui/sliderTrack2.png"); - slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); - slider->loadProgressBarTexture("cocosgui/slider_bar_active_9patch.png"); + slider->loadBarTexture("cocosui/sliderTrack2.png"); + slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); slider->setScale9Enabled(true); slider->setCapInsets(Rect(0, 0, 0, 0)); slider->setSize(Size(250.0f, 19)); @@ -133,9 +133,9 @@ bool UISliderTest_Scale9::init() // sliderAllow->setMinAllowPercent(20); // sliderAllow->setMaxAllowPercent(80); sliderAllow->setTouchEnabled(true); - sliderAllow->loadBarTexture("cocosgui/sliderTrack2.png"); - sliderAllow->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); - sliderAllow->loadProgressBarTexture("cocosgui/slider_bar_active_9patch.png"); + sliderAllow->loadBarTexture("cocosui/sliderTrack2.png"); + sliderAllow->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + sliderAllow->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); sliderAllow->setScale9Enabled(true); sliderAllow->setCapInsets(Rect(0, 0, 0, 0)); sliderAllow->setSize(Size(250.0f, 10.0f / Director::getInstance()->getContentScaleFactor())); @@ -157,4 +157,4 @@ void UISliderTest_Scale9::sliderEvent(Ref *pSender, SliderEventType type) int percent = slider->getPercent(); _displayValueLabel->setText(String::createWithFormat("Percent %d", percent)->getCString()); } -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp index 8225aa0d07..1c65ab219e 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp @@ -20,7 +20,7 @@ bool UISliderTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp index f9b659ef85..b752cdb56a 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp @@ -22,11 +22,11 @@ bool UITextAtlasTest::init() // Create the text atlas TextAtlas* textAtlas = TextAtlas::create(); - textAtlas->setProperty("1234567890", "cocosgui/labelatlas.png", 17, 22, "0"); + textAtlas->setProperty("1234567890", "cocosui/labelatlas.png", 17, 22, "0"); textAtlas->setPosition(Point((widgetSize.width) / 2, widgetSize.height / 2.0f)); _uiLayer->addChild(textAtlas); return true; } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp index 04f73b7a8c..32814e5006 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp @@ -8,7 +8,7 @@ bool UITextAtlasTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp index b920195635..8e14c9b270 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp @@ -21,7 +21,7 @@ bool UITextBMFontTest::init() // Create the TextBMFont TextBMFont* textBMFont = TextBMFont::create(); - textBMFont->setFntFile("cocosgui/bitmapFontTest2.fnt"); + textBMFont->setFntFile("cocosui/bitmapFontTest2.fnt"); textBMFont->setText("BMFont"); textBMFont->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2.0f + textBMFont->getSize().height / 8.0f)); _uiLayer->addChild(textBMFont); @@ -29,4 +29,4 @@ bool UITextBMFontTest::init() return true; } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp index 4435dc0915..8c197e1b3d 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp @@ -9,7 +9,7 @@ bool UITextBMFontTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -27,4 +27,4 @@ bool UITextBMFontTest_Editor::init() } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp index 7275f84304..71f0744825 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp @@ -20,7 +20,7 @@ bool UITextFieldTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp index fd43f36f61..d6fa9e0ee6 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp @@ -1,7 +1,7 @@ #include "UITextTest_Editor.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" // UITextTest_Editor @@ -11,7 +11,7 @@ bool UITextTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -29,4 +29,4 @@ bool UITextTest_Editor::init() } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp index 22261b2669..b50be77f77 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp @@ -34,11 +34,11 @@ bool UIWidgetAddNodeTest::init() widget->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(widget); - Sprite* sprite = Sprite::create("cocosgui/ccicon.png"); + Sprite* sprite = Sprite::create("cocosui/ccicon.png"); sprite->setPosition(Point(0, sprite->getBoundingBox().size.height / 4)); widget->addNode(sprite); return true; } return false; -} \ No newline at end of file +} diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp index a11f2ab147..6bc4101250 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp @@ -19,7 +19,7 @@ bool UIWidgetAddNodeTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosgui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -40,7 +40,7 @@ bool UIWidgetAddNodeTest_Editor::init() widget->setZOrder(_layout->getZOrder() + 1); _layout->addChild(widget); - Sprite* sprite = Sprite::create("cocosgui/ccicon.png"); + Sprite* sprite = Sprite::create("cocosui/ccicon.png"); widget->addNode(sprite); return true; diff --git a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp index eb0362dead..e8f947004e 100644 --- a/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp +++ b/samples/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp @@ -3,7 +3,7 @@ #include "../ExtensionsTest.h" #include "SceneEditorTest.h" #include "cocostudio/CocoStudio.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" #include "TriggerCode/EventDef.h" #include "../../testResource.h" diff --git a/samples/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/samples/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index a57c84cd36..73e4f6c2e2 100644 --- a/samples/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -1372,9 +1372,9 @@ LabelShadowTest::LabelShadowTest() auto slider = ui::Slider::create(); slider->setTag(1); slider->setTouchEnabled(true); - slider->loadBarTexture("cocosgui/sliderTrack.png"); - slider->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); - slider->loadProgressBarTexture("cocosgui/sliderProgress.png"); + slider->loadBarTexture("cocosui/sliderTrack.png"); + slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider->loadProgressBarTexture("cocosui/sliderProgress.png"); slider->setPosition(Point(size.width / 2.0f, size.height * 0.15f + slider->getSize().height * 2.0f)); slider->setPercent(52); slider->addEventListenerSlider(this, sliderpercentchangedselector(LabelShadowTest::sliderEvent)); @@ -1383,9 +1383,9 @@ LabelShadowTest::LabelShadowTest() auto slider2 = ui::Slider::create(); slider2->setTag(2); slider2->setTouchEnabled(true); - slider2->loadBarTexture("cocosgui/sliderTrack.png"); - slider2->loadSlidBallTextures("cocosgui/sliderThumb.png", "cocosgui/sliderThumb.png", ""); - slider2->loadProgressBarTexture("cocosgui/sliderProgress.png"); + slider2->loadBarTexture("cocosui/sliderTrack.png"); + slider2->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider2->loadProgressBarTexture("cocosui/sliderProgress.png"); slider2->setPosition(Point(size.width * 0.15f, size.height / 2.0)); slider2->setRotation(90); slider2->setPercent(52); diff --git a/samples/cpp-tests/Classes/LabelTest/LabelTestNew.h b/samples/cpp-tests/Classes/LabelTest/LabelTestNew.h index 697adfc48b..6017b9e851 100644 --- a/samples/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/samples/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -4,7 +4,7 @@ #include "../testBasic.h" #include "../BaseTest.h" #include "renderer/CCCustomCommand.h" -#include "gui/CocosGUI.h" +#include "ui/CocosGUI.h" class AtlasDemoNew : public BaseTest From 032ca5f309be71664a4986559e0bf43b4bf64bea Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 17:17:14 +0800 Subject: [PATCH 03/17] rename cocosgui resource to cocosui --- build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- .../Resources/{cocosgui => cocosui}/Hello.png.REMOVED.git-id | 0 .../UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id | 0 .../UICheckBox_Editor/background.png.REMOVED.git-id | 0 .../UIImageView_Editor/background.png.REMOVED.git-id | 0 .../UILabelAtlas_Editor/background.png.REMOVED.git-id | 0 .../UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id | 0 .../UILabelBMFont_Editor/background.png.REMOVED.git-id | 0 .../UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id | 0 .../UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../UILayout_Color_Editor/background.png.REMOVED.git-id | 0 .../UILayout_Editor/background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../UIListView_Horizontal_Editor/background.png.REMOVED.git-id | 0 .../UIListView_Vertical_Editor/background.png.REMOVED.git-id | 0 .../UILoadingBar_Editor/background.png.REMOVED.git-id | 0 .../UIPageView_Editor/background.png.REMOVED.git-id | 0 .../UIScrollView_Both_Editor/background.png.REMOVED.git-id | 0 .../background.png.REMOVED.git-id | 0 .../UIScrollView_Vertical_Editor/background.png.REMOVED.git-id | 0 .../UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id | 0 .../UITextField_Editor/background.png.REMOVED.git-id | 0 .../UIWidgetAddNode_Editor/background.png.REMOVED.git-id | 0 .../{cocosgui => cocosui}/UITest/background.png.REMOVED.git-id | 0 .../Resources/{cocosgui => cocosui}/b11.png.REMOVED.git-id | 0 .../{cocosgui => cocosui}/bitmapFontTest2.png.REMOVED.git-id | 0 .../{cocosgui => cocosui}/examples/examples.json.REMOVED.git-id | 0 .../gui_examples/map_1/map_pve.png.REMOVED.git-id | 0 .../gui_examples/page_1/background.png.REMOVED.git-id | 0 35 files changed, 1 insertion(+), 1 deletion(-) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/Hello.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/UITest/background.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/b11.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/bitmapFontTest2.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/examples/examples.json.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/gui_examples/map_1/map_pve.png.REMOVED.git-id (100%) rename samples/cpp-tests/Resources/{cocosgui => cocosui}/gui_examples/page_1/background.png.REMOVED.git-id (100%) diff --git a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id index 4936b3446c..e419cc5e28 100644 --- a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -828f0bfcdb53dea52131e3bd9fb86ba153449816 \ No newline at end of file +93cf35f598f47739015a3d72a8c5749d254b87af \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/UITest/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/UITest/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/examples/examples.json.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/examples/examples.json.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id similarity index 100% rename from samples/cpp-tests/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id rename to samples/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id From dcc98ef79fec1964886b2b0a34a2a02b3702b95e Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 17:37:00 +0800 Subject: [PATCH 04/17] rename cocos2dx_gui to cocos2dx_ui --- .../lua-bindings/auto/api/ScrollView.lua | 255 +++--- .../auto/api/lua_cocos2dx_gui_auto_api.lua | 94 --- .../lua_cocos2dx_gui_auto.cpp.REMOVED.git-id | 1 - .../auto/lua_cocos2dx_gui_auto.hpp | 351 -------- .../manual/lua_cocos2dx_gui_manual.cpp | 765 ------------------ .../manual/lua_cocos2dx_gui_manual.hpp | 48 -- .../{cocos2dx_gui.ini => cocos2dx_ui.ini} | 0 tools/tolua/genbindings.py | 6 +- 8 files changed, 141 insertions(+), 1379 deletions(-) delete mode 100644 cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_gui_auto_api.lua delete mode 100644 cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.cpp.REMOVED.git-id delete mode 100644 cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.hpp delete mode 100644 cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.cpp delete mode 100644 cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.hpp rename tools/tolua/{cocos2dx_gui.ini => cocos2dx_ui.ini} (100%) diff --git a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua index 05ce95c9ee..e2a02c3d00 100644 --- a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua @@ -2,176 +2,197 @@ -------------------------------- -- @module ScrollView -------------------------------- --- @function [parent=#ScrollView] scrollToTop --- @param self --- @param #float float --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] scrollToPercentHorizontal --- @param self --- @param #float float --- @param #float float --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] isInertiaScrollEnabled +-- @function [parent=#ScrollView] isClippingToBounds -- @param self -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ScrollView] scrollToPercentBothDirection +-- @function [parent=#ScrollView] setContainer +-- @param self +-- @param #cc.Node node + +-------------------------------- +-- @function [parent=#ScrollView] onTouchEnded +-- @param self +-- @param #cc.Touch touch +-- @param #cc.Event event + +-------------------------------- +-- @function [parent=#ScrollView] setContentOffsetInDuration -- @param self -- @param #point_table point -- @param #float float + +-------------------------------- +-- @function [parent=#ScrollView] setZoomScaleInDuration +-- @param self +-- @param #float float +-- @param #float float + +-------------------------------- +-- @function [parent=#ScrollView] setBounceable +-- @param self -- @param #bool bool -------------------------------- -- @function [parent=#ScrollView] getDirection -- @param self --- @return SCROLLVIEW_DIR#SCROLLVIEW_DIR ret (return value: ccui.SCROLLVIEW_DIR) +-- @return ScrollView::Direction#ScrollView::Direction ret (return value: cc.ScrollView::Direction) -------------------------------- --- @function [parent=#ScrollView] scrollToBottomLeft +-- @function [parent=#ScrollView] getContainer +-- @param self +-- @return Node#Node ret (return value: cc.Node) + +-------------------------------- +-- @function [parent=#ScrollView] updateTweenAction -- @param self -- @param #float float --- @param #bool bool +-- @param #string str -------------------------------- --- @function [parent=#ScrollView] getInnerContainer +-- @function [parent=#ScrollView] getZoomScale -- @param self --- @return Layout#Layout ret (return value: ccui.Layout) +-- @return float#float ret (return value: float) -------------------------------- --- @function [parent=#ScrollView] jumpToBottom +-- @function [parent=#ScrollView] updateInset -- @param self +-------------------------------- +-- @function [parent=#ScrollView] initWithViewSize +-- @param self +-- @param #size_table size +-- @param #cc.Node node +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] pause +-- @param self +-- @param #cc.Ref ref + -------------------------------- -- @function [parent=#ScrollView] setDirection -- @param self --- @param #ccui.SCROLLVIEW_DIR scrollview_dir +-- @param #cc.ScrollView::Direction direction -------------------------------- --- @function [parent=#ScrollView] scrollToTopLeft --- @param self --- @param #float float --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] jumpToTopRight --- @param self - --------------------------------- --- @function [parent=#ScrollView] jumpToBottomLeft --- @param self - --------------------------------- --- @function [parent=#ScrollView] setInnerContainerSize --- @param self --- @param #size_table size - --------------------------------- --- @function [parent=#ScrollView] getInnerContainerSize --- @param self --- @return size_table#size_table ret (return value: size_table) - --------------------------------- --- @function [parent=#ScrollView] isBounceEnabled +-- @function [parent=#ScrollView] init -- @param self -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ScrollView] jumpToPercentVertical --- @param self --- @param #float float - --------------------------------- --- @function [parent=#ScrollView] setInertiaScrollEnabled --- @param self --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] jumpToTopLeft --- @param self - --------------------------------- --- @function [parent=#ScrollView] jumpToPercentHorizontal --- @param self --- @param #float float - --------------------------------- --- @function [parent=#ScrollView] jumpToBottomRight --- @param self - --------------------------------- --- @function [parent=#ScrollView] setBounceEnabled --- @param self --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] jumpToTop --- @param self - --------------------------------- --- @function [parent=#ScrollView] scrollToLeft --- @param self --- @param #float float --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] jumpToPercentBothDirection +-- @function [parent=#ScrollView] setContentOffset -- @param self -- @param #point_table point - --------------------------------- --- @function [parent=#ScrollView] scrollToPercentVertical --- @param self --- @param #float float --- @param #float float -- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] scrollToBottom +-- @function [parent=#ScrollView] isDragging +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] isTouchEnabled +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] isBounceable +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] setTouchEnabled -- @param self --- @param #float float -- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] scrollToBottomRight +-- @function [parent=#ScrollView] onTouchMoved +-- @param self +-- @param #cc.Touch touch +-- @param #cc.Event event + +-------------------------------- +-- @function [parent=#ScrollView] getContentOffset +-- @param self +-- @return point_table#point_table ret (return value: point_table) + +-------------------------------- +-- @function [parent=#ScrollView] resume +-- @param self +-- @param #cc.Ref ref + +-------------------------------- +-- @function [parent=#ScrollView] setClippingToBounds -- @param self --- @param #float float -- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] jumpToLeft +-- @function [parent=#ScrollView] setViewSize -- @param self +-- @param #size_table size -------------------------------- --- @function [parent=#ScrollView] scrollToRight +-- @function [parent=#ScrollView] onTouchCancelled +-- @param self +-- @param #cc.Touch touch +-- @param #cc.Event event + +-------------------------------- +-- @function [parent=#ScrollView] getViewSize +-- @param self +-- @return size_table#size_table ret (return value: size_table) + +-------------------------------- +-- @function [parent=#ScrollView] maxContainerOffset +-- @param self +-- @return point_table#point_table ret (return value: point_table) + +-------------------------------- +-- @function [parent=#ScrollView] onTouchBegan +-- @param self +-- @param #cc.Touch touch +-- @param #cc.Event event +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] isTouchMoved +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] isNodeVisible +-- @param self +-- @param #cc.Node node +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- @function [parent=#ScrollView] minContainerOffset +-- @param self +-- @return point_table#point_table ret (return value: point_table) + +-------------------------------- +-- overload function: setZoomScale(float, bool) +-- +-- overload function: setZoomScale(float) +-- +-- @function [parent=#ScrollView] setZoomScale -- @param self -- @param #float float -- @param #bool bool - + -------------------------------- --- @function [parent=#ScrollView] jumpToRight +-- overload function: create() +-- +-- overload function: create(size_table, cc.Node) +-- +-- @function [parent=#ScrollView] create -- @param self - --------------------------------- --- @function [parent=#ScrollView] scrollToTopRight --- @param self --- @param #float float --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] create --- @param self --- @return ScrollView#ScrollView ret (return value: ccui.ScrollView) - --------------------------------- --- @function [parent=#ScrollView] createInstance --- @param self --- @return Ref#Ref ret (return value: cc.Ref) - +-- @param #size_table size +-- @param #cc.Node node +-- @return ScrollView#ScrollView ret (retunr value: cc.ScrollView) + -------------------------------- -- @function [parent=#ScrollView] ScrollView -- @param self diff --git a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_gui_auto_api.lua b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_gui_auto_api.lua deleted file mode 100644 index 918cb1f330..0000000000 --- a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_gui_auto_api.lua +++ /dev/null @@ -1,94 +0,0 @@ --------------------------------- --- @module ccui - --------------------------------------------------------- --- the ccui LayoutParameter --- @field [parent=#ccui] LayoutParameter#LayoutParameter LayoutParameter preloaded module - - --------------------------------------------------------- --- the ccui LinearLayoutParameter --- @field [parent=#ccui] LinearLayoutParameter#LinearLayoutParameter LinearLayoutParameter preloaded module - - --------------------------------------------------------- --- the ccui RelativeLayoutParameter --- @field [parent=#ccui] RelativeLayoutParameter#RelativeLayoutParameter RelativeLayoutParameter preloaded module - - --------------------------------------------------------- --- the ccui Widget --- @field [parent=#ccui] Widget#Widget Widget preloaded module - - --------------------------------------------------------- --- the ccui Layout --- @field [parent=#ccui] Layout#Layout Layout preloaded module - - --------------------------------------------------------- --- the ccui Button --- @field [parent=#ccui] Button#Button Button preloaded module - - --------------------------------------------------------- --- the ccui CheckBox --- @field [parent=#ccui] CheckBox#CheckBox CheckBox preloaded module - - --------------------------------------------------------- --- the ccui ImageView --- @field [parent=#ccui] ImageView#ImageView ImageView preloaded module - - --------------------------------------------------------- --- the ccui Text --- @field [parent=#ccui] Text#Text Text preloaded module - - --------------------------------------------------------- --- the ccui TextAtlas --- @field [parent=#ccui] TextAtlas#TextAtlas TextAtlas preloaded module - - --------------------------------------------------------- --- the ccui LoadingBar --- @field [parent=#ccui] LoadingBar#LoadingBar LoadingBar preloaded module - - --------------------------------------------------------- --- the ccui ScrollView --- @field [parent=#ccui] ScrollView#ScrollView ScrollView preloaded module - - --------------------------------------------------------- --- the ccui ListView --- @field [parent=#ccui] ListView#ListView ListView preloaded module - - --------------------------------------------------------- --- the ccui Slider --- @field [parent=#ccui] Slider#Slider Slider preloaded module - - --------------------------------------------------------- --- the ccui TextField --- @field [parent=#ccui] TextField#TextField TextField preloaded module - - --------------------------------------------------------- --- the ccui TextBMFont --- @field [parent=#ccui] TextBMFont#TextBMFont TextBMFont preloaded module - - --------------------------------------------------------- --- the ccui PageView --- @field [parent=#ccui] PageView#PageView PageView preloaded module - - --------------------------------------------------------- --- the ccui Helper --- @field [parent=#ccui] Helper#Helper Helper preloaded module - - -return nil diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.cpp.REMOVED.git-id deleted file mode 100644 index f894d8b69c..0000000000 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.cpp.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -8a35e56a7f283d9816a34997ab75c41201e1c1da \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.hpp deleted file mode 100644 index 472d1be093..0000000000 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_gui_auto.hpp +++ /dev/null @@ -1,351 +0,0 @@ -#ifndef __cocos2dx_ui_h__ -#define __cocos2dx_ui_h__ - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua++.h" -#ifdef __cplusplus -} -#endif - -int register_all_cocos2dx_ui(lua_State* tolua_S); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#endif // __cocos2dx_ui_h__ diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.cpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.cpp deleted file mode 100644 index 2fb9b15452..0000000000 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.cpp +++ /dev/null @@ -1,765 +0,0 @@ -/**************************************************************************** - 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 "lua_cocos2dx_gui_manual.hpp" -#include "cocos2d.h" -#include "tolua_fix.h" -#include "LuaBasicConversions.h" -#include "LuaScriptHandlerMgr.h" -#include "CCLuaValue.h" -#include "CocosGUI.h" -#include "CCLuaEngine.h" - -using namespace ui; - -class LuaCocoStudioEventListener:public Ref -{ -public: - LuaCocoStudioEventListener(); - virtual ~LuaCocoStudioEventListener(); - - static LuaCocoStudioEventListener* create(); - - virtual void eventCallbackFunc(Ref* sender,int eventType); -}; - -LuaCocoStudioEventListener::LuaCocoStudioEventListener() -{ - -} - -LuaCocoStudioEventListener::~LuaCocoStudioEventListener() -{ - -} - -LuaCocoStudioEventListener* LuaCocoStudioEventListener::create() -{ - LuaCocoStudioEventListener* listener = new LuaCocoStudioEventListener(); - if (nullptr == listener) - return nullptr; - - listener->autorelease(); - - return listener; -} - -void LuaCocoStudioEventListener::eventCallbackFunc(Ref* sender,int eventType) -{ - int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - if (0 != handler) - { - LuaStudioEventListenerData eventData(sender,eventType); - BasicScriptData data(this,(void*)&eventData); - LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER, (void*)&data); - } -} - -static int lua_cocos2dx_Widget_addTouchEventListener(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Widget* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Widget_addTouchEventListener'\n", NULL); - return 0; - } -#endif - - argc = lua_gettop(L) - 1; - - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "widgetTouchEvent"); - - self->addTouchEventListener(listener, toucheventselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addTouchEventListener' function of Widget has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addTouchEventListener'.",&tolua_err); - return 0; -#endif -} - -static void extendWidget(lua_State* L) -{ - lua_pushstring(L, "ccui.Widget"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addTouchEventListener", lua_cocos2dx_Widget_addTouchEventListener); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_CheckBox_addEventListenerCheckBox(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - CheckBox* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.CheckBox",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_CheckBox_addEventListenerCheckBox'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "checkBoxEventListener"); - - self->addEventListenerCheckBox(listener, checkboxselectedeventselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addEventListenerCheckBox' function of CheckBox has wrong number of arguments: %d, was expecting %d\n", argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addEventListenerCheckBox'.",&tolua_err); - return 0; -#endif -} - - -static void extendCheckBox(lua_State* L) -{ - lua_pushstring(L, "ccui.CheckBox"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addEventListenerCheckBox", lua_cocos2dx_CheckBox_addEventListenerCheckBox); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_Slider_addEventListenerSlider(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - Slider* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.Slider",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Slider_addEventListenerSlider'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) ) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "sliderEventListener"); - - self->addEventListenerSlider(listener, sliderpercentchangedselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addEventListenerSlider' function of Slider has wrong number of arguments: %d, was expecting %d\n", argc, 1); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addEventListenerSlider'.",&tolua_err); - return 0; -#endif -} - -static void extendSlider(lua_State* L) -{ - lua_pushstring(L, "ccui.Slider"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addEventListenerSlider", lua_cocos2dx_Slider_addEventListenerSlider); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_TextField_addEventListenerTextField(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - TextField* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TextField_addEventListenerTextField'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "textfieldEventListener"); - - self->addEventListenerTextField(listener, textfieldeventselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addEventListenerTextField' function of TextField has wrong number of arguments: %d, was expecting %d\n", argc, 1); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addEventListenerTextField'.",&tolua_err); - return 0; -#endif -} - -static void extendTextField(lua_State* L) -{ - lua_pushstring(L, "ccui.TextField"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addEventListenerTextField", lua_cocos2dx_TextField_addEventListenerTextField); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_PageView_addEventListenerPageView(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - PageView* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_PageView_addEventListenerPageView'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) ) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "pageViewEventListener"); - - self->addEventListenerPageView(listener, pagevieweventselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addEventListenerPageView' function of PageView has wrong number of arguments: %d, was expecting %d\n", argc, 1); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addEventListenerPageView'.",&tolua_err); - return 0; -#endif -} - -static void extendPageView(lua_State* L) -{ - lua_pushstring(L, "ccui.PageView"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addEventListenerPageView", lua_cocos2dx_PageView_addEventListenerPageView); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_ScrollView_addEventListenerScrollView(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - ScrollView* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ScrollView_addEventListenerScrollView'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "scrollViewEventListener"); - - self->addEventListenerScrollView(listener, scrollvieweventselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addEventListenerScrollView' function of ScrollView has wrong number of arguments: %d, was expecting %d\n", argc, 1); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addEventListenerScrollView'.",&tolua_err); - return 0; -#endif -} - -static void extendScrollView(lua_State* L) -{ - lua_pushstring(L, "ccui.ScrollView"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addEventListenerScrollView", lua_cocos2dx_ScrollView_addEventListenerScrollView); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_ListView_addEventListenerListView(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - ListView* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addEventListenerListView'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) - { - goto tolua_lerror; - } -#endif - LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); - if (nullptr == listener) - { - tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); - return 0; - } - - LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); - - ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); - - __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); - if (nullptr == dict) - { - dict = Dictionary::create(); - self->setUserObject(dict); - } - dict->setObject(listener, "listViewEventListener"); - - self->addEventListenerListView(listener, listvieweventselector(LuaCocoStudioEventListener::eventCallbackFunc)); - - return 0; - } - - CCLOG("'addEventListenerListView' function of ListView has wrong number of arguments: %d, was expecting %d\n", argc, 1); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'addEventListenerListView'.",&tolua_err); - return 0; -#endif -} - -static void extendListView(lua_State* L) -{ - lua_pushstring(L, "ccui.ListView"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "addEventListenerListView", lua_cocos2dx_ListView_addEventListenerListView); - } - lua_pop(L, 1); -} - -static int lua_cocos2dx_LayoutParameter_setMargin(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - LayoutParameter* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_setMargin'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - - if (1 == argc) - { -#if COCOS2D_DEBUG >= 1 - if (!tolua_istable(L, 2, 0, &tolua_err)) - { - goto tolua_lerror; - } -#endif - - Margin margin; - lua_pushstring(L, "left"); - lua_gettable(L,2); - margin.left = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushstring(L, "top"); - lua_gettable(L,2); - margin.top = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushstring(L, "right"); - lua_gettable(L,2); - margin.right = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); - lua_pop(L,1); - - lua_pushstring(L, "bottom"); - lua_gettable(L,2); - margin.bottom = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); - lua_pop(L,1); - - self->setMargin(margin); - return 0; - } - - CCLOG("'setMargin' function of LayoutParameter has wrong number of arguments: %d, was expecting %d\n", argc, 1); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'setMargin'.",&tolua_err); - return 0; -#endif -} - -static int lua_cocos2dx_LayoutParameter_getMargin(lua_State* L) -{ - if (nullptr == L) - return 0; - - int argc = 0; - LayoutParameter* self = nullptr; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; -#endif - - self = static_cast(tolua_tousertype(L,1,0)); - -#if COCOS2D_DEBUG >= 1 - if (nullptr == self) { - tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_getMargin'\n", NULL); - return 0; - } -#endif - argc = lua_gettop(L) - 1; - - if (0 == argc) - { - Margin margin = self->getMargin(); - - lua_newtable(L); - - lua_pushstring(L, "left"); - lua_pushnumber(L, (lua_Number) margin.left); - lua_rawset(L, -3); - - lua_pushstring(L, "top"); - lua_pushnumber(L, (lua_Number) margin.top); - lua_rawset(L, -3); - - lua_pushstring(L, "right"); - lua_pushnumber(L, (lua_Number) margin.right); - lua_rawset(L, -3); - - lua_pushstring(L, "bottom"); - lua_pushnumber(L, (lua_Number) margin.bottom); - lua_rawset(L, -3); - - return 1; - } - - CCLOG("'getMargin' function of LayoutParameter has wrong number of arguments: %d, was expecting %d\n", argc, 0); - - return 0; - -#if COCOS2D_DEBUG >= 1 -tolua_lerror: - tolua_error(L,"#ferror in function 'getMargin'.",&tolua_err); - return 0; -#endif -} - -static void extendLayoutParameter(lua_State* L) -{ - lua_pushstring(L, "ccui.LayoutParameter"); - lua_rawget(L, LUA_REGISTRYINDEX); - if (lua_istable(L,-1)) - { - tolua_function(L, "setMargin", lua_cocos2dx_LayoutParameter_setMargin); - tolua_function(L, "getMargin", lua_cocos2dx_LayoutParameter_getMargin); - } - lua_pop(L, 1); -} - -int register_all_cocos2dx_ui_manual(lua_State* L) -{ - if (nullptr == L) - return 0; - extendWidget(L); - extendCheckBox(L); - extendSlider(L); - extendTextField(L); - extendPageView(L); - extendScrollView(L); - extendListView(L); - extendLayoutParameter(L); - - return 0; -} diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.hpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.hpp deleted file mode 100644 index a1846cb815..0000000000 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_gui_manual.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - 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. - ****************************************************************************/ -#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_GUI_MANUAL_H -#define COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_GUI_MANUAL_H - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua++.h" -#ifdef __cplusplus -} -#endif - -#include "CCRef.h" - -TOLUA_API int register_all_cocos2dx_ui_manual(lua_State* L); - -struct LuaStudioEventListenerData -{ - cocos2d::Ref* objTarget; - int eventType; - - LuaStudioEventListenerData(cocos2d::Ref* _objTarget, int _eventType):objTarget(_objTarget),eventType(_eventType) - { - } -}; -#endif // #ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_GUI_MANUAL_H diff --git a/tools/tolua/cocos2dx_gui.ini b/tools/tolua/cocos2dx_ui.ini similarity index 100% rename from tools/tolua/cocos2dx_gui.ini rename to tools/tolua/cocos2dx_ui.ini diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 8905394f87..6e8b59c35d 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -106,7 +106,7 @@ def main(): if platform == 'win32': config.set('DEFAULT', 'extra_flags', '-D__WCHAR_MAX__=0x7fffffff -U__MINGW32__') - conf_ini_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'userconf.ini')) + conf_ini_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'userconf.ini')) print 'generating userconf.ini...' with open(conf_ini_file, 'w') as configfile: @@ -128,7 +128,7 @@ def main(): cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'lua_cocos2dx_auto'), \ 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'lua_cocos2dx_extension_auto'), \ - 'cocos2dx_gui.ini' : ('cocos2dx_gui', 'lua_cocos2dx_gui_auto'), \ + 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'lua_cocos2dx_ui_auto'), \ 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'lua_cocos2dx_studio_auto'), \ 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto'), \ 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ @@ -158,7 +158,7 @@ def main(): sys.exit(1) else: raise - + # -------------- main -------------- if __name__ == '__main__': From 026ef95b077f0a602b660b3fe60584eb1da2ed1c Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 17:51:12 +0800 Subject: [PATCH 05/17] add lua ui binding --- .../lua-bindings/auto/api/ScrollView.lua | 239 +++--- .../lua_cocos2dx_ui_auto.cpp.REMOVED.git-id | 1 + .../auto/lua_cocos2dx_ui_auto.hpp | 351 ++++++++ .../lua-bindings/manual/CCLuaEngine.cpp | 2 +- .../lua-bindings/manual/CCLuaStack.cpp | 4 +- .../manual/lua_cocos2dx_ui_manual.cpp | 765 ++++++++++++++++++ .../manual/lua_cocos2dx_ui_manual.hpp | 48 ++ .../project.pbxproj | 36 +- tools/tolua/cocos2dx_ui.ini | 6 +- 9 files changed, 1292 insertions(+), 160 deletions(-) create mode 100644 cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id create mode 100644 cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp create mode 100644 cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp create mode 100644 cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.hpp diff --git a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua index e2a02c3d00..05ce95c9ee 100644 --- a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua @@ -2,197 +2,176 @@ -------------------------------- -- @module ScrollView -------------------------------- --- @function [parent=#ScrollView] isClippingToBounds +-- @function [parent=#ScrollView] scrollToTop +-- @param self +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] scrollToPercentHorizontal +-- @param self +-- @param #float float +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] isInertiaScrollEnabled -- @param self -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ScrollView] setContainer --- @param self --- @param #cc.Node node - --------------------------------- --- @function [parent=#ScrollView] onTouchEnded --- @param self --- @param #cc.Touch touch --- @param #cc.Event event - --------------------------------- --- @function [parent=#ScrollView] setContentOffsetInDuration +-- @function [parent=#ScrollView] scrollToPercentBothDirection -- @param self -- @param #point_table point -- @param #float float - --------------------------------- --- @function [parent=#ScrollView] setZoomScaleInDuration --- @param self --- @param #float float --- @param #float float - --------------------------------- --- @function [parent=#ScrollView] setBounceable --- @param self -- @param #bool bool -------------------------------- -- @function [parent=#ScrollView] getDirection -- @param self --- @return ScrollView::Direction#ScrollView::Direction ret (return value: cc.ScrollView::Direction) +-- @return SCROLLVIEW_DIR#SCROLLVIEW_DIR ret (return value: ccui.SCROLLVIEW_DIR) -------------------------------- --- @function [parent=#ScrollView] getContainer --- @param self --- @return Node#Node ret (return value: cc.Node) - --------------------------------- --- @function [parent=#ScrollView] updateTweenAction +-- @function [parent=#ScrollView] scrollToBottomLeft -- @param self -- @param #float float --- @param #string str +-- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] getZoomScale +-- @function [parent=#ScrollView] getInnerContainer -- @param self --- @return float#float ret (return value: float) +-- @return Layout#Layout ret (return value: ccui.Layout) -------------------------------- --- @function [parent=#ScrollView] updateInset +-- @function [parent=#ScrollView] jumpToBottom -- @param self --------------------------------- --- @function [parent=#ScrollView] initWithViewSize --- @param self --- @param #size_table size --- @param #cc.Node node --- @return bool#bool ret (return value: bool) - --------------------------------- --- @function [parent=#ScrollView] pause --- @param self --- @param #cc.Ref ref - -------------------------------- -- @function [parent=#ScrollView] setDirection -- @param self --- @param #cc.ScrollView::Direction direction +-- @param #ccui.SCROLLVIEW_DIR scrollview_dir -------------------------------- --- @function [parent=#ScrollView] init +-- @function [parent=#ScrollView] scrollToTopLeft -- @param self --- @return bool#bool ret (return value: bool) - --------------------------------- --- @function [parent=#ScrollView] setContentOffset --- @param self --- @param #point_table point +-- @param #float float -- @param #bool bool -------------------------------- --- @function [parent=#ScrollView] isDragging +-- @function [parent=#ScrollView] jumpToTopRight -- @param self --- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ScrollView] isTouchEnabled +-- @function [parent=#ScrollView] jumpToBottomLeft -- @param self --- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ScrollView] isBounceable --- @param self --- @return bool#bool ret (return value: bool) - --------------------------------- --- @function [parent=#ScrollView] setTouchEnabled --- @param self --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] onTouchMoved --- @param self --- @param #cc.Touch touch --- @param #cc.Event event - --------------------------------- --- @function [parent=#ScrollView] getContentOffset --- @param self --- @return point_table#point_table ret (return value: point_table) - --------------------------------- --- @function [parent=#ScrollView] resume --- @param self --- @param #cc.Ref ref - --------------------------------- --- @function [parent=#ScrollView] setClippingToBounds --- @param self --- @param #bool bool - --------------------------------- --- @function [parent=#ScrollView] setViewSize +-- @function [parent=#ScrollView] setInnerContainerSize -- @param self -- @param #size_table size -------------------------------- --- @function [parent=#ScrollView] onTouchCancelled --- @param self --- @param #cc.Touch touch --- @param #cc.Event event - --------------------------------- --- @function [parent=#ScrollView] getViewSize +-- @function [parent=#ScrollView] getInnerContainerSize -- @param self -- @return size_table#size_table ret (return value: size_table) -------------------------------- --- @function [parent=#ScrollView] maxContainerOffset --- @param self --- @return point_table#point_table ret (return value: point_table) - --------------------------------- --- @function [parent=#ScrollView] onTouchBegan --- @param self --- @param #cc.Touch touch --- @param #cc.Event event --- @return bool#bool ret (return value: bool) - --------------------------------- --- @function [parent=#ScrollView] isTouchMoved +-- @function [parent=#ScrollView] isBounceEnabled -- @param self -- @return bool#bool ret (return value: bool) -------------------------------- --- @function [parent=#ScrollView] isNodeVisible +-- @function [parent=#ScrollView] jumpToPercentVertical -- @param self --- @param #cc.Node node --- @return bool#bool ret (return value: bool) +-- @param #float float -------------------------------- --- @function [parent=#ScrollView] minContainerOffset +-- @function [parent=#ScrollView] setInertiaScrollEnabled -- @param self --- @return point_table#point_table ret (return value: point_table) +-- @param #bool bool -------------------------------- --- overload function: setZoomScale(float, bool) --- --- overload function: setZoomScale(float) --- --- @function [parent=#ScrollView] setZoomScale +-- @function [parent=#ScrollView] jumpToTopLeft +-- @param self + +-------------------------------- +-- @function [parent=#ScrollView] jumpToPercentHorizontal +-- @param self +-- @param #float float + +-------------------------------- +-- @function [parent=#ScrollView] jumpToBottomRight +-- @param self + +-------------------------------- +-- @function [parent=#ScrollView] setBounceEnabled +-- @param self +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] jumpToTop +-- @param self + +-------------------------------- +-- @function [parent=#ScrollView] scrollToLeft -- @param self -- @param #float float -- @param #bool bool - + -------------------------------- --- overload function: create() --- --- overload function: create(size_table, cc.Node) --- --- @function [parent=#ScrollView] create +-- @function [parent=#ScrollView] jumpToPercentBothDirection -- @param self --- @param #size_table size --- @param #cc.Node node --- @return ScrollView#ScrollView ret (retunr value: cc.ScrollView) - +-- @param #point_table point + +-------------------------------- +-- @function [parent=#ScrollView] scrollToPercentVertical +-- @param self +-- @param #float float +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] scrollToBottom +-- @param self +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] scrollToBottomRight +-- @param self +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] jumpToLeft +-- @param self + +-------------------------------- +-- @function [parent=#ScrollView] scrollToRight +-- @param self +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] jumpToRight +-- @param self + +-------------------------------- +-- @function [parent=#ScrollView] scrollToTopRight +-- @param self +-- @param #float float +-- @param #bool bool + +-------------------------------- +-- @function [parent=#ScrollView] create +-- @param self +-- @return ScrollView#ScrollView ret (return value: ccui.ScrollView) + +-------------------------------- +-- @function [parent=#ScrollView] createInstance +-- @param self +-- @return Ref#Ref ret (return value: cc.Ref) + -------------------------------- -- @function [parent=#ScrollView] ScrollView -- @param self diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id new file mode 100644 index 0000000000..8db5a53eed --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id @@ -0,0 +1 @@ +c9cf8f3050b95aec88a2452e60fe492252ad30c3 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp new file mode 100644 index 0000000000..472d1be093 --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -0,0 +1,351 @@ +#ifndef __cocos2dx_ui_h__ +#define __cocos2dx_ui_h__ + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + +int register_all_cocos2dx_ui(lua_State* tolua_S); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif // __cocos2dx_ui_h__ diff --git a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp index a37c5017e6..d0e9eefc94 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaEngine.cpp @@ -33,7 +33,7 @@ #include "lua_cocos2dx_manual.hpp" #include "lua_cocos2dx_extension_manual.h" #include "lua_cocos2dx_coco_studio_manual.hpp" -#include "lua_cocos2dx_gui_manual.hpp" +#include "lua_cocos2dx_ui_manual.hpp" NS_CC_BEGIN diff --git a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp index 4d325bf430..3a37f471c7 100644 --- a/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp +++ b/cocos/scripting/lua-bindings/manual/CCLuaStack.cpp @@ -63,8 +63,8 @@ extern "C" { #include "lua_cocos2dx_spine_manual.hpp" #include "lua_cocos2dx_physics_auto.hpp" #include "lua_cocos2dx_physics_manual.hpp" -#include "lua_cocos2dx_gui_auto.hpp" -#include "lua_cocos2dx_gui_manual.hpp" +#include "lua_cocos2dx_ui_auto.hpp" +#include "lua_cocos2dx_ui_manual.hpp" namespace { int lua_print(lua_State * luastate) diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp new file mode 100644 index 0000000000..2fb9b15452 --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp @@ -0,0 +1,765 @@ +/**************************************************************************** + 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 "lua_cocos2dx_gui_manual.hpp" +#include "cocos2d.h" +#include "tolua_fix.h" +#include "LuaBasicConversions.h" +#include "LuaScriptHandlerMgr.h" +#include "CCLuaValue.h" +#include "CocosGUI.h" +#include "CCLuaEngine.h" + +using namespace ui; + +class LuaCocoStudioEventListener:public Ref +{ +public: + LuaCocoStudioEventListener(); + virtual ~LuaCocoStudioEventListener(); + + static LuaCocoStudioEventListener* create(); + + virtual void eventCallbackFunc(Ref* sender,int eventType); +}; + +LuaCocoStudioEventListener::LuaCocoStudioEventListener() +{ + +} + +LuaCocoStudioEventListener::~LuaCocoStudioEventListener() +{ + +} + +LuaCocoStudioEventListener* LuaCocoStudioEventListener::create() +{ + LuaCocoStudioEventListener* listener = new LuaCocoStudioEventListener(); + if (nullptr == listener) + return nullptr; + + listener->autorelease(); + + return listener; +} + +void LuaCocoStudioEventListener::eventCallbackFunc(Ref* sender,int eventType) +{ + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + if (0 != handler) + { + LuaStudioEventListenerData eventData(sender,eventType); + BasicScriptData data(this,(void*)&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER, (void*)&data); + } +} + +static int lua_cocos2dx_Widget_addTouchEventListener(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + Widget* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Widget_addTouchEventListener'\n", NULL); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "widgetTouchEvent"); + + self->addTouchEventListener(listener, toucheventselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addTouchEventListener' function of Widget has wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addTouchEventListener'.",&tolua_err); + return 0; +#endif +} + +static void extendWidget(lua_State* L) +{ + lua_pushstring(L, "ccui.Widget"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addTouchEventListener", lua_cocos2dx_Widget_addTouchEventListener); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_CheckBox_addEventListenerCheckBox(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + CheckBox* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.CheckBox",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_CheckBox_addEventListenerCheckBox'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "checkBoxEventListener"); + + self->addEventListenerCheckBox(listener, checkboxselectedeventselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addEventListenerCheckBox' function of CheckBox has wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addEventListenerCheckBox'.",&tolua_err); + return 0; +#endif +} + + +static void extendCheckBox(lua_State* L) +{ + lua_pushstring(L, "ccui.CheckBox"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addEventListenerCheckBox", lua_cocos2dx_CheckBox_addEventListenerCheckBox); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_Slider_addEventListenerSlider(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + Slider* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.Slider",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_Slider_addEventListenerSlider'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) ) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "sliderEventListener"); + + self->addEventListenerSlider(listener, sliderpercentchangedselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addEventListenerSlider' function of Slider has wrong number of arguments: %d, was expecting %d\n", argc, 1); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addEventListenerSlider'.",&tolua_err); + return 0; +#endif +} + +static void extendSlider(lua_State* L) +{ + lua_pushstring(L, "ccui.Slider"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addEventListenerSlider", lua_cocos2dx_Slider_addEventListenerSlider); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_TextField_addEventListenerTextField(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + TextField* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.TextField",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TextField_addEventListenerTextField'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "textfieldEventListener"); + + self->addEventListenerTextField(listener, textfieldeventselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addEventListenerTextField' function of TextField has wrong number of arguments: %d, was expecting %d\n", argc, 1); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addEventListenerTextField'.",&tolua_err); + return 0; +#endif +} + +static void extendTextField(lua_State* L) +{ + lua_pushstring(L, "ccui.TextField"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addEventListenerTextField", lua_cocos2dx_TextField_addEventListenerTextField); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_PageView_addEventListenerPageView(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + PageView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_PageView_addEventListenerPageView'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) ) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "pageViewEventListener"); + + self->addEventListenerPageView(listener, pagevieweventselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addEventListenerPageView' function of PageView has wrong number of arguments: %d, was expecting %d\n", argc, 1); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addEventListenerPageView'.",&tolua_err); + return 0; +#endif +} + +static void extendPageView(lua_State* L) +{ + lua_pushstring(L, "ccui.PageView"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addEventListenerPageView", lua_cocos2dx_PageView_addEventListenerPageView); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_ScrollView_addEventListenerScrollView(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + ScrollView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ScrollView_addEventListenerScrollView'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "scrollViewEventListener"); + + self->addEventListenerScrollView(listener, scrollvieweventselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addEventListenerScrollView' function of ScrollView has wrong number of arguments: %d, was expecting %d\n", argc, 1); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addEventListenerScrollView'.",&tolua_err); + return 0; +#endif +} + +static void extendScrollView(lua_State* L) +{ + lua_pushstring(L, "ccui.ScrollView"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addEventListenerScrollView", lua_cocos2dx_ScrollView_addEventListenerScrollView); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_ListView_addEventListenerListView(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + ListView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_ListView_addEventListenerListView'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LuaCocoStudioEventListener* listener = LuaCocoStudioEventListener::create(); + if (nullptr == listener) + { + tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL); + return 0; + } + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listener, handler, ScriptHandlerMgr::HandlerType::STUDIO_EVENT_LISTENER); + + __Dictionary* dict = static_cast<__Dictionary*>(self->getUserObject()); + if (nullptr == dict) + { + dict = Dictionary::create(); + self->setUserObject(dict); + } + dict->setObject(listener, "listViewEventListener"); + + self->addEventListenerListView(listener, listvieweventselector(LuaCocoStudioEventListener::eventCallbackFunc)); + + return 0; + } + + CCLOG("'addEventListenerListView' function of ListView has wrong number of arguments: %d, was expecting %d\n", argc, 1); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addEventListenerListView'.",&tolua_err); + return 0; +#endif +} + +static void extendListView(lua_State* L) +{ + lua_pushstring(L, "ccui.ListView"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "addEventListenerListView", lua_cocos2dx_ListView_addEventListenerListView); + } + lua_pop(L, 1); +} + +static int lua_cocos2dx_LayoutParameter_setMargin(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + LayoutParameter* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_setMargin'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!tolua_istable(L, 2, 0, &tolua_err)) + { + goto tolua_lerror; + } +#endif + + Margin margin; + lua_pushstring(L, "left"); + lua_gettable(L,2); + margin.left = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); + lua_pop(L,1); + + lua_pushstring(L, "top"); + lua_gettable(L,2); + margin.top = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); + lua_pop(L,1); + + lua_pushstring(L, "right"); + lua_gettable(L,2); + margin.right = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); + lua_pop(L,1); + + lua_pushstring(L, "bottom"); + lua_gettable(L,2); + margin.bottom = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1); + lua_pop(L,1); + + self->setMargin(margin); + return 0; + } + + CCLOG("'setMargin' function of LayoutParameter has wrong number of arguments: %d, was expecting %d\n", argc, 1); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'setMargin'.",&tolua_err); + return 0; +#endif +} + +static int lua_cocos2dx_LayoutParameter_getMargin(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + LayoutParameter* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_getMargin'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + + if (0 == argc) + { + Margin margin = self->getMargin(); + + lua_newtable(L); + + lua_pushstring(L, "left"); + lua_pushnumber(L, (lua_Number) margin.left); + lua_rawset(L, -3); + + lua_pushstring(L, "top"); + lua_pushnumber(L, (lua_Number) margin.top); + lua_rawset(L, -3); + + lua_pushstring(L, "right"); + lua_pushnumber(L, (lua_Number) margin.right); + lua_rawset(L, -3); + + lua_pushstring(L, "bottom"); + lua_pushnumber(L, (lua_Number) margin.bottom); + lua_rawset(L, -3); + + return 1; + } + + CCLOG("'getMargin' function of LayoutParameter has wrong number of arguments: %d, was expecting %d\n", argc, 0); + + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'getMargin'.",&tolua_err); + return 0; +#endif +} + +static void extendLayoutParameter(lua_State* L) +{ + lua_pushstring(L, "ccui.LayoutParameter"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "setMargin", lua_cocos2dx_LayoutParameter_setMargin); + tolua_function(L, "getMargin", lua_cocos2dx_LayoutParameter_getMargin); + } + lua_pop(L, 1); +} + +int register_all_cocos2dx_ui_manual(lua_State* L) +{ + if (nullptr == L) + return 0; + extendWidget(L); + extendCheckBox(L); + extendSlider(L); + extendTextField(L); + extendPageView(L); + extendScrollView(L); + extendListView(L); + extendLayoutParameter(L); + + return 0; +} diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.hpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.hpp new file mode 100644 index 0000000000..a1846cb815 --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.hpp @@ -0,0 +1,48 @@ +/**************************************************************************** + 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. + ****************************************************************************/ +#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_GUI_MANUAL_H +#define COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_GUI_MANUAL_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + +#include "CCRef.h" + +TOLUA_API int register_all_cocos2dx_ui_manual(lua_State* L); + +struct LuaStudioEventListenerData +{ + cocos2d::Ref* objTarget; + int eventType; + + LuaStudioEventListenerData(cocos2d::Ref* _objTarget, int _eventType):objTarget(_objTarget),eventType(_eventType) + { + } +}; +#endif // #ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_GUI_MANUAL_H diff --git a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj index 74c7a9210d..931786a311 100644 --- a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj @@ -17,10 +17,6 @@ 1AACE7BC18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */; }; 1AACE7BD18BC45C200215002 /* lua_cocos2dx_extension_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE74D18BC45C200215002 /* lua_cocos2dx_extension_auto.hpp */; }; 1AACE7BE18BC45C200215002 /* lua_cocos2dx_extension_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE74D18BC45C200215002 /* lua_cocos2dx_extension_auto.hpp */; }; - 1AACE7C118BC45C200215002 /* lua_cocos2dx_gui_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74F18BC45C200215002 /* lua_cocos2dx_gui_auto.cpp */; }; - 1AACE7C218BC45C200215002 /* lua_cocos2dx_gui_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74F18BC45C200215002 /* lua_cocos2dx_gui_auto.cpp */; }; - 1AACE7C318BC45C200215002 /* lua_cocos2dx_gui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE75018BC45C200215002 /* lua_cocos2dx_gui_auto.hpp */; }; - 1AACE7C418BC45C200215002 /* lua_cocos2dx_gui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE75018BC45C200215002 /* lua_cocos2dx_gui_auto.hpp */; }; 1AACE7C718BC45C200215002 /* lua_cocos2dx_physics_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE75218BC45C200215002 /* lua_cocos2dx_physics_auto.cpp */; }; 1AACE7C818BC45C200215002 /* lua_cocos2dx_physics_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE75218BC45C200215002 /* lua_cocos2dx_physics_auto.cpp */; }; 1AACE7C918BC45C200215002 /* lua_cocos2dx_physics_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE75318BC45C200215002 /* lua_cocos2dx_physics_auto.hpp */; }; @@ -69,10 +65,6 @@ 1AACE7FA18BC45C200215002 /* lua_cocos2dx_extension_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE76E18BC45C200215002 /* lua_cocos2dx_extension_manual.cpp */; }; 1AACE7FB18BC45C200215002 /* lua_cocos2dx_extension_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE76F18BC45C200215002 /* lua_cocos2dx_extension_manual.h */; }; 1AACE7FC18BC45C200215002 /* lua_cocos2dx_extension_manual.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE76F18BC45C200215002 /* lua_cocos2dx_extension_manual.h */; }; - 1AACE7FD18BC45C200215002 /* lua_cocos2dx_gui_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE77018BC45C200215002 /* lua_cocos2dx_gui_manual.cpp */; }; - 1AACE7FE18BC45C200215002 /* lua_cocos2dx_gui_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE77018BC45C200215002 /* lua_cocos2dx_gui_manual.cpp */; }; - 1AACE7FF18BC45C200215002 /* lua_cocos2dx_gui_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE77118BC45C200215002 /* lua_cocos2dx_gui_manual.hpp */; }; - 1AACE80018BC45C200215002 /* lua_cocos2dx_gui_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE77118BC45C200215002 /* lua_cocos2dx_gui_manual.hpp */; }; 1AACE80118BC45C200215002 /* lua_cocos2dx_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE77218BC45C200215002 /* lua_cocos2dx_manual.cpp */; }; 1AACE80218BC45C200215002 /* lua_cocos2dx_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE77218BC45C200215002 /* lua_cocos2dx_manual.cpp */; }; 1AACE80318BC45C200215002 /* lua_cocos2dx_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE77318BC45C200215002 /* lua_cocos2dx_manual.hpp */; }; @@ -207,6 +199,10 @@ 1ABCA26F18CD8F7D0087CE3A /* usocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABCA22E18CD8F7D0087CE3A /* usocket.h */; }; 1ABCA27018CD8F7D0087CE3A /* usocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABCA22E18CD8F7D0087CE3A /* usocket.h */; }; 1ABCA36318CD9D7F0087CE3A /* libluajit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ABCA1F618CD8F5F0087CE3A /* libluajit.a */; }; + 2905FAD018CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FACE18CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp */; }; + 2905FAD118CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FACE18CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp */; }; + 2905FAD218CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */; }; + 2905FAD318CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */; }; C0FEF4D618BE0E70001F446C /* lua_debugger.c in Sources */ = {isa = PBXBuildFile; fileRef = C0FEF4D418BE0E70001F446C /* lua_debugger.c */; }; C0FEF4D718BE0E70001F446C /* lua_debugger.c in Sources */ = {isa = PBXBuildFile; fileRef = C0FEF4D418BE0E70001F446C /* lua_debugger.c */; }; C0FEF4D818BE0E70001F446C /* lua_debugger.h in Headers */ = {isa = PBXBuildFile; fileRef = C0FEF4D518BE0E70001F446C /* lua_debugger.h */; }; @@ -221,8 +217,6 @@ 1AACE74A18BC45C200215002 /* lua_cocos2dx_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_auto.hpp; sourceTree = ""; }; 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_extension_auto.cpp; sourceTree = ""; }; 1AACE74D18BC45C200215002 /* lua_cocos2dx_extension_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_extension_auto.hpp; sourceTree = ""; }; - 1AACE74F18BC45C200215002 /* lua_cocos2dx_gui_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_gui_auto.cpp; sourceTree = ""; }; - 1AACE75018BC45C200215002 /* lua_cocos2dx_gui_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_gui_auto.hpp; sourceTree = ""; }; 1AACE75218BC45C200215002 /* lua_cocos2dx_physics_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_physics_auto.cpp; sourceTree = ""; }; 1AACE75318BC45C200215002 /* lua_cocos2dx_physics_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_physics_auto.hpp; sourceTree = ""; }; 1AACE75518BC45C200215002 /* lua_cocos2dx_spine_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_spine_auto.cpp; sourceTree = ""; }; @@ -247,8 +241,6 @@ 1AACE76D18BC45C200215002 /* lua_cocos2dx_deprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lua_cocos2dx_deprecated.h; sourceTree = ""; }; 1AACE76E18BC45C200215002 /* lua_cocos2dx_extension_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_extension_manual.cpp; sourceTree = ""; }; 1AACE76F18BC45C200215002 /* lua_cocos2dx_extension_manual.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lua_cocos2dx_extension_manual.h; sourceTree = ""; }; - 1AACE77018BC45C200215002 /* lua_cocos2dx_gui_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_gui_manual.cpp; sourceTree = ""; }; - 1AACE77118BC45C200215002 /* lua_cocos2dx_gui_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_gui_manual.hpp; sourceTree = ""; }; 1AACE77218BC45C200215002 /* lua_cocos2dx_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_manual.cpp; sourceTree = ""; }; 1AACE77318BC45C200215002 /* lua_cocos2dx_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_manual.hpp; sourceTree = ""; }; 1AACE77418BC45C200215002 /* lua_cocos2dx_physics_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_physics_manual.cpp; sourceTree = ""; }; @@ -317,6 +309,8 @@ 1ABCA22C18CD8F7D0087CE3A /* unix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unix.h; sourceTree = ""; }; 1ABCA22D18CD8F7D0087CE3A /* usocket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = usocket.c; sourceTree = ""; }; 1ABCA22E18CD8F7D0087CE3A /* usocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = usocket.h; sourceTree = ""; }; + 2905FACE18CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_ui_auto.cpp; sourceTree = ""; }; + 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_ui_auto.hpp; sourceTree = ""; }; C0FEF4D418BE0E70001F446C /* lua_debugger.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lua_debugger.c; sourceTree = ""; }; C0FEF4D518BE0E70001F446C /* lua_debugger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lua_debugger.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -355,12 +349,12 @@ 1AACE74818BC45C200215002 /* auto */ = { isa = PBXGroup; children = ( + 2905FACE18CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp */, + 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */, 1AACE74918BC45C200215002 /* lua_cocos2dx_auto.cpp */, 1AACE74A18BC45C200215002 /* lua_cocos2dx_auto.hpp */, 1AACE74C18BC45C200215002 /* lua_cocos2dx_extension_auto.cpp */, 1AACE74D18BC45C200215002 /* lua_cocos2dx_extension_auto.hpp */, - 1AACE74F18BC45C200215002 /* lua_cocos2dx_gui_auto.cpp */, - 1AACE75018BC45C200215002 /* lua_cocos2dx_gui_auto.hpp */, 1AACE75218BC45C200215002 /* lua_cocos2dx_physics_auto.cpp */, 1AACE75318BC45C200215002 /* lua_cocos2dx_physics_auto.hpp */, 1AACE75518BC45C200215002 /* lua_cocos2dx_spine_auto.cpp */, @@ -395,8 +389,6 @@ 1AACE76D18BC45C200215002 /* lua_cocos2dx_deprecated.h */, 1AACE76E18BC45C200215002 /* lua_cocos2dx_extension_manual.cpp */, 1AACE76F18BC45C200215002 /* lua_cocos2dx_extension_manual.h */, - 1AACE77018BC45C200215002 /* lua_cocos2dx_gui_manual.cpp */, - 1AACE77118BC45C200215002 /* lua_cocos2dx_gui_manual.hpp */, 1AACE77218BC45C200215002 /* lua_cocos2dx_manual.cpp */, 1AACE77318BC45C200215002 /* lua_cocos2dx_manual.hpp */, 1AACE77418BC45C200215002 /* lua_cocos2dx_physics_manual.cpp */, @@ -581,10 +573,9 @@ 1ABCA24418CD8F7D0087CE3A /* luasocket_buffer.h in Headers */, 1AACE82418BC45C200215002 /* LuaScriptHandlerMgr.h in Headers */, 1AACE7FC18BC45C200215002 /* lua_cocos2dx_extension_manual.h in Headers */, - 1AACE80018BC45C200215002 /* lua_cocos2dx_gui_manual.hpp in Headers */, + 2905FAD318CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */, 1AACE7EC18BC45C200215002 /* CCLuaValue.h in Headers */, 1AACE80C18BC45C200215002 /* lua_cocos2dx_spine_manual.hpp in Headers */, - 1AACE7C418BC45C200215002 /* lua_cocos2dx_gui_auto.hpp in Headers */, 1ABCA25018CD8F7D0087CE3A /* options.h in Headers */, 1ABCA1F118CD8F470087CE3A /* lualib.h in Headers */, 1ABCA20318CD8F6E0087CE3A /* tolua_event.h in Headers */, @@ -639,10 +630,9 @@ 1ABCA24318CD8F7D0087CE3A /* luasocket_buffer.h in Headers */, 1AACE82318BC45C200215002 /* LuaScriptHandlerMgr.h in Headers */, 1AACE7FB18BC45C200215002 /* lua_cocos2dx_extension_manual.h in Headers */, - 1AACE7FF18BC45C200215002 /* lua_cocos2dx_gui_manual.hpp in Headers */, + 2905FAD218CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */, 1AACE7EB18BC45C200215002 /* CCLuaValue.h in Headers */, 1AACE80B18BC45C200215002 /* lua_cocos2dx_spine_manual.hpp in Headers */, - 1AACE7C318BC45C200215002 /* lua_cocos2dx_gui_auto.hpp in Headers */, 1ABCA24F18CD8F7D0087CE3A /* options.h in Headers */, 1ABCA1F018CD8F470087CE3A /* lualib.h in Headers */, 1ABCA20218CD8F6E0087CE3A /* tolua_event.h in Headers */, @@ -741,7 +731,6 @@ 1ABCA24E18CD8F7D0087CE3A /* options.c in Sources */, 1A262AB918BEEF5900D2DB92 /* tolua_fix.cpp in Sources */, 1AACE81E18BC45C200215002 /* LuaOpengl.cpp in Sources */, - 1AACE7C218BC45C200215002 /* lua_cocos2dx_gui_auto.cpp in Sources */, 1AACE7CE18BC45C200215002 /* lua_cocos2dx_spine_auto.cpp in Sources */, 1AACE80218BC45C200215002 /* lua_cocos2dx_manual.cpp in Sources */, 1ABCA24618CD8F7D0087CE3A /* luasocket_io.c in Sources */, @@ -769,6 +758,7 @@ 1AACE7DA18BC45C200215002 /* CCBProxy.cpp in Sources */, 1AACE81618BC45C200215002 /* lua_xml_http_request.cpp in Sources */, 1ABCA23A18CD8F7D0087CE3A /* inet.c in Sources */, + 2905FAD118CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp in Sources */, 1AACE7E218BC45C200215002 /* CCLuaEngine.cpp in Sources */, 1ABCA26E18CD8F7D0087CE3A /* usocket.c in Sources */, 1AACE81218BC45C200215002 /* Lua_web_socket.cpp in Sources */, @@ -783,7 +773,6 @@ 1ABCA20718CD8F6E0087CE3A /* tolua_map.c in Sources */, 1ABCA25618CD8F7D0087CE3A /* serial.c in Sources */, 1ABCA20B18CD8F6E0087CE3A /* tolua_to.c in Sources */, - 1AACE7FE18BC45C200215002 /* lua_cocos2dx_gui_manual.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -798,7 +787,6 @@ 1ABCA24D18CD8F7D0087CE3A /* options.c in Sources */, 1A262AB818BEEF5900D2DB92 /* tolua_fix.cpp in Sources */, 1AACE81D18BC45C200215002 /* LuaOpengl.cpp in Sources */, - 1AACE7C118BC45C200215002 /* lua_cocos2dx_gui_auto.cpp in Sources */, 1AACE7CD18BC45C200215002 /* lua_cocos2dx_spine_auto.cpp in Sources */, 1AACE80118BC45C200215002 /* lua_cocos2dx_manual.cpp in Sources */, 1ABCA24518CD8F7D0087CE3A /* luasocket_io.c in Sources */, @@ -826,6 +814,7 @@ 1AACE7D918BC45C200215002 /* CCBProxy.cpp in Sources */, 1AACE81518BC45C200215002 /* lua_xml_http_request.cpp in Sources */, 1ABCA23918CD8F7D0087CE3A /* inet.c in Sources */, + 2905FAD018CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp in Sources */, 1AACE7E118BC45C200215002 /* CCLuaEngine.cpp in Sources */, 1ABCA26D18CD8F7D0087CE3A /* usocket.c in Sources */, 1AACE81118BC45C200215002 /* Lua_web_socket.cpp in Sources */, @@ -840,7 +829,6 @@ 1ABCA20618CD8F6E0087CE3A /* tolua_map.c in Sources */, 1ABCA25518CD8F7D0087CE3A /* serial.c in Sources */, 1ABCA20A18CD8F6E0087CE3A /* tolua_to.c in Sources */, - 1AACE7FD18BC45C200215002 /* lua_cocos2dx_gui_manual.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/tools/tolua/cocos2dx_ui.ini b/tools/tolua/cocos2dx_ui.ini index 2e13310ce8..538a46cfb0 100644 --- a/tools/tolua/cocos2dx_ui.ini +++ b/tools/tolua/cocos2dx_ui.ini @@ -1,4 +1,4 @@ -[cocos2dx_gui] +[cocos2dx_ui] # the prefix to be added to the generated functions. You might or might not use this in your own # templates prefix = cocos2dx_ui @@ -16,7 +16,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/ui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT @@ -26,7 +26,7 @@ cxxgenerator_headers = extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s # what headers to parse -headers = %(cocosdir)s/cocos/gui/CocosGUI.h +headers = %(cocosdir)s/cocos/ui/CocosGUI.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". From df7aa27b8b67197728c0ae526423794bb3b6f7c9 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 17:55:41 +0800 Subject: [PATCH 06/17] fix mac lua --- .../manual/lua_cocos2dx_ui_manual.cpp | 2 +- .../project.pbxproj | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp index 2fb9b15452..f8bbb050de 100644 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "lua_cocos2dx_gui_manual.hpp" +#include "lua_cocos2dx_ui_manual.hpp" #include "cocos2d.h" #include "tolua_fix.h" #include "LuaBasicConversions.h" diff --git a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj index 931786a311..64c6b685f2 100644 --- a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj @@ -203,6 +203,10 @@ 2905FAD118CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FACE18CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp */; }; 2905FAD218CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */; }; 2905FAD318CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */; }; + 2905FAD618CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FAD418CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp */; }; + 2905FAD718CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FAD418CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp */; }; + 2905FAD818CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2905FAD518CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp */; }; + 2905FAD918CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2905FAD518CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp */; }; C0FEF4D618BE0E70001F446C /* lua_debugger.c in Sources */ = {isa = PBXBuildFile; fileRef = C0FEF4D418BE0E70001F446C /* lua_debugger.c */; }; C0FEF4D718BE0E70001F446C /* lua_debugger.c in Sources */ = {isa = PBXBuildFile; fileRef = C0FEF4D418BE0E70001F446C /* lua_debugger.c */; }; C0FEF4D818BE0E70001F446C /* lua_debugger.h in Headers */ = {isa = PBXBuildFile; fileRef = C0FEF4D518BE0E70001F446C /* lua_debugger.h */; }; @@ -311,6 +315,8 @@ 1ABCA22E18CD8F7D0087CE3A /* usocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = usocket.h; sourceTree = ""; }; 2905FACE18CF12E600240AA3 /* lua_cocos2dx_ui_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_ui_auto.cpp; sourceTree = ""; }; 2905FACF18CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_ui_auto.hpp; sourceTree = ""; }; + 2905FAD418CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_ui_manual.cpp; sourceTree = ""; }; + 2905FAD518CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_ui_manual.hpp; sourceTree = ""; }; C0FEF4D418BE0E70001F446C /* lua_debugger.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lua_debugger.c; sourceTree = ""; }; C0FEF4D518BE0E70001F446C /* lua_debugger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lua_debugger.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -369,6 +375,8 @@ 1AACE75B18BC45C200215002 /* manual */ = { isa = PBXGroup; children = ( + 2905FAD418CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp */, + 2905FAD518CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp */, 1AACE75E18BC45C200215002 /* CCBProxy.cpp */, C0FEF4D418BE0E70001F446C /* lua_debugger.c */, C0FEF4D518BE0E70001F446C /* lua_debugger.h */, @@ -575,6 +583,7 @@ 1AACE7FC18BC45C200215002 /* lua_cocos2dx_extension_manual.h in Headers */, 2905FAD318CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */, 1AACE7EC18BC45C200215002 /* CCLuaValue.h in Headers */, + 2905FAD918CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp in Headers */, 1AACE80C18BC45C200215002 /* lua_cocos2dx_spine_manual.hpp in Headers */, 1ABCA25018CD8F7D0087CE3A /* options.h in Headers */, 1ABCA1F118CD8F470087CE3A /* lualib.h in Headers */, @@ -632,6 +641,7 @@ 1AACE7FB18BC45C200215002 /* lua_cocos2dx_extension_manual.h in Headers */, 2905FAD218CF12E600240AA3 /* lua_cocos2dx_ui_auto.hpp in Headers */, 1AACE7EB18BC45C200215002 /* CCLuaValue.h in Headers */, + 2905FAD818CF143800240AA3 /* lua_cocos2dx_ui_manual.hpp in Headers */, 1AACE80B18BC45C200215002 /* lua_cocos2dx_spine_manual.hpp in Headers */, 1ABCA24F18CD8F7D0087CE3A /* options.h in Headers */, 1ABCA1F018CD8F470087CE3A /* lualib.h in Headers */, @@ -741,6 +751,7 @@ 1ABCA26618CD8F7D0087CE3A /* udp.c in Sources */, 1AACE82218BC45C200215002 /* LuaScriptHandlerMgr.cpp in Sources */, 1ABCA23618CD8F7D0087CE3A /* except.c in Sources */, + 2905FAD718CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp in Sources */, 1ABCA26A18CD8F7D0087CE3A /* unix.c in Sources */, 1AACE7F218BC45C200215002 /* lua_cocos2dx_coco_studio_manual.cpp in Sources */, 1AACE80E18BC45C200215002 /* lua_extensions.c in Sources */, @@ -797,6 +808,7 @@ 1ABCA26518CD8F7D0087CE3A /* udp.c in Sources */, 1AACE82118BC45C200215002 /* LuaScriptHandlerMgr.cpp in Sources */, 1ABCA23518CD8F7D0087CE3A /* except.c in Sources */, + 2905FAD618CF143800240AA3 /* lua_cocos2dx_ui_manual.cpp in Sources */, 1ABCA26918CD8F7D0087CE3A /* unix.c in Sources */, 1AACE7F118BC45C200215002 /* lua_cocos2dx_coco_studio_manual.cpp in Sources */, 1AACE80D18BC45C200215002 /* lua_extensions.c in Sources */, @@ -869,7 +881,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../2d $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../gui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../2d $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua"; }; name = Debug; }; @@ -902,7 +914,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../2d $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../gui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../.. $(SRCROOT)/../../.. $(SRCROOT)/../../../base $(SRCROOT)/../../../2d $(SRCROOT)/../../../physics $(SRCROOT)/../../../math/kazmath $(SRCROOT)/../../../2d/platform $(SRCROOT)/../../../audio/include $(SRCROOT)/../../../editor-support $(SRCROOT)/../../../editor-support/spine $(SRCROOT)/../../../editor-support/cocostudio $(SRCROOT)/../../../editor-support/cocosbuilder $(SRCROOT)/../../../ui $(SRCROOT)/../../../storage $(SRCROOT)/../../../../extensions $(SRCROOT)/../../../../external $(SRCROOT)/../../../../external/chipmunk/include/chipmunk $(SRCROOT)/../../../../external/lua $(SRCROOT)/../../../../external/lua/luajit/include $(SRCROOT)/../../../../external/lua/tolua"; VALIDATE_PRODUCT = YES; }; name = Release; From 48772fb95206c6c9fbf288808d31b10b4f7f2848 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 18:14:37 +0800 Subject: [PATCH 07/17] modify android makefile --- cocos/editor-support/cocostudio/Android.mk | 4 ++-- cocos/ui/Android.mk | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/editor-support/cocostudio/Android.mk b/cocos/editor-support/cocostudio/Android.mk index 019af9d284..6cb98d869c 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -68,11 +68,11 @@ LOCAL_EXPORT_CFLAGS += -Wno-psabi LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static -LOCAL_WHOLE_STATIC_LIBRARIES += cocos_gui_static +LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static include $(BUILD_STATIC_LIBRARY) $(call import-module,2d) $(call import-module,audio/android) -$(call import-module,gui) +$(call import-module,ui) diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index ba8a3dcf17..ed93d6060a 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -1,9 +1,9 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE := cocos_gui_static +LOCAL_MODULE := cocos_ui_static -LOCAL_MODULE_FILENAME := libgui +LOCAL_MODULE_FILENAME := libui LOCAL_SRC_FILES := \ UIWidget.cpp \ From b95bba56d8fbd054fea4175e95c103d45f52f62e Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 18:41:15 +0800 Subject: [PATCH 08/17] update vs2012 project dependency --- build/cocos2d-win32.vc2012.sln | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/cocos2d-win32.vc2012.sln b/build/cocos2d-win32.vc2012.sln index b7fd3b9d54..805608b261 100644 --- a/build/cocos2d-win32.vc2012.sln +++ b/build/cocos2d-win32.vc2012.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2012 for Windows Desktop +# Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libAudio", "..\cocos\audio\proj.win32\CocosDenshion.vcxproj", "{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcocos2d", "..\cocos\2d\cocos2d.vcxproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}" @@ -17,8 +17,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosBuilder", "..\cocos EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosStudio", "..\cocos\editor-support\cocostudio\proj.win32\libCocosStudio.vcxproj", "{B57CF53F-2E49-4031-9822-047CC0E6BDE2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGUI", "..\cocos\gui\proj.win32\libGUI.vcxproj", "{7E06E92C-537A-442B-9E4A-4761C84F8A1A}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libNetwork", "..\cocos\network\proj.win32\libNetwork.vcxproj", "{DF2638C0-8128-4847-867C-6EAFE3DEE7B5}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\cocos\editor-support\spine\proj.win32\libSpine.vcxproj", "{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}" @@ -29,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liblua", "..\cocos\scriptin EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLua", "..\samples\lua-tests\project\proj.win32\TestLua.win32.vcxproj", "{4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGUI", "..\cocos\ui\proj.win32\libGUI.vcxproj", "{7E06E92C-537A-442B-9E4A-4761C84F8A1A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -67,10 +67,6 @@ Global {B57CF53F-2E49-4031-9822-047CC0E6BDE2}.Debug|Win32.Build.0 = Debug|Win32 {B57CF53F-2E49-4031-9822-047CC0E6BDE2}.Release|Win32.ActiveCfg = Release|Win32 {B57CF53F-2E49-4031-9822-047CC0E6BDE2}.Release|Win32.Build.0 = Release|Win32 - {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Debug|Win32.ActiveCfg = Debug|Win32 - {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Debug|Win32.Build.0 = Debug|Win32 - {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Release|Win32.ActiveCfg = Release|Win32 - {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Release|Win32.Build.0 = Release|Win32 {DF2638C0-8128-4847-867C-6EAFE3DEE7B5}.Debug|Win32.ActiveCfg = Debug|Win32 {DF2638C0-8128-4847-867C-6EAFE3DEE7B5}.Debug|Win32.Build.0 = Debug|Win32 {DF2638C0-8128-4847-867C-6EAFE3DEE7B5}.Release|Win32.ActiveCfg = Release|Win32 @@ -91,6 +87,10 @@ Global {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Debug|Win32.Build.0 = Debug|Win32 {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Release|Win32.ActiveCfg = Release|Win32 {4E6A7A0E-DDD8-4BAA-8B22-C964069364ED}.Release|Win32.Build.0 = Release|Win32 + {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Debug|Win32.ActiveCfg = Debug|Win32 + {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Debug|Win32.Build.0 = Debug|Win32 + {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Release|Win32.ActiveCfg = Release|Win32 + {7E06E92C-537A-442B-9E4A-4761C84F8A1A}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 448b1015783c0532707e8b269ec5f9d0861e5ef4 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 20:46:11 +0800 Subject: [PATCH 09/17] fix linux compile error --- CMakeLists.txt | 4 ++-- cocos/ui/CMakeLists.txt | 4 ++-- samples/cpp-tests/CMakeLists.txt | 2 +- samples/lua-tests/project/CMakeLists.txt | 2 +- templates/cpp-template-default/CMakeLists.txt | 6 +++--- tools/cocos2d-console | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 075489b2be..92d9ff04fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,8 +244,8 @@ add_subdirectory(cocos/storage) endif(BUILD_STORAGE) if(BUILD_GUI) -# gui -add_subdirectory(cocos/gui) +# ui +add_subdirectory(cocos/ui) endif(BUILD_GUI) if(BUILD_NETWORK) diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index 4b78830596..8843bed83e 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -20,11 +20,11 @@ set(GUI_SRC UIRichText.cpp ) -add_library(gui STATIC +add_library(ui STATIC ${GUI_SRC} ) -set_target_properties(gui +set_target_properties(ui PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" diff --git a/samples/cpp-tests/CMakeLists.txt b/samples/cpp-tests/CMakeLists.txt index 3037e8fabd..8f16bf350d 100644 --- a/samples/cpp-tests/CMakeLists.txt +++ b/samples/cpp-tests/CMakeLists.txt @@ -191,7 +191,7 @@ add_executable(${APP_NAME} ) target_link_libraries(${APP_NAME} - gui + ui network spine cocostudio diff --git a/samples/lua-tests/project/CMakeLists.txt b/samples/lua-tests/project/CMakeLists.txt index d17275aed1..da49200a12 100644 --- a/samples/lua-tests/project/CMakeLists.txt +++ b/samples/lua-tests/project/CMakeLists.txt @@ -20,7 +20,7 @@ add_executable(${APP_NAME} target_link_libraries(${APP_NAME} luabinding - gui + ui network cocostudio cocosbuilder diff --git a/templates/cpp-template-default/CMakeLists.txt b/templates/cpp-template-default/CMakeLists.txt index b04b06c1b2..302399de3a 100644 --- a/templates/cpp-template-default/CMakeLists.txt +++ b/templates/cpp-template-default/CMakeLists.txt @@ -114,8 +114,8 @@ add_subdirectory(${COCOS2D_ROOT}/cocos/2d) # cocos storage add_subdirectory(${COCOS2D_ROOT}/cocos/storage) -# gui -add_subdirectory(${COCOS2D_ROOT}/cocos/gui) +# ui +add_subdirectory(${COCOS2D_ROOT}/cocos/ui) # network add_subdirectory(${COCOS2D_ROOT}/cocos/network) @@ -146,7 +146,7 @@ set(FMOD_LIB "fmodex") endif() target_link_libraries(${APP_NAME} - gui + ui network storage spine diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 013a5f557b..3973895021 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 013a5f557b46f9c947a6f5ffd93dd635a6877273 +Subproject commit 39738950219adba48ae97e853673278337df4658 From f6a9824df1d090199299e64e1f095f9b784edabb Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 20:59:35 +0800 Subject: [PATCH 10/17] fix win32 compile error --- .../auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id | 2 +- .../lua-bindings/manual/lua_cocos2dx_ui_manual.cpp | 2 +- cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id index 8db5a53eed..ca4e93a680 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp.REMOVED.git-id @@ -1 +1 @@ -c9cf8f3050b95aec88a2452e60fe492252ad30c3 \ No newline at end of file +7ce0f269261b418b148cd10d428bafe18a36d58e \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp index f8bbb050de..5d27bc7a50 100644 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_ui_manual.cpp @@ -27,7 +27,7 @@ #include "LuaBasicConversions.h" #include "LuaScriptHandlerMgr.h" #include "CCLuaValue.h" -#include "CocosGUI.h" +#include "ui/CocosGUI.h" #include "CCLuaEngine.h" using namespace ui; diff --git a/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj b/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj index b736737153..978d03e99f 100644 --- a/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj +++ b/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj @@ -32,10 +32,10 @@ - + @@ -49,10 +49,10 @@ - + @@ -83,10 +83,10 @@ - + @@ -100,10 +100,10 @@ - + From 4ed33fa4c8d4b73d6959a1e2f669da8e7681bbca Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 11 Mar 2014 21:36:00 +0800 Subject: [PATCH 11/17] fix lua bindings --- cocos/scripting/lua-bindings/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index d854cdff76..30d215e573 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -2,7 +2,7 @@ set(LUABINDING_SRC auto/lua_cocos2dx_auto.cpp auto/lua_cocos2dx_extension_auto.cpp auto/lua_cocos2dx_studio_auto.cpp - auto/lua_cocos2dx_gui_auto.cpp + auto/lua_cocos2dx_ui_auto.cpp auto/lua_cocos2dx_spine_auto.cpp auto/lua_cocos2dx_physics_auto.cpp manual/tolua_fix.cpp @@ -18,7 +18,7 @@ set(LUABINDING_SRC manual/lua_cocos2dx_manual.cpp manual/lua_cocos2dx_extension_manual.cpp manual/lua_cocos2dx_coco_studio_manual.cpp - manual/lua_cocos2dx_gui_manual.cpp + manual/lua_cocos2dx_ui_manual.cpp manual/lua_cocos2dx_spine_manual.cpp manual/lua_cocos2dx_physics_manual.cpp manual/lua_cocos2dx_deprecated.cpp @@ -32,7 +32,7 @@ include_directories( ../../editor-support/cocosbuilder ../../editor-support/cocostudio ../../editor-support/spine - ../../gui + ../../ui ../../../external/lua/lua ../../../external/lua/tolua ) From 469bee1e879cefb5de7636bccb19e8fcef5d2f8f Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 12 Mar 2014 10:10:14 +0800 Subject: [PATCH 12/17] delete samples --- samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id | 1 - .../UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id | 1 - .../UIImageView_Editor/background.png.REMOVED.git-id | 1 - .../UILabelAtlas_Editor/background.png.REMOVED.git-id | 1 - .../UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id | 1 - .../UILabelBMFont_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id | 1 - .../UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../UILayout_Color_Editor/background.png.REMOVED.git-id | 1 - .../UILayout_Editor/background.png.REMOVED.git-id | 1 - .../UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../UIListView_Horizontal_Editor/background.png.REMOVED.git-id | 1 - .../UIListView_Vertical_Editor/background.png.REMOVED.git-id | 1 - .../UILoadingBar_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id | 1 - .../UIScrollView_Both_Editor/background.png.REMOVED.git-id | 1 - .../UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id | 1 - .../UIScrollView_Vertical_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id | 1 - .../UITextField_Editor/background.png.REMOVED.git-id | 1 - .../UIWidgetAddNode_Editor/background.png.REMOVED.git-id | 1 - .../Resources/cocosui/UITest/background.png.REMOVED.git-id | 1 - samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id | 1 - .../Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id | 1 - .../Resources/cocosui/examples/examples.json.REMOVED.git-id | 1 - .../cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id | 1 - .../cocosui/gui_examples/page_1/background.png.REMOVED.git-id | 1 - tests/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id | 1 - .../UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id | 1 - .../UIImageView_Editor/background.png.REMOVED.git-id | 1 - .../UILabelAtlas_Editor/background.png.REMOVED.git-id | 1 - .../UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id | 1 - .../UILabelBMFont_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id | 1 - .../UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../UILayout_Color_Editor/background.png.REMOVED.git-id | 1 - .../UILayout_Editor/background.png.REMOVED.git-id | 1 - .../UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../background.png.REMOVED.git-id | 1 - .../UIListView_Horizontal_Editor/background.png.REMOVED.git-id | 1 - .../UIListView_Vertical_Editor/background.png.REMOVED.git-id | 1 - .../UILoadingBar_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id | 1 - .../UIScrollView_Both_Editor/background.png.REMOVED.git-id | 1 - .../UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id | 1 - .../UIScrollView_Vertical_Editor/background.png.REMOVED.git-id | 1 - .../UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id | 1 - .../UITextField_Editor/background.png.REMOVED.git-id | 1 - .../UIWidgetAddNode_Editor/background.png.REMOVED.git-id | 1 - .../Resources/cocosgui/UITest/background.png.REMOVED.git-id | 1 - tests/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id | 1 - .../Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id | 1 - .../Resources/cocosgui/examples/examples.json.REMOVED.git-id | 1 - .../cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id | 1 - .../cocosgui/gui_examples/page_1/background.png.REMOVED.git-id | 1 - 68 files changed, 68 deletions(-) delete mode 100644 samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id delete mode 100644 samples/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/UITest/background.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/examples/examples.json.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id delete mode 100644 tests/cpp-tests/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id diff --git a/samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id deleted file mode 100644 index f02d84fd8f..0000000000 --- a/samples/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id deleted file mode 100644 index 53ce8980e1..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9d2adf428a20b8facb57c0b3dc8dd782c74e27ea \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id deleted file mode 100644 index 02b4320e6c..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -94b49354965ace4e2408e5faaa310f87a3bf914a \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id deleted file mode 100644 index 0b4502562c..0000000000 --- a/samples/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -39179659c7b94b213b6ab7b24372c96378f61062 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id deleted file mode 100644 index d025022480..0000000000 --- a/samples/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9975e4961272d5bda6d5f3bbd61ea0fc02222199 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id deleted file mode 100644 index f45f8e2ea7..0000000000 --- a/samples/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9794da238f4eddd121498848aeb524c6224138a2 \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id deleted file mode 100644 index 6f99243a26..0000000000 --- a/samples/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -39d29cbeb700598c3e4ad6d3ee0ac273a3385fcd \ No newline at end of file diff --git a/samples/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id b/samples/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/samples/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id deleted file mode 100644 index f02d84fd8f..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/Hello.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id deleted file mode 100644 index 53ce8980e1..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9d2adf428a20b8facb57c0b3dc8dd782c74e27ea \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id deleted file mode 100644 index 02b4320e6c..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -94b49354965ace4e2408e5faaa310f87a3bf914a \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/UITest/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/UITest/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/UITest/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id deleted file mode 100644 index 0b4502562c..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/b11.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -39179659c7b94b213b6ab7b24372c96378f61062 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id deleted file mode 100644 index d025022480..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/bitmapFontTest2.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9975e4961272d5bda6d5f3bbd61ea0fc02222199 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/examples/examples.json.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/examples/examples.json.REMOVED.git-id deleted file mode 100644 index f45f8e2ea7..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/examples/examples.json.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -9794da238f4eddd121498848aeb524c6224138a2 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id deleted file mode 100644 index 6f99243a26..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/gui_examples/map_1/map_pve.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -39d29cbeb700598c3e4ad6d3ee0ac273a3385fcd \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id deleted file mode 100644 index 746e4e19e9..0000000000 --- a/tests/cpp-tests/Resources/cocosgui/gui_examples/page_1/background.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file From d806274f98c21ff10f33c5aecca77ff4d84de77e Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 12 Mar 2014 10:12:02 +0800 Subject: [PATCH 13/17] change gui to ui --- build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- tests/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id | 1 + .../UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id | 1 + .../UICheckBox_Editor/background.png.REMOVED.git-id | 1 + .../UIImageView_Editor/background.png.REMOVED.git-id | 1 + .../UILabelAtlas_Editor/background.png.REMOVED.git-id | 1 + .../UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id | 1 + .../UILabelBMFont_Editor/background.png.REMOVED.git-id | 1 + .../UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id | 1 + .../UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../UILayout_Color_Editor/background.png.REMOVED.git-id | 1 + .../UILayout_Editor/background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../UIListView_Horizontal_Editor/background.png.REMOVED.git-id | 1 + .../UIListView_Vertical_Editor/background.png.REMOVED.git-id | 1 + .../UILoadingBar_Editor/background.png.REMOVED.git-id | 1 + .../UIPageView_Editor/background.png.REMOVED.git-id | 1 + .../UIScrollView_Both_Editor/background.png.REMOVED.git-id | 1 + .../background.png.REMOVED.git-id | 1 + .../UIScrollView_Vertical_Editor/background.png.REMOVED.git-id | 1 + .../UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id | 1 + .../UITextField_Editor/background.png.REMOVED.git-id | 1 + .../UIWidgetAddNode_Editor/background.png.REMOVED.git-id | 1 + .../Resources/cocosui/UITest/background.png.REMOVED.git-id | 1 + tests/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id | 1 + .../Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id | 1 + .../Resources/cocosui/examples/examples.json.REMOVED.git-id | 1 + .../cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id | 1 + .../cocosui/gui_examples/page_1/background.png.REMOVED.git-id | 1 + 35 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id create mode 100644 tests/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id index 75ce22c5ee..56a923f0d4 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -1c0cfb1ac4272e26690b9265c721c0a7e5ae83c3 \ No newline at end of file +d1fc711da588a7a766053acd822128eba9a38af7 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id new file mode 100644 index 0000000000..f02d84fd8f --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/Hello.png.REMOVED.git-id @@ -0,0 +1 @@ +5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIButton_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UICheckBox_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIImageView_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelAtlas_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id new file mode 100644 index 0000000000..53ce8980e1 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/GUI/missing-font.png.REMOVED.git-id @@ -0,0 +1 @@ +9d2adf428a20b8facb57c0b3dc8dd782c74e27ea \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabelBMFont_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILabel_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id new file mode 100644 index 0000000000..02b4320e6c --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/Hello.png.REMOVED.git-id @@ -0,0 +1 @@ +94b49354965ace4e2408e5faaa310f87a3bf914a \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UILoadingBar_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIPageView_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UISlider_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UITextField_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UIEditorTest/UIWidgetAddNode_Editor/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/UITest/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id new file mode 100644 index 0000000000..0b4502562c --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/b11.png.REMOVED.git-id @@ -0,0 +1 @@ +39179659c7b94b213b6ab7b24372c96378f61062 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id new file mode 100644 index 0000000000..d025022480 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/bitmapFontTest2.png.REMOVED.git-id @@ -0,0 +1 @@ +9975e4961272d5bda6d5f3bbd61ea0fc02222199 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id new file mode 100644 index 0000000000..f45f8e2ea7 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/examples/examples.json.REMOVED.git-id @@ -0,0 +1 @@ +9794da238f4eddd121498848aeb524c6224138a2 \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id new file mode 100644 index 0000000000..6f99243a26 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/gui_examples/map_1/map_pve.png.REMOVED.git-id @@ -0,0 +1 @@ +39d29cbeb700598c3e4ad6d3ee0ac273a3385fcd \ No newline at end of file diff --git a/tests/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id b/tests/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id new file mode 100644 index 0000000000..746e4e19e9 --- /dev/null +++ b/tests/cpp-tests/Resources/cocosui/gui_examples/page_1/background.png.REMOVED.git-id @@ -0,0 +1 @@ +500d95937f3fd81659da66d2099b6c80d988a6b5 \ No newline at end of file From 0634a1accd1b5068f30664dc2fd6decf552e5ec4 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 12 Mar 2014 10:19:41 +0800 Subject: [PATCH 14/17] fix lua resource path --- .../CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id index 0279040f69..8acb2af820 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id @@ -1 +1 @@ -09ed3c488f6d182685c416c291f8f325fb5cc2d2 \ No newline at end of file +a28b4af8f8f426d3719766b446d2fc2a18c4ba25 \ No newline at end of file From 90938429d0d403bfe76b3d6f64c537acb18e7130 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 12 Mar 2014 10:37:33 +0800 Subject: [PATCH 15/17] reset cocos-console commit --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 3973895021..7e7f6d215c 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 39738950219adba48ae97e853673278337df4658 +Subproject commit 7e7f6d215c9bb83ac926a1436b20a685e3d5b66b From 2c2a5ee38ef9f536a7b8f481a2ab51cf8ed0cd4e Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 12 Mar 2014 10:46:49 +0800 Subject: [PATCH 16/17] rename gui to ui --- .../project.pbxproj.REMOVED.git-id | 2 +- .../project.pbxproj.REMOVED.git-id | 2 +- cocos/scripting/lua-bindings/Android.mk | 6 +++--- .../lua-bindings/proj.win32/liblua.vcxproj.filters | 10 +++++----- templates/cocos2dx_files.json.REMOVED.git-id | 2 +- .../proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj | 4 ++-- .../proj.ios_mac/HelloLua.xcodeproj/project.pbxproj | 4 ++-- .../frameworks/runtime-src/proj.win32/HelloLua.sln | 2 +- .../frameworks/runtime-src/proj.win32/HelloLua.vcxproj | 4 ++-- .../proj.ios_mac/HelloLua.xcodeproj/project.pbxproj | 4 ++-- .../frameworks/runtime-src/proj.win32/HelloLua.sln | 2 +- .../frameworks/runtime-src/proj.win32/HelloLua.vcxproj | 4 ++-- tests/cpp-tests/proj.win32/TestCpp.vcxproj | 4 ++-- tools/tolua/cocos2dx_spine.ini | 2 +- tools/tolua/cocos2dx_studio.ini | 4 ++-- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 7b4843b4f0..f04874a8ec 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -2eabffffc9ac4960f8e1ae33fc712be031827127 \ No newline at end of file +71a61fb97a4db05adaabc4cc03035fe419cc35d6 \ No newline at end of file diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id index 56a923f0d4..82864a9aa4 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -d1fc711da588a7a766053acd822128eba9a38af7 \ No newline at end of file +08fd638cd925dfad54a49df207a72130942102d3 \ No newline at end of file diff --git a/cocos/scripting/lua-bindings/Android.mk b/cocos/scripting/lua-bindings/Android.mk index 0c148e9ab8..134c453f88 100644 --- a/cocos/scripting/lua-bindings/Android.mk +++ b/cocos/scripting/lua-bindings/Android.mk @@ -20,7 +20,7 @@ LOCAL_SRC_FILES := manual/CCLuaBridge.cpp \ manual/lua_cocos2dx_manual.cpp \ manual/lua_cocos2dx_extension_manual.cpp \ manual/lua_cocos2dx_coco_studio_manual.cpp \ - manual/lua_cocos2dx_gui_manual.cpp \ + manual/lua_cocos2dx_ui_manual.cpp \ manual/lua_cocos2dx_spine_manual.cpp \ manual/lua_cocos2dx_physics_manual.cpp \ manual/lua_cocos2dx_deprecated.cpp \ @@ -32,7 +32,7 @@ LOCAL_SRC_FILES := manual/CCLuaBridge.cpp \ auto/lua_cocos2dx_auto.cpp \ auto/lua_cocos2dx_extension_auto.cpp \ auto/lua_cocos2dx_studio_auto.cpp \ - auto/lua_cocos2dx_gui_auto.cpp \ + auto/lua_cocos2dx_ui_auto.cpp \ auto/lua_cocos2dx_spine_auto.cpp \ auto/lua_cocos2dx_physics_auto.cpp \ ../../../external/lua/tolua/tolua_event.c \ @@ -65,7 +65,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../external/lua/tolua \ $(LOCAL_PATH)/../../editor-support/spine \ $(LOCAL_PATH)/../../editor-support/cocosbuilder \ $(LOCAL_PATH)/../../editor-support/cocostudio \ - $(LOCAL_PATH)/../../gui \ + $(LOCAL_PATH)/../../ui \ $(LOCAL_PATH)/auto \ $(LOCAL_PATH)/manual \ $(LOCAL_PATH)/manual/platform/android \ diff --git a/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj.filters b/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj.filters index c6c7a4dc80..5f1a7e127e 100644 --- a/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj.filters +++ b/cocos/scripting/lua-bindings/proj.win32/liblua.vcxproj.filters @@ -21,7 +21,7 @@ auto - + auto @@ -60,7 +60,7 @@ manual - + manual @@ -164,7 +164,7 @@ auto - + auto @@ -203,7 +203,7 @@ manual - + manual @@ -362,4 +362,4 @@ script - \ No newline at end of file + diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id index 251bec07e4..78f903166b 100644 --- a/templates/cocos2dx_files.json.REMOVED.git-id +++ b/templates/cocos2dx_files.json.REMOVED.git-id @@ -1 +1 @@ -e4f656f3e06fc5c267880b95d80deba8b2640c77 \ No newline at end of file +2556bc226669ba393f6fb1900d941f17baeacb02 \ No newline at end of file diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj index 4ad489f766..83a4e2ebe7 100644 --- a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj +++ b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj @@ -933,7 +933,7 @@ "$(SRCROOT)/../cocos2d/cocos/physics", "$(SRCROOT)/../cocos2d/cocos/math/kazmath", "$(SRCROOT)/../cocos2d/cocos/2d", - "$(SRCROOT)/../cocos2d/cocos/gui", + "$(SRCROOT)/../cocos2d/cocos/ui", "$(SRCROOT)/../cocos2d/cocos/network", "$(SRCROOT)/../cocos2d/cocos/audio/include", "$(SRCROOT)/../cocos2d/cocos/editor-support", @@ -961,7 +961,7 @@ "$(SRCROOT)/../cocos2d/cocos/physics", "$(SRCROOT)/../cocos2d/cocos/math/kazmath", "$(SRCROOT)/../cocos2d/cocos/2d", - "$(SRCROOT)/../cocos2d/cocos/gui", + "$(SRCROOT)/../cocos2d/cocos/ui", "$(SRCROOT)/../cocos2d/cocos/network", "$(SRCROOT)/../cocos2d/cocos/audio/include", "$(SRCROOT)/../cocos2d/cocos/editor-support", diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index 58b62f1160..e894d09394 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -978,7 +978,7 @@ HEADER_SEARCH_PATHS = ""; ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = "$(TARGET_NAME)"; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/gui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/ui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; }; name = Debug; }; @@ -999,7 +999,7 @@ HEADER_SEARCH_PATHS = ""; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; PRODUCT_NAME = "$(TARGET_NAME)"; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/gui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/ui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.sln b/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.sln index 96979213d0..47be636d6c 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.sln +++ b/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.sln @@ -30,7 +30,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosBuilder", "..\..\co EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosStudio", "..\..\cocos2d-x\cocos\editor-support\cocostudio\proj.win32\libCocosStudio.vcxproj", "{B57CF53F-2E49-4031-9822-047CC0E6BDE2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGUI", "..\..\cocos2d-x\cocos\gui\proj.win32\libGUI.vcxproj", "{7E06E92C-537A-442B-9E4A-4761C84F8A1A}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGUI", "..\..\cocos2d-x\cocos\ui\proj.win32\libGUI.vcxproj", "{7E06E92C-537A-442B-9E4A-4761C84F8A1A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\..\cocos2d-x\cocos\editor-support\spine\proj.win32\libSpine.vcxproj", "{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}" EndProject diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.vcxproj b/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.vcxproj index 36985508d8..ed405aed3a 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.vcxproj +++ b/templates/lua-template-default/frameworks/runtime-src/proj.win32/HelloLua.vcxproj @@ -201,7 +201,7 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" {b7c2a162-dec9-4418-972e-240ab3cbfcae} - + {7e06e92c-537a-442b-9e4a-4761c84f8a1a} @@ -226,4 +226,4 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" - \ No newline at end of file + diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index 325c617515..f81659bdb7 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -1018,7 +1018,7 @@ HEADER_SEARCH_PATHS = ""; ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = "$(TARGET_NAME)"; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/gui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/ui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; }; name = Debug; }; @@ -1039,7 +1039,7 @@ HEADER_SEARCH_PATHS = ""; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; PRODUCT_NAME = "$(TARGET_NAME)"; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/gui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/../../cocos2d-x $(SRCROOT)/../../cocos2d-x/cocos $(SRCROOT)/../../cocos2d-x/cocos/base $(SRCROOT)/../../cocos2d-x/cocos/physics $(SRCROOT)/../../cocos2d-x/cocos/math/kazmath $(SRCROOT)/../../cocos2d-x/cocos/2d $(SRCROOT)/../../cocos2d-x/cocos/ui $(SRCROOT)/../../cocos2d-x/cocos/network $(SRCROOT)/../../cocos2d-x/cocos/audio/include $(SRCROOT)/../../cocos2d-x/cocos/editor-support $(SRCROOT)/../../cocos2d-x/extensions $(SRCROOT)/../../cocos2d-x/external $(SRCROOT)/../../cocos2d-x/external/chipmunk/include/chipmunk $(SRCROOT)/../../cocos2d-x/external/lua/luajit/include $(SRCROOT)/../../cocos2d-x/external/lua/tolua $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/manual $(SRCROOT)/../../cocos2d-x/cocos/scripting/lua-bindings/auto"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.sln b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.sln index 96979213d0..47be636d6c 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.sln +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.sln @@ -30,7 +30,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosBuilder", "..\..\co EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCocosStudio", "..\..\cocos2d-x\cocos\editor-support\cocostudio\proj.win32\libCocosStudio.vcxproj", "{B57CF53F-2E49-4031-9822-047CC0E6BDE2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGUI", "..\..\cocos2d-x\cocos\gui\proj.win32\libGUI.vcxproj", "{7E06E92C-537A-442B-9E4A-4761C84F8A1A}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGUI", "..\..\cocos2d-x\cocos\ui\proj.win32\libGUI.vcxproj", "{7E06E92C-537A-442B-9E4A-4761C84F8A1A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSpine", "..\..\cocos2d-x\cocos\editor-support\spine\proj.win32\libSpine.vcxproj", "{B7C2A162-DEC9-4418-972E-240AB3CBFCAE}" EndProject diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj index 8e1830ec70..1c05d2dffb 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/HelloLua.vcxproj @@ -206,7 +206,7 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" {b7c2a162-dec9-4418-972e-240ab3cbfcae} - + {7e06e92c-537a-442b-9e4a-4761c84f8a1a} @@ -231,4 +231,4 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" - \ No newline at end of file + diff --git a/tests/cpp-tests/proj.win32/TestCpp.vcxproj b/tests/cpp-tests/proj.win32/TestCpp.vcxproj index cc185a6354..172ef28da3 100644 --- a/tests/cpp-tests/proj.win32/TestCpp.vcxproj +++ b/tests/cpp-tests/proj.win32/TestCpp.vcxproj @@ -558,7 +558,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou {b7c2a162-dec9-4418-972e-240ab3cbfcae} - + {7e06e92c-537a-442b-9e4a-4761c84f8a1a} @@ -583,4 +583,4 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou - \ No newline at end of file + diff --git a/tools/tolua/cocos2dx_spine.ini b/tools/tolua/cocos2dx_spine.ini index ff94bb0c1b..6fce549122 100644 --- a/tools/tolua/cocos2dx_spine.ini +++ b/tools/tolua/cocos2dx_spine.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/ui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT diff --git a/tools/tolua/cocos2dx_studio.ini b/tools/tolua/cocos2dx_studio.ini index 21c49f10e9..38136febfd 100644 --- a/tools/tolua/cocos2dx_studio.ini +++ b/tools/tolua/cocos2dx_studio.ini @@ -7,7 +7,7 @@ prefix = cocos2dx_studio # all classes will be embedded in that namespace target_namespace = ccs -# the native namespace in which this module locates, this parameter is used for avoid conflict of the same class name in different modules, as "cocos2d::Label" <-> "cocos2d::gui::Label". +# the native namespace in which this module locates, this parameter is used for avoid conflict of the same class name in different modules, as "cocos2d::Label" <-> "cocos2d::ui::Label". cpp_namespace = cocostudio android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include @@ -16,7 +16,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/ui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT From cb4acc6311dd2e941054cd711dc6f7a3f3e1326a Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 12 Mar 2014 11:03:23 +0800 Subject: [PATCH 17/17] fix linux compile error --- templates/cocos2dx_files.json.REMOVED.git-id | 2 +- tests/lua-empty-test/project/CMakeLists.txt | 2 +- tests/lua-empty-test/project/proj.win32/HelloLua.vcxproj | 4 ++-- tests/lua-tests/project/proj.win32/TestLua.win32.vcxproj | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id index 78f903166b..15d6dd3dcc 100644 --- a/templates/cocos2dx_files.json.REMOVED.git-id +++ b/templates/cocos2dx_files.json.REMOVED.git-id @@ -1 +1 @@ -2556bc226669ba393f6fb1900d941f17baeacb02 \ No newline at end of file +ac17b42db61c1dee0e31ae7df7bcb2fa33e899d1 \ No newline at end of file diff --git a/tests/lua-empty-test/project/CMakeLists.txt b/tests/lua-empty-test/project/CMakeLists.txt index aaeb5b1e55..9c4544ac0c 100644 --- a/tests/lua-empty-test/project/CMakeLists.txt +++ b/tests/lua-empty-test/project/CMakeLists.txt @@ -19,7 +19,7 @@ add_executable(${APP_NAME} target_link_libraries(${APP_NAME} luabinding - gui + ui network cocostudio cocosbuilder diff --git a/tests/lua-empty-test/project/proj.win32/HelloLua.vcxproj b/tests/lua-empty-test/project/proj.win32/HelloLua.vcxproj index 6ed5cb8431..1967dfe52d 100644 --- a/tests/lua-empty-test/project/proj.win32/HelloLua.vcxproj +++ b/tests/lua-empty-test/project/proj.win32/HelloLua.vcxproj @@ -181,7 +181,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$ {b7c2a162-dec9-4418-972e-240ab3cbfcae} - + {7e06e92c-537a-442b-9e4a-4761c84f8a1a} @@ -203,4 +203,4 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$ - \ No newline at end of file + diff --git a/tests/lua-tests/project/proj.win32/TestLua.win32.vcxproj b/tests/lua-tests/project/proj.win32/TestLua.win32.vcxproj index 0cdffe39e5..66d853f657 100644 --- a/tests/lua-tests/project/proj.win32/TestLua.win32.vcxproj +++ b/tests/lua-tests/project/proj.win32/TestLua.win32.vcxproj @@ -202,7 +202,7 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" {b7c2a162-dec9-4418-972e-240ab3cbfcae} - + {7e06e92c-537a-442b-9e4a-4761c84f8a1a} @@ -221,4 +221,4 @@ xcopy /Y /Q "$(EngineRoot)external\websockets\prebuilt\win32\*.*" "$(OutDir)" - \ No newline at end of file +