Adding FontTest for TestLua.

This commit is contained in:
James Chen 2013-04-06 14:00:17 +08:00
parent 17b948367a
commit 5171e11765
3 changed files with 118 additions and 4 deletions

View File

@ -0,0 +1,114 @@
local kTagLabel1 = 0
local kTagLabel2 = 1
local kTagLabel3 = 2
local kTagLabel4 = 3
local fontList = {
"fonts/A Damn Mess.ttf",
"fonts/Abberancy.ttf",
"fonts/Abduction.ttf",
"fonts/Paint Boy.ttf",
"fonts/Schwarzwald Regular.ttf",
"fonts/Scissor Cuts.ttf"
}
local fontCount = table.getn(fontList)
cclog("font count = "..fontCount)
local vAlignIdx = 1
local verticalAlignment = {
kCCVerticalTextAlignmentTop,
kCCVerticalTextAlignmentCenter,
kCCVerticalTextAlignmentBottom,
}
local vAlignCount = table.getn(verticalAlignment)
local function showFont(ret, pFont)
cclog("vAlignIdx="..vAlignIdx)
local s = CCDirector:sharedDirector():getWinSize()
local blockSize = CCSizeMake(s.width/3, 200)
local fontSize = 26
ret:removeChildByTag(kTagLabel1, true)
ret:removeChildByTag(kTagLabel2, true)
ret:removeChildByTag(kTagLabel3, true)
ret:removeChildByTag(kTagLabel4, true)
local top = CCLabelTTF:create(pFont, pFont, 24)
local left = CCLabelTTF:create("alignment left", pFont, fontSize,
blockSize, kCCTextAlignmentLeft, verticalAlignment[vAlignIdx])
local center = CCLabelTTF:create("alignment center", pFont, fontSize,
blockSize, kCCTextAlignmentCenter, verticalAlignment[vAlignIdx])
local right = CCLabelTTF:create("alignment right", pFont, fontSize,
blockSize, kCCTextAlignmentRight, verticalAlignment[vAlignIdx])
local leftColor = CCLayerColor:create(ccc4(100, 100, 100, 255), blockSize.width, blockSize.height)
local centerColor = CCLayerColor:create(ccc4(200, 100, 100, 255), blockSize.width, blockSize.height)
local rightColor = CCLayerColor:create(ccc4(100, 100, 200, 255), blockSize.width, blockSize.height)
leftColor:ignoreAnchorPointForPosition(false)
centerColor:ignoreAnchorPointForPosition(false)
rightColor:ignoreAnchorPointForPosition(false)
top:setAnchorPoint(ccp(0.5, 1))
left:setAnchorPoint(ccp(0,0.5))
leftColor:setAnchorPoint(ccp(0,0.5))
center:setAnchorPoint(ccp(0,0.5))
centerColor:setAnchorPoint(ccp(0,0.5))
right:setAnchorPoint(ccp(0,0.5))
rightColor:setAnchorPoint(ccp(0,0.5))
top:setPosition(ccp(s.width/2,s.height-20))
left:setPosition(ccp(0,s.height/2))
leftColor:setPosition(left:getPosition())
center:setPosition(ccp(blockSize.width, s.height/2))
centerColor:setPosition(center:getPosition())
right:setPosition(ccp(blockSize.width*2, s.height/2))
rightColor:setPosition(right:getPosition())
ret:addChild(leftColor, -1)
ret:addChild(left, 0, kTagLabel1)
ret:addChild(rightColor, -1)
ret:addChild(right, 0, kTagLabel2)
ret:addChild(centerColor, -1)
ret:addChild(center, 0, kTagLabel3)
ret:addChild(top, 0, kTagLabel4)
end
local isFirst = true
local originCreateLayer = createTestLayer
local function createTestLayer()
if isFirst == false then
if Helper.index == 1 then
vAlignIdx = vAlignIdx % vAlignCount + 1
end
else
isFirst = false
end
local ret = originCreateLayer("")
cclog("Helper.index = "..Helper.index)
showFont(ret, fontList[Helper.index])
return ret
end
function FontTestMain()
cclog("FontTestMain")
Helper.index = 1
vAlignIdx = 1
local scene = CCScene:create()
Helper.createFunctionTable = {
createTestLayer,
createTestLayer,
createTestLayer,
createTestLayer,
createTestLayer,
createTestLayer
}
scene:addChild(createTestLayer())
scene:addChild(CreateBackMenuItem())
return scene
end

View File

@ -106,7 +106,7 @@ local function CreateTestScene(nIdx)
elseif nIdx == Test_Table.TEST_BUGS then
elseif nIdx == Test_Table.TEST_FONTS then
scene = FontTestMain()
elseif nIdx == Test_Table.TEST_CURRENT_LANGUAGE then
--#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)

View File

@ -25,7 +25,7 @@ require "luaScript/SceneTest/SceneTest"
require "luaScript/Texture2dTest/Texture2dTest"
require "luaScript/RenderTextureTest/RenderTextureTest"
require "luaScript/ZwoptexTest/ZwoptexTest"
require "luaScript/FontTest/FontTest"
----------------------------------------------------
-- tests scene
@ -68,7 +68,7 @@ Test_Table =
-- "TEST_CURL",
-- "TEST_USERDEFAULT",
-- "TEST_BUGS",
-- "TEST_FONTS",
"TEST_FONTS",
-- "TEST_CURRENT_LANGUAGE",
-- "TEST_TEXTURECACHE",
-- "TEST_EXTENSIONS",
@ -118,7 +118,7 @@ Test_Name =
-- "CurlTest",
-- "UserDefaultTest",
-- "BugsTest",
-- "FontTest",
"FontTest",
-- "CurrentLanguageTest",
-- "TextureCacheTest",
-- "ExtensionsTest",