PuzzleSDK
UITextAtlasTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25#include "UITextAtlasTest.h"
26
28using namespace cocos2d::ui;
29
30UITextAtlasTests::UITextAtlasTests()
31{
34}
35// UITextAtlasTest
36
38{
39 if (UIScene::init())
40 {
41 Size widgetSize = _widget->getContentSize();
42
43 // Add the alert
44 Text* alert = Text::create("TextAtlas","fonts/Marker Felt.ttf",30);
45 alert->setColor(Color3B(159, 168, 176));
46 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
47 _uiLayer->addChild(alert);
48
49 // Create the text atlas
50 TextAtlas* textAtlas = nullptr;
51 if (Director::getInstance()->getWinSizeInPixels().height > 320.f)
52 {
53 textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 34, 44, "0");
54 }
55 else
56 {
57 textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.png", 17, 22, "0");
58 }
59 textAtlas->setPosition(Vec2((widgetSize.width) / 2, widgetSize.height / 2.0f));
60 _uiLayer->addChild(textAtlas);
61 _textAtlas = textAtlas;
62
63 TTFConfig ttfConfig("fonts/arial.ttf", 15);
64 auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
65 auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UITextAtlasTest::printWidgetResources, this));
66 item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
67 auto pMenu1 = Menu::create(item1, nullptr);
68 pMenu1->setPosition(Vec2(0, 0));
69 this->addChild(pMenu1, 10);
70 return true;
71 }
72 return false;
73}
74void UITextAtlasTest::printWidgetResources(cocos2d::Ref* sender)
75{
76 cocos2d::ResourceData textureFile = _textAtlas->getRenderFile();
77 CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
78}
79
80// UITextAtlasETC1ShadowTest
81
83{
84 if (UIScene::init())
85 {
86 Size widgetSize = _widget->getContentSize();
87
88 // Add the alert
89 Text* alert = Text::create("TextAtlas With ETC1 format","fonts/Marker Felt.ttf",30);
90 alert->setColor(Color3B(159, 168, 176));
91 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
92 _uiLayer->addChild(alert);
93
94 // Create the text atlas
95 TextAtlas* textAtlas = nullptr;
96 if (Director::getInstance()->getWinSizeInPixels().height > 320.f)
97 {
98 textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.pkm", 34, 44, "0");
99 }
100 else
101 {
102 textAtlas = TextAtlas::create("1234567890", "cocosui/labelatlas.pkm", 17, 22, "0");
103 }
104 textAtlas->setPosition(Vec2((widgetSize.width) / 2, widgetSize.height / 2.0f));
105 _uiLayer->addChild(textAtlas);
106 auto labelAtlas = (Label*)textAtlas->getVirtualRenderer();
107 labelAtlas->enableShadow(Color4B::GREEN);
108 _textAtlas = textAtlas;
109
110 TTFConfig ttfConfig("fonts/arial.ttf", 15);
111 auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
112 auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UITextAtlasETC1ShadowTest::printWidgetResources, this));
113 item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
114 auto pMenu1 = Menu::create(item1, nullptr);
115 pMenu1->setPosition(Vec2(0, 0));
116 this->addChild(pMenu1, 10);
117 return true;
118 }
119 return false;
120}
122{
123 cocos2d::ResourceData textureFile = _textAtlas->getRenderFile();
124 CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
125}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
USING_NS_CC
cocos2d::Layer * _uiLayer
Definition: UIScene.h:44
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45
void printWidgetResources(cocos2d::Ref *sender)
cocos2d::ui::TextAtlas * _textAtlas
virtual bool init() override
void printWidgetResources(cocos2d::Ref *sender)
cocos2d::ui::TextAtlas * _textAtlas
virtual bool init() override
static cocos2d::Vec2 bottom()
Definition: VisibleRect.cpp:63
static cocos2d::Vec2 left()
Definition: VisibleRect.cpp:45