diff --git a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h index df49bf50e0..afe3017b63 100644 --- a/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h +++ b/cocos/scripting/lua-bindings/manual/LuaScriptHandlerMgr.h @@ -161,6 +161,8 @@ public: EVENT_PHYSICS_CONTACT_POSTSOLVE, EVENT_PHYSICS_CONTACT_SEPERATE, + EVENT_FOCUS, + EVENT_CUSTOM_BEGAN = 10000, EVENT_CUSTOM_ENDED = 11000, }; diff --git a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp index 6c4076f154..115d67d617 100644 --- a/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/lua_cocos2dx_manual.cpp @@ -31,6 +31,7 @@ #else #include #endif +#include "ui/UIWidget.h" static int tolua_cocos2d_MenuItemImage_create(lua_State* tolua_S) { @@ -6134,6 +6135,182 @@ static void extendTMXLayer(lua_State* tolua_S) lua_pop(tolua_S, 1); } +static int tolua_cocos2dx_EventListenerFocus_create(lua_State* tolua_S) +{ + if (nullptr == tolua_S) + return 0; + + int argc = 0; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertable(tolua_S, 1, "cc.EventListenerFocus", 0, &tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + cocos2d::EventListenerFocus* tolua_ret = cocos2d::EventListenerFocus::create(); + if(nullptr == tolua_ret) + return 0; + + int ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; + int* luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"cc.EventListenerFocus"); + + return 1; + } + + CCLOG("'create' has wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err); + return 0; +#endif +} + +static void cloneFocusHandler(const EventListenerFocus* src,EventListenerFocus* dst ) +{ + if (nullptr == src || nullptr == dst) + return; + + LUA_FUNCTION handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)src, ScriptHandlerMgr::HandlerType::EVENT_FOCUS); + if (0 != handler) + { + int newscriptHandler = cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->reallocateScriptHandler(handler); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)dst, newscriptHandler, ScriptHandlerMgr::HandlerType::EVENT_FOCUS); + dst->onFocusChanged = [=](ui::Widget* widgetLostFocus, ui::Widget* widgetGetFocus){ + lua_State* tolua_S = LuaEngine::getInstance()->getLuaStack()->getLuaState(); + int id = (widgetLostFocus) ? (int)widgetLostFocus->_ID : -1; + int* luaID = (widgetLostFocus) ? &widgetLostFocus->_luaID : nullptr; + toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)widgetLostFocus,"ccui.Widget"); + id = (widgetGetFocus) ? (int)widgetGetFocus->_ID : -1; + luaID = (widgetGetFocus) ? &widgetGetFocus->_luaID : nullptr; + toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)widgetGetFocus,"ccui.Widget"); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + } +} + +static int tolua_cocos2dx_EventListenerFocus_clone(lua_State* tolua_S) +{ + if (nullptr == tolua_S) + return 0; + + int argc = 0; + EventListenerFocus* self = nullptr; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S, 1, "cc.EventListenerFocus", 0, &tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(tolua_S,1,0)); +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2dx_EventListenerFocus_clone'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + cocos2d::EventListenerFocus* tolua_ret = cocos2d::EventListenerFocus::create(); + if(nullptr == tolua_ret) + return 0; + + cloneFocusHandler(self, tolua_ret); + + int ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; + int* luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"cc.EventListenerFocus"); + + return 1; + } + + CCLOG("'clone' has wrong number of arguments: %d, was expecting %d\n", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'clone'.",&tolua_err); + return 0; +#endif +} + + +static int tolua_cocos2dx_EventListenerFocus_registerScriptHandler(lua_State* tolua_S) +{ + if (nullptr == tolua_S) + return 0; + + int argc = 0; + EventListenerFocus* self = nullptr; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S, 1, "cc.EventListenerFocus", 0, &tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(tolua_S,1,0)); +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2dx_EventListenerFocus_registerScriptHandler'\n", nullptr); + return 0; + } +#endif + argc = lua_gettop(tolua_S) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::EVENT_FOCUS); + + self->onFocusChanged = [=](ui::Widget* widgetLostFocus, ui::Widget* widgetGetFocus){ + int id = (widgetLostFocus) ? (int)widgetLostFocus->_ID : -1; + int* luaID = (widgetLostFocus) ? &widgetLostFocus->_luaID : nullptr; + toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)widgetLostFocus,"ccui.Widget"); + id = (widgetGetFocus) ? (int)widgetGetFocus->_ID : -1; + luaID = (widgetGetFocus) ? &widgetGetFocus->_luaID : nullptr; + toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)widgetGetFocus,"ccui.Widget"); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + return 0; + } + + CCLOG("'registerScriptHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +static void extendEventListenerFocus(lua_State* tolua_S) +{ + lua_pushstring(tolua_S, "cc.EventListenerFocus"); + lua_rawget(tolua_S, LUA_REGISTRYINDEX); + if (lua_istable(tolua_S,-1)) + { + tolua_function(tolua_S, "create", tolua_cocos2dx_EventListenerFocus_create); + tolua_function(tolua_S, "registerScriptHandler", tolua_cocos2dx_EventListenerFocus_registerScriptHandler); + tolua_function(tolua_S, "clone", tolua_cocos2dx_EventListenerFocus_clone); + } + lua_pop(tolua_S, 1); +} + int register_all_cocos2dx_manual(lua_State* tolua_S) { @@ -6186,6 +6363,7 @@ int register_all_cocos2dx_manual(lua_State* tolua_S) extendGLProgramState(tolua_S); extendOrbitCamera(tolua_S); extendTMXLayer(tolua_S); + extendEventListenerFocus(tolua_S); return 0; } diff --git a/cocos/scripting/lua-bindings/script/Deprecated.lua b/cocos/scripting/lua-bindings/script/Deprecated.lua index 96f98e5535..bd2b0689bb 100644 --- a/cocos/scripting/lua-bindings/script/Deprecated.lua +++ b/cocos/scripting/lua-bindings/script/Deprecated.lua @@ -1230,6 +1230,18 @@ function UIWidgetDeprecated.getTopInParent(self) end rawset(ccui.Widget,"getTopInParent", UIWidgetDeprecated.getTopInParent) +function UIWidgetDeprecated.getSize(self) + deprecatedTip("ccui.Widget:getSize","ccui.Widget:getContentSize") + return self:getContentSize() +end +rawset(ccui.Widget,"getSize", UIWidgetDeprecated.getSize) + +function UIWidgetDeprecated.setSize(self, ...) + deprecatedTip("ccui.Widget:setSize","ccui.Widget:setContentSize") + return self:setContentSize(...) +end +rawset(ccui.Widget,"setSize", UIWidgetDeprecated.setSize) + --functions of ccui.Widget will be deprecated end --functions of ccui.CheckBox will be deprecated begin diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua index bd26c09888..e2a6b31408 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua @@ -102,7 +102,7 @@ end function UIButtonTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") @@ -118,7 +118,7 @@ function UIButtonTest:initExtend() alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function touchEvent(sender,eventType) @@ -166,7 +166,7 @@ function UIButtonScale9Test:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") @@ -181,7 +181,7 @@ function UIButtonScale9Test:initExtend() alert:setFontName(font_UIButtonTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function touchEvent(sender,eventType) @@ -201,7 +201,7 @@ function UIButtonScale9Test:initExtend() button:setScale9Enabled(true) button:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0)) - button:setSize(cc.size(150, button:getVirtualRendererSize().height * 1.5)) + button:setContentSize(cc.size(150, button:getVirtualRendererSize().height * 1.5)) button:addTouchEventListener(touchEvent) self._uiLayer:addChild(button) end @@ -231,7 +231,7 @@ function UIButtonPressedActionTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() @@ -247,7 +247,7 @@ function UIButtonPressedActionTest:initExtend() alert:setFontName(font_UIButtonTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function touchEvent(sender,eventType) @@ -296,7 +296,7 @@ function UITextButtonTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() @@ -312,7 +312,7 @@ function UITextButtonTest:initExtend() alert:setFontName(font_UIButtonTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function touchEvent(sender,eventType) @@ -361,7 +361,7 @@ function UITextButtonScale9Test:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") @@ -376,7 +376,7 @@ function UITextButtonScale9Test:initExtend() alert:setFontName(font_UIButtonTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function touchEvent(sender,eventType) @@ -395,7 +395,7 @@ function UITextButtonScale9Test:initExtend() textButton:setTouchEnabled(true) textButton:setScale9Enabled(true) textButton:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") - textButton:setSize(cc.size(180, textButton:getVirtualRendererSize().height * 1.5)) + textButton:setContentSize(cc.size(180, textButton:getVirtualRendererSize().height * 1.5)) textButton:setTitleText("Text Button scale9 render") textButton:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0)) textButton:addTouchEventListener(touchEvent) @@ -427,7 +427,7 @@ function UICheckBoxTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") @@ -442,7 +442,7 @@ function UICheckBoxTest:initExtend() alert:setFontName(font_UICheckBoxTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function selectedEvent(sender,eventType) @@ -492,7 +492,7 @@ function UISliderTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move the slider thumb") @@ -507,7 +507,7 @@ function UISliderTest:initExtend() alert:setFontName(font_UISliderTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function percentChangedEvent(sender,eventType) @@ -554,7 +554,7 @@ function UISliderScale9Test:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move the slider thumb") @@ -569,7 +569,7 @@ function UISliderScale9Test:initExtend() alert:setFontName(font_UISliderTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function percentChangedEvent(sender,eventType) @@ -587,7 +587,7 @@ function UISliderScale9Test:initExtend() slider:loadProgressBarTexture("cocosui/slider_bar_active_9patch.png") slider:setScale9Enabled(true) slider:setCapInsets(cc.rect(0, 0, 0, 0)) - slider:setSize(cc.size(250, 10)) + slider:setContentSize(cc.size(250, 10)) slider:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0)) slider:addEventListener(percentChangedEvent) @@ -618,19 +618,19 @@ function UIImageViewTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("ImageView") alert:setFontName(font_UIImageViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local imageView = ccui.ImageView:create() imageView:loadTexture("cocosui/ccicon.png") - imageView:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + imageView:getSize().height / 4.0)) + imageView:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + imageView:getContentSize().height / 4.0)) self._uiLayer:addChild(imageView) end @@ -659,21 +659,21 @@ function UIImageViewScale9Test:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("ImageView scale9 render") alert:setFontName(font_UIImageViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local imageView = ccui.ImageView:create() imageView:setScale9Enabled(true) imageView:loadTexture("cocosui/buttonHighlighted.png") - imageView:setSize(cc.size(200, 85)) - imageView:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + imageView:getSize().height / 4.0)) + imageView:setContentSize(cc.size(200, 85)) + imageView:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + imageView:getContentSize().height / 4.0)) self._uiLayer:addChild(imageView) end @@ -712,14 +712,14 @@ function UILoadingBarLeftTest:initExtend() local back_label = root:getChildByName("back") back_label:setVisible(false) - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("LoadingBar") alert:setFontName(font_UILoadingBarTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local loadingBar = ccui.LoadingBar:create() @@ -728,7 +728,7 @@ function UILoadingBarLeftTest:initExtend() loadingBar:loadTexture("cocosui/sliderProgress.png") loadingBar:setPercent(0) - loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getSize().height / 4.0)) + loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getContentSize().height / 4.0)) self._uiLayer:addChild(loadingBar) local function update(delta) @@ -838,14 +838,14 @@ function UILoadingBarRightTest:initExtend() local back_label = root:getChildByName("back") back_label:setVisible(false) - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("LoadingBar") alert:setFontName(font_UILoadingBarTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local loadingBar = ccui.LoadingBar:create() @@ -855,7 +855,7 @@ function UILoadingBarRightTest:initExtend() loadingBar:setDirection(ccui.LoadingBarDirection.RIGHT) loadingBar:setPercent(0) - loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getSize().height / 4.0)) + loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getContentSize().height / 4.0)) self._uiLayer:addChild(loadingBar) local function update(delta) @@ -965,14 +965,14 @@ function UILoadingBarLeftScale9Test:initExtend() local back_label = root:getChildByName("back") back_label:setVisible(false) - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("LoadingBar Scale9 Render") alert:setFontName(font_UILoadingBarTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local loadingBar = ccui.LoadingBar:create() @@ -981,10 +981,10 @@ function UILoadingBarLeftScale9Test:initExtend() loadingBar:loadTexture("cocosui/slider_bar_active_9patch.png") loadingBar:setScale9Enabled(true) loadingBar:setCapInsets(cc.rect(0, 0, 0, 0)) - loadingBar:setSize(cc.size(300, 30)) + loadingBar:setContentSize(cc.size(300, 30)) loadingBar:setPercent(0) - loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getSize().height / 4.0)) + loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getContentSize().height / 4.0)) self._uiLayer:addChild(loadingBar) local function update(delta) @@ -1094,14 +1094,14 @@ function UILoadingBarRightScale9Test:initExtend() local back_label = root:getChildByName("back") back_label:setVisible(false) - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("LoadingBar Scale9 Render") alert:setFontName(font_UILoadingBarTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local loadingBar = ccui.LoadingBar:create() @@ -1110,11 +1110,11 @@ function UILoadingBarRightScale9Test:initExtend() loadingBar:loadTexture("cocosui/slider_bar_active_9patch.png") loadingBar:setScale9Enabled(true) loadingBar:setCapInsets(cc.rect(0, 0, 0, 0)) - loadingBar:setSize(cc.size(300, 30)) + loadingBar:setContentSize(cc.size(300, 30)) loadingBar:setDirection(ccui.LoadingBarDirection.LEFT) loadingBar:setPercent(0) - loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getSize().height / 4.0)) + loadingBar:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + loadingBar:getContentSize().height / 4.0)) self._uiLayer:addChild(loadingBar) local function update(delta) @@ -1212,14 +1212,14 @@ end function UILabelAtlasTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("LabelAtlas") alert:setFontName(font_UILabelAtlasTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) @@ -1253,21 +1253,21 @@ end function UILabelBMFontTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("LabelBMFont") alert:setFontName(font_UILabelBMFontTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local labelBMFont = ccui.TextBMFont:create() labelBMFont:setFntFile("cocosui/bitmapFontTest2.fnt") labelBMFont:setString("BMFont") - labelBMFont:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2.0 + labelBMFont:getSize().height / 8.0)) + labelBMFont:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2.0 + labelBMFont:getContentSize().height / 8.0)) self._uiLayer:addChild(labelBMFont) end @@ -1295,21 +1295,21 @@ end function UILabelTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Label") alert:setFontName(font_UILabelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local label = ccui.Text:create() label:setString("Label") label:setFontName("AmericanTypewriter") label:setFontSize(30) - label:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + label:getSize().height / 4)) + label:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + label:getContentSize().height / 4)) self._uiLayer:addChild(label) end @@ -1336,14 +1336,14 @@ end function UITextAreaTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("TextArea") alert:setFontName(font_UITextAreaTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local textArea = ccui.Text:create() @@ -1352,7 +1352,7 @@ function UITextAreaTest:initExtend() textArea:setString("TextArea widget can line wrap") textArea:setFontName("AmericanTypewriter") textArea:setFontSize(32) - textArea:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - textArea:getSize().height / 8)) + textArea:setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - textArea:getContentSize().height / 8)) self._uiLayer:addChild(textArea) end @@ -1380,14 +1380,14 @@ end function UITextFieldTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") self._displayValueLabel:setFontName(font_UITextFieldTest) self._displayValueLabel:setFontSize(32) self._displayValueLabel:setAnchorPoint(cc.p(0.5, -1)) - self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getSize().height * 1.5)) + self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getContentSize().height * 1.5)) self._uiLayer:addChild(self._displayValueLabel) local alert = ccui.Text:create() @@ -1395,7 +1395,7 @@ function UITextFieldTest:initExtend() alert:setFontName(font_UITextFieldTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function textFieldEvent(sender, eventType) @@ -1450,14 +1450,14 @@ end function UITextFieldMaxLengthTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") self._displayValueLabel:setFontName(font_UITextFieldTest) self._displayValueLabel:setFontSize(32) self._displayValueLabel:setAnchorPoint(cc.p(0.5, -1)) - self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getSize().height * 1.5)) + self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getContentSize().height * 1.5)) self._uiLayer:addChild(self._displayValueLabel) local alert = ccui.Text:create() @@ -1465,7 +1465,7 @@ function UITextFieldMaxLengthTest:initExtend() alert:setFontName(font_UITextFieldTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function textFieldEvent(sender, eventType) @@ -1528,14 +1528,14 @@ end function UITextFieldPasswordTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") self._displayValueLabel:setFontName(font_UITextFieldTest) self._displayValueLabel:setFontSize(32) self._displayValueLabel:setAnchorPoint(cc.p(0.5, -1)) - self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getSize().height * 1.5)) + self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getContentSize().height * 1.5)) self._uiLayer:addChild(self._displayValueLabel) local alert = ccui.Text:create() @@ -1543,7 +1543,7 @@ function UITextFieldPasswordTest:initExtend() alert:setFontName(font_UITextFieldTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local function textFieldEvent(sender, eventType) @@ -1600,47 +1600,47 @@ function UIPanelTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) local background = root:getChildByName("background_Panel") local layout = ccui.Layout:create() - layout:setSize(cc.size(280, 150)) - local backgroundSize = background:getSize() + layout:setContentSize(cc.size(280, 150)) + local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(button:getSize().width / 2, layout:getSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(button:getContentSize().width / 2, layout:getContentSize().height - button:getContentSize().height / 2)) layout:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + textButton:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(layout:getSize().width - button_scale9:getSize().width / 2, button_scale9:getSize().height / 2)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(layout:getContentSize().width - button_scale9:getContentSize().width / 2, button_scale9:getContentSize().height / 2)) layout:addChild(button_scale9) end @@ -1668,14 +1668,14 @@ function UIPanelColorTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel color render") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -1684,33 +1684,33 @@ function UIPanelColorTest:initExtend() local layout = ccui.Layout:create() layout:setBackGroundColorType(ccui.LayoutBackGroundColorType.solid) layout:setBackGroundColor(cc.c3b(128, 128, 128)) - layout:setSize(cc.size(280, 150)) + layout:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(button:getSize().width / 2, layout:getSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(button:getContentSize().width / 2, layout:getContentSize().height - button:getContentSize().height / 2)) layout:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + textButton:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(layout:getSize().width - button_scale9:getSize().width / 2, button_scale9:getSize().height / 2)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(layout:getContentSize().width - button_scale9:getContentSize().width / 2, button_scale9:getContentSize().height / 2)) layout:addChild(button_scale9) end @@ -1738,14 +1738,14 @@ function UIPanelGradientTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel color Gradient") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -1754,33 +1754,33 @@ function UIPanelGradientTest:initExtend() local layout = ccui.Layout:create() layout:setBackGroundColorType(ccui.LayoutBackGroundColorType.gradient) layout:setBackGroundColor(cc.c3b(64, 64, 64), cc.c3b(192, 192, 192)) - layout:setSize(cc.size(280, 150)) + layout:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(button:getSize().width / 2, layout:getSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(button:getContentSize().width / 2, layout:getContentSize().height - button:getContentSize().height / 2)) layout:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + textButton:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(layout:getSize().width - button_scale9:getSize().width / 2, button_scale9:getSize().height / 2)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(layout:getContentSize().width - button_scale9:getContentSize().width / 2, button_scale9:getContentSize().height / 2)) layout:addChild(button_scale9) end @@ -1808,14 +1808,14 @@ function UIPanelBackGroundImageTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel background image") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -1824,33 +1824,33 @@ function UIPanelBackGroundImageTest:initExtend() local layout = ccui.Layout:create() layout:setClippingEnabled(true) layout:setBackGroundImage("cocosui/Hello.png") - layout:setSize(cc.size(280, 150)) + layout:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(button:getSize().width / 2, layout:getSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(button:getContentSize().width / 2, layout:getContentSize().height - button:getContentSize().height / 2)) layout:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + textButton:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(layout:getSize().width - button_scale9:getSize().width / 2, button_scale9:getSize().height / 2)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(layout:getContentSize().width - button_scale9:getContentSize().width / 2, button_scale9:getContentSize().height / 2)) layout:addChild(button_scale9) end @@ -1878,14 +1878,14 @@ function UIPanelBackGroundImageScale9Test:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel background image scale9") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -1894,33 +1894,33 @@ function UIPanelBackGroundImageScale9Test:initExtend() local layout = ccui.Layout:create() layout:setBackGroundImageScale9Enabled(true) layout:setBackGroundImage("cocosui/green_edit.png") - layout:setSize(cc.size(280, 150)) + layout:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(button:getSize().width / 2, layout:getSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(button:getContentSize().width / 2, layout:getContentSize().height - button:getContentSize().height / 2)) layout:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + textButton:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(layout:getSize().width - button_scale9:getSize().width / 2, button_scale9:getSize().height / 2)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(layout:getContentSize().width - button_scale9:getContentSize().width / 2, button_scale9:getContentSize().height / 2)) layout:addChild(button_scale9) end @@ -1948,14 +1948,14 @@ function UIPanelLayoutLinearVerticalTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel Layout Linear Vertical") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -1963,12 +1963,12 @@ function UIPanelLayoutLinearVerticalTest:initExtend() local layout = ccui.Layout:create() layout:setLayoutType(ccui.LayoutType.VERTICAL) - layout:setSize(cc.size(280, 150)) + layout:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() @@ -1998,7 +1998,7 @@ function UIPanelLayoutLinearVerticalTest:initExtend() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) layout:addChild(button_scale9) local lp3 = ccui.LinearLayoutParameter:create() @@ -2031,14 +2031,14 @@ function UIPanelLayoutLinearHorizontalTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() alert:setString("Panel Layout Linear Horizontal") alert:setFontName(font_UIPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -2047,12 +2047,12 @@ function UIPanelLayoutLinearHorizontalTest:initExtend() local layout = ccui.Layout:create() layout:setLayoutType(ccui.LayoutType.HORIZONTAL) layout:setClippingEnabled(true) - layout:setSize(cc.size(280, 150)) + layout:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() layout:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - layout:getSize().width) / 2, + (backgroundSize.width - layout:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - layout:getSize().height) / 2)) + (backgroundSize.height - layout:getContentSize().height) / 2)) self._uiLayer:addChild(layout) local button = ccui.Button:create() @@ -2082,7 +2082,7 @@ function UIPanelLayoutLinearHorizontalTest:initExtend() button_scale9:setTouchEnabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") button_scale9:setScale9Enabled(true) - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) layout:addChild(button_scale9) local lp3 = ccui.LinearLayoutParameter:create() @@ -2116,7 +2116,7 @@ function UIScrollViewVerticalTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move by vertical direction") @@ -2131,7 +2131,7 @@ function UIScrollViewVerticalTest:initExtend() alert:setFontName(font_UIScrollViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -2139,44 +2139,44 @@ function UIScrollViewVerticalTest:initExtend() local scrollView = ccui.ScrollView:create() scrollView:setTouchEnabled(true) - scrollView:setSize(cc.size(280, 150)) + scrollView:setContentSize(cc.size(280, 150)) local backgroundSize = background:getContentSize() scrollView:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - scrollView:getSize().width) / 2, + (backgroundSize.width - scrollView:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - scrollView:getSize().height) / 2)) + (backgroundSize.height - scrollView:getContentSize().height) / 2)) self._uiLayer:addChild(scrollView) local imageView = ccui.ImageView:create() imageView:loadTexture("cocosui/ccicon.png") - local innerWidth = scrollView:getSize().width - local innerHeight = scrollView:getSize().height + imageView:getSize().height + local innerWidth = scrollView:getContentSize().width + local innerHeight = scrollView:getContentSize().height + imageView:getContentSize().height scrollView:setInnerContainerSize(cc.size(innerWidth, innerHeight)) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(innerWidth / 2, scrollView:getInnerContainerSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(innerWidth / 2, scrollView:getInnerContainerSize().height - button:getContentSize().height / 2)) scrollView:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(innerWidth / 2, button:getBottomBoundary() - button:getSize().height)) + textButton:setPosition(cc.p(innerWidth / 2, button:getBottomBoundary() - button:getContentSize().height)) scrollView:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:setScale9Enabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(innerWidth / 2, textButton:getBottomBoundary() - textButton:getSize().height)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(innerWidth / 2, textButton:getBottomBoundary() - textButton:getContentSize().height)) scrollView:addChild(button_scale9) - imageView:setPosition(cc.p(innerWidth / 2, imageView:getSize().height / 2)) + imageView:setPosition(cc.p(innerWidth / 2, imageView:getContentSize().height / 2)) scrollView:addChild(imageView) end @@ -2205,7 +2205,7 @@ function UIScrollViewHorizontalTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move by horizontal direction") @@ -2220,7 +2220,7 @@ function UIScrollViewHorizontalTest:initExtend() alert:setFontName(font_UIScrollViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -2230,49 +2230,49 @@ function UIScrollViewHorizontalTest:initExtend() scrollView:setBounceEnabled(true) scrollView:setDirection(ccui.ScrollViewDir.horizontal) scrollView:setTouchEnabled(true) - scrollView:setSize(cc.size(280, 150)) - scrollView:setInnerContainerSize(scrollView:getSize()) + scrollView:setContentSize(cc.size(280, 150)) + scrollView:setInnerContainerSize(scrollView:getContentSize()) local backgroundSize = background:getContentSize() scrollView:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - scrollView:getSize().width) / 2, + (backgroundSize.width - scrollView:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - scrollView:getSize().height) / 2)) + (backgroundSize.height - scrollView:getContentSize().height) / 2)) self._uiLayer:addChild(scrollView) local imageView = ccui.ImageView:create() imageView:loadTexture("cocosui/ccicon.png") - local innerWidth = scrollView:getSize().width + imageView:getSize().width - local innerHeight = scrollView:getSize().height + local innerWidth = scrollView:getContentSize().width + imageView:getContentSize().width + local innerHeight = scrollView:getContentSize().height scrollView:setInnerContainerSize(cc.size(innerWidth, innerHeight)) local button = ccui.Button:create() button:setTouchEnabled(true) button:loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "") - button:setPosition(cc.p(button:getSize().width / 2, - scrollView:getInnerContainerSize().height - button:getSize().height / 2)) + button:setPosition(cc.p(button:getContentSize().width / 2, + scrollView:getInnerContainerSize().height - button:getContentSize().height / 2)) scrollView:addChild(button) local textButton = ccui.Button:create() textButton:setTouchEnabled(true) textButton:loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "") textButton:setTitleText("Text Button") - textButton:setPosition(cc.p(button:getRightBoundary() + button:getSize().width / 2, - button:getBottomBoundary() - button:getSize().height / 2)) + textButton:setPosition(cc.p(button:getRightBoundary() + button:getContentSize().width / 2, + button:getBottomBoundary() - button:getContentSize().height / 2)) scrollView:addChild(textButton) local button_scale9 = ccui.Button:create() button_scale9:setTouchEnabled(true) button_scale9:setScale9Enabled(true) button_scale9:loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "") - button_scale9:setSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) - button_scale9:setPosition(cc.p(textButton:getRightBoundary() + textButton:getSize().width / 2, - textButton:getBottomBoundary() - textButton:getSize().height / 2)) + button_scale9:setContentSize(cc.size(100, button_scale9:getVirtualRendererSize().height)) + button_scale9:setPosition(cc.p(textButton:getRightBoundary() + textButton:getContentSize().width / 2, + textButton:getBottomBoundary() - textButton:getContentSize().height / 2)) scrollView:addChild(button_scale9) - imageView:setPosition(cc.p(innerWidth - imageView:getSize().width / 2, - button_scale9:getBottomBoundary() - button_scale9:getSize().height / 2)) + imageView:setPosition(cc.p(innerWidth - imageView:getContentSize().width / 2, + button_scale9:getBottomBoundary() - button_scale9:getContentSize().height / 2)) scrollView:addChild(imageView) end @@ -2301,7 +2301,7 @@ function UIPageViewTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move by horizontal direction") @@ -2316,7 +2316,7 @@ function UIPageViewTest:initExtend() alert:setFontName(font_UIPageViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -2324,23 +2324,23 @@ function UIPageViewTest:initExtend() local pageView = ccui.PageView:create() pageView:setTouchEnabled(true) - pageView:setSize(cc.size(240, 130)) + pageView:setContentSize(cc.size(240, 130)) local backgroundSize = background:getContentSize() pageView:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2 + - (backgroundSize.width - pageView:getSize().width) / 2, + (backgroundSize.width - pageView:getContentSize().width) / 2, (widgetSize.height - backgroundSize.height) / 2 + - (backgroundSize.height - pageView:getSize().height) / 2)) + (backgroundSize.height - pageView:getContentSize().height) / 2)) for i = 1 , 3 do local layout = ccui.Layout:create() - layout:setSize(cc.size(240, 130)) + layout:setContentSize(cc.size(240, 130)) local imageView = ccui.ImageView:create() imageView:setTouchEnabled(true) imageView:setScale9Enabled(true) imageView:loadTexture("cocosui/scrollviewbg.png") - imageView:setSize(cc.size(240, 130)) - imageView:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + imageView:setContentSize(cc.size(240, 130)) + imageView:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(imageView) local label = ccui.Text:create() @@ -2349,7 +2349,7 @@ function UIPageViewTest:initExtend() label:setFontName(font_UIPageViewTest) label:setFontSize(30) label:setColor(cc.c3b(192, 192, 192)) - label:setPosition(cc.p(layout:getSize().width / 2, layout:getSize().height / 2)) + label:setPosition(cc.p(layout:getContentSize().width / 2, layout:getContentSize().height / 2)) layout:addChild(label) pageView:addPage(layout) @@ -2395,7 +2395,7 @@ function UIListViewVerticalTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move by vertical direction") @@ -2410,7 +2410,7 @@ function UIListViewVerticalTest:initExtend() alert:setFontName(font_UIListViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local root = self._uiLayer:getChildByTag(81) @@ -2443,11 +2443,11 @@ function UIListViewVerticalTest:initExtend() listView:setBounceEnabled(true) listView:setBackGroundImage("cocosui/green_edit.png") listView:setBackGroundImageScale9Enabled(true) - listView:setSize(cc.size(240, 130)) + listView:setContentSize(cc.size(240, 130)) listView:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + - (backgroundSize.width - listView:getSize().width) / 2.0, + (backgroundSize.width - listView:getContentSize().width) / 2.0, (widgetSize.height - backgroundSize.height) / 2.0 + - (backgroundSize.height - listView:getSize().height) / 2.0)) + (backgroundSize.height - listView:getContentSize().height) / 2.0)) listView:addEventListener(listViewEvent) listView:addScrollViewEventListener(scrollViewEvent) self._uiLayer:addChild(listView) @@ -2459,8 +2459,8 @@ function UIListViewVerticalTest:initExtend() local default_item = ccui.Layout:create() default_item:setTouchEnabled(true) - default_item:setSize(default_button:getSize()) - default_button:setPosition(cc.p(default_item:getSize().width / 2.0, default_item:getSize().height / 2.0)) + default_item:setContentSize(default_button:getContentSize()) + default_button:setPosition(cc.p(default_item:getContentSize().width / 2.0, default_item:getContentSize().height / 2.0)) default_item:addChild(default_button) --set model @@ -2487,11 +2487,11 @@ function UIListViewVerticalTest:initExtend() local custom_button = ccui.Button:create("cocosui/button.png", "cocosui/buttonHighlighted.png") custom_button:setName("Title Button") custom_button:setScale9Enabled(true) - custom_button:setSize(default_button:getSize()) + custom_button:setContentSize(default_button:getContentSize()) local custom_item = ccui.Layout:create() - custom_item:setSize(custom_button:getSize()) - custom_button:setPosition(cc.p(custom_item:getSize().width / 2.0, custom_item:getSize().height / 2.0)) + custom_item:setContentSize(custom_button:getContentSize()) + custom_button:setPosition(cc.p(custom_item:getContentSize().width / 2.0, custom_item:getContentSize().height / 2.0)) custom_item:addChild(custom_button) listView:addChild(custom_item) @@ -2504,11 +2504,11 @@ function UIListViewVerticalTest:initExtend() local custom_button = ccui.Button:create("cocosui/button.png", "cocosui/buttonHighlighted.png") custom_button:setName("Title Button") custom_button:setScale9Enabled(true) - custom_button:setSize(default_button:getSize()) + custom_button:setContentSize(default_button:getContentSize()) local custom_item = ccui.Layout:create() - custom_item:setSize(custom_button:getSize()) - custom_button:setPosition(cc.p(custom_item:getSize().width / 2.0, custom_item:getSize().height / 2.0)) + custom_item:setContentSize(custom_button:getContentSize()) + custom_button:setPosition(cc.p(custom_item:getContentSize().width / 2.0, custom_item:getContentSize().height / 2.0)) custom_item:addChild(custom_button) custom_item:setTag(1) @@ -2563,7 +2563,7 @@ function UIListViewHorizontalTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("Move by vertical direction") @@ -2578,7 +2578,7 @@ function UIListViewHorizontalTest:initExtend() alert:setFontName(font_UIListViewTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) @@ -2605,11 +2605,11 @@ function UIListViewHorizontalTest:initExtend() listView:setBounceEnabled(true) listView:setBackGroundImage("cocosui/green_edit.png") listView:setBackGroundImageScale9Enabled(true) - listView:setSize(cc.size(240, 130)) + listView:setContentSize(cc.size(240, 130)) listView:setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + - (backgroundSize.width - listView:getSize().width) / 2.0, + (backgroundSize.width - listView:getContentSize().width) / 2.0, (widgetSize.height - backgroundSize.height) / 2.0 + - (backgroundSize.height - listView:getSize().height) / 2.0)) + (backgroundSize.height - listView:getContentSize().height) / 2.0)) listView:addEventListener(listViewEvent) self._uiLayer:addChild(listView) @@ -2620,8 +2620,8 @@ function UIListViewHorizontalTest:initExtend() local default_item = ccui.Layout:create() default_item:setTouchEnabled(true) - default_item:setSize(default_button:getSize()) - default_button:setPosition(cc.p(default_item:getSize().width / 2.0, default_item:getSize().height / 2.0)) + default_item:setContentSize(default_button:getContentSize()) + default_button:setPosition(cc.p(default_item:getContentSize().width / 2.0, default_item:getContentSize().height / 2.0)) default_item:addChild(default_button) --set model @@ -2642,11 +2642,11 @@ function UIListViewHorizontalTest:initExtend() local custom_button = ccui.Button:create("cocosui/button.png", "cocosui/buttonHighlighted.png") custom_button:setName("Title Button") custom_button:setScale9Enabled(true) - custom_button:setSize(default_button:getSize()) + custom_button:setContentSize(default_button:getContentSize()) local custom_item = ccui.Layout:create() - custom_item:setSize(custom_button:getSize()) - custom_button:setPosition(cc.p(custom_item:getSize().width / 2.0, custom_item:getSize().height / 2.0)) + custom_item:setContentSize(custom_button:getContentSize()) + custom_button:setPosition(cc.p(custom_item:getContentSize().width / 2.0, custom_item:getContentSize().height / 2.0)) custom_item:addChild(custom_button) listView:pushBackCustomItem(custom_item) @@ -2659,11 +2659,11 @@ function UIListViewHorizontalTest:initExtend() local custom_button = ccui.Button:create("cocosui/button.png", "cocosui/buttonHighlighted.png") custom_button:setName("Title Button") custom_button:setScale9Enabled(true) - custom_button:setSize(default_button:getSize()) + custom_button:setContentSize(default_button:getContentSize()) local custom_item = ccui.Layout:create() - custom_item:setSize(custom_button:getSize()) - custom_button:setPosition(cc.p(custom_item:getSize().width / 2.0, custom_item:getSize().height / 2.0)) + custom_item:setContentSize(custom_button:getContentSize()) + custom_button:setPosition(cc.p(custom_item:getContentSize().width / 2.0, custom_item:getContentSize().height / 2.0)) custom_item:addChild(custom_button) listView:insertCustomItem(custom_item, items_count) @@ -2719,14 +2719,14 @@ function UIDragPanelTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") self._displayValueLabel:setFontName(font_UIDragPanelTest) self._displayValueLabel:setFontSize(32) self._displayValueLabel:setAnchorPoint(cc.p(0.5, -1)) - self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getSize().height * 1.5)) + self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getContentSize().height * 1.5)) self._uiLayer:addChild(self._displayValueLabel) local alert = ccui.Text:create() @@ -2734,7 +2734,7 @@ function UIDragPanelTest:initExtend() alert:setFontName(font_UIDragPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local sc = ccui.ScrollView:create() @@ -2742,7 +2742,7 @@ function UIDragPanelTest:initExtend() sc:setBackGroundColorType(ccui.LayoutBackGroundColorType.solid) sc:setDirection(ccui.ScrollViewDir.both) sc:setInnerContainerSize(cc.size(480, 320)) - sc:setSize(cc.size(100,100)) + sc:setContentSize(cc.size(100,100)) sc:setPosition(cc.p(100,100)) sc:scrollToPercentBothDirection(cc.p(50, 50), 1, true) local iv = ccui.ImageView:create() @@ -2778,14 +2778,14 @@ function UIDragPanelBounceTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("No Event") self._displayValueLabel:setFontName(font_UIDragPanelTest) self._displayValueLabel:setFontSize(32) self._displayValueLabel:setAnchorPoint(cc.p(0.5, -1)) - self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getSize().height * 1.5)) + self._displayValueLabel:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + self._displayValueLabel:getContentSize().height * 1.5)) self._uiLayer:addChild(self._displayValueLabel) @@ -2794,7 +2794,7 @@ function UIDragPanelBounceTest:initExtend() alert:setFontName(font_UIDragPanelTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 2.925)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 2.925)) self._uiLayer:addChild(alert) local sc = ccui.ScrollView:create() @@ -2803,7 +2803,7 @@ function UIDragPanelBounceTest:initExtend() sc:setBounceEnabled(true) sc:setDirection(ccui.ScrollViewDir.both) sc:setInnerContainerSize(cc.size(480, 320)) - sc:setSize(cc.size(100,100)) + sc:setContentSize(cc.size(100,100)) sc:setPosition(cc.p(100,100)) sc:scrollToPercentBothDirection(cc.p(50, 50), 1, true) local iv = ccui.ImageView:create() @@ -2838,7 +2838,7 @@ function UINodeContainerTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() self._displayValueLabel = ccui.Text:create() self._displayValueLabel:setString("NodeContainer Add CCNode") @@ -2853,7 +2853,7 @@ function UINodeContainerTest:initExtend() alert:setFontName(font_UINodeContainerTest) alert:setFontSize(30) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 1.75)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 1.75)) self._uiLayer:addChild(alert) local nodeContainer = ccui.Widget:create() @@ -2889,12 +2889,12 @@ function UIRichTextTest:initExtend() self:init() - local widgetSize = self._widget:getSize() + local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create("RichText", "fonts/Marker Felt.ttf", 30) alert:setFontName(font_UINodeContainerTest) alert:setColor(cc.c3b(159, 168, 176)) - alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getSize().height * 3.125)) + alert:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert:getContentSize().height * 3.125)) self._widget:addChild(alert) @@ -2902,7 +2902,7 @@ function UIRichTextTest:initExtend() if eventType == ccui.TouchEventType.ended then if self._richText:isIgnoreContentAdaptWithSize() then self._richText:ignoreContentAdaptWithSize(false) - self._richText:setSize(cc.size(100, 100)) + self._richText:setContentSize(cc.size(100, 100)) else self._richText:ignoreContentAdaptWithSize(true) end @@ -2912,14 +2912,14 @@ function UIRichTextTest:initExtend() local button = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") button:setTouchEnabled(true) button:setTitleText("switch") - button:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + button:getSize().height * 2.5)) + button:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + button:getContentSize().height * 2.5)) button:addTouchEventListener(touchEvent) button:setLocalZOrder(10) self._widget:addChild(button) self._richText = ccui.RichText:create() self._richText:ignoreContentAdaptWithSize(false) - self._richText:setSize(cc.size(100, 100)) + self._richText:setContentSize(cc.size(100, 100)) local re1 = ccui.RichElementText:create(1, cc.c3b(255, 255, 255), 255, "This color is white. ", "Helvetica", 10) local re2 = ccui.RichElementText:create(2, cc.c3b(255, 255, 0), 255, "And this is yellow. ", "Helvetica", 10) @@ -2960,8 +2960,896 @@ function UIRichTextTest.create() return scene end +local UIFocusTestHorizontal = class("UIFocusTestHorizontal",UIScene) +function UIFocusTestHorizontal.extend( target ) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, UIFocusTestHorizontal) + return target +end + +function UIFocusTestHorizontal:initExtend() + self:init() + + local root = self._uiLayer:getChildByTag(81) + local background = root:getChildByName("background_Panel") + background:removeFromParent(true) + + local function onLeftKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_LEFT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onRightKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_RIGHT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onUpKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_UP, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onDownKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_DOWN, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + self._dpadMenu = cc.Menu:create() + local winSize = cc.Director:getInstance():getVisibleSize() + + local leftItem = cc.MenuItemFont:create("Left") + leftItem:setPosition(cc.p(winSize.width - 100, winSize.height/2)) + leftItem:registerScriptTapHandler(onLeftKeyPressed) + self._dpadMenu:addChild(leftItem) + + local rightItem = cc.MenuItemFont:create("Right") + rightItem:setPosition(cc.p(winSize.width - 30, winSize.height/2)) + rightItem:registerScriptTapHandler(onRightKeyPressed) + self._dpadMenu:addChild(rightItem) + + local upItem = cc.MenuItemFont:create("Up") + upItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 + 50)) + upItem:registerScriptTapHandler(onUpKeyPressed) + self._dpadMenu:addChild(upItem) + + local downItem = cc.MenuItemFont:create("Down") + downItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 - 50)) + downItem:registerScriptTapHandler(onDownKeyPressed) + self._dpadMenu:addChild(downItem) + self._dpadMenu:setPosition(cc.p(0, 0)) + self._uiLayer:addChild(self._dpadMenu) + + ccui.Widget:enableDpadNavigation(true) + + local function onFocusChanged(widgetLostFocus,widgetGetFocus) + if nil ~= widgetGetFocus and widgetGetFocus:isFocusEnabled() then + widgetGetFocus:setColor(cc.c3b(255, 0, 0)) + end + + if nil ~= widgetLostFocus and widgetLostFocus:isFocusEnabled() then + widgetLostFocus:setColor(cc.c3b(255, 255, 255)) + end + + if nil ~= widgetLostFocus and nil ~= widgetGetFocus then + print(string.format("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus:getTag(), widgetLostFocus:getTag())) + end + end + + local eventListener = cc.EventListenerFocus:create() + eventListener:registerScriptHandler(onFocusChanged) + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithFixedPriority(eventListener, 1) + + local winSize = cc.Director:getInstance():getVisibleSize() + self._horizontalLayout = ccui.HBox:create() + self._horizontalLayout:setPosition(cc.p(20, winSize.height / 2 + 40)) + self._uiLayer:addChild(self._horizontalLayout) + + self._horizontalLayout:setFocused(true) + self._horizontalLayout:setLoopFocus(true) + self._horizontalLayout:setTag(100) + self._firstFocusedWidget = self._horizontalLayout + + local function onImageViewClicked(sender, eventType) + if eventType == ccui.TouchEventType.ended then + local w = sender + if w:isFocusEnabled() then + w:setFocusEnabled(false) + w:setColor(cc.c3b(255, 255, 0)) + else + w:setFocusEnabled(true) + w:setColor(cc.c3b(255, 255, 255)) + end + end + end + + local count = 3 + for i = 1, count do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setTouchEnabled(true) + imageView:setTag(i) + imageView:addTouchEventListener(onImageViewClicked) + self._horizontalLayout:addChild(imageView) + end + + self._loopText = ccui.Text:create("loop enabled", "Airal", 20) + self._loopText:setPosition(cc.p(winSize.width/2, winSize.height - 50)) + self._loopText:setColor(cc.c3b(255, 0 ,0)) + self:addChild(self._loopText) + + local function toggleFocusLoop(sender, eventType) + if eventType == ccui.TouchEventType.ended then + self._horizontalLayout:setLoopFocus(not self._horizontalLayout:isLoopFocus()) + if self._horizontalLayout:isLoopFocus() then + self._loopText:setString("loop enabled") + else + self._loopText:setString("loop disabled") + end + end + end + + local btn = ccui.Button:create("cocosui/switch-mask.png") + btn:setTitleText("Toggle Loop") + btn:setPosition(cc.p(60, winSize.height - 50)) + btn:setTitleColor(cc.c3b(0, 255, 0)) + btn:addTouchEventListener(toggleFocusLoop) + self:addChild(btn) +end + +function UIFocusTestHorizontal.create() + local scene = cc.Scene:create() + local layer = UIFocusTestHorizontal.extend(cc.Layer:create()) + layer:initExtend() + scene:addChild(layer) + return scene +end + +local UIFocusTestVertical = class("UIFocusTestVertical",UIScene) + +function UIFocusTestVertical.extend( target ) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, UIFocusTestVertical) + return target +end + +function UIFocusTestVertical:initExtend() + self:init() + + local root = self._uiLayer:getChildByTag(81) + local background = root:getChildByName("background_Panel") + background:removeFromParent(true) + + local function onLeftKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_LEFT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onRightKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_RIGHT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onUpKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_UP, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onDownKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_DOWN, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + self._dpadMenu = cc.Menu:create() + local winSize = cc.Director:getInstance():getVisibleSize() + + local leftItem = cc.MenuItemFont:create("Left") + leftItem:setPosition(cc.p(winSize.width - 100, winSize.height/2)) + leftItem:registerScriptTapHandler(onLeftKeyPressed) + self._dpadMenu:addChild(leftItem) + + local rightItem = cc.MenuItemFont:create("Right") + rightItem:setPosition(cc.p(winSize.width - 30, winSize.height/2)) + rightItem:registerScriptTapHandler(onRightKeyPressed) + self._dpadMenu:addChild(rightItem) + + local upItem = cc.MenuItemFont:create("Up") + upItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 + 50)) + upItem:registerScriptTapHandler(onUpKeyPressed) + self._dpadMenu:addChild(upItem) + + local downItem = cc.MenuItemFont:create("Down") + downItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 - 50)) + downItem:registerScriptTapHandler(onDownKeyPressed) + self._dpadMenu:addChild(downItem) + self._dpadMenu:setPosition(cc.p(0, 0)) + self._uiLayer:addChild(self._dpadMenu) + + ccui.Widget:enableDpadNavigation(true) + + local function onFocusChanged(widgetLostFocus,widgetGetFocus) + if nil ~= widgetGetFocus and widgetGetFocus:isFocusEnabled() then + widgetGetFocus:setColor(cc.c3b(255, 0, 0)) + end + + if nil ~= widgetLostFocus and widgetLostFocus:isFocusEnabled() then + widgetLostFocus:setColor(cc.c3b(255, 255, 255)) + end + + if nil ~= widgetLostFocus and nil ~= widgetGetFocus then + print(string.format("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus:getTag(), widgetLostFocus:getTag())) + end + end + + local eventListener = cc.EventListenerFocus:create() + eventListener:registerScriptHandler(onFocusChanged) + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithFixedPriority(eventListener, 1) + + local winSize = cc.Director:getInstance():getVisibleSize() + self._verticalLayout = ccui.VBox:create() + self._verticalLayout:setPosition(cc.p(winSize.width/2 - 100, winSize.height - 70)) + self._uiLayer:addChild(self._verticalLayout) + + self._verticalLayout:setFocused(true) + self._verticalLayout:setLoopFocus(true) + self._verticalLayout:setTag(100) + self._verticalLayout:setScale(0.5) + self._firstFocusedWidget = self._verticalLayout + + local function onImageViewClicked(sender, eventType) + if eventType == ccui.TouchEventType.ended then + local w = sender + if w:isFocusEnabled() then + w:setFocusEnabled(false) + w:setColor(cc.c3b(255, 255, 0)) + else + w:setFocusEnabled(true) + w:setColor(cc.c3b(255, 255, 255)) + end + end + end + + local count = 3 + for i = 1, count do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setTouchEnabled(true) + imageView:setTag(i) + imageView:addTouchEventListener(onImageViewClicked) + self._verticalLayout:addChild(imageView) + end + + self._loopText = ccui.Text:create("loop enabled", "Airal", 20) + self._loopText:setPosition(cc.p(winSize.width/2, winSize.height - 50)) + self._loopText:setColor(cc.c3b(255, 0 ,0)) + self:addChild(self._loopText) + + local function toggleFocusLoop(sender, eventType) + if eventType == ccui.TouchEventType.ended then + self._verticalLayout:setLoopFocus(not self._verticalLayout:isLoopFocus()) + if self._verticalLayout:isLoopFocus() then + self._loopText:setString("loop enabled") + else + self._loopText:setString("loop disabled") + end + end + end + + local btn = ccui.Button:create("cocosui/switch-mask.png") + btn:setTitleText("Toggle Loop") + btn:setPosition(cc.p(60, winSize.height - 50)) + btn:setTitleColor(cc.c3b(0, 255, 0)) + btn:addTouchEventListener(toggleFocusLoop) + self:addChild(btn) +end + +function UIFocusTestVertical.create() + local scene = cc.Scene:create() + local layer = UIFocusTestVertical.extend(cc.Layer:create()) + layer:initExtend() + scene:addChild(layer) + return scene +end + +local UIFocusTestNestedLayout1 = class("UIFocusTestNestedLayout1",UIScene) + +function UIFocusTestNestedLayout1.extend( target ) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, UIFocusTestNestedLayout1) + return target +end + +function UIFocusTestNestedLayout1:initExtend() + self:init() + + local root = self._uiLayer:getChildByTag(81) + local background = root:getChildByName("background_Panel") + background:removeFromParent(true) + + local function onLeftKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_LEFT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onRightKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_RIGHT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onUpKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_UP, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onDownKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_DOWN, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + self._dpadMenu = cc.Menu:create() + local winSize = cc.Director:getInstance():getVisibleSize() + + local leftItem = cc.MenuItemFont:create("Left") + leftItem:setPosition(cc.p(winSize.width - 100, winSize.height/2)) + leftItem:registerScriptTapHandler(onLeftKeyPressed) + self._dpadMenu:addChild(leftItem) + + local rightItem = cc.MenuItemFont:create("Right") + rightItem:setPosition(cc.p(winSize.width - 30, winSize.height/2)) + rightItem:registerScriptTapHandler(onRightKeyPressed) + self._dpadMenu:addChild(rightItem) + + local upItem = cc.MenuItemFont:create("Up") + upItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 + 50)) + upItem:registerScriptTapHandler(onUpKeyPressed) + self._dpadMenu:addChild(upItem) + + local downItem = cc.MenuItemFont:create("Down") + downItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 - 50)) + downItem:registerScriptTapHandler(onDownKeyPressed) + self._dpadMenu:addChild(downItem) + self._dpadMenu:setPosition(cc.p(0, 0)) + self._uiLayer:addChild(self._dpadMenu) + + ccui.Widget:enableDpadNavigation(true) + + local function onFocusChanged(widgetLostFocus,widgetGetFocus) + if nil ~= widgetGetFocus and widgetGetFocus:isFocusEnabled() then + widgetGetFocus:setColor(cc.c3b(255, 0, 0)) + end + + if nil ~= widgetLostFocus and widgetLostFocus:isFocusEnabled() then + widgetLostFocus:setColor(cc.c3b(255, 255, 255)) + end + + if nil ~= widgetLostFocus and nil ~= widgetGetFocus then + print(string.format("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus:getTag(), widgetLostFocus:getTag())) + end + end + + local eventListener = cc.EventListenerFocus:create() + eventListener:registerScriptHandler(onFocusChanged) + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithFixedPriority(eventListener, 1) + + local winSize = cc.Director:getInstance():getVisibleSize() + + self._verticalLayout = ccui.VBox:create() + self._verticalLayout:setPosition(cc.p(winSize.width/2 - 80, winSize.height - 70)) + self._uiLayer:addChild(self._verticalLayout) + self._verticalLayout:setScale(0.5) + + self._verticalLayout:setFocused(true) + self._verticalLayout:setLoopFocus(true) + self._verticalLayout:setTag(100) + self._firstFocusedWidget = self._verticalLayout + + local function onImageViewClicked(sender, eventType) + if eventType == ccui.TouchEventType.ended then + local w = sender + if w:isFocusEnabled() then + w:setFocusEnabled(false) + w:setColor(cc.c3b(255, 255, 0)) + else + w:setFocusEnabled(true) + w:setColor(cc.c3b(255, 255, 255)) + end + end + end + + local count1 = 1 + for i = 1, count1 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setAnchorPoint(cc.p(0, 0)) + imageView:setTouchEnabled(true) + imageView:setScaleX(2.5) + imageView:setTag(i - 1 + count1) + imageView:addTouchEventListener(onImageViewClicked) + self._verticalLayout:addChild(imageView) + end + + local hbox = ccui.HBox:create() + hbox:setScale(0.8) + hbox:setTag(101) + self._verticalLayout:addChild(hbox) + + local count2 = 2 + for i = 1, count2 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setAnchorPoint(cc.p(0, 1)) + imageView:setScaleY(2.0) + imageView:setTouchEnabled(true) + imageView:setTag(i - 1 + count1 + count2) + imageView:addTouchEventListener(onImageViewClicked) + hbox:addChild(imageView) + end + + local innerVBox = ccui.VBox:create() + hbox:addChild(innerVBox) + innerVBox:setTag(102) + + local count3 = 2 + for i = 1, count3 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setTouchEnabled(true) + imageView:setTag(i - 1 + count1 + count2 + count3) + imageView:addTouchEventListener(onImageViewClicked) + innerVBox:addChild(imageView) + end + + self._loopText = ccui.Text:create("loop enabled", "Airal", 20) + self._loopText:setPosition(cc.p(winSize.width/2, winSize.height - 50)) + self._loopText:setColor(cc.c3b(255, 0 ,0)) + self:addChild(self._loopText) + + local function toggleFocusLoop(sender, eventType) + if eventType == ccui.TouchEventType.ended then + self._verticalLayout:setLoopFocus(not self._verticalLayout:isLoopFocus()) + if self._verticalLayout:isLoopFocus() then + self._loopText:setString("loop enabled") + else + self._loopText:setString("loop disabled") + end + end + end + + local btn = ccui.Button:create("cocosui/switch-mask.png") + btn:setTitleText("Toggle Loop") + btn:setPosition(cc.p(60, winSize.height - 50)) + btn:setTitleColor(cc.c3b(0, 255, 0)) + btn:addTouchEventListener(toggleFocusLoop) + self:addChild(btn) +end + +function UIFocusTestNestedLayout1.create() + local scene = cc.Scene:create() + local layer = UIFocusTestNestedLayout1.extend(cc.Layer:create()) + layer:initExtend() + scene:addChild(layer) + return scene +end + +local UIFocusTestNestedLayout2 = class("UIFocusTestNestedLayout2",UIScene) + +function UIFocusTestNestedLayout2.extend( target ) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, UIFocusTestNestedLayout2) + return target +end + +function UIFocusTestNestedLayout2:initExtend() + self:init() + + local root = self._uiLayer:getChildByTag(81) + local background = root:getChildByName("background_Panel") + background:removeFromParent(true) + + local function onLeftKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_LEFT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onRightKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_RIGHT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onUpKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_UP, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onDownKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_DOWN, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + self._dpadMenu = cc.Menu:create() + local winSize = cc.Director:getInstance():getVisibleSize() + + local leftItem = cc.MenuItemFont:create("Left") + leftItem:setPosition(cc.p(winSize.width - 100, winSize.height/2)) + leftItem:registerScriptTapHandler(onLeftKeyPressed) + self._dpadMenu:addChild(leftItem) + + local rightItem = cc.MenuItemFont:create("Right") + rightItem:setPosition(cc.p(winSize.width - 30, winSize.height/2)) + rightItem:registerScriptTapHandler(onRightKeyPressed) + self._dpadMenu:addChild(rightItem) + + local upItem = cc.MenuItemFont:create("Up") + upItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 + 50)) + upItem:registerScriptTapHandler(onUpKeyPressed) + self._dpadMenu:addChild(upItem) + + local downItem = cc.MenuItemFont:create("Down") + downItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 - 50)) + downItem:registerScriptTapHandler(onDownKeyPressed) + self._dpadMenu:addChild(downItem) + self._dpadMenu:setPosition(cc.p(0, 0)) + self._uiLayer:addChild(self._dpadMenu) + + ccui.Widget:enableDpadNavigation(true) + + local function onFocusChanged(widgetLostFocus,widgetGetFocus) + if nil ~= widgetGetFocus and widgetGetFocus:isFocusEnabled() then + widgetGetFocus:setColor(cc.c3b(255, 0, 0)) + end + + if nil ~= widgetLostFocus and widgetLostFocus:isFocusEnabled() then + widgetLostFocus:setColor(cc.c3b(255, 255, 255)) + end + + if nil ~= widgetLostFocus and nil ~= widgetGetFocus then + print(string.format("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus:getTag(), widgetLostFocus:getTag())) + end + end + + local eventListener = cc.EventListenerFocus:create() + eventListener:registerScriptHandler(onFocusChanged) + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithFixedPriority(eventListener, 1) + + local winSize = cc.Director:getInstance():getVisibleSize() + + self._horizontalLayout = ccui.HBox:create() + self._horizontalLayout:setPosition(cc.p(winSize.width/2 - 200, winSize.height - 70)) + self._uiLayer:addChild(self._horizontalLayout) + self._horizontalLayout:setScale(0.6) + + self._horizontalLayout:setFocused(true) + self._horizontalLayout:setLoopFocus(true) + self._horizontalLayout:setTag(100) + self._firstFocusedWidget = self._horizontalLayout + + local function onImageViewClicked(sender, eventType) + if eventType == ccui.TouchEventType.ended then + local w = sender + if w:isFocusEnabled() then + w:setFocusEnabled(false) + w:setColor(cc.c3b(255, 255, 0)) + else + w:setFocusEnabled(true) + w:setColor(cc.c3b(255, 255, 255)) + end + end + end + + local count1 = 2 + for i = 1, count1 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setAnchorPoint(cc.p(0, 1)) + imageView:setTouchEnabled(true) + imageView:setScaleY(2.4) + imageView:setTag(i - 1 + count1) + imageView:addTouchEventListener(onImageViewClicked) + self._horizontalLayout:addChild(imageView) + end + + local vbox = ccui.VBox:create() + vbox:setScale(0.8) + vbox:setTag(101) + self._horizontalLayout:addChild(vbox) + + local count2 = 2 + for i = 1, count2 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setAnchorPoint(cc.p(0, 1)) + imageView:setScaleX(2.0) + imageView:setTouchEnabled(true) + imageView:setTag(i - 1 + count1 + count2) + imageView:addTouchEventListener(onImageViewClicked) + vbox:addChild(imageView) + end + + local innerVBox = ccui.HBox:create() + vbox:addChild(innerVBox) + innerVBox:setTag(102) + + local count3 = 2 + for i = 1, count3 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setTouchEnabled(true) + imageView:setTag(i - 1 + count1 + count2 + count3) + imageView:addTouchEventListener(onImageViewClicked) + innerVBox:addChild(imageView) + end + + self._loopText = ccui.Text:create("loop enabled", "Airal", 20) + self._loopText:setPosition(cc.p(winSize.width/2, winSize.height - 50)) + self._loopText:setColor(cc.c3b(255, 0 ,0)) + self:addChild(self._loopText) + + local function toggleFocusLoop(sender, eventType) + if eventType == ccui.TouchEventType.ended then + self._horizontalLayout:setLoopFocus(not self._horizontalLayout:isLoopFocus()) + if self._horizontalLayout:isLoopFocus() then + self._loopText:setString("loop enabled") + else + self._loopText:setString("loop disabled") + end + end + end + + local btn = ccui.Button:create("cocosui/switch-mask.png") + btn:setTitleText("Toggle Loop") + btn:setPosition(cc.p(60, winSize.height - 50)) + btn:setTitleColor(cc.c3b(0, 255, 0)) + btn:addTouchEventListener(toggleFocusLoop) + self:addChild(btn) +end + +function UIFocusTestNestedLayout2.create() + local scene = cc.Scene:create() + local layer = UIFocusTestNestedLayout2.extend(cc.Layer:create()) + layer:initExtend() + scene:addChild(layer) + return scene +end + +local UIFocusTestNestedLayout3 = class("UIFocusTestNestedLayout3",UIScene) + +function UIFocusTestNestedLayout3.extend( target ) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, UIFocusTestNestedLayout3) + return target +end + +function UIFocusTestNestedLayout3:initExtend() + self:init() + + local root = self._uiLayer:getChildByTag(81) + local background = root:getChildByName("background_Panel") + background:removeFromParent(true) + + local function onLeftKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_LEFT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onRightKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_RIGHT, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onUpKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_UP, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + local function onDownKeyPressed() + local event = cc.EventKeyboard:new(cc.KeyCode.KEY_DPAD_DOWN, false) + cc.Director:getInstance():getEventDispatcher():dispatchEvent(event) + end + + self._dpadMenu = cc.Menu:create() + local winSize = cc.Director:getInstance():getVisibleSize() + + local leftItem = cc.MenuItemFont:create("Left") + leftItem:setPosition(cc.p(winSize.width - 100, winSize.height/2)) + leftItem:registerScriptTapHandler(onLeftKeyPressed) + self._dpadMenu:addChild(leftItem) + + local rightItem = cc.MenuItemFont:create("Right") + rightItem:setPosition(cc.p(winSize.width - 30, winSize.height/2)) + rightItem:registerScriptTapHandler(onRightKeyPressed) + self._dpadMenu:addChild(rightItem) + + local upItem = cc.MenuItemFont:create("Up") + upItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 + 50)) + upItem:registerScriptTapHandler(onUpKeyPressed) + self._dpadMenu:addChild(upItem) + + local downItem = cc.MenuItemFont:create("Down") + downItem:setPosition(cc.p(winSize.width - 60, winSize.height/2 - 50)) + downItem:registerScriptTapHandler(onDownKeyPressed) + self._dpadMenu:addChild(downItem) + self._dpadMenu:setPosition(cc.p(0, 0)) + self._uiLayer:addChild(self._dpadMenu) + + ccui.Widget:enableDpadNavigation(true) + + local function onFocusChanged(widgetLostFocus,widgetGetFocus) + if nil ~= widgetGetFocus and widgetGetFocus:isFocusEnabled() then + widgetGetFocus:setColor(cc.c3b(255, 0, 0)) + end + + if nil ~= widgetLostFocus and widgetLostFocus:isFocusEnabled() then + widgetLostFocus:setColor(cc.c3b(255, 255, 255)) + end + + if nil ~= widgetLostFocus and nil ~= widgetGetFocus then + print(string.format("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus:getTag(), widgetLostFocus:getTag())) + end + end + + local eventListener = cc.EventListenerFocus:create() + eventListener:registerScriptHandler(onFocusChanged) + local eventDispatcher = self:getEventDispatcher() + eventDispatcher:addEventListenerWithFixedPriority(eventListener, 1) + + local winSize = cc.Director:getInstance():getVisibleSize() + + self._verticalLayout = ccui.VBox:create() + self._verticalLayout:setPosition(cc.p(40, winSize.height - 70)) + self._uiLayer:addChild(self._verticalLayout) + self._verticalLayout:setScale(0.8) + + self._verticalLayout:setFocused(true) + self._verticalLayout:setLoopFocus(true) + self._verticalLayout:setTag(-1000) + self._firstFocusedWidget = self._verticalLayout + + local upperHBox = ccui.HBox:create() + upperHBox:setTag(-200) + self._verticalLayout:addChild(upperHBox) + + local params = ccui.LinearLayoutParameter:create() + params:setMargin({left = 0, top = 0, right = 50, bottom = 0}) + + local vparams = ccui.LinearLayoutParameter:create() + vparams:setMargin({left = 10, top = 0, right = 0, bottom = 140}) + upperHBox:setLayoutParameter(vparams) + + local function onImageViewClicked(sender, eventType) + if eventType == ccui.TouchEventType.ended then + local w = sender + if w:isFocusEnabled() then + w:setFocusEnabled(false) + w:setColor(cc.c3b(255, 255, 0)) + else + w:setFocusEnabled(true) + w:setColor(cc.c3b(255, 255, 255)) + end + end + end + + local count = 3 + for i = 1, count do + local firstVbox = ccui.VBox:create() + firstVbox:setScale(0.5) + firstVbox:setLayoutParameter(params) + firstVbox:setTag(i * 100) + + local count1 = 3 + for j = 1, count1 do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setTouchEnabled(true) + imageView:setTag(j + firstVbox:getTag()) + imageView:addTouchEventListener(onImageViewClicked) + firstVbox:addChild(imageView) + end + + upperHBox:addChild(firstVbox) + end + + local bottomHBox = ccui.HBox:create() + bottomHBox:setScale(0.5) + bottomHBox:setTag(600) + bottomHBox:setLayoutParameter(vparams) + + count = 3 + local bottomParams = ccui.LinearLayoutParameter:create() + bottomParams:setMargin({left = 0, top = 0, right = 8, bottom = 0}) + for i = 1, count do + local imageView = ccui.ImageView:create("cocosui/scrollviewbg.png") + imageView:setLayoutParameter(bottomParams) + imageView:setTouchEnabled(true) + imageView:setTag(i + 600) + imageView:addTouchEventListener(onImageViewClicked) + bottomHBox:addChild(imageView) + end + + self._verticalLayout:addChild(bottomHBox) + + self._loopText = ccui.Text:create("loop enabled", "Airal", 20) + self._loopText:setPosition(cc.p(winSize.width/2, winSize.height - 50)) + self._loopText:setColor(cc.c3b(255, 0 ,0)) + self:addChild(self._loopText) + + local function toggleFocusLoop(sender, eventType) + if eventType == ccui.TouchEventType.ended then + self._verticalLayout:setLoopFocus(not self._verticalLayout:isLoopFocus()) + if self._verticalLayout:isLoopFocus() then + self._loopText:setString("loop enabled") + else + self._loopText:setString("loop disabled") + end + end + end + + local btn = ccui.Button:create("cocosui/switch-mask.png") + btn:setTitleText("Toggle Loop") + btn:setPosition(cc.p(60, winSize.height - 50)) + btn:setTitleColor(cc.c3b(0, 255, 0)) + btn:addTouchEventListener(toggleFocusLoop) + self:addChild(btn) +end + +function UIFocusTestNestedLayout3.create() + local scene = cc.Scene:create() + local layer = UIFocusTestNestedLayout3.extend(cc.Layer:create()) + layer:initExtend() + scene:addChild(layer) + return scene +end + local cocoStudioGuiArray = { + { + title = "UIFocusTestHorizontal", + func = function () + return UIFocusTestHorizontal.create() + end, + }, + + { + title = "UIFocusTestVertical", + func = function () + return UIFocusTestVertical.create() + end, + }, + + { + title = "UIFocusTestNestedLayout1", + func = function () + return UIFocusTestNestedLayout1.create() + end, + }, + + { + title = "UIFocusTestNestedLayout2", + func = function () + return UIFocusTestNestedLayout2.create() + end, + }, + + { + title = "UIFocusTestNestedLayout3", + func = function () + return UIFocusTestNestedLayout3.create() + end, + }, + { title = "UIButtonTest", func = function () diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 6a2a9cd6e6..20ef1d54cc 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -44,7 +44,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS LayerColor::[getBlendFunc setBlendFunc], ParticleSystem::[(g|s)etBlendFunc updateQuadWithParticle initParticle], DrawNode::[getBlendFunc setBlendFunc drawPolygon listenBackToForeground], - Director::[getAccelerometer (g|s)et.*Dispatcher getProjection getFrustum getRenderer], + Director::[getAccelerometer getProjection getFrustum getRenderer], Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased], Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns], MenuItem.*::[create setCallback initWithCallback], diff --git a/tools/tolua/cocos2dx_ui.ini b/tools/tolua/cocos2dx_ui.ini index 1befd7db27..1bbc7331f4 100644 --- a/tools/tolua/cocos2dx_ui.ini +++ b/tools/tolua/cocos2dx_ui.ini @@ -30,7 +30,7 @@ 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*$". -classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* +classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also