PuzzleSDK
UIRadioButtonTwoGroupsTest类 参考

#include <UIRadioButtonTest.h>

+ 类 UIRadioButtonTwoGroupsTest 继承关系图:
+ UIRadioButtonTwoGroupsTest 的协作图:

Public 成员函数

 CREATE_FUNC (UIRadioButtonTwoGroupsTest)
 
 UIRadioButtonTwoGroupsTest ()
 
 ~UIRadioButtonTwoGroupsTest ()
 
virtual bool init () override
 
void onChangedRadioButtonGroup1 (cocos2d::ui::RadioButton *radioButton, int index, cocos2d::ui::RadioButtonGroup::EventType type)
 
void onChangedRadioButtonGroup2 (cocos2d::ui::RadioButton *radioButton, int index, cocos2d::ui::RadioButtonGroup::EventType type)
 
void onChangedRadioButtonSelect (cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)
 
void clearRadioButtonGroup (Ref *sender)
 
- Public 成员函数 继承自 UIScene
 UIScene ()
 
 ~UIScene ()
 
virtual void onEnter () override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual std::string title () const
 
virtual std::string subtitle () const
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

Protected 成员函数

void addLog (const std::string &log)
 

Protected 属性

cocos2d::ui::RadioButtonGroup * _radioButtonGroups [2]
 
cocos2d::ui::Text * _groupEventLabel
 
cocos2d::ui::Text * _buttonEventLabel
 
cocos2d::ui::Text * _logConsole
 
int _numberOfLogLines
 
- Protected 属性 继承自 UIScene
cocos2d::Layer * _uiLayer
 
cocos2d::ui::Layout * _widget
 
cocos2d::ui::Text * _sceneTitle
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 UIRadioButtonTest.h53 行定义.

构造及析构函数说明

◆ UIRadioButtonTwoGroupsTest()

UIRadioButtonTwoGroupsTest::UIRadioButtonTwoGroupsTest ( )

在文件 UIRadioButtonTest.cpp146 行定义.

147: _groupEventLabel(nullptr),
148_buttonEventLabel(nullptr),
149_logConsole(nullptr),
151{
152 _radioButtonGroups[0] = nullptr;
153 _radioButtonGroups[1] = nullptr;
154}
cocos2d::ui::RadioButtonGroup * _radioButtonGroups[2]
cocos2d::ui::Text * _logConsole
cocos2d::ui::Text * _groupEventLabel
cocos2d::ui::Text * _buttonEventLabel

引用了 _radioButtonGroups.

◆ ~UIRadioButtonTwoGroupsTest()

UIRadioButtonTwoGroupsTest::~UIRadioButtonTwoGroupsTest ( )

在文件 UIRadioButtonTest.cpp156 行定义.

157{
158}

成员函数说明

◆ addLog()

void UIRadioButtonTwoGroupsTest::addLog ( const std::string &  log)
protected

在文件 UIRadioButtonTest.cpp295 行定义.

296{
297 std::string existingLog = _logConsole->getString();
298 if(!existingLog.empty())
299 {
300 existingLog = existingLog + "\n";
301 }
302 existingLog = existingLog + log;
304
305 if(_numberOfLogLines > 10)
306 {
307 size_t pos = existingLog.find('\n') + 1;
308 std::string newLog = existingLog.substr(pos);
309 existingLog = newLog;
311 }
312
313 _logConsole->setString(existingLog);
314}

引用了 _logConsole , 以及 _numberOfLogLines.

被这些函数引用 onChangedRadioButtonGroup1(), onChangedRadioButtonGroup2() , 以及 onChangedRadioButtonSelect().

+ 这是这个函数的调用关系图:

◆ clearRadioButtonGroup()

void UIRadioButtonTwoGroupsTest::clearRadioButtonGroup ( Ref *  sender)

在文件 UIRadioButtonTest.cpp287 行定义.

288{
289 for(int i = 0; i < 2; ++i)
290 {
291 _radioButtonGroups[i]->setSelectedButton(nullptr);
292 }
293}

引用了 _radioButtonGroups.

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ CREATE_FUNC()

UIRadioButtonTwoGroupsTest::CREATE_FUNC ( UIRadioButtonTwoGroupsTest  )

◆ init()

bool UIRadioButtonTwoGroupsTest::init ( )
overridevirtual

重载 UIScene .

在文件 UIRadioButtonTest.cpp160 行定义.

161{
162 if (UIScene::init())
163 {
164 Size widgetSize = _widget->getContentSize();
165
166 // Add a label in which the radio button events will be displayed
167 _groupEventLabel = Text::create("RadioButtonGroup : No Event", "fonts/Marker Felt.ttf", 25);
168 _groupEventLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
169 _groupEventLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 70));
170 _uiLayer->addChild(_groupEventLabel);
171
172 _buttonEventLabel = Text::create("RadioButton : No Event", "fonts/Marker Felt.ttf", 25);
173 _buttonEventLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
174 _buttonEventLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 35));
175 _uiLayer->addChild(_buttonEventLabel);
176
177 _logConsole = Text::create("", "fonts/Marker Felt.ttf", 10);
178 _logConsole->setAnchorPoint(Vec2(0.0f, 1.0f));
179 _logConsole->setPosition(Vec2(widgetSize.width / 2.0f + 110, widgetSize.height / 2.0f + 55));
180 _uiLayer->addChild(_logConsole);
181
182 static const int NUMBER_OF_BUTTONS = 4;
183 static const float SPACE_BETWEEN_BUTTONS = 50;
184 float startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * SPACE_BETWEEN_BUTTONS;
185
186 for(int type = 0; type < 2; ++type)
187 {
188 // Create a radio button group
189 const char *normalImage, *selectedImage;
190 float posYAdjust = 0;
191 _radioButtonGroups[type] = RadioButtonGroup::create();
192 if(type == 0)
193 {
194 _radioButtonGroups[type]->addEventListener(CC_CALLBACK_3(UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup1, this));
195 normalImage = "cocosui/radio_button_off.png";
196 selectedImage = "cocosui/radio_button_on.png";
197 posYAdjust = 35;
198 }
199 else
200 {
201 _radioButtonGroups[type]->addEventListener(CC_CALLBACK_3(UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup2, this));
202 normalImage = "cocosui/UIEditorTest/2.1/Button/button_common_box03_003 copy 221.png";
203 selectedImage = "cocosui/UIEditorTest/2.1/Button/button_common_box03_001.png";
204 posYAdjust = -15;
205 }
206 _uiLayer->addChild(_radioButtonGroups[type]);
207
208 // Set allowing no selections
209 _radioButtonGroups[type]->setAllowedNoSelection(type == 0);
210
211 // Create the radio buttons
212 for(int i = 0; i < NUMBER_OF_BUTTONS; ++i)
213 {
214 RadioButton* radioButton = nullptr;
215 float posY = widgetSize.height / 2.0f + posYAdjust;
216 radioButton = RadioButton::create(normalImage, selectedImage);
217 float posX = startPosX + SPACE_BETWEEN_BUTTONS * i;
218 radioButton->setScale(1.5f);
219 radioButton->setPosition(Vec2(posX, posY));
220
221 radioButton->addEventListener(CC_CALLBACK_2(UIRadioButtonTwoGroupsTest::onChangedRadioButtonSelect, this));
222 radioButton->setTag(i);
223 _uiLayer->addChild(radioButton);
224 _radioButtonGroups[type]->addRadioButton(radioButton);
225 }
226 }
227
228 Button* clearButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
229 clearButton->setTitleText("Clear");
230 clearButton->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 65));
231 clearButton->addClickEventListener(CC_CALLBACK_1(UIRadioButtonTwoGroupsTest::clearRadioButtonGroup, this));
232 clearButton->setScale(0.8f);
233 _uiLayer->addChild(clearButton);
234
235 Text* text1 = Text::create("Upper radio button group is allowed non-selection, but lower one is not.", "fonts/Marker Felt.ttf", 15);
236 text1->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 100));
237 _uiLayer->addChild(text1);
238
239 return true;
240 }
241 return false;
242}
static float startPosX
void onChangedRadioButtonGroup2(cocos2d::ui::RadioButton *radioButton, int index, cocos2d::ui::RadioButtonGroup::EventType type)
void onChangedRadioButtonSelect(cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)
void clearRadioButtonGroup(Ref *sender)
void onChangedRadioButtonGroup1(cocos2d::ui::RadioButton *radioButton, int index, cocos2d::ui::RadioButtonGroup::EventType type)
cocos2d::Layer * _uiLayer
Definition: UIScene.h:44
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45

引用了 _buttonEventLabel, _groupEventLabel, _logConsole, _radioButtonGroups, UIScene::_uiLayer, UIScene::_widget, clearRadioButtonGroup(), UIScene::init(), onChangedRadioButtonGroup1(), onChangedRadioButtonGroup2(), onChangedRadioButtonSelect() , 以及 startPosX.

+ 函数调用图:

◆ onChangedRadioButtonGroup1()

void UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup1 ( cocos2d::ui::RadioButton *  radioButton,
int  index,
cocos2d::ui::RadioButtonGroup::EventType  type 
)

在文件 UIRadioButtonTest.cpp244 行定义.

245{
246 CCASSERT(index == _radioButtonGroups[0]->getSelectedButtonIndex(), "The two indexes must match!");
247 auto text = StringUtils::format("RadioButtonGroup1 : %d", index);
248 _groupEventLabel->setString(text);
249 addLog(text);
250}
void addLog(const std::string &log)

引用了 _groupEventLabel, _radioButtonGroups , 以及 addLog().

被这些函数引用 init().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onChangedRadioButtonGroup2()

void UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup2 ( cocos2d::ui::RadioButton *  radioButton,
int  index,
cocos2d::ui::RadioButtonGroup::EventType  type 
)

在文件 UIRadioButtonTest.cpp252 行定义.

253{
254 CCASSERT(index == _radioButtonGroups[1]->getSelectedButtonIndex(), "The two indexes must match!");
255 auto text = StringUtils::format("RadioButtonGroup2 : %d", index);
256 _groupEventLabel->setString(text);
257 addLog(text);
258}

引用了 _groupEventLabel, _radioButtonGroups , 以及 addLog().

被这些函数引用 init().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ onChangedRadioButtonSelect()

void UIRadioButtonTwoGroupsTest::onChangedRadioButtonSelect ( cocos2d::ui::RadioButton *  radioButton,
cocos2d::ui::RadioButton::EventType  type 
)

在文件 UIRadioButtonTest.cpp260 行定义.

261{
262 if(radioButton == nullptr)
263 {
264 return;
265 }
266 auto text = StringUtils::format("RadioButton %d : ", radioButton->getTag());
267 switch (type)
268 {
269 case RadioButton::EventType::SELECTED:
270 {
271 text.append("Selected");
272 break;
273 }
274
275 case RadioButton::EventType::UNSELECTED:
276 {
277 text.append("Unselected");
278 break;
279 }
280 default:
281 break;
282 }
283 _buttonEventLabel->setString(text);
284 addLog(text);
285}

引用了 _buttonEventLabel , 以及 addLog().

被这些函数引用 init().

+ 函数调用图:
+ 这是这个函数的调用关系图:

类成员变量说明

◆ _buttonEventLabel

cocos2d::ui::Text* UIRadioButtonTwoGroupsTest::_buttonEventLabel
protected

在文件 UIRadioButtonTest.h73 行定义.

被这些函数引用 init() , 以及 onChangedRadioButtonSelect().

◆ _groupEventLabel

cocos2d::ui::Text* UIRadioButtonTwoGroupsTest::_groupEventLabel
protected

在文件 UIRadioButtonTest.h72 行定义.

被这些函数引用 init(), onChangedRadioButtonGroup1() , 以及 onChangedRadioButtonGroup2().

◆ _logConsole

cocos2d::ui::Text* UIRadioButtonTwoGroupsTest::_logConsole
protected

在文件 UIRadioButtonTest.h74 行定义.

被这些函数引用 addLog() , 以及 init().

◆ _numberOfLogLines

int UIRadioButtonTwoGroupsTest::_numberOfLogLines
protected

在文件 UIRadioButtonTest.h75 行定义.

被这些函数引用 addLog().

◆ _radioButtonGroups

cocos2d::ui::RadioButtonGroup* UIRadioButtonTwoGroupsTest::_radioButtonGroups[2]
protected

该类的文档由以下文件生成: