{"action":"created","comment":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments/33745157","id":33745157,"diff_hunk":"@@ -0,0 +1,343 @@\n+/****************************************************************************\n+Copyright (c) 2015 Neo Kim (neo.kim@neofect.com)\n+\n+http://www.cocos2d-x.org\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in\n+all copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+THE SOFTWARE.\n+****************************************************************************/\n+\n+#include \"ui/UIRadioButton.h\"\n+\n+NS_CC_BEGIN\n+\n+namespace ui {\n+    \n+IMPLEMENT_CLASS_GUI_INFO(RadioButton)\n+\n+RadioButton::RadioButton() :\n+_radioButtonEventCallback(nullptr),\n+_group(nullptr)\n+{\n+}\n+\n+RadioButton::~RadioButton()\n+{\n+    _radioButtonEventCallback = nullptr;\n+    _group = nullptr;\n+}\n+\n+RadioButton* RadioButton::create()\n+{\n+    RadioButton* widget = new (std::nothrow) RadioButton();\n+    if (widget && widget->init())\n+    {\n+        widget->autorelease();\n+        return widget;\n+    }\n+    CC_SAFE_DELETE(widget);\n+    return nullptr;\n+}\n+\n+RadioButton* RadioButton::create(const std::string& backGround,\n+                           const std::string& backGroundSeleted,\n+                           const std::string& cross,\n+                           const std::string& backGroundDisabled,\n+                           const std::string& frontCrossDisabled,\n+                           TextureResType texType)\n+{\n+    RadioButton *pWidget = new (std::nothrow) RadioButton;\n+    if (pWidget && pWidget->init(backGround,\n+                                 backGroundSeleted,\n+                                 cross,\n+                                 backGroundDisabled,\n+                                 frontCrossDisabled,\n+                                 texType))\n+    {\n+        pWidget->autorelease();\n+        return pWidget;\n+    }\n+    CC_SAFE_DELETE(pWidget);\n+    return nullptr;\n+}\n+\n+RadioButton* RadioButton::create(const std::string& backGround,\n+                           const std::string& cross,\n+                           TextureResType texType)\n+{\n+    RadioButton *pWidget = new (std::nothrow) RadioButton;\n+    if (pWidget && pWidget->init(backGround,\n+                                 \"\",\n+                                 cross,\n+                                 \"\",\n+                                 \"\",\n+                                 texType))\n+    {\n+        pWidget->autorelease();\n+        return pWidget;\n+    }\n+    CC_SAFE_DELETE(pWidget);\n+    return nullptr;\n+}\n+\n+void RadioButton::dispatchSelectChangedEvent(bool selected)\n+{\n+    EventType eventType = (selected ? EventType::SELECTED : EventType::UNSELECTED);\n+    this->retain();\n+    if (_radioButtonEventCallback)\n+    {\n+        _radioButtonEventCallback(this, eventType);\n+    }\n+    if (_ccEventCallback)\n+    {\n+        _ccEventCallback(this, static_cast<int>(eventType));\n+    }\n+    \n+    if(selected && _group != nullptr)\n+    {\n+        _group->onChangedRadioButtonSelect(this);\n+    }\n+    this->release();\n+}\n+\n+void RadioButton::addEventListener(const ccRadioButtonCallback& callback)\n+{\n+    _radioButtonEventCallback = callback;\n+}\n+\n+void RadioButton::releaseUpEvent()\n+{\n+    Widget::releaseUpEvent();\n+    \n+    if (!_isSelected)\n+    {\n+        setSelected(true);\n+        dispatchSelectChangedEvent(true);\n+    }\n+}\n+\n+std::string RadioButton::getDescription() const\n+{\n+    return \"RadioButton\";\n+}\n+\n+Widget* RadioButton::createCloneInstance()\n+{\n+    return RadioButton::create();\n+}\n+\n+void RadioButton::copySpecialProperties(Widget *widget)\n+{\n+    RadioButton* radioButton = dynamic_cast<RadioButton*>(widget);\n+    if (radioButton)\n+    {\n+        AbstractCheckButton::copySpecialProperties(widget);\n+        _radioButtonEventCallback = radioButton->_radioButtonEventCallback;\n+        _ccEventCallback = radioButton->_ccEventCallback;\n+        _group = radioButton->_group;\n+    }\n+}\n+\n+RadioButtonGroup::RadioButtonGroup() :\n+_radioButtonGroupEventCallback(nullptr),\n+_selectedRadioButton(nullptr),\n+_allowedNoSelection(false)\n+{\n+}\n+\n+RadioButtonGroup::~RadioButtonGroup()\n+{\n+    _radioButtonGroupEventCallback = nullptr;\n+    _selectedRadioButton = nullptr;\n+    _radioButtons.clear();\n+}\n+\n+RadioButtonGroup* RadioButtonGroup::create()\n+{\n+    RadioButtonGroup* widget = new (std::nothrow) RadioButtonGroup();\n+    if (widget && widget->init())\n+    {\n+        widget->autorelease();\n+        return widget;\n+    }\n+    CC_SAFE_DELETE(widget);\n+    return nullptr;\n+}\n+\n+void RadioButtonGroup::addEventListener(const ccRadioButtonGroupCallback& callback)\n+{\n+    _radioButtonGroupEventCallback = callback;\n+}\n+\n+void RadioButtonGroup::addRadioButton(RadioButton* radioButton)\n+{\n+    if(radioButton != nullptr)\n+    {\n+        radioButton->_group = this;","path":"cocos/ui/UIRadioButton.cpp","position":191,"original_position":191,"commit_id":"c4aa5a6274149a7a5cf3f526253ba848008456e9","original_commit_id":"c4aa5a6274149a7a5cf3f526253ba848008456e9","user":{"login":"lite3","id":1288575,"avatar_url":"https://avatars.githubusercontent.com/u/1288575?v=3","gravatar_id":"","url":"https://api.github.com/users/lite3","html_url":"https://github.com/lite3","followers_url":"https://api.github.com/users/lite3/followers","following_url":"https://api.github.com/users/lite3/following{/other_user}","gists_url":"https://api.github.com/users/lite3/gists{/gist_id}","starred_url":"https://api.github.com/users/lite3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lite3/subscriptions","organizations_url":"https://api.github.com/users/lite3/orgs","repos_url":"https://api.github.com/users/lite3/repos","events_url":"https://api.github.com/users/lite3/events{/privacy}","received_events_url":"https://api.github.com/users/lite3/received_events","type":"User","site_admin":false},"body":"CCAssert(!radioButtion->_group)","created_at":"2015-07-02T03:34:23Z","updated_at":"2015-07-02T03:34:23Z","html_url":"https://github.com/cocos2d/cocos2d-x/pull/12607#discussion_r33745157","pull_request_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607","_links":{"self":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments/33745157"},"html":{"href":"https://github.com/cocos2d/cocos2d-x/pull/12607#discussion_r33745157"},"pull_request":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607"}}},"pull_request":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607","id":38862476,"html_url":"https://github.com/cocos2d/cocos2d-x/pull/12607","diff_url":"https://github.com/cocos2d/cocos2d-x/pull/12607.diff","patch_url":"https://github.com/cocos2d/cocos2d-x/pull/12607.patch","issue_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/12607","number":12607,"state":"open","locked":false,"title":"Add RadioButton and RadioButtonGroup widgets","user":{"login":"neokim","id":3601028,"avatar_url":"https://avatars.githubusercontent.com/u/3601028?v=3","gravatar_id":"","url":"https://api.github.com/users/neokim","html_url":"https://github.com/neokim","followers_url":"https://api.github.com/users/neokim/followers","following_url":"https://api.github.com/users/neokim/following{/other_user}","gists_url":"https://api.github.com/users/neokim/gists{/gist_id}","starred_url":"https://api.github.com/users/neokim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neokim/subscriptions","organizations_url":"https://api.github.com/users/neokim/orgs","repos_url":"https://api.github.com/users/neokim/repos","events_url":"https://api.github.com/users/neokim/events{/privacy}","received_events_url":"https://api.github.com/users/neokim/received_events","type":"User","site_admin":false},"body":"Radio button has almost same logic with check box and only little part is different. To reuse the common part, it is extracted from CheckBox and become AbstractCheckButton class. RadioButton and CheckBox are subclassing AbstractCheckButton now.\r\nAnd RadioButtonGroup is added to handle the interaction between radio buttons and to provide user with callback.\r\nTest cases are included. For tests, some resources are added into `ccs-res` submodule. I will also create a PR for it.","created_at":"2015-06-30T10:17:02Z","updated_at":"2015-07-02T03:34:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"caa6147ec0c5d6d7413c4ca37c0306a272633988","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607/commits","review_comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607/comments","review_comment_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/12607/comments","statuses_url":"https://api.github.com/repos/cocos2d/cocos2d-x/statuses/c4aa5a6274149a7a5cf3f526253ba848008456e9","head":{"label":"neokim:add_radio_button_and_group","ref":"add_radio_button_and_group","sha":"c4aa5a6274149a7a5cf3f526253ba848008456e9","user":{"login":"neokim","id":3601028,"avatar_url":"https://avatars.githubusercontent.com/u/3601028?v=3","gravatar_id":"","url":"https://api.github.com/users/neokim","html_url":"https://github.com/neokim","followers_url":"https://api.github.com/users/neokim/followers","following_url":"https://api.github.com/users/neokim/following{/other_user}","gists_url":"https://api.github.com/users/neokim/gists{/gist_id}","starred_url":"https://api.github.com/users/neokim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neokim/subscriptions","organizations_url":"https://api.github.com/users/neokim/orgs","repos_url":"https://api.github.com/users/neokim/repos","events_url":"https://api.github.com/users/neokim/events{/privacy}","received_events_url":"https://api.github.com/users/neokim/received_events","type":"User","site_admin":false},"repo":{"id":37460139,"name":"cocos2d-x","full_name":"neokim/cocos2d-x","owner":{"login":"neokim","id":3601028,"avatar_url":"https://avatars.githubusercontent.com/u/3601028?v=3","gravatar_id":"","url":"https://api.github.com/users/neokim","html_url":"https://github.com/neokim","followers_url":"https://api.github.com/users/neokim/followers","following_url":"https://api.github.com/users/neokim/following{/other_user}","gists_url":"https://api.github.com/users/neokim/gists{/gist_id}","starred_url":"https://api.github.com/users/neokim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neokim/subscriptions","organizations_url":"https://api.github.com/users/neokim/orgs","repos_url":"https://api.github.com/users/neokim/repos","events_url":"https://api.github.com/users/neokim/events{/privacy}","received_events_url":"https://api.github.com/users/neokim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neokim/cocos2d-x","description":"cocos2d-x for C++","fork":true,"url":"https://api.github.com/repos/neokim/cocos2d-x","forks_url":"https://api.github.com/repos/neokim/cocos2d-x/forks","keys_url":"https://api.github.com/repos/neokim/cocos2d-x/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neokim/cocos2d-x/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neokim/cocos2d-x/teams","hooks_url":"https://api.github.com/repos/neokim/cocos2d-x/hooks","issue_events_url":"https://api.github.com/repos/neokim/cocos2d-x/issues/events{/number}","events_url":"https://api.github.com/repos/neokim/cocos2d-x/events","assignees_url":"https://api.github.com/repos/neokim/cocos2d-x/assignees{/user}","branches_url":"https://api.github.com/repos/neokim/cocos2d-x/branches{/branch}","tags_url":"https://api.github.com/repos/neokim/cocos2d-x/tags","blobs_url":"https://api.github.com/repos/neokim/cocos2d-x/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neokim/cocos2d-x/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neokim/cocos2d-x/git/refs{/sha}","trees_url":"https://api.github.com/repos/neokim/cocos2d-x/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neokim/cocos2d-x/statuses/{sha}","languages_url":"https://api.github.com/repos/neokim/cocos2d-x/languages","stargazers_url":"https://api.github.com/repos/neokim/cocos2d-x/stargazers","contributors_url":"https://api.github.com/repos/neokim/cocos2d-x/contributors","subscribers_url":"https://api.github.com/repos/neokim/cocos2d-x/subscribers","subscription_url":"https://api.github.com/repos/neokim/cocos2d-x/subscription","commits_url":"https://api.github.com/repos/neokim/cocos2d-x/commits{/sha}","git_commits_url":"https://api.github.com/repos/neokim/cocos2d-x/git/commits{/sha}","comments_url":"https://api.github.com/repos/neokim/cocos2d-x/comments{/number}","issue_comment_url":"https://api.github.com/repos/neokim/cocos2d-x/issues/comments{/number}","contents_url":"https://api.github.com/repos/neokim/cocos2d-x/contents/{+path}","compare_url":"https://api.github.com/repos/neokim/cocos2d-x/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neokim/cocos2d-x/merges","archive_url":"https://api.github.com/repos/neokim/cocos2d-x/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neokim/cocos2d-x/downloads","issues_url":"https://api.github.com/repos/neokim/cocos2d-x/issues{/number}","pulls_url":"https://api.github.com/repos/neokim/cocos2d-x/pulls{/number}","milestones_url":"https://api.github.com/repos/neokim/cocos2d-x/milestones{/number}","notifications_url":"https://api.github.com/repos/neokim/cocos2d-x/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neokim/cocos2d-x/labels{/name}","releases_url":"https://api.github.com/repos/neokim/cocos2d-x/releases{/id}","created_at":"2015-06-15T11:05:43Z","updated_at":"2015-06-15T11:06:05Z","pushed_at":"2015-07-02T02:53:46Z","git_url":"git://github.com/neokim/cocos2d-x.git","ssh_url":"git@github.com:neokim/cocos2d-x.git","clone_url":"https://github.com/neokim/cocos2d-x.git","svn_url":"https://github.com/neokim/cocos2d-x","homepage":"http://www.cocos2d-x.org","size":852810,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"v3"}},"base":{"label":"cocos2d:v3","ref":"v3","sha":"40521ad1c4f04319785c1758420d758d59895b21","user":{"login":"cocos2d","id":234324,"avatar_url":"https://avatars.githubusercontent.com/u/234324?v=3","gravatar_id":"","url":"https://api.github.com/users/cocos2d","html_url":"https://github.com/cocos2d","followers_url":"https://api.github.com/users/cocos2d/followers","following_url":"https://api.github.com/users/cocos2d/following{/other_user}","gists_url":"https://api.github.com/users/cocos2d/gists{/gist_id}","starred_url":"https://api.github.com/users/cocos2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cocos2d/subscriptions","organizations_url":"https://api.github.com/users/cocos2d/orgs","repos_url":"https://api.github.com/users/cocos2d/repos","events_url":"https://api.github.com/users/cocos2d/events{/privacy}","received_events_url":"https://api.github.com/users/cocos2d/received_events","type":"Organization","site_admin":false},"repo":{"id":1093228,"name":"cocos2d-x","full_name":"cocos2d/cocos2d-x","owner":{"login":"cocos2d","id":234324,"avatar_url":"https://avatars.githubusercontent.com/u/234324?v=3","gravatar_id":"","url":"https://api.github.com/users/cocos2d","html_url":"https://github.com/cocos2d","followers_url":"https://api.github.com/users/cocos2d/followers","following_url":"https://api.github.com/users/cocos2d/following{/other_user}","gists_url":"https://api.github.com/users/cocos2d/gists{/gist_id}","starred_url":"https://api.github.com/users/cocos2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cocos2d/subscriptions","organizations_url":"https://api.github.com/users/cocos2d/orgs","repos_url":"https://api.github.com/users/cocos2d/repos","events_url":"https://api.github.com/users/cocos2d/events{/privacy}","received_events_url":"https://api.github.com/users/cocos2d/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cocos2d/cocos2d-x","description":"cocos2d-x for C++","fork":false,"url":"https://api.github.com/repos/cocos2d/cocos2d-x","forks_url":"https://api.github.com/repos/cocos2d/cocos2d-x/forks","keys_url":"https://api.github.com/repos/cocos2d/cocos2d-x/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cocos2d/cocos2d-x/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cocos2d/cocos2d-x/teams","hooks_url":"https://api.github.com/repos/cocos2d/cocos2d-x/hooks","issue_events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/events{/number}","events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/events","assignees_url":"https://api.github.com/repos/cocos2d/cocos2d-x/assignees{/user}","branches_url":"https://api.github.com/repos/cocos2d/cocos2d-x/branches{/branch}","tags_url":"https://api.github.com/repos/cocos2d/cocos2d-x/tags","blobs_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/refs{/sha}","trees_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cocos2d/cocos2d-x/statuses/{sha}","languages_url":"https://api.github.com/repos/cocos2d/cocos2d-x/languages","stargazers_url":"https://api.github.com/repos/cocos2d/cocos2d-x/stargazers","contributors_url":"https://api.github.com/repos/cocos2d/cocos2d-x/contributors","subscribers_url":"https://api.github.com/repos/cocos2d/cocos2d-x/subscribers","subscription_url":"https://api.github.com/repos/cocos2d/cocos2d-x/subscription","commits_url":"https://api.github.com/repos/cocos2d/cocos2d-x/commits{/sha}","git_commits_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/commits{/sha}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/comments{/number}","issue_comment_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/comments{/number}","contents_url":"https://api.github.com/repos/cocos2d/cocos2d-x/contents/{+path}","compare_url":"https://api.github.com/repos/cocos2d/cocos2d-x/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cocos2d/cocos2d-x/merges","archive_url":"https://api.github.com/repos/cocos2d/cocos2d-x/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cocos2d/cocos2d-x/downloads","issues_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues{/number}","pulls_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls{/number}","milestones_url":"https://api.github.com/repos/cocos2d/cocos2d-x/milestones{/number}","notifications_url":"https://api.github.com/repos/cocos2d/cocos2d-x/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cocos2d/cocos2d-x/labels{/name}","releases_url":"https://api.github.com/repos/cocos2d/cocos2d-x/releases{/id}","created_at":"2010-11-18T23:17:00Z","updated_at":"2015-07-02T01:13:16Z","pushed_at":"2015-07-02T03:01:16Z","git_url":"git://github.com/cocos2d/cocos2d-x.git","ssh_url":"git@github.com:cocos2d/cocos2d-x.git","clone_url":"https://github.com/cocos2d/cocos2d-x.git","svn_url":"https://github.com/cocos2d/cocos2d-x","homepage":"http://www.cocos2d-x.org","size":1509116,"stargazers_count":6147,"watchers_count":6147,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4413,"mirror_url":null,"open_issues_count":740,"forks":4413,"open_issues":740,"watchers":6147,"default_branch":"v3"}},"_links":{"self":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607"},"html":{"href":"https://github.com/cocos2d/cocos2d-x/pull/12607"},"issue":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/12607"},"comments":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/12607/comments"},"review_comments":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607/comments"},"review_comment":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/12607/commits"},"statuses":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/statuses/c4aa5a6274149a7a5cf3f526253ba848008456e9"}}}}