From 31aae38fac7c3e6a8b5d5bac6620fcfc0a8cbe67 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Thu, 18 Jun 2015 09:41:16 +0800 Subject: [PATCH] issue #12414:Add UIS9NinePatchTest for Lua and js --- tests/js-tests/project.json | 1 + tests/js-tests/src/GUITest/UISceneManager.js | 8 ++ .../CocoStudioGUITest/CocoStudioGUITest.lua | 78 +++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/tests/js-tests/project.json b/tests/js-tests/project.json index a014ce397f..c29ee28983 100644 --- a/tests/js-tests/project.json +++ b/tests/js-tests/project.json @@ -171,6 +171,7 @@ "src/GUITest/UITextTest/UITextTest.js", "src/GUITest/UIVideoPlayerTest/UIVideoPlayerTest.js", "src/GUITest/UIWebViewTest/UIWebViewTest.js", + "src/GUITest/UIS9NinePatchTest/UIS9NinePatchTest.js", "src/CocoStudioTest/SceneTest/TriggerCode/Acts.js", "src/CocoStudioTest/SceneTest/TriggerCode/Cons.js", diff --git a/tests/js-tests/src/GUITest/UISceneManager.js b/tests/js-tests/src/GUITest/UISceneManager.js index 38c7824c63..b492f45c53 100644 --- a/tests/js-tests/src/GUITest/UISceneManager.js +++ b/tests/js-tests/src/GUITest/UISceneManager.js @@ -528,6 +528,14 @@ return new UIRichTextTest(); } } + ], + "UIS9NinePatchTest": [ + { + title: "UIS9NinePatchTest", + func: function () { + return new UIS9NinePatchTest(); + } + } ] }; diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua index 44626fee77..7f476084a6 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua @@ -4017,6 +4017,78 @@ function UIFocusTestNestedLayout3.create() return scene end +local UIS9NinePatchTest = class("UIS9NinePatchTest",UIScene) + +function UIS9NinePatchTest.extend(target) + local t = tolua.getpeer(target) + if not t then + t = {} + tolua.setpeer(target, t) + end + setmetatable(t, UIS9NinePatchTest) + return target +end + +function UIS9NinePatchTest:initExtend() + self:init() + + local widgetSize = self._widget:getContentSize() + self._displayValueLabel = ccui.Text:create() + self._displayValueLabel:setString("UIS9NinePatchTest") + self._displayValueLabel:setFontName(font_TextName) + 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:getContentSize().height * 1.8)) + self._uiLayer:addChild(self._displayValueLabel) + + cc.SpriteFrameCache:getInstance():addSpriteFrames("cocosui/android9patch.plist") + + local winSize = cc.Director:getInstance():getWinSize() + local x = winSize.width / 2 + local y = 0 + (winSize.height / 2 + 50) + + local preferedSize = cc.size(99,99) + + --9-patch sprite with filename + local playerSprite = ccui.Scale9Sprite:create("cocosui/player.9.png") + playerSprite:setPosition(x, y) + playerSprite:setContentSize(preferedSize) + local capInsets = playerSprite:getCapInsets() + print(string.format("player sprite capInset = %f, %f %f, %f", capInsets.x, + capInsets.y, capInsets.width, capInsets.height)) + self:addChild(playerSprite) + + local animationBtnSprite = ccui.Scale9Sprite:createWithSpriteFrameName("animationbuttonpressed.png") + animationBtnSprite:setPosition(x-100, y-100) + capInsets = animationBtnSprite:getCapInsets() + print(string.format("animationBtnSprite capInset = %f, %f %f, %f", capInsets.x, + capInsets.y, capInsets.width, capInsets.height)) + self:addChild(animationBtnSprite) + + + local monsterSprite = ccui.Scale9Sprite:createWithSpriteFrameName("monster.9.png") + monsterSprite:setPosition(x+100, y-100) + capInsets = monsterSprite:getCapInsets() + monsterSprite:setContentSize(preferedSize) + print(string.format("monsterSprite capInset = %f, %f %f, %f", capInsets.x, + capInsets.y, capInsets.width, capInsets.height)) + self:addChild(monsterSprite) + + local spriteFrame = cc.SpriteFrameCache:getInstance():getSpriteFrame("buttonnormal.9.png") + local buttonScale9Sprite = ccui.Scale9Sprite:createWithSpriteFrame(spriteFrame) + buttonScale9Sprite:setContentSize(cc.size(150,80)) + buttonScale9Sprite:setPosition(cc.p(100,200)) + self:addChild(buttonScale9Sprite) +end + +function UIS9NinePatchTest.create() + local scene = cc.Scene:create() + local layer = UIS9NinePatchTest.extend(cc.Layer:create()) + layer:initExtend() + scene:addChild(layer) + return scene +end + local cocoStudioGuiArray = { { @@ -4326,6 +4398,12 @@ local cocoStudioGuiArray = return UIRichTextTest.create() end }, + { + title = "UIS9NinePatchTest", + func = function() + return UIS9NinePatchTest.create() + end + }, } function guiSceneManager.nextUIScene()