axmol/samples/Lua/TestLua/Resources/luaScript/FontTest/FontTest.lua

114 lines
3.6 KiB
Lua
Raw Normal View History

2013-04-06 14:00:17 +08:00
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:getInstance():getWinSize()
2013-04-06 14:00:17 +08:00
local blockSize = CCSize(s.width/3, 200)
2013-04-06 14:00:17 +08:00
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(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height)
local centerColor = CCLayerColor:create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height)
local rightColor = CCLayerColor:create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height)
2013-04-06 14:00:17 +08:00
leftColor:ignoreAnchorPointForPosition(false)
centerColor:ignoreAnchorPointForPosition(false)
rightColor:ignoreAnchorPointForPosition(false)
top:setAnchorPoint(CCPoint(0.5, 1))
left:setAnchorPoint(CCPoint(0,0.5))
leftColor:setAnchorPoint(CCPoint(0,0.5))
center:setAnchorPoint(CCPoint(0,0.5))
centerColor:setAnchorPoint(CCPoint(0,0.5))
right:setAnchorPoint(CCPoint(0,0.5))
rightColor:setAnchorPoint(CCPoint(0,0.5))
2013-04-06 14:00:17 +08:00
top:setPosition(CCPoint(s.width/2,s.height-20))
left:setPosition(CCPoint(0,s.height/2))
2013-04-06 14:00:17 +08:00
leftColor:setPosition(left:getPosition())
center:setPosition(CCPoint(blockSize.width, s.height/2))
2013-04-06 14:00:17 +08:00
centerColor:setPosition(center:getPosition())
right:setPosition(CCPoint(blockSize.width*2, s.height/2))
2013-04-06 14:00:17 +08:00
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("")
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