diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index b3297c7deb..8e5326b405 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -2009,6 +2009,14 @@ B29A7E3F19EE1B7700872B35 /* AnimationState.h in Headers */ = {isa = PBXBuildFile; fileRef = B29A7DC619EE1B7700872B35 /* AnimationState.h */; }; B29A7E4019EE1B7700872B35 /* AnimationState.h in Headers */ = {isa = PBXBuildFile; fileRef = B29A7DC619EE1B7700872B35 /* AnimationState.h */; }; B2CC507C19776DD10041958E /* CCPhysicsJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A170721807CE7A005B8026 /* CCPhysicsJoint.cpp */; }; + B5CE6DBE1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DBC1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp */; }; + B5CE6DBF1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DBC1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp */; }; + B5CE6DC01B3BF2B1002B0419 /* UIAbstractCheckButton.h in Headers */ = {isa = PBXBuildFile; fileRef = B5CE6DBD1B3BF2B1002B0419 /* UIAbstractCheckButton.h */; }; + B5CE6DC11B3BF2B1002B0419 /* UIAbstractCheckButton.h in Headers */ = {isa = PBXBuildFile; fileRef = B5CE6DBD1B3BF2B1002B0419 /* UIAbstractCheckButton.h */; }; + B5CE6DC81B3C05BA002B0419 /* UIRadioButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DC61B3C05BA002B0419 /* UIRadioButton.cpp */; }; + B5CE6DC91B3C05BA002B0419 /* UIRadioButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DC61B3C05BA002B0419 /* UIRadioButton.cpp */; }; + B5CE6DCA1B3C05BA002B0419 /* UIRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */; }; + B5CE6DCB1B3C05BA002B0419 /* UIRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */; }; B603F1A81AC8EA0900A9579C /* CCTerrain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B603F1A61AC8EA0900A9579C /* CCTerrain.cpp */; }; B603F1A91AC8EA0900A9579C /* CCTerrain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B603F1A61AC8EA0900A9579C /* CCTerrain.cpp */; }; B603F1AA1AC8EA0900A9579C /* CCTerrain.h in Headers */ = {isa = PBXBuildFile; fileRef = B603F1A71AC8EA0900A9579C /* CCTerrain.h */; }; @@ -4692,6 +4700,10 @@ B29A7DC619EE1B7700872B35 /* AnimationState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimationState.h; sourceTree = ""; }; B3AF019E1842FBA400A98B85 /* b2MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MotorJoint.cpp; sourceTree = ""; }; B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = ""; }; + B5CE6DBC1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIAbstractCheckButton.cpp; sourceTree = ""; }; + B5CE6DBD1B3BF2B1002B0419 /* UIAbstractCheckButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIAbstractCheckButton.h; sourceTree = ""; }; + B5CE6DC61B3C05BA002B0419 /* UIRadioButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIRadioButton.cpp; sourceTree = ""; }; + B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIRadioButton.h; sourceTree = ""; }; B603F1A61AC8EA0900A9579C /* CCTerrain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTerrain.cpp; sourceTree = ""; }; B603F1A71AC8EA0900A9579C /* CCTerrain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTerrain.h; sourceTree = ""; }; B603F1B11AC8F1FD00A9579C /* ccShader_3D_Terrain.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_Terrain.frag; sourceTree = ""; }; @@ -6841,8 +6853,12 @@ 2905FA1218CF08D100240AA3 /* UITextField.h */, 2905F9F018CF08D000240AA3 /* UIButton.cpp */, 2905F9F118CF08D000240AA3 /* UIButton.h */, + B5CE6DBC1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp */, + B5CE6DBD1B3BF2B1002B0419 /* UIAbstractCheckButton.h */, 2905F9F218CF08D000240AA3 /* UICheckBox.cpp */, 2905F9F318CF08D000240AA3 /* UICheckBox.h */, + B5CE6DC61B3C05BA002B0419 /* UIRadioButton.cpp */, + B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */, 2905F9F618CF08D000240AA3 /* UIImageView.cpp */, 2905F9F718CF08D000240AA3 /* UIImageView.h */, ); @@ -9483,6 +9499,7 @@ 50643BD419BFAECF00EF68ED /* CCGL.h in Headers */, 15AE190C19AAD35000C27E9E /* CCDisplayFactory.h in Headers */, 15AE1A8B19AAD40300C27E9E /* b2PulleyJoint.h in Headers */, + B5CE6DCA1B3C05BA002B0419 /* UIRadioButton.h in Headers */, 15AE1A5119AAD40300C27E9E /* b2BlockAllocator.h in Headers */, 15AE199119AAD37200C27E9E /* ImageViewReader.h in Headers */, B6CAB42B1AF9AA1A00B9B856 /* btRaycastVehicle.h in Headers */, @@ -9763,6 +9780,7 @@ 50ABBECD1925AB6F00A911A9 /* s3tc.h in Headers */, B6CAB3651AF9AA1A00B9B856 /* btContinuousConvexCollision.h in Headers */, 15AE1BD119AAE01E00C27E9E /* CCControlHuePicker.h in Headers */, + B5CE6DC01B3BF2B1002B0419 /* UIAbstractCheckButton.h in Headers */, D0FD03571A3B51AA00825BB5 /* CCAllocatorMutex.h in Headers */, B6CAB36D1AF9AA1A00B9B856 /* btDiscreteCollisionDetectorInterface.h in Headers */, 50ABBE771925AB6F00A911A9 /* CCEventListenerTouch.h in Headers */, @@ -9880,6 +9898,7 @@ ED74D76A1A5B8A2600157FD4 /* CCPhysicsHelper.h in Headers */, 5034CA40191D591100CE6051 /* ccShader_Position_uColor.vert in Headers */, B6DD2FD41B04825B00E47F5F /* DetourStatus.h in Headers */, + B5CE6DCB1B3C05BA002B0419 /* UIRadioButton.h in Headers */, B665E2891AA80A6500DDB1C5 /* CCPUDoStopSystemEventHandlerTranslator.h in Headers */, 15AE184719AAD2F700C27E9E /* CCSprite3DMaterial.h in Headers */, B6DD2FC21B04825B00E47F5F /* DetourMath.h in Headers */, @@ -10225,6 +10244,7 @@ B6CAB2F41AF9AA1A00B9B856 /* btTetrahedronShape.h in Headers */, 1A5701E9180BCB8C0088DEC7 /* CCTransition.h in Headers */, 15AE198F19AAD36E00C27E9E /* CheckBoxReader.h in Headers */, + B5CE6DC11B3BF2B1002B0419 /* UIAbstractCheckButton.h in Headers */, B665E3911AA80A6500DDB1C5 /* CCPUPlaneCollider.h in Headers */, B6DD2FAE1B04825B00E47F5F /* DetourDebugDraw.h in Headers */, 382384011A258FA7002C4610 /* util.h in Headers */, @@ -10886,6 +10906,7 @@ B665E3961AA80A6500DDB1C5 /* CCPUPointEmitter.cpp in Sources */, 15AE184019AAD2F700C27E9E /* CCSprite3D.cpp in Sources */, B6CAB2E51AF9AA1A00B9B856 /* btSphereShape.cpp in Sources */, + B5CE6DBE1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp in Sources */, B6CAB41F1AF9AA1A00B9B856 /* btMLCPSolver.cpp in Sources */, 46A170E61807CECA005B8026 /* CCPhysicsBody.cpp in Sources */, B665E40A1AA80A6600DDB1C5 /* CCPUSphereSurfaceEmitterTranslator.cpp in Sources */, @@ -11593,6 +11614,7 @@ B665E42A1AA80A6600DDB1C5 /* CCPUVelocityMatchingAffector.cpp in Sources */, 15AE19A619AAD39600C27E9E /* TextReader.cpp in Sources */, 15AE198819AAD36A00C27E9E /* ButtonReader.cpp in Sources */, + B5CE6DC81B3C05BA002B0419 /* UIRadioButton.cpp in Sources */, B6CAB4131AF9AA1A00B9B856 /* btMultiBodyPoint2Point.cpp in Sources */, B6CAB2C91AF9AA1A00B9B856 /* btMinkowskiSumShape.cpp in Sources */, 4D76BE3A1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */, @@ -11985,6 +12007,7 @@ 1A5701BA180BCB5A0088DEC7 /* CCLabel.cpp in Sources */, 15AE18AD19AAD33D00C27E9E /* CCBFileLoader.cpp in Sources */, B6CAB1F61AF9AA1A00B9B856 /* btDbvt.cpp in Sources */, + B5CE6DC91B3C05BA002B0419 /* UIRadioButton.cpp in Sources */, 15AE18AB19AAD33D00C27E9E /* CCBAnimationManager.cpp in Sources */, 15AE1B7219AADA9A00C27E9E /* UIListView.cpp in Sources */, 1A5701BE180BCB5A0088DEC7 /* CCLabelAtlas.cpp in Sources */, @@ -12240,6 +12263,7 @@ 15AE195319AAD35100C27E9E /* CCDisplayFactory.cpp in Sources */, 182C5CD71A98F30500C30D34 /* Sprite3DReader.cpp in Sources */, 50ABC0061926664800A911A9 /* CCThread-apple.mm in Sources */, + B5CE6DBF1B3BF2B1002B0419 /* UIAbstractCheckButton.cpp in Sources */, B6CAB4B81AF9AA1A00B9B856 /* SpuFakeDma.cpp in Sources */, 50ABBEB61925AB6F00A911A9 /* CCUserDefault-android.cpp in Sources */, B6CAB4481AF9AA1A00B9B856 /* btThreadSupportInterface.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 550e9fa150..f1a8b18e4b 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ buildPhases = ( ); dependencies = ( + 293CE83A1B43F3ED00F66EF1 /* PBXTargetDependency */, 1ADA8BA418CF277400AE24B9 /* PBXTargetDependency */, 1ADA8BA618CF277400AE24B9 /* PBXTargetDependency */, 1ADA8BA818CF277400AE24B9 /* PBXTargetDependency */, @@ -27,6 +28,7 @@ buildPhases = ( ); dependencies = ( + 293CE83C1B43F3F300F66EF1 /* PBXTargetDependency */, 1ADA8BAC18CF277C00AE24B9 /* PBXTargetDependency */, 1ADA8BAE18CF277C00AE24B9 /* PBXTargetDependency */, 1ADA8BB018CF277C00AE24B9 /* PBXTargetDependency */, @@ -897,6 +899,8 @@ A5030C3619D059DA000E78E7 /* OpenURLTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */; }; B2507B6B192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; B2507B6C192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; + B5CE6DD11B3C08F8002B0419 /* UIRadioButtonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DCD1B3C08F8002B0419 /* UIRadioButtonTest.cpp */; }; + B5CE6DD21B3C08F8002B0419 /* UIRadioButtonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DCD1B3C08F8002B0419 /* UIRadioButtonTest.cpp */; }; B603F1AF1AC8EA4E00A9579C /* TerrainTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B603F1AD1AC8EA4E00A9579C /* TerrainTest.cpp */; }; B603F1B01AC8EA4E00A9579C /* TerrainTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B603F1AD1AC8EA4E00A9579C /* TerrainTest.cpp */; }; B603F1B41AC8FBFB00A9579C /* TerrainTest in Resources */ = {isa = PBXBuildFile; fileRef = B603F1B31AC8FBFB00A9579C /* TerrainTest */; }; @@ -1126,6 +1130,20 @@ remoteGlobalIDString = 1A0EE41918CDF799004CD58F; remoteInfo = "lua-empty-test iOS"; }; + 293CE8391B43F3ED00F66EF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */; + proxyType = 1; + remoteGlobalIDString = 1856634B1B4155D3009EF2AE; + remoteInfo = "js-tests Mac"; + }; + 293CE83B1B43F3F300F66EF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */; + proxyType = 1; + remoteGlobalIDString = 185663961B4155DD009EF2AE; + remoteInfo = "js-tests iOS"; + }; 3E6177011960FAED00DE83F5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 46A15F9C1807A4F8005B8026 /* cocos2d_libs.xcodeproj */; @@ -1938,6 +1956,8 @@ A5030C3319D059DA000E78E7 /* OpenURLTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpenURLTest.cpp; path = OpenURLTest/OpenURLTest.cpp; sourceTree = ""; }; A5030C3419D059DA000E78E7 /* OpenURLTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenURLTest.h; path = OpenURLTest/OpenURLTest.h; sourceTree = ""; }; B2507B6A192589AF00FA4972 /* Shaders3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Shaders3D; path = "../tests/cpp-tests/Resources/Shaders3D"; sourceTree = ""; }; + B5CE6DCD1B3C08F8002B0419 /* UIRadioButtonTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIRadioButtonTest.cpp; sourceTree = ""; }; + B5CE6DCE1B3C08F8002B0419 /* UIRadioButtonTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIRadioButtonTest.h; sourceTree = ""; }; B603F1AD1AC8EA4E00A9579C /* TerrainTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TerrainTest.cpp; path = TerrainTest/TerrainTest.cpp; sourceTree = ""; }; B603F1AE1AC8EA4E00A9579C /* TerrainTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TerrainTest.h; path = TerrainTest/TerrainTest.h; sourceTree = ""; }; B603F1B31AC8FBFB00A9579C /* TerrainTest */ = {isa = PBXFileReference; lastKnownFileType = folder; name = TerrainTest; path = "../tests/cpp-tests/Resources/TerrainTest"; sourceTree = ""; }; @@ -3493,15 +3513,6 @@ path = ZwoptexTest; sourceTree = ""; }; - 1AC35C6F18CECF0C00F37B72 /* VibrateTest */ = { - isa = PBXGroup; - children = ( - 1AC35C6D18CECF0C00F37B72 /* VibrateTest.cpp */, - 1AC35C6E18CECF0C00F37B72 /* VibrateTest.h */, - ); - path = VibrateTest; - sourceTree = ""; - }; 1AC35C6D18CECF1400F37B72 /* proj.ios */ = { isa = PBXGroup; children = ( @@ -3542,6 +3553,15 @@ path = Classes; sourceTree = ""; }; + 1AC35C6F18CECF0C00F37B72 /* VibrateTest */ = { + isa = PBXGroup; + children = ( + 1AC35C6D18CECF0C00F37B72 /* VibrateTest.cpp */, + 1AC35C6E18CECF0C00F37B72 /* VibrateTest.h */, + ); + path = VibrateTest; + sourceTree = ""; + }; 1AC35C9A18CECF1E00F37B72 /* proj.mac */ = { isa = PBXGroup; children = ( @@ -4154,6 +4174,7 @@ 29080D50191B595E0066F8DF /* UIListViewTest */, 29080D55191B595E0066F8DF /* UILoadingBarTest */, 29080D5A191B595E0066F8DF /* UIPageViewTest */, + B5CE6DCC1B3C08F8002B0419 /* UIRadioButtonTest */, 29080D5F191B595E0066F8DF /* UIRichTextTest */, 3EA0FB6F191C844400B170C8 /* UIVideoPlayerTest */, ); @@ -4329,6 +4350,15 @@ name = OpenURLTest; sourceTree = ""; }; + B5CE6DCC1B3C08F8002B0419 /* UIRadioButtonTest */ = { + isa = PBXGroup; + children = ( + B5CE6DCD1B3C08F8002B0419 /* UIRadioButtonTest.cpp */, + B5CE6DCE1B3C08F8002B0419 /* UIRadioButtonTest.h */, + ); + path = UIRadioButtonTest; + sourceTree = ""; + }; B603F1AC1AC8EA2E00A9579C /* TerrainTest */ = { isa = PBXGroup; children = ( @@ -5424,6 +5454,7 @@ 1AC35C4F18CECF0C00F37B72 /* SpriteTest.cpp in Sources */, 29080D9D191B595E0066F8DF /* CustomParticleWidgetReader.cpp in Sources */, 1AC35C0318CECF0C00F37B72 /* FileUtilsTest.cpp in Sources */, + B5CE6DD11B3C08F8002B0419 /* UIRadioButtonTest.cpp in Sources */, B6C039D919C95D83007207DC /* LightTest.cpp in Sources */, 1AC35B5B18CECF0C00F37B72 /* CurlTest.cpp in Sources */, 29080DD5191B595E0066F8DF /* UITextAtlasTest_Editor.cpp in Sources */, @@ -5574,6 +5605,7 @@ B6CAB54F1AF9AA6C00B9B856 /* Physics3DTest.cpp in Sources */, 1AC35C1E18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */, 5EBEECB11995247000429821 /* DrawNode3D.cpp in Sources */, + B5CE6DD21B3C08F8002B0419 /* UIRadioButtonTest.cpp in Sources */, 1AC35B6818CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */, 29080D8E191B595E0066F8DF /* CocosGUIScene.cpp in Sources */, 1AC35BFA18CECF0C00F37B72 /* WebSocketTest.cpp in Sources */, @@ -5890,6 +5922,16 @@ target = 1A0EE41918CDF799004CD58F /* lua-empty-test iOS */; targetProxy = 1ADA8BAF18CF277C00AE24B9 /* PBXContainerItemProxy */; }; + 293CE83A1B43F3ED00F66EF1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 1856634B1B4155D3009EF2AE /* js-tests Mac */; + targetProxy = 293CE8391B43F3ED00F66EF1 /* PBXContainerItemProxy */; + }; + 293CE83C1B43F3F300F66EF1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 185663961B4155DD009EF2AE /* js-tests iOS */; + targetProxy = 293CE83B1B43F3F300F66EF1 /* PBXContainerItemProxy */; + }; 3E6177001960FAED00DE83F5 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = "cocos2dx iOS"; diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 556b7f4070..8a18237822 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -627,7 +627,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index caea880765..8137a888dc 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -889,9 +889,15 @@ ui\UIWidgets + + ui\UIWidgets + ui\UIWidgets + + ui\UIWidgets + ui\UIWidgets diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index aac1ec770e..06518ba58c 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems @@ -1116,7 +1116,9 @@ + + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters index a11c19fede..27516b1a9d 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters @@ -2294,9 +2294,15 @@ ui\UIWidgets + + ui\UIWidgets + ui\UIWidgets + + ui\UIWidgets + ui\UIWidgets diff --git a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj index 29858d6c1b..48e35ec96f 100644 --- a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj @@ -622,7 +622,9 @@ + + diff --git a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters index f85f970f0d..179ad04589 100644 --- a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters @@ -1764,9 +1764,15 @@ ui\UIWidgets + + ui\UIWidgets + ui\UIWidgets + + ui\UIWidgets + ui\UIWidgets diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index d97fdda1b5..d68a3e937f 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -20,7 +20,9 @@ UIListView.cpp \ UIPageView.cpp \ UIScrollView.cpp \ UIButton.cpp \ +UIAbstractCheckButton.cpp \ UICheckBox.cpp \ +UIRadioButton.cpp \ UIImageView.cpp \ UIText.cpp \ UITextAtlas.cpp \ diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index 42f2cde9a8..f5f2653e1f 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -24,7 +24,9 @@ set(COCOS_UI_SRC ui/CocosGUI.cpp ui/UIButton.cpp + ui/UIAbstractCheckButton.cpp ui/UICheckBox.cpp + ui/UIRadioButton.cpp ui/UIDeprecated.cpp ui/UIHBox.cpp ui/UIHelper.cpp diff --git a/cocos/ui/CocosGUI.h b/cocos/ui/CocosGUI.h index 126fb057dd..375bf9da10 100644 --- a/cocos/ui/CocosGUI.h +++ b/cocos/ui/CocosGUI.h @@ -30,6 +30,7 @@ THE SOFTWARE. #include "ui/UILayout.h" #include "ui/UIButton.h" #include "ui/UICheckBox.h" +#include "ui/UIRadioButton.h" #include "ui/UIImageView.h" #include "ui/UIText.h" #include "ui/UITextAtlas.h" diff --git a/cocos/ui/UIAbstractCheckButton.cpp b/cocos/ui/UIAbstractCheckButton.cpp new file mode 100644 index 0000000000..b6be4a3bc1 --- /dev/null +++ b/cocos/ui/UIAbstractCheckButton.cpp @@ -0,0 +1,582 @@ +/**************************************************************************** +Copyright (c) 2013-2014 Chukong Technologies Inc. + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "ui/UIAbstractCheckButton.h" +#include "2d/CCSprite.h" + +NS_CC_BEGIN + +namespace ui { + +static const int BACKGROUNDBOX_RENDERER_Z = (-1); +static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1); +static const int FRONTCROSS_RENDERER_Z = (-1); +static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1); +static const int FRONTCROSSDISABLED_RENDERER_Z = (-1); + +AbstractCheckButton::AbstractCheckButton(): +_backGroundBoxRenderer(nullptr), +_backGroundSelectedBoxRenderer(nullptr), +_frontCrossRenderer(nullptr), +_backGroundBoxDisabledRenderer(nullptr), +_frontCrossDisabledRenderer(nullptr), +_isSelected(true), +_isBackgroundSelectedTextureLoaded(false), +_isBackgroundDisabledTextureLoaded(false), +_isFrontCrossDisabledTextureLoaded(false), +_backGroundTexType(TextureResType::LOCAL), +_backGroundSelectedTexType(TextureResType::LOCAL), +_frontCrossTexType(TextureResType::LOCAL), +_backGroundDisabledTexType(TextureResType::LOCAL), +_frontCrossDisabledTexType(TextureResType::LOCAL), +_zoomScale(0.1f), +_backgroundTextureScaleX(1.0), +_backgroundTextureScaleY(1.0), +_backGroundBoxRendererAdaptDirty(true), +_backGroundSelectedBoxRendererAdaptDirty(true), +_frontCrossRendererAdaptDirty(true), +_backGroundBoxDisabledRendererAdaptDirty(true), +_frontCrossDisabledRendererAdaptDirty(true) +{ + setTouchEnabled(true); +} + +AbstractCheckButton::~AbstractCheckButton() +{ +} + +bool AbstractCheckButton::init(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType) +{ + bool ret = true; + do + { + if (!Widget::init()) + { + ret = false; + break; + } + + setSelected(false); + loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType); + } while (0); + return ret; +} + +bool AbstractCheckButton::init() +{ + if (Widget::init()) + { + setSelected(false); + return true; + } + return false; +} + +void AbstractCheckButton::initRenderer() +{ + _backGroundBoxRenderer = Sprite::create(); + _backGroundSelectedBoxRenderer = Sprite::create(); + _frontCrossRenderer = Sprite::create(); + _backGroundBoxDisabledRenderer = Sprite::create(); + _frontCrossDisabledRenderer = Sprite::create(); + + addProtectedChild(_backGroundBoxRenderer, BACKGROUNDBOX_RENDERER_Z, -1); + addProtectedChild(_backGroundSelectedBoxRenderer, BACKGROUNDSELECTEDBOX_RENDERER_Z, -1); + addProtectedChild(_frontCrossRenderer, FRONTCROSS_RENDERER_Z, -1); + addProtectedChild(_backGroundBoxDisabledRenderer, BACKGROUNDBOXDISABLED_RENDERER_Z, -1); + addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1); +} + +void AbstractCheckButton::loadTextures(const std::string& backGround, + const std::string& backGroundSelected, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType) +{ + loadTextureBackGround(backGround,texType); + loadTextureBackGroundSelected(backGroundSelected,texType); + loadTextureFrontCross(cross,texType); + loadTextureBackGroundDisabled(backGroundDisabled,texType); + loadTextureFrontCrossDisabled(frontCrossDisabled,texType); +} + +void AbstractCheckButton::loadTextureBackGround(const std::string& backGround,TextureResType texType) +{ + if (backGround.empty()) + { + return; + } + _backGroundTexType = texType; + switch (_backGroundTexType) + { + case TextureResType::LOCAL: + _backGroundBoxRenderer->setTexture(backGround); + break; + case TextureResType::PLIST: + _backGroundBoxRenderer->setSpriteFrame(backGround); + break; + default: + break; + } + + this->setupBackgroundTexture(); +} + +void AbstractCheckButton::setupBackgroundTexture() +{ + + this->updateChildrenDisplayedRGBA(); + + updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize()); + _backGroundBoxRendererAdaptDirty = true; +} + +void AbstractCheckButton::loadTextureBackGround(SpriteFrame* spriteFrame) +{ + _backGroundBoxRenderer->setSpriteFrame(spriteFrame); + this->setupBackgroundTexture(); +} + +void AbstractCheckButton::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType) +{ + if (backGroundSelected.empty()) + { + return; + } + + _backGroundSelectedTexType = texType; + _isBackgroundSelectedTextureLoaded = true; + switch (_backGroundSelectedTexType) + { + case TextureResType::LOCAL: + _backGroundSelectedBoxRenderer->setTexture(backGroundSelected); + break; + case TextureResType::PLIST: + _backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected); + break; + default: + break; + } + this->setupBackgroundSelectedTexture(); +} + +void AbstractCheckButton::loadTextureBackGroundSelected(SpriteFrame* spriteframe) +{ + this->_backGroundSelectedBoxRenderer->setSpriteFrame(spriteframe); + this->setupBackgroundSelectedTexture(); +} + +void AbstractCheckButton::setupBackgroundSelectedTexture() +{ + this->updateChildrenDisplayedRGBA(); + _backGroundSelectedBoxRendererAdaptDirty = true; +} + +void AbstractCheckButton::loadTextureFrontCross(const std::string& cross,TextureResType texType) +{ + if (cross.empty()) + { + return; + } + _frontCrossTexType = texType; + switch (_frontCrossTexType) + { + case TextureResType::LOCAL: + _frontCrossRenderer->setTexture(cross); + break; + case TextureResType::PLIST: + _frontCrossRenderer->setSpriteFrame(cross); + break; + default: + break; + } + this->setupFrontCrossTexture(); +} + +void AbstractCheckButton::loadTextureFrontCross(SpriteFrame* spriteFrame) +{ + this->_frontCrossRenderer->setSpriteFrame(spriteFrame); + this->setupFrontCrossTexture(); +} + +void AbstractCheckButton::setupFrontCrossTexture() +{ + this->updateChildrenDisplayedRGBA(); + _frontCrossRendererAdaptDirty = true; +} + +void AbstractCheckButton::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType) +{ + if (backGroundDisabled.empty()) + { + return; + } + _backGroundDisabledTexType = texType; + _isBackgroundDisabledTextureLoaded = true; + switch (_backGroundDisabledTexType) + { + case TextureResType::LOCAL: + _backGroundBoxDisabledRenderer->setTexture(backGroundDisabled); + break; + case TextureResType::PLIST: + _backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled); + break; + default: + break; + } + this->setupBackgroundDisable(); +} + +void AbstractCheckButton::loadTextureBackGroundDisabled(SpriteFrame* spriteframe) +{ + this->_backGroundBoxDisabledRenderer->setSpriteFrame(spriteframe); + this->setupBackgroundDisable(); +} + +void AbstractCheckButton::setupBackgroundDisable() +{ + this->updateChildrenDisplayedRGBA(); + + _backGroundBoxDisabledRendererAdaptDirty = true; +} + +void AbstractCheckButton::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType) +{ + if (frontCrossDisabled.empty()) + { + return; + } + _frontCrossDisabledTexType = texType; + _isFrontCrossDisabledTextureLoaded = true; + switch (_frontCrossDisabledTexType) + { + case TextureResType::LOCAL: + _frontCrossDisabledRenderer->setTexture(frontCrossDisabled); + break; + case TextureResType::PLIST: + _frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled); + break; + default: + break; + } + this->setupFrontCrossDisableTexture(); + +} + +void AbstractCheckButton::loadTextureFrontCrossDisabled(SpriteFrame* spriteframe) +{ + this->_frontCrossDisabledRenderer->setSpriteFrame(spriteframe); + this->setupFrontCrossDisableTexture(); +} + +void AbstractCheckButton::setupFrontCrossDisableTexture() +{ + this->updateChildrenDisplayedRGBA(); + _frontCrossDisabledRendererAdaptDirty = true; +} + +void AbstractCheckButton::onPressStateChangedToNormal() +{ + _backGroundBoxRenderer->setVisible(true); + _backGroundSelectedBoxRenderer->setVisible(false); + _backGroundBoxDisabledRenderer->setVisible(false); + _frontCrossDisabledRenderer->setVisible(false); + + _backGroundBoxRenderer->setGLProgramState(this->getNormalGLProgramState()); + _frontCrossRenderer->setGLProgramState(this->getNormalGLProgramState()); + + + _backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); + _frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); + + + if (_isSelected) + { + _frontCrossRenderer->setVisible(true); + } +} + +void AbstractCheckButton::onPressStateChangedToPressed() +{ + _backGroundBoxRenderer->setGLProgramState(this->getNormalGLProgramState()); + _frontCrossRenderer->setGLProgramState(this->getNormalGLProgramState()); + + if (!_isBackgroundSelectedTextureLoaded) + { + _backGroundBoxRenderer->setScale(_backgroundTextureScaleX + _zoomScale, + _backgroundTextureScaleY + _zoomScale); + _frontCrossRenderer->setScale(_backgroundTextureScaleX + _zoomScale, + _backgroundTextureScaleY + _zoomScale); + } + else + { + _backGroundBoxRenderer->setVisible(false); + _backGroundSelectedBoxRenderer->setVisible(true); + _backGroundBoxDisabledRenderer->setVisible(false); + _frontCrossDisabledRenderer->setVisible(false); + } +} + +void AbstractCheckButton::onPressStateChangedToDisabled() +{ + if (!_isBackgroundDisabledTextureLoaded + || !_isFrontCrossDisabledTextureLoaded) + { + _backGroundBoxRenderer->setGLProgramState(this->getGrayGLProgramState()); + _frontCrossRenderer->setGLProgramState(this->getGrayGLProgramState()); + } + else + { + _backGroundBoxRenderer->setVisible(false); + _backGroundBoxDisabledRenderer->setVisible(true); + } + + _backGroundSelectedBoxRenderer->setVisible(false); + _frontCrossRenderer->setVisible(false); + _backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); + _frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); + + if (_isSelected) + { + _frontCrossDisabledRenderer->setVisible(true); + } +} + +void AbstractCheckButton::setZoomScale(float scale) +{ + _zoomScale = scale; +} + +float AbstractCheckButton::getZoomScale()const +{ + return _zoomScale; +} + +void AbstractCheckButton::setSelected(bool selected) +{ + if (selected == _isSelected) + { + return; + } + _isSelected = selected; + _frontCrossRenderer->setVisible(_isSelected); +} + +bool AbstractCheckButton::isSelected()const +{ + return _isSelected; +} + +void AbstractCheckButton::onSizeChanged() +{ + Widget::onSizeChanged(); + _backGroundBoxRendererAdaptDirty = true; + _backGroundSelectedBoxRendererAdaptDirty = true; + _frontCrossRendererAdaptDirty = true; + _backGroundBoxDisabledRendererAdaptDirty = true; + _frontCrossDisabledRendererAdaptDirty = true; +} + +void AbstractCheckButton::adaptRenderers() +{ + if (_backGroundBoxRendererAdaptDirty) + { + backGroundTextureScaleChangedWithSize(); + _backGroundBoxRendererAdaptDirty = false; + } + if (_backGroundSelectedBoxRendererAdaptDirty) + { + backGroundSelectedTextureScaleChangedWithSize(); + _backGroundSelectedBoxRendererAdaptDirty = false; + } + if (_frontCrossRendererAdaptDirty) + { + frontCrossTextureScaleChangedWithSize(); + _frontCrossRendererAdaptDirty = false; + } + if (_backGroundBoxDisabledRendererAdaptDirty) + { + backGroundDisabledTextureScaleChangedWithSize(); + _backGroundBoxDisabledRendererAdaptDirty = false; + } + if (_frontCrossDisabledRendererAdaptDirty) + { + frontCrossDisabledTextureScaleChangedWithSize(); + _frontCrossDisabledRendererAdaptDirty = false; + } +} + +Size AbstractCheckButton::getVirtualRendererSize() const +{ + return _backGroundBoxRenderer->getContentSize(); +} + +Node* AbstractCheckButton::getVirtualRenderer() +{ + return _backGroundBoxRenderer; +} + +void AbstractCheckButton::backGroundTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _backGroundBoxRenderer->setScale(1.0f); + _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; + } + else + { + Size textureSize = _backGroundBoxRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _backGroundBoxRenderer->setScale(1.0f); + _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; + return; + } + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; + _backgroundTextureScaleX = scaleX; + _backgroundTextureScaleY = scaleY; + _backGroundBoxRenderer->setScaleX(scaleX); + _backGroundBoxRenderer->setScaleY(scaleY); + } + _backGroundBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); +} + +void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _backGroundSelectedBoxRenderer->setScale(1.0f); + } + else + { + Size textureSize = _backGroundSelectedBoxRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _backGroundSelectedBoxRenderer->setScale(1.0f); + return; + } + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; + _backGroundSelectedBoxRenderer->setScaleX(scaleX); + _backGroundSelectedBoxRenderer->setScaleY(scaleY); + } + _backGroundSelectedBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); +} + +void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _frontCrossRenderer->setScale(1.0f); + } + else + { + Size textureSize = _frontCrossRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _frontCrossRenderer->setScale(1.0f); + return; + } + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; + _frontCrossRenderer->setScaleX(scaleX); + _frontCrossRenderer->setScaleY(scaleY); + } + _frontCrossRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); +} + +void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _backGroundBoxDisabledRenderer->setScale(1.0f); + } + else + { + Size textureSize = _backGroundBoxDisabledRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _backGroundBoxDisabledRenderer->setScale(1.0f); + return; + } + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; + _backGroundBoxDisabledRenderer->setScaleX(scaleX); + _backGroundBoxDisabledRenderer->setScaleY(scaleY); + } + _backGroundBoxDisabledRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); +} + +void AbstractCheckButton::frontCrossDisabledTextureScaleChangedWithSize() +{ + if (_ignoreSize) + { + _frontCrossDisabledRenderer->setScale(1.0f); + } + else + { + Size textureSize = _frontCrossDisabledRenderer->getContentSize(); + if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) + { + _frontCrossDisabledRenderer->setScale(1.0f); + return; + } + float scaleX = _contentSize.width / textureSize.width; + float scaleY = _contentSize.height / textureSize.height; + _frontCrossDisabledRenderer->setScaleX(scaleX); + _frontCrossDisabledRenderer->setScaleY(scaleY); + } + _frontCrossDisabledRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); +} + +void AbstractCheckButton::copySpecialProperties(Widget *widget) +{ + AbstractCheckButton* abstractCheckButton = dynamic_cast(widget); + if (abstractCheckButton) + { + loadTextureBackGround(abstractCheckButton->_backGroundBoxRenderer->getSpriteFrame()); + loadTextureBackGroundSelected(abstractCheckButton->_backGroundSelectedBoxRenderer->getSpriteFrame()); + loadTextureFrontCross(abstractCheckButton->_frontCrossRenderer->getSpriteFrame()); + loadTextureBackGroundDisabled(abstractCheckButton->_backGroundBoxDisabledRenderer->getSpriteFrame()); + loadTextureFrontCrossDisabled(abstractCheckButton->_frontCrossDisabledRenderer->getSpriteFrame()); + setSelected(abstractCheckButton->_isSelected); + _zoomScale = abstractCheckButton->_zoomScale; + _backgroundTextureScaleX = abstractCheckButton->_backgroundTextureScaleX; + _backgroundTextureScaleY = abstractCheckButton->_backgroundTextureScaleY; + _isBackgroundSelectedTextureLoaded = abstractCheckButton->_isBackgroundSelectedTextureLoaded; + _isBackgroundDisabledTextureLoaded = abstractCheckButton->_isBackgroundDisabledTextureLoaded; + _isFrontCrossDisabledTextureLoaded = abstractCheckButton->_isFrontCrossDisabledTextureLoaded; + } +} + +} + +NS_CC_END diff --git a/cocos/ui/UIAbstractCheckButton.h b/cocos/ui/UIAbstractCheckButton.h new file mode 100644 index 0000000000..8ff64aa7cc --- /dev/null +++ b/cocos/ui/UIAbstractCheckButton.h @@ -0,0 +1,218 @@ +/**************************************************************************** +Copyright (c) 2013-2014 Chukong Technologies Inc. + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __UIABSTRACTCHECKBUTTON_H__ +#define __UIABSTRACTCHECKBUTTON_H__ + +#include "ui/UIWidget.h" +#include "ui/GUIExport.h" + +/** + * @addtogroup ui + * @{ + */ +NS_CC_BEGIN +class Sprite; + +namespace ui { + +/** + * AbstractCheckButton is a specific type of two-states button that can be either checked or unchecked. + */ +class CC_GUI_DLL AbstractCheckButton : public Widget +{ + +public: + /** + * Load all textures for initializing a check button. + * + * @param background The background image name. + * @param backgroundSelected The background selected image name. + * @param cross The cross image name. + * @param backgroundDisabled The background disabled state texture. + * @param frontCrossDisabled The front cross disabled state image name. + * @param texType @see `Widget::TextureResType` + */ + void loadTextures(const std::string& background, + const std::string& backgroundSelected, + const std::string& cross, + const std::string& backgroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType = TextureResType::LOCAL); + + /** + * Load background texture for check button. + * + * @param backGround The background image name. + * @param type @see `Widget::TextureResType` + */ + void loadTextureBackGround(const std::string& backGround,TextureResType type = TextureResType::LOCAL); + + /** + * Load background selected state texture for check button. + * + * @param backGroundSelected The background selected state image name. + * @param texType @see `Widget::TextureResType` + */ + void loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType = TextureResType::LOCAL); + + /** + * Load cross texture for check button. + * + * @param crossTextureName The cross texture name. + * @param texType @see `Widget::TextureResType` + */ + void loadTextureFrontCross(const std::string& crossTextureName,TextureResType texType = TextureResType::LOCAL); + + /** + * Load background disabled state texture for checkbox. + * + * @param backGroundDisabled The background disabled state texture name. + * + * @param texType @see `Widget::TextureResType` + */ + void loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType = TextureResType::LOCAL); + + /** + * Load frontcross disabled texture for checkbox. + * + * @param frontCrossDisabled The front cross disabled state texture name. + * @param texType @see `Widget::TextureResType` + */ + void loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType = TextureResType::LOCAL); + + /** + * Query whether CheckBox is selected or not. + *@return true means "selected", false otherwise. + */ + bool isSelected()const; + + /** + * Change CheckBox state. + * Set to true will cause the CheckBox's state to "selected", false otherwise. + *@param selected Set to true will change CheckBox to selected state, false otherwise. + */ + void setSelected(bool selected); + + //override functions + virtual Size getVirtualRendererSize() const override; + virtual Node* getVirtualRenderer() override; + + /** When user pressed the CheckBox, the button will zoom to a scale. + * The final scale of the CheckBox equals (CheckBox original scale + _zoomScale) + * @since v3.3 + */ + void setZoomScale(float scale); + /** + * @brief Return a zoom scale + * @return A zoom scale of Checkbox. + * @since v3.3 + */ + float getZoomScale()const; + +CC_CONSTRUCTOR_ACCESS: + virtual bool init() override; + virtual bool init(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType = TextureResType::LOCAL); + +protected: + /** + * Default constructor. + */ + AbstractCheckButton(); + + /** + * Default destructor. + * + * @lua NA + */ + virtual ~AbstractCheckButton(); + + virtual void initRenderer() override; + virtual void onPressStateChangedToNormal() override; + virtual void onPressStateChangedToPressed() override; + virtual void onPressStateChangedToDisabled() override; + + void setupBackgroundTexture(); + void loadTextureBackGround(SpriteFrame* spriteFrame); + void setupBackgroundSelectedTexture(); + void loadTextureBackGroundSelected(SpriteFrame* spriteFrame); + void setupFrontCrossTexture(); + void loadTextureFrontCross(SpriteFrame* spriteframe); + void setupBackgroundDisable(); + void loadTextureBackGroundDisabled(SpriteFrame* spriteframe); + void setupFrontCrossDisableTexture(); + void loadTextureFrontCrossDisabled(SpriteFrame* spriteframe); + + virtual void dispatchSelectChangedEvent(bool selected) = 0; + + virtual void onSizeChanged() override; + + void backGroundTextureScaleChangedWithSize(); + void backGroundSelectedTextureScaleChangedWithSize(); + void frontCrossTextureScaleChangedWithSize(); + void backGroundDisabledTextureScaleChangedWithSize(); + void frontCrossDisabledTextureScaleChangedWithSize(); + + virtual void copySpecialProperties(Widget* model) override; + virtual void adaptRenderers() override; +protected: + Sprite* _backGroundBoxRenderer; + Sprite* _backGroundSelectedBoxRenderer; + Sprite* _frontCrossRenderer; + Sprite* _backGroundBoxDisabledRenderer; + Sprite* _frontCrossDisabledRenderer; + bool _isSelected; + + bool _isBackgroundSelectedTextureLoaded; + bool _isBackgroundDisabledTextureLoaded; + bool _isFrontCrossDisabledTextureLoaded; + TextureResType _backGroundTexType; + TextureResType _backGroundSelectedTexType; + TextureResType _frontCrossTexType; + TextureResType _backGroundDisabledTexType; + TextureResType _frontCrossDisabledTexType; + + float _zoomScale; + float _backgroundTextureScaleX; + float _backgroundTextureScaleY; + + bool _backGroundBoxRendererAdaptDirty; + bool _backGroundSelectedBoxRendererAdaptDirty; + bool _frontCrossRendererAdaptDirty; + bool _backGroundBoxDisabledRendererAdaptDirty; + bool _frontCrossDisabledRendererAdaptDirty; +}; + +} + +NS_CC_END +// end of ui group +/// @} + +#endif /* defined(__UIABSTRACTCHECKBUTTON_H__) */ diff --git a/cocos/ui/UICheckBox.cpp b/cocos/ui/UICheckBox.cpp index 1aeb04c368..e22430ce74 100644 --- a/cocos/ui/UICheckBox.cpp +++ b/cocos/ui/UICheckBox.cpp @@ -23,47 +23,17 @@ THE SOFTWARE. ****************************************************************************/ #include "ui/UICheckBox.h" -#include "2d/CCSprite.h" NS_CC_BEGIN namespace ui { -static const int BACKGROUNDBOX_RENDERER_Z = (-1); -static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1); -static const int FRONTCROSS_RENDERER_Z = (-1); -static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1); -static const int FRONTCROSSDISABLED_RENDERER_Z = (-1); - IMPLEMENT_CLASS_GUI_INFO(CheckBox) CheckBox::CheckBox(): -_backGroundBoxRenderer(nullptr), -_backGroundSelectedBoxRenderer(nullptr), -_frontCrossRenderer(nullptr), -_backGroundBoxDisabledRenderer(nullptr), -_frontCrossDisabledRenderer(nullptr), -_isSelected(true), _checkBoxEventListener(nullptr), -_checkBoxEventSelector(nullptr), -_isBackgroundSelectedTextureLoaded(false), -_isBackgroundDisabledTextureLoaded(false), -_isFrontCrossDisabledTextureLoaded(false), -_backGroundTexType(TextureResType::LOCAL), -_backGroundSelectedTexType(TextureResType::LOCAL), -_frontCrossTexType(TextureResType::LOCAL), -_backGroundDisabledTexType(TextureResType::LOCAL), -_frontCrossDisabledTexType(TextureResType::LOCAL), -_zoomScale(0.1f), -_backgroundTextureScaleX(1.0), -_backgroundTextureScaleY(1.0), -_backGroundBoxRendererAdaptDirty(true), -_backGroundSelectedBoxRendererAdaptDirty(true), -_frontCrossRendererAdaptDirty(true), -_backGroundBoxDisabledRendererAdaptDirty(true), -_frontCrossDisabledRendererAdaptDirty(true) +_checkBoxEventSelector(nullptr) { - setTouchEnabled(true); } CheckBox::~CheckBox() @@ -124,243 +94,6 @@ CheckBox* CheckBox::create(const std::string& backGround, return nullptr; } -bool CheckBox::init(const std::string& backGround, - const std::string& backGroundSeleted, - const std::string& cross, - const std::string& backGroundDisabled, - const std::string& frontCrossDisabled, - TextureResType texType) -{ - bool ret = true; - do - { - if (!Widget::init()) - { - ret = false; - break; - } - - setSelected(false); - loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType); - } while (0); - return ret; -} - -bool CheckBox::init() -{ - if (Widget::init()) - { - setSelected(false); - return true; - } - return false; -} - -void CheckBox::initRenderer() -{ - _backGroundBoxRenderer = Sprite::create(); - _backGroundSelectedBoxRenderer = Sprite::create(); - _frontCrossRenderer = Sprite::create(); - _backGroundBoxDisabledRenderer = Sprite::create(); - _frontCrossDisabledRenderer = Sprite::create(); - - addProtectedChild(_backGroundBoxRenderer, BACKGROUNDBOX_RENDERER_Z, -1); - addProtectedChild(_backGroundSelectedBoxRenderer, BACKGROUNDSELECTEDBOX_RENDERER_Z, -1); - addProtectedChild(_frontCrossRenderer, FRONTCROSS_RENDERER_Z, -1); - addProtectedChild(_backGroundBoxDisabledRenderer, BACKGROUNDBOXDISABLED_RENDERER_Z, -1); - addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1); -} - -void CheckBox::loadTextures(const std::string& backGround, - const std::string& backGroundSelected, - const std::string& cross, - const std::string& backGroundDisabled, - const std::string& frontCrossDisabled, - TextureResType texType) -{ - loadTextureBackGround(backGround,texType); - loadTextureBackGroundSelected(backGroundSelected,texType); - loadTextureFrontCross(cross,texType); - loadTextureBackGroundDisabled(backGroundDisabled,texType); - loadTextureFrontCrossDisabled(frontCrossDisabled,texType); -} - -void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResType texType) -{ - if (backGround.empty()) - { - return; - } - _backGroundTexType = texType; - switch (_backGroundTexType) - { - case TextureResType::LOCAL: - _backGroundBoxRenderer->setTexture(backGround); - break; - case TextureResType::PLIST: - _backGroundBoxRenderer->setSpriteFrame(backGround); - break; - default: - break; - } - - this->setupBackgroundTexture(); -} - -void CheckBox::setupBackgroundTexture() -{ - - this->updateChildrenDisplayedRGBA(); - - updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize()); - _backGroundBoxRendererAdaptDirty = true; -} - -void CheckBox::loadTextureBackGround(SpriteFrame* spriteFrame) -{ - _backGroundBoxRenderer->setSpriteFrame(spriteFrame); - this->setupBackgroundTexture(); -} - -void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType) -{ - if (backGroundSelected.empty()) - { - return; - } - - _backGroundSelectedTexType = texType; - _isBackgroundSelectedTextureLoaded = true; - switch (_backGroundSelectedTexType) - { - case TextureResType::LOCAL: - _backGroundSelectedBoxRenderer->setTexture(backGroundSelected); - break; - case TextureResType::PLIST: - _backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected); - break; - default: - break; - } - this->setupBackgroundSelectedTexture(); -} - -void CheckBox::loadTextureBackGroundSelected(SpriteFrame* spriteframe) -{ - this->_backGroundSelectedBoxRenderer->setSpriteFrame(spriteframe); - this->setupBackgroundSelectedTexture(); -} - -void CheckBox::setupBackgroundSelectedTexture() -{ - this->updateChildrenDisplayedRGBA(); - _backGroundSelectedBoxRendererAdaptDirty = true; -} - -void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType) -{ - if (cross.empty()) - { - return; - } - _frontCrossTexType = texType; - switch (_frontCrossTexType) - { - case TextureResType::LOCAL: - _frontCrossRenderer->setTexture(cross); - break; - case TextureResType::PLIST: - _frontCrossRenderer->setSpriteFrame(cross); - break; - default: - break; - } - this->setupFrontCrossTexture(); -} - -void CheckBox::loadTextureFrontCross(SpriteFrame* spriteFrame) -{ - this->_frontCrossRenderer->setSpriteFrame(spriteFrame); - this->setupFrontCrossTexture(); -} - -void CheckBox::setupFrontCrossTexture() -{ - this->updateChildrenDisplayedRGBA(); - _frontCrossRendererAdaptDirty = true; -} - -void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType) -{ - if (backGroundDisabled.empty()) - { - return; - } - _backGroundDisabledTexType = texType; - _isBackgroundDisabledTextureLoaded = true; - switch (_backGroundDisabledTexType) - { - case TextureResType::LOCAL: - _backGroundBoxDisabledRenderer->setTexture(backGroundDisabled); - break; - case TextureResType::PLIST: - _backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled); - break; - default: - break; - } - this->setupBackgroundDisable(); -} - -void CheckBox::loadTextureBackGroundDisabled(SpriteFrame* spriteframe) -{ - this->_backGroundBoxDisabledRenderer->setSpriteFrame(spriteframe); - this->setupBackgroundDisable(); -} - -void CheckBox::setupBackgroundDisable() -{ - this->updateChildrenDisplayedRGBA(); - - _backGroundBoxDisabledRendererAdaptDirty = true; -} - -void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType) -{ - if (frontCrossDisabled.empty()) - { - return; - } - _frontCrossDisabledTexType = texType; - _isFrontCrossDisabledTextureLoaded = true; - switch (_frontCrossDisabledTexType) - { - case TextureResType::LOCAL: - _frontCrossDisabledRenderer->setTexture(frontCrossDisabled); - break; - case TextureResType::PLIST: - _frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled); - break; - default: - break; - } - this->setupFrontCrossDisableTexture(); - -} - -void CheckBox::loadTextureFrontCrossDisabled(SpriteFrame* spriteframe) -{ - this->_frontCrossDisabledRenderer->setSpriteFrame(spriteframe); - this->setupFrontCrossDisableTexture(); -} - -void CheckBox::setupFrontCrossDisableTexture() -{ - this->updateChildrenDisplayedRGBA(); - _frontCrossDisabledRendererAdaptDirty = true; -} - - void CheckBox::releaseUpEvent() { Widget::releaseUpEvent(); @@ -368,144 +101,36 @@ void CheckBox::releaseUpEvent() if (_isSelected) { setSelected(false); - unSelectedEvent(); + dispatchSelectChangedEvent(false); } else { setSelected(true); - selectedEvent(); + dispatchSelectChangedEvent(true); } } - -void CheckBox::onPressStateChangedToNormal() +void CheckBox::dispatchSelectChangedEvent(bool selected) { - _backGroundBoxRenderer->setVisible(true); - _backGroundSelectedBoxRenderer->setVisible(false); - _backGroundBoxDisabledRenderer->setVisible(false); - _frontCrossDisabledRenderer->setVisible(false); + EventType eventType = (selected ? EventType::SELECTED : EventType::UNSELECTED); + CheckBoxEventType checkBoxEventType = (selected ? CHECKBOX_STATE_EVENT_SELECTED : CHECKBOX_STATE_EVENT_UNSELECTED); - _backGroundBoxRenderer->setGLProgramState(this->getNormalGLProgramState()); - _frontCrossRenderer->setGLProgramState(this->getNormalGLProgramState()); - - - _backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); - _frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); - - - if (_isSelected) - { - _frontCrossRenderer->setVisible(true); - } -} - -void CheckBox::onPressStateChangedToPressed() -{ - _backGroundBoxRenderer->setGLProgramState(this->getNormalGLProgramState()); - _frontCrossRenderer->setGLProgramState(this->getNormalGLProgramState()); - - if (!_isBackgroundSelectedTextureLoaded) - { - _backGroundBoxRenderer->setScale(_backgroundTextureScaleX + _zoomScale, - _backgroundTextureScaleY + _zoomScale); - _frontCrossRenderer->setScale(_backgroundTextureScaleX + _zoomScale, - _backgroundTextureScaleY + _zoomScale); - } - else - { - _backGroundBoxRenderer->setVisible(false); - _backGroundSelectedBoxRenderer->setVisible(true); - _backGroundBoxDisabledRenderer->setVisible(false); - _frontCrossDisabledRenderer->setVisible(false); - } -} - -void CheckBox::onPressStateChangedToDisabled() -{ - if (!_isBackgroundDisabledTextureLoaded - || !_isFrontCrossDisabledTextureLoaded) - { - _backGroundBoxRenderer->setGLProgramState(this->getGrayGLProgramState()); - _frontCrossRenderer->setGLProgramState(this->getGrayGLProgramState()); - } - else - { - _backGroundBoxRenderer->setVisible(false); - _backGroundBoxDisabledRenderer->setVisible(true); - - } - - _backGroundSelectedBoxRenderer->setVisible(false); - _frontCrossRenderer->setVisible(false); - _backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); - _frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY); - - if (_isSelected) - { - _frontCrossDisabledRenderer->setVisible(true); - } -} - -void CheckBox::setZoomScale(float scale) -{ - _zoomScale = scale; -} - -float CheckBox::getZoomScale()const -{ - return _zoomScale; -} - -void CheckBox::setSelected(bool selected) -{ - if (selected == _isSelected) - { - return; - } - _isSelected = selected; - _frontCrossRenderer->setVisible(_isSelected); -} - -bool CheckBox::isSelected()const -{ - return _isSelected; -} - -void CheckBox::selectedEvent() -{ this->retain(); if (_checkBoxEventCallback) { - _checkBoxEventCallback(this, EventType::SELECTED); + _checkBoxEventCallback(this, eventType); } if (_ccEventCallback) { - _ccEventCallback(this, static_cast(EventType::SELECTED)); + _ccEventCallback(this, static_cast(eventType)); } if (_checkBoxEventListener && _checkBoxEventSelector) { - (_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_SELECTED); - } - this->release(); -} - -void CheckBox::unSelectedEvent() -{ - this->retain(); - if (_checkBoxEventCallback) - { - _checkBoxEventCallback(this, EventType::UNSELECTED); - } - if (_ccEventCallback) - { - _ccEventCallback(this, static_cast(EventType::UNSELECTED)); - } - if (_checkBoxEventListener && _checkBoxEventSelector) - { - (_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_UNSELECTED); + (_checkBoxEventListener->*_checkBoxEventSelector)(this, checkBoxEventType); } this->release(); + } void CheckBox::addEventListenerCheckBox(Ref *target, SEL_SelectedStateEvent selector) @@ -519,169 +144,6 @@ void CheckBox::addEventListener(const ccCheckBoxCallback& callback) _checkBoxEventCallback = callback; } -void CheckBox::onSizeChanged() -{ - Widget::onSizeChanged(); - _backGroundBoxRendererAdaptDirty = true; - _backGroundSelectedBoxRendererAdaptDirty = true; - _frontCrossRendererAdaptDirty = true; - _backGroundBoxDisabledRendererAdaptDirty = true; - _frontCrossDisabledRendererAdaptDirty = true; -} - -void CheckBox::adaptRenderers() -{ - if (_backGroundBoxRendererAdaptDirty) - { - backGroundTextureScaleChangedWithSize(); - _backGroundBoxRendererAdaptDirty = false; - } - if (_backGroundSelectedBoxRendererAdaptDirty) - { - backGroundSelectedTextureScaleChangedWithSize(); - _backGroundSelectedBoxRendererAdaptDirty = false; - } - if (_frontCrossRendererAdaptDirty) - { - frontCrossTextureScaleChangedWithSize(); - _frontCrossRendererAdaptDirty = false; - } - if (_backGroundBoxDisabledRendererAdaptDirty) - { - backGroundDisabledTextureScaleChangedWithSize(); - _backGroundBoxDisabledRendererAdaptDirty = false; - } - if (_frontCrossDisabledRendererAdaptDirty) - { - frontCrossDisabledTextureScaleChangedWithSize(); - _frontCrossDisabledRendererAdaptDirty = false; - } -} - -Size CheckBox::getVirtualRendererSize() const -{ - return _backGroundBoxRenderer->getContentSize(); -} - -Node* CheckBox::getVirtualRenderer() -{ - return _backGroundBoxRenderer; -} - -void CheckBox::backGroundTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _backGroundBoxRenderer->setScale(1.0f); - _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; - } - else - { - Size textureSize = _backGroundBoxRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _backGroundBoxRenderer->setScale(1.0f); - _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _backgroundTextureScaleX = scaleX; - _backgroundTextureScaleY = scaleY; - _backGroundBoxRenderer->setScaleX(scaleX); - _backGroundBoxRenderer->setScaleY(scaleY); - } - _backGroundBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); -} - -void CheckBox::backGroundSelectedTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _backGroundSelectedBoxRenderer->setScale(1.0f); - } - else - { - Size textureSize = _backGroundSelectedBoxRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _backGroundSelectedBoxRenderer->setScale(1.0f); - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _backGroundSelectedBoxRenderer->setScaleX(scaleX); - _backGroundSelectedBoxRenderer->setScaleY(scaleY); - } - _backGroundSelectedBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); -} - -void CheckBox::frontCrossTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _frontCrossRenderer->setScale(1.0f); - } - else - { - Size textureSize = _frontCrossRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _frontCrossRenderer->setScale(1.0f); - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _frontCrossRenderer->setScaleX(scaleX); - _frontCrossRenderer->setScaleY(scaleY); - } - _frontCrossRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); -} - -void CheckBox::backGroundDisabledTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _backGroundBoxDisabledRenderer->setScale(1.0f); - } - else - { - Size textureSize = _backGroundBoxDisabledRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _backGroundBoxDisabledRenderer->setScale(1.0f); - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _backGroundBoxDisabledRenderer->setScaleX(scaleX); - _backGroundBoxDisabledRenderer->setScaleY(scaleY); - } - _backGroundBoxDisabledRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); -} - -void CheckBox::frontCrossDisabledTextureScaleChangedWithSize() -{ - if (_ignoreSize) - { - _frontCrossDisabledRenderer->setScale(1.0f); - } - else - { - Size textureSize = _frontCrossDisabledRenderer->getContentSize(); - if (textureSize.width <= 0.0f || textureSize.height <= 0.0f) - { - _frontCrossDisabledRenderer->setScale(1.0f); - return; - } - float scaleX = _contentSize.width / textureSize.width; - float scaleY = _contentSize.height / textureSize.height; - _frontCrossDisabledRenderer->setScaleX(scaleX); - _frontCrossDisabledRenderer->setScaleY(scaleY); - } - _frontCrossDisabledRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2); -} - std::string CheckBox::getDescription() const { return "CheckBox"; @@ -697,22 +159,11 @@ void CheckBox::copySpecialProperties(Widget *widget) CheckBox* checkBox = dynamic_cast(widget); if (checkBox) { - loadTextureBackGround(checkBox->_backGroundBoxRenderer->getSpriteFrame()); - loadTextureBackGroundSelected(checkBox->_backGroundSelectedBoxRenderer->getSpriteFrame()); - loadTextureFrontCross(checkBox->_frontCrossRenderer->getSpriteFrame()); - loadTextureBackGroundDisabled(checkBox->_backGroundBoxDisabledRenderer->getSpriteFrame()); - loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledRenderer->getSpriteFrame()); - setSelected(checkBox->_isSelected); + AbstractCheckButton::copySpecialProperties(widget); _checkBoxEventListener = checkBox->_checkBoxEventListener; _checkBoxEventSelector = checkBox->_checkBoxEventSelector; _checkBoxEventCallback = checkBox->_checkBoxEventCallback; _ccEventCallback = checkBox->_ccEventCallback; - _zoomScale = checkBox->_zoomScale; - _backgroundTextureScaleX = checkBox->_backgroundTextureScaleX; - _backgroundTextureScaleY = checkBox->_backgroundTextureScaleY; - _isBackgroundSelectedTextureLoaded = checkBox->_isBackgroundSelectedTextureLoaded; - _isBackgroundDisabledTextureLoaded = checkBox->_isBackgroundDisabledTextureLoaded; - _isFrontCrossDisabledTextureLoaded = checkBox->_isFrontCrossDisabledTextureLoaded; } } diff --git a/cocos/ui/UICheckBox.h b/cocos/ui/UICheckBox.h index ae3df31fa0..ec7cf15796 100644 --- a/cocos/ui/UICheckBox.h +++ b/cocos/ui/UICheckBox.h @@ -25,7 +25,7 @@ THE SOFTWARE. #ifndef __UICHECKBOX_H__ #define __UICHECKBOX_H__ -#include "ui/UIWidget.h" +#include "ui/UIAbstractCheckButton.h" #include "ui/GUIExport.h" /** @@ -33,7 +33,6 @@ THE SOFTWARE. * @{ */ NS_CC_BEGIN -class Sprite; namespace ui { @@ -47,7 +46,7 @@ typedef enum { CHECKBOX_STATE_EVENT_SELECTED, CHECKBOX_STATE_EVENT_UNSELECTED -}CheckBoxEventType; +} CheckBoxEventType; /** * A callback which will be called after checkbox event happens. @@ -59,7 +58,7 @@ typedef void (Ref::*SEL_SelectedStateEvent)(Ref*,CheckBoxEventType); /** * Checkbox is a specific type of two-states button that can be either checked or unchecked. */ -class CC_GUI_DLL CheckBox : public Widget +class CC_GUI_DLL CheckBox : public AbstractCheckButton { DECLARE_CLASS_GUI_INFO @@ -130,64 +129,6 @@ public: const std::string& cross, TextureResType texType = TextureResType::LOCAL); - /** - * Load all textures for initializing a checkbox. - * - * @param background The background image name. - * @param backgroundSelected The background selected image name. - * @param cross The cross image name. - * @param backgroundDisabled The background disabled state texture. - * @param frontCrossDisabled The front cross disabled state image name. - * @param texType @see `Widget::TextureResType` - */ - void loadTextures(const std::string& background, - const std::string& backgroundSelected, - const std::string& cross, - const std::string& backgroundDisabled, - const std::string& frontCrossDisabled, - TextureResType texType = TextureResType::LOCAL); - - /** - * Load background texture for checkbox. - * - * @param backGround The background image name. - * @param type @see `Widget::TextureResType` - */ - void loadTextureBackGround(const std::string& backGround,TextureResType type = TextureResType::LOCAL); - - /** - * Load background selected state texture for checkbox. - * - * @param backGroundSelected The background selected state image name. - * @param texType @see `Widget::TextureResType` - */ - void loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType = TextureResType::LOCAL); - - /** - * Load cross texture for checkbox. - * - * @param crossTextureName The cross texture name. - * @param texType @see `Widget::TextureResType` - */ - void loadTextureFrontCross(const std::string& crossTextureName,TextureResType texType = TextureResType::LOCAL); - - /** - * Load background disabled state texture for checkbox. - * - * @param backGroundDisabled The background disabled state texture name. - * - * @param texType @see `Widget::TextureResType` - */ - void loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType = TextureResType::LOCAL); - - /** - * Load frontcross disabled texture for checkbox. - * - * @param frontCrossDisabled The front cross disabled state texture name. - * @param texType @see `Widget::TextureResType` - */ - void loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType = TextureResType::LOCAL); - /** * Change Checkbox state to selected. * @@ -204,19 +145,6 @@ public: */ CC_DEPRECATED_ATTRIBUTE bool getSelectedState()const{return this->isSelected();} - /** - * Query whether CheckBox is selected or not. - *@return true means "selected", false otherwise. - */ - bool isSelected()const; - - /** - * Change CheckBox state. - * Set to true will cause the CheckBox's state to "selected", false otherwise. - *@param selected Set to true will change CheckBox to selected state, false otherwise. - */ - void setSelected(bool selected); - /**Add a callback function which would be called when checkbox is selected or unselected. *@deprecated use `addEventListener(const ccCheckBoxCallback&)` instead *@param target A pointer type in Ref*. @@ -232,71 +160,17 @@ public: //override functions - virtual Size getVirtualRendererSize() const override; - virtual Node* getVirtualRenderer() override; virtual std::string getDescription() const override; - /** When user pressed the CheckBox, the button will zoom to a scale. - * The final scale of the CheckBox equals (CheckBox original scale + _zoomScale) - * @since v3.3 - */ - void setZoomScale(float scale); - /** - * @brief Return a zoom scale - * @return A zoom scale of Checkbox. - * @since v3.3 - */ - float getZoomScale()const; - -CC_CONSTRUCTOR_ACCESS: - virtual bool init() override; - virtual bool init(const std::string& backGround, - const std::string& backGroundSeleted, - const std::string& cross, - const std::string& backGroundDisabled, - const std::string& frontCrossDisabled, - TextureResType texType = TextureResType::LOCAL); - protected: - virtual void initRenderer() override; - virtual void onPressStateChangedToNormal() override; - virtual void onPressStateChangedToPressed() override; - virtual void onPressStateChangedToDisabled() override; - - void setupBackgroundTexture(); - void loadTextureBackGround(SpriteFrame* spriteFrame); - void setupBackgroundSelectedTexture(); - void loadTextureBackGroundSelected(SpriteFrame* spriteFrame); - void setupFrontCrossTexture(); - void loadTextureFrontCross(SpriteFrame* spriteframe); - void setupBackgroundDisable(); - void loadTextureBackGroundDisabled(SpriteFrame* spriteframe); - void setupFrontCrossDisableTexture(); - void loadTextureFrontCrossDisabled(SpriteFrame* spriteframe); - - void selectedEvent(); - void unSelectedEvent(); - virtual void releaseUpEvent() override; - virtual void onSizeChanged() override; - - void backGroundTextureScaleChangedWithSize(); - void backGroundSelectedTextureScaleChangedWithSize(); - void frontCrossTextureScaleChangedWithSize(); - void backGroundDisabledTextureScaleChangedWithSize(); - void frontCrossDisabledTextureScaleChangedWithSize(); + virtual void dispatchSelectChangedEvent(bool selected) override; virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; - virtual void adaptRenderers() override; + protected: - Sprite* _backGroundBoxRenderer; - Sprite* _backGroundSelectedBoxRenderer; - Sprite* _frontCrossRenderer; - Sprite* _backGroundBoxDisabledRenderer; - Sprite* _frontCrossDisabledRenderer; - bool _isSelected; //if you use the old event callback, it will retain the _checkBoxEventListener Ref* _checkBoxEventListener; @@ -315,24 +189,6 @@ protected: ccCheckBoxCallback _checkBoxEventCallback; - bool _isBackgroundSelectedTextureLoaded; - bool _isBackgroundDisabledTextureLoaded; - bool _isFrontCrossDisabledTextureLoaded; - TextureResType _backGroundTexType; - TextureResType _backGroundSelectedTexType; - TextureResType _frontCrossTexType; - TextureResType _backGroundDisabledTexType; - TextureResType _frontCrossDisabledTexType; - - float _zoomScale; - float _backgroundTextureScaleX; - float _backgroundTextureScaleY; - - bool _backGroundBoxRendererAdaptDirty; - bool _backGroundSelectedBoxRendererAdaptDirty; - bool _frontCrossRendererAdaptDirty; - bool _backGroundBoxDisabledRendererAdaptDirty; - bool _frontCrossDisabledRendererAdaptDirty; }; } diff --git a/cocos/ui/UIRadioButton.cpp b/cocos/ui/UIRadioButton.cpp new file mode 100644 index 0000000000..fa46cfc133 --- /dev/null +++ b/cocos/ui/UIRadioButton.cpp @@ -0,0 +1,349 @@ +/**************************************************************************** +Copyright (c) 2015 Neo Kim (neo.kim@neofect.com) + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "ui/UIRadioButton.h" + +NS_CC_BEGIN + +namespace ui { + +IMPLEMENT_CLASS_GUI_INFO(RadioButton) + +RadioButton::RadioButton() : +_radioButtonEventCallback(nullptr), +_group(nullptr) +{ +} + +RadioButton::~RadioButton() +{ + _radioButtonEventCallback = nullptr; + _group = nullptr; +} + +RadioButton* RadioButton::create() +{ + RadioButton* widget = new (std::nothrow) RadioButton(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +RadioButton* RadioButton::create(const std::string& backGround, + const std::string& backGroundSeleted, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType) +{ + RadioButton *pWidget = new (std::nothrow) RadioButton; + if (pWidget && pWidget->init(backGround, + backGroundSeleted, + cross, + backGroundDisabled, + frontCrossDisabled, + texType)) + { + pWidget->autorelease(); + return pWidget; + } + CC_SAFE_DELETE(pWidget); + return nullptr; +} + +RadioButton* RadioButton::create(const std::string& backGround, + const std::string& cross, + TextureResType texType) +{ + RadioButton *pWidget = new (std::nothrow) RadioButton; + if (pWidget && pWidget->init(backGround, + "", + cross, + "", + "", + texType)) + { + pWidget->autorelease(); + return pWidget; + } + CC_SAFE_DELETE(pWidget); + return nullptr; +} + +void RadioButton::dispatchSelectChangedEvent(bool selected) +{ + EventType eventType = (selected ? EventType::SELECTED : EventType::UNSELECTED); + this->retain(); + if (_radioButtonEventCallback) + { + _radioButtonEventCallback(this, eventType); + } + if (_ccEventCallback) + { + _ccEventCallback(this, static_cast(eventType)); + } + + if(selected && _group != nullptr) + { + _group->onChangedRadioButtonSelect(this); + } + this->release(); +} + +void RadioButton::addEventListener(const ccRadioButtonCallback& callback) +{ + _radioButtonEventCallback = callback; +} + +void RadioButton::releaseUpEvent() +{ + Widget::releaseUpEvent(); + + if (!_isSelected) + { + setSelected(true); + dispatchSelectChangedEvent(true); + } +} + +std::string RadioButton::getDescription() const +{ + return "RadioButton"; +} + +Widget* RadioButton::createCloneInstance() +{ + return RadioButton::create(); +} + +void RadioButton::copySpecialProperties(Widget *widget) +{ + RadioButton* radioButton = dynamic_cast(widget); + if (radioButton) + { + AbstractCheckButton::copySpecialProperties(widget); + _radioButtonEventCallback = radioButton->_radioButtonEventCallback; + _ccEventCallback = radioButton->_ccEventCallback; + _group = radioButton->_group; + } +} + +RadioButtonGroup::RadioButtonGroup() : +_radioButtonGroupEventCallback(nullptr), +_selectedRadioButton(nullptr), +_allowedNoSelection(false) +{ +} + +RadioButtonGroup::~RadioButtonGroup() +{ + _radioButtonGroupEventCallback = nullptr; + _selectedRadioButton = nullptr; + _radioButtons.clear(); +} + +RadioButtonGroup* RadioButtonGroup::create() +{ + RadioButtonGroup* widget = new (std::nothrow) RadioButtonGroup(); + if (widget && widget->init()) + { + widget->autorelease(); + return widget; + } + CC_SAFE_DELETE(widget); + return nullptr; +} + +void RadioButtonGroup::addEventListener(const ccRadioButtonGroupCallback& callback) +{ + _radioButtonGroupEventCallback = callback; +} + +void RadioButtonGroup::addRadioButton(RadioButton* radioButton) +{ + if(radioButton != nullptr) + { + CCASSERT(!radioButton->_group, "It already belongs to a group!"); + radioButton->_group = this; + _radioButtons.pushBack(radioButton); + + if(!_allowedNoSelection && _selectedRadioButton == nullptr) + { + setSelectedButton(radioButton); + } + } +} + +void RadioButtonGroup::removeRadioButton(RadioButton* radioButton) +{ + ssize_t index = _radioButtons.getIndex(radioButton); + if( index == CC_INVALID_INDEX ) + { + CCLOGERROR("The radio button does not belong to this group!"); + return; + } + + if(radioButton != nullptr) + { + radioButton->_group = nullptr; + if(radioButton == _selectedRadioButton) + { + deselect(); + } + _radioButtons.erase(index); + + if(!_allowedNoSelection && _selectedRadioButton == nullptr && !_radioButtons.empty()) + { + setSelectedButton(0); + } + } +} + +ssize_t RadioButtonGroup::getNumberOfRadioButtons() const +{ + return _radioButtons.size(); +} + +RadioButton* RadioButtonGroup::getRadioButtonByIndex(int index) const +{ + if(index >= _radioButtons.size()) + { + CCLOGERROR("Out of array index! length=%d, requestedIndex=%d", (int)_radioButtons.size(), index); + return nullptr; + } + return _radioButtons.at(index); +} + +void RadioButtonGroup::deselect() +{ + if(_selectedRadioButton != nullptr) + { + _selectedRadioButton->setSelected(false); + _selectedRadioButton->dispatchSelectChangedEvent(false); + } + _selectedRadioButton = nullptr; +} + +int RadioButtonGroup::getSelectedButtonIndex() const +{ + return (int) _radioButtons.getIndex(_selectedRadioButton); +} + +void RadioButtonGroup::setSelectedButton(int index) +{ + CCASSERT(index < _radioButtons.size(), "Out of array index!"); + setSelectedButton(_radioButtons.at(index)); +} + +void RadioButtonGroup::setSelectedButton(RadioButton* radioButton) +{ + if(!_allowedNoSelection && radioButton == nullptr) + { + return; + } + if(_selectedRadioButton == radioButton) + { + return; + } + if(!_radioButtons.contains(radioButton)) + { + CCLOGERROR("The radio button does not belong to this group!"); + return; + } + + deselect(); + _selectedRadioButton = radioButton; + if(_selectedRadioButton != nullptr) + { + _selectedRadioButton->setSelected(true); + } + onChangedRadioButtonSelect(_selectedRadioButton); +} + +std::string RadioButtonGroup::getDescription() const +{ + return "RadioButtonGroup"; +} + +void RadioButtonGroup::setAllowedNoSelection(bool allowedNoSelection) +{ + _allowedNoSelection = allowedNoSelection; +} + +bool RadioButtonGroup::isAllowedNoSelection() const +{ + return _allowedNoSelection; +} + +Widget* RadioButtonGroup::createCloneInstance() +{ + return RadioButtonGroup::create(); +} + +void RadioButtonGroup::copySpecialProperties(Widget *widget) +{ + RadioButtonGroup* radioButtonGroup = dynamic_cast(widget); + if (radioButtonGroup) + { + _radioButtonGroupEventCallback = radioButtonGroup->_radioButtonGroupEventCallback; + _ccEventCallback = radioButtonGroup->_ccEventCallback; + _selectedRadioButton = radioButtonGroup->_selectedRadioButton; + _allowedNoSelection = radioButtonGroup->_allowedNoSelection; + + _radioButtons.clear(); + for(const auto& radioButton : radioButtonGroup->_radioButtons) + { + _radioButtons.pushBack(radioButton); + } + } +} + +void RadioButtonGroup::onChangedRadioButtonSelect(RadioButton* radioButton) +{ + if(_selectedRadioButton != radioButton) + { + deselect(); + _selectedRadioButton = radioButton; + } + + this->retain(); + if (_radioButtonGroupEventCallback) + { + int index = (int) _radioButtons.getIndex(radioButton); + _radioButtonGroupEventCallback(_selectedRadioButton, index, EventType::SELECT_CHANGED); + } + if (_ccEventCallback) + { + _ccEventCallback(this, static_cast(EventType::SELECT_CHANGED)); + } + this->release(); +} + +} + +NS_CC_END diff --git a/cocos/ui/UIRadioButton.h b/cocos/ui/UIRadioButton.h new file mode 100644 index 0000000000..2e51820851 --- /dev/null +++ b/cocos/ui/UIRadioButton.h @@ -0,0 +1,275 @@ +/**************************************************************************** +Copyright (c) 2015 Neo Kim (neo.kim@neofect.com) + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __UIRADIOBUTTON_H__ +#define __UIRADIOBUTTON_H__ + +#include "ui/UIAbstractCheckButton.h" +#include "ui/GUIExport.h" + +/** + * @addtogroup ui + * @{ + */ +NS_CC_BEGIN + +namespace ui { + +class RadioButtonGroup; + +/** + * RadioButton is a specific type of two-states button that is similar to CheckBox. + * Additionally, it can be used together with RadioButtonGroup to interact with other radio buttons. + */ +class CC_GUI_DLL RadioButton : public AbstractCheckButton +{ + + DECLARE_CLASS_GUI_INFO + + friend class RadioButtonGroup; + +public: + /** + * Radio button event types. + */ + enum class EventType + { + SELECTED, + UNSELECTED + }; + + /** + * A callback which will be called after certain RadioButton event issue. + * @see `RadioButton::EventType` + */ + typedef std::function ccRadioButtonCallback; + + /** + * Default constructor. + * + * @lua new + */ + RadioButton(); + + /** + * Default destructor. + * + * @lua NA + */ + virtual ~RadioButton(); + + /** + * Create and return a empty RadioButton instance pointer. + */ + static RadioButton* create(); + + /** + * Create a radio button with various images. + * + * @param backGround backGround texture. + * @param backGroundSelected backGround selected state texture. + * @param cross cross texture. + * @param backGroundDisabled backGround disabled state texture. + * @param frontCrossDisabled cross dark state texture. + * @param texType @see `Widget::TextureResType` + * + * @return A RadioButton instance pointer. + */ + static RadioButton* create(const std::string& backGround, + const std::string& backGroundSelected, + const std::string& cross, + const std::string& backGroundDisabled, + const std::string& frontCrossDisabled, + TextureResType texType = TextureResType::LOCAL); + + /** + * Another factory method to create a RadioButton instance. + * This method uses less resource to create a RadioButton. + * @param backGround The background image name in `std::string`. + * @param cross The cross image name in `std::string`. + * @param texType The texture's resource type in `Widget::TextureResType`. + * @return A RadioButton instance pointer + */ + static RadioButton* create(const std::string& backGround, + const std::string& cross, + TextureResType texType = TextureResType::LOCAL); + + /** + * Add a callback function which would be called when radio button is selected or unselected. + *@param callback A std::function with type @see `ccRadioButtonCallback` + */ + void addEventListener(const ccRadioButtonCallback& callback); + + virtual std::string getDescription() const override; + +protected: + virtual void releaseUpEvent() override; + + virtual void dispatchSelectChangedEvent(bool selected) override; + + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; + + ccRadioButtonCallback _radioButtonEventCallback; + RadioButtonGroup* _group; + +}; + +/** + * RadioButtonGroup groups designated radio buttons to make them interact to each other. + * In one RadioButtonGroup, only one or no RadioButton can be checked. + */ +class CC_GUI_DLL RadioButtonGroup : public Widget +{ + friend class RadioButton; +public: + /** + * Radio button group event types. + */ + enum class EventType + { + SELECT_CHANGED, + }; + + /** + * A callback which will be called after RadioButtonGroup event issue. + * @see `RadioButtonGroup::EventType` + */ + typedef std::function ccRadioButtonGroupCallback; + + /** + * Default constructor. + * + * @lua new + */ + RadioButtonGroup(); + + /** + * Default destructor. + * + * @lua NA + */ + virtual ~RadioButtonGroup(); + + /** + * Create and return a empty RadioButtonGroup instance pointer. + */ + static RadioButtonGroup* create(); + + /** + * Add a callback function which would be called when radio button is selected or unselected. + *@param callback A std::function with type @see `ccRadioButtonGroupCallback` + */ + void addEventListener(const ccRadioButtonGroupCallback& callback); + + /** + * Get the index of selected radio button. + * + * @return the selected button's index. Returns -1 if no button is selected. + */ + virtual int getSelectedButtonIndex() const; + + /** + * Select a radio button by index. + * + * @param index of the radio button + */ + virtual void setSelectedButton(int index); + + /** + * Select a radio button by instance. + * + * @param radio button instance + */ + virtual void setSelectedButton(RadioButton* radioButton); + + /** + * Add a radio button into this group. + * + * @param radio button instance + */ + virtual void addRadioButton(RadioButton* radioButton); + + /** + * Remove a radio button from this group. + * + * @param radio button instance + */ + virtual void removeRadioButton(RadioButton* radioButton); + + /** + * Get the number of radio buttons in this group. + * + * @return the number of radio buttons in this group + */ + ssize_t getNumberOfRadioButtons() const; + + /** + * Get a radio button in this group by index. + * + * @param index of the radio button + * @return radio button instance. Returns nullptr if out of index. + */ + RadioButton* getRadioButtonByIndex(int index) const; + + /** + * Set a flag for allowing no-selection feature. + * If it is allowed, no radio button can be selected. + * If it is not allowed, one radio button must be selected all time except it is empty. + * Default is not allowed. + * + * @param true means allowing no-selection, false means disallowing no-selection. + */ + void setAllowedNoSelection(bool allowedNoSelection); + + /** + * Query whether no-selection is allowed or not. + * + * @param true means no-selection is allowed, false means no-selection is not allowed. + */ + bool isAllowedNoSelection() const; + + virtual std::string getDescription() const override; + +protected: + virtual Widget* createCloneInstance() override; + virtual void copySpecialProperties(Widget* model) override; + + void onChangedRadioButtonSelect(RadioButton* radioButton); + void deselect(); + + Vector _radioButtons; + ccRadioButtonGroupCallback _radioButtonGroupEventCallback; + RadioButton* _selectedRadioButton; + bool _allowedNoSelection; + +}; + +} + +NS_CC_END +// end of ui group +/// @} + +#endif /* defined(__UIRADIOBUTTON_H__) */ diff --git a/cocos/ui/proj.win32/libui.vcxproj b/cocos/ui/proj.win32/libui.vcxproj index d2e2674f9a..2455a54cf6 100644 --- a/cocos/ui/proj.win32/libui.vcxproj +++ b/cocos/ui/proj.win32/libui.vcxproj @@ -47,7 +47,9 @@ + + diff --git a/cocos/ui/proj.win32/libui.vcxproj.filters b/cocos/ui/proj.win32/libui.vcxproj.filters index bd27e70201..8f12f2c2c5 100644 --- a/cocos/ui/proj.win32/libui.vcxproj.filters +++ b/cocos/ui/proj.win32/libui.vcxproj.filters @@ -131,9 +131,15 @@ UIWidgets + + UIWidgets + UIWidgets + + UIWidgets + UIWidgets diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 19d46c4850..3b14ef82af 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -1165,8 +1165,12 @@ "cocos/ui/GUIExport.h", "cocos/ui/UIButton.cpp", "cocos/ui/UIButton.h", + "cocos/ui/UIAbstractCheckButton.cpp", + "cocos/ui/UIAbstractCheckButton.h", "cocos/ui/UICheckBox.cpp", "cocos/ui/UICheckBox.h", + "cocos/ui/UIRadioButton.cpp", + "cocos/ui/UIRadioButton.h", "cocos/ui/UIDeprecated.cpp", "cocos/ui/UIDeprecated.h", "cocos/ui/UIEditBox/UIEditBox.cpp", diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index cc85e0560b..532be1fb28 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -169,6 +169,7 @@ set(TESTS_SRC Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp + Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 580dddba9a..47c9f4f52e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -2,6 +2,7 @@ #include "UIButtonTest/UIButtonTest.h" #include "UICheckBoxTest/UICheckBoxTest.h" +#include "UIRadioButtonTest/UIRadioButtonTest.h" #include "UISliderTest/UISliderTest.h" #include "UIImageViewTest/UIImageViewTest.h" #include "UILoadingBarTest/UILoadingBarTest.h" @@ -42,6 +43,7 @@ GUIDynamicCreateTests::GUIDynamicCreateTests() addTest("Scale9Sprite Test", [](){ return new (std::nothrow) UIScale9SpriteTests; }); addTest("Button Test", [](){ return new (std::nothrow) UIButtonTests; }); addTest("CheckBox Test", [](){ return new (std::nothrow) UICheckBoxTests; }); + addTest("RadioButton Test", [](){ return new (std::nothrow) UIRadioButtonTests; }); addTest("Slider Test", [](){ return new (std::nothrow) UISliderTests; }); addTest("ImageView Test", [](){ return new (std::nothrow) UIImageViewTests; }); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp new file mode 100644 index 0000000000..00d46b8ea5 --- /dev/null +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp @@ -0,0 +1,334 @@ +#include "UIRadioButtonTest.h" + +USING_NS_CC; +using namespace cocos2d::ui; + +UIRadioButtonTests::UIRadioButtonTests() +{ + ADD_TEST_CASE(UIRadioButtonTest); + ADD_TEST_CASE(UIRadioButtonTwoGroupsTest); + ADD_TEST_CASE(UIRadioButtonTabTest); +} + + +// UIRadioButtonTest +UIRadioButtonTest::UIRadioButtonTest() : +_radioButtonGroup(nullptr), +_allowNoSelectionText(nullptr) +{ +} +UIRadioButtonTest::~UIRadioButtonTest() +{ +} + +static const float BUTTON_WIDTH = 30; +static float startPosX = 0; + +bool UIRadioButtonTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Create a radio button group + _radioButtonGroup = RadioButtonGroup::create(); + _uiLayer->addChild(_radioButtonGroup); + + // Create the radio buttons + static const int NUMBER_OF_BUTTONS = 5; + startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * BUTTON_WIDTH; + for(int i = 0; i < NUMBER_OF_BUTTONS; ++i) + { + RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png"); + float posX = startPosX + BUTTON_WIDTH * i; + radioButton->setPosition(Vec2(posX, widgetSize.height / 2.0f + 10)); + radioButton->setScale(1.2f); + _radioButtonGroup->addRadioButton(radioButton); + _uiLayer->addChild(radioButton); + } + + // Add button + Button* addButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); + addButton->setTitleText("Add"); + addButton->setPosition(Vec2(widgetSize.width / 2.0f - 100, widgetSize.height / 2.0f - 65)); + addButton->addClickEventListener(CC_CALLBACK_1(UIRadioButtonTest::addRadioButton, this)); + addButton->setScale(0.7f); + _uiLayer->addChild(addButton); + + // Delete button + Button* deleteButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); + deleteButton->setTitleText("Delete"); + deleteButton->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 65)); + deleteButton->addClickEventListener(CC_CALLBACK_1(UIRadioButtonTest::deleteRadioButton, this)); + deleteButton->setScale(0.7f); + _uiLayer->addChild(deleteButton); + + // Toggle button + Button* allowNoSelectionToggle = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); + allowNoSelectionToggle->setTitleText("Toggle Allow-No-Selection"); + allowNoSelectionToggle->setPosition(Vec2(widgetSize.width / 2.0f + 100, widgetSize.height / 2.0f - 65)); + allowNoSelectionToggle->addClickEventListener([this](Ref*) { + _radioButtonGroup->setAllowedNoSelection(!_radioButtonGroup->isAllowedNoSelection()); + _allowNoSelectionText->setString(_radioButtonGroup->isAllowedNoSelection() ? "No selection is allowed." : "No selection is disallowed."); + }); + allowNoSelectionToggle->setScale(0.7f); + _uiLayer->addChild(allowNoSelectionToggle); + + // Add a label for toggle + _allowNoSelectionText = Text::create("No selection is disallowed.", "fonts/Marker Felt.ttf", 20); + _allowNoSelectionText->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 70)); + _uiLayer->addChild(_allowNoSelectionText); + + return true; + } + return false; +} + +void UIRadioButtonTest::addRadioButton(Ref* sender) +{ + Vec2 pos; + if(_radioButtonGroup->getNumberOfRadioButtons() > 0) + { + RadioButton* lastRadioButton = _radioButtonGroup->getRadioButtonByIndex((int)_radioButtonGroup->getNumberOfRadioButtons() - 1); + pos = lastRadioButton->getPosition(); + } + else + { + pos.x = startPosX - BUTTON_WIDTH; + pos.y = _widget->getContentSize().height / 2.0f + 10; + } + + RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png"); + pos.x += + BUTTON_WIDTH; + radioButton->setPosition(pos); + _radioButtonGroup->addRadioButton(radioButton); + _uiLayer->addChild(radioButton); +} + +void UIRadioButtonTest::deleteRadioButton(Ref* sender) +{ + if(_radioButtonGroup->getNumberOfRadioButtons() > 0) + { + RadioButton* radioButton = _radioButtonGroup->getRadioButtonByIndex((int)_radioButtonGroup->getNumberOfRadioButtons() - 1); + _radioButtonGroup->removeRadioButton(radioButton); + _uiLayer->removeChild(radioButton); + } +} + + + + +// UIRadioButtonTwoGroupsTest +UIRadioButtonTwoGroupsTest::UIRadioButtonTwoGroupsTest() +: _groupEventLabel(nullptr), +_buttonEventLabel(nullptr), +_logConsole(nullptr), +_numberOfLogLines(0) +{ + _radioButtonGroups[0] = nullptr; + _radioButtonGroups[1] = nullptr; +} + +UIRadioButtonTwoGroupsTest::~UIRadioButtonTwoGroupsTest() +{ +} + +bool UIRadioButtonTwoGroupsTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize();; + + // Add a label in which the radio button events will be displayed + _groupEventLabel = Text::create("RadioButtonGroup : No Event", "fonts/Marker Felt.ttf", 25); + _groupEventLabel->setAnchorPoint(Vec2(0.5f, -1)); + _groupEventLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 70)); + _uiLayer->addChild(_groupEventLabel); + + _buttonEventLabel = Text::create("RadioButton : No Event", "fonts/Marker Felt.ttf", 25); + _buttonEventLabel->setAnchorPoint(Vec2(0.5f, -1)); + _buttonEventLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 35)); + _uiLayer->addChild(_buttonEventLabel); + + _logConsole = Text::create("", "fonts/Marker Felt.ttf", 10); + _logConsole->setAnchorPoint(Vec2(0, 1)); + _logConsole->setPosition(Vec2(widgetSize.width / 2.0f + 110, widgetSize.height / 2.0f + 55)); + _uiLayer->addChild(_logConsole); + + static const int NUMBER_OF_BUTTONS = 4; + static const float SPACE_BETWEEN_BUTTONS = 50; + float startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * SPACE_BETWEEN_BUTTONS; + + for(int type = 0; type < 2; ++type) + { + // Create a radio button group + const char *normalImage, *selectedImage; + float posYAdjust = 0; + _radioButtonGroups[type] = RadioButtonGroup::create(); + if(type == 0) + { + _radioButtonGroups[type]->addEventListener(CC_CALLBACK_3(UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup1, this)); + normalImage = "cocosui/radio_button_off.png"; + selectedImage = "cocosui/radio_button_on.png"; + posYAdjust = 35; + } + else + { + _radioButtonGroups[type]->addEventListener(CC_CALLBACK_3(UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup2, this)); + normalImage = "cocosui/UIEditorTest/2.1/Button/button_common_box03_003 copy 221.png"; + selectedImage = "cocosui/UIEditorTest/2.1/Button/button_common_box03_001.png"; + posYAdjust = -15; + } + _uiLayer->addChild(_radioButtonGroups[type]); + + // Set allowing no selections + _radioButtonGroups[type]->setAllowedNoSelection(type == 0); + + // Create the radio buttons + for(int i = 0; i < NUMBER_OF_BUTTONS; ++i) + { + RadioButton* radioButton = nullptr; + float posY = widgetSize.height / 2.0f + posYAdjust; + radioButton = RadioButton::create(normalImage, selectedImage); + float posX = startPosX + SPACE_BETWEEN_BUTTONS * i; + radioButton->setScale(1.5f); + radioButton->setPosition(Vec2(posX, posY)); + + radioButton->addEventListener(CC_CALLBACK_2(UIRadioButtonTwoGroupsTest::onChangedRadioButtonSelect, this)); + radioButton->setTag(i); + _uiLayer->addChild(radioButton); + _radioButtonGroups[type]->addRadioButton(radioButton); + } + } + + Button* clearButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); + clearButton->setTitleText("Clear"); + clearButton->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 65)); + clearButton->addClickEventListener(CC_CALLBACK_1(UIRadioButtonTwoGroupsTest::clearRadioButtonGroup, this)); + clearButton->setScale(0.8f); + _uiLayer->addChild(clearButton); + + Text* text1 = Text::create("Upper radio button group is allowed non-selection, but lower one is not.", "fonts/Marker Felt.ttf", 15); + text1->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 100)); + _uiLayer->addChild(text1); + + return true; + } + return false; +} + +void UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup1(RadioButton* radioButton, int index, cocos2d::ui::RadioButtonGroup::EventType type) +{ + CCASSERT(index == _radioButtonGroups[0]->getSelectedButtonIndex(), "The two indexes must match!"); + __String* text = String::createWithFormat("RadioButtonGroup1 : %d", index); + _groupEventLabel->setString(text->getCString()); + addLog(text->getCString()); +} + +void UIRadioButtonTwoGroupsTest::onChangedRadioButtonGroup2(RadioButton* radioButton, int index, cocos2d::ui::RadioButtonGroup::EventType type) +{ + CCASSERT(index == _radioButtonGroups[1]->getSelectedButtonIndex(), "The two indexes must match!"); + __String* text = String::createWithFormat("RadioButtonGroup2 : %d", index); + _groupEventLabel->setString(text->getCString()); + addLog(text->getCString()); +} + +void UIRadioButtonTwoGroupsTest::onChangedRadioButtonSelect(RadioButton* radioButton, RadioButton::EventType type) +{ + if(radioButton == nullptr) + { + return; + } + __String* text = String::createWithFormat("RadioButton %d : ", radioButton->getTag()); + switch (type) + { + case RadioButton::EventType::SELECTED: + { + text->append("Selected"); + break; + } + + case RadioButton::EventType::UNSELECTED: + { + text->append("Unselected"); + break; + } + default: + break; + } + _buttonEventLabel->setString(text->getCString()); + addLog(text->getCString()); +} + +void UIRadioButtonTwoGroupsTest::clearRadioButtonGroup(Ref* sender) +{ + for(int i = 0; i < 2; ++i) + { + _radioButtonGroups[i]->setSelectedButton(nullptr); + } +} + +void UIRadioButtonTwoGroupsTest::addLog(const std::string& log) +{ + std::string existingLog = _logConsole->getString(); + if(!existingLog.empty()) + { + existingLog = existingLog + "\n"; + } + existingLog = existingLog + log; + ++_numberOfLogLines; + + if(_numberOfLogLines > 10) + { + size_t pos = existingLog.find("\n") + 1; + std::string newLog = existingLog.substr(pos); + existingLog = newLog; + --_numberOfLogLines; + } + + _logConsole->setString(existingLog); +} + + +// UIRadioButtonTabTest +bool UIRadioButtonTabTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize();; + + static const float BUTTON_SCALE = 0.5f; + const float buttonWidth = 350 * BUTTON_SCALE / Director::getInstance()->getContentScaleFactor(); + + // Background for buttons + LayerColor* colorLayer = LayerColor::create(Color4B::WHITE); + colorLayer->ignoreAnchorPointForPosition(false); + colorLayer->setAnchorPoint(Vec2::ANCHOR_MIDDLE); + colorLayer->setContentSize(Size(buttonWidth * 3, 170 / Director::getInstance()->getContentScaleFactor())); + colorLayer->setPosition(widgetSize / 2.0f); + _uiLayer->addChild(colorLayer); + + // Create a radio button group + RadioButtonGroup* radioButtonGroup = RadioButtonGroup::create(); + _uiLayer->addChild(radioButtonGroup); + + // Create the radio buttons + static const int NUMBER_OF_BUTTONS = 3; + float startPosX = widgetSize.width / 2.0f - ((NUMBER_OF_BUTTONS - 1) / 2.0f) * buttonWidth; + for(int i = 0; i < NUMBER_OF_BUTTONS; ++i) + { + __String* filePathNormal = String::createWithFormat("cocosui/btn_exercise%02d_n.png", i + 1); + __String* filePathSelected = String::createWithFormat("cocosui/btn_exercise%02d_p.png", i + 1); + RadioButton* radioButton = RadioButton::create(filePathNormal->getCString(), filePathSelected->getCString()); + float posX = startPosX + buttonWidth * i; + radioButton->setPosition(Vec2(posX, widgetSize.height / 2.0f)); + radioButton->setScale(BUTTON_SCALE); + radioButton->setZoomScale(0.05f); + radioButtonGroup->addRadioButton(radioButton); + _uiLayer->addChild(radioButton); + } + radioButtonGroup->setSelectedButton(0); + return true; + } + return false; +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.h new file mode 100644 index 0000000000..42bf9d6ad2 --- /dev/null +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.h @@ -0,0 +1,84 @@ +/**************************************************************************** + Copyright (c) 2015 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef __TestCpp__UIRadioButtonTest__ +#define __TestCpp__UIRadioButtonTest__ + +#include "../UIScene.h" + +DEFINE_TEST_SUITE(UIRadioButtonTests); + +class UIRadioButtonTest : public UIScene +{ +public: + CREATE_FUNC(UIRadioButtonTest); + + UIRadioButtonTest(); + ~UIRadioButtonTest(); + + virtual bool init() override; + + void addRadioButton(Ref* sender); + void deleteRadioButton(Ref* sender); + +private: + cocos2d::ui::RadioButtonGroup* _radioButtonGroup; + cocos2d::ui::Text* _allowNoSelectionText; + +}; + + +class UIRadioButtonTwoGroupsTest : public UIScene +{ +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); + + +protected: + void addLog(const std::string& log); + + cocos2d::ui::RadioButtonGroup* _radioButtonGroups[2]; + cocos2d::ui::Text* _groupEventLabel; + cocos2d::ui::Text* _buttonEventLabel; + cocos2d::ui::Text* _logConsole; + int _numberOfLogLines; +}; + +class UIRadioButtonTabTest : public UIScene +{ +public: + CREATE_FUNC(UIRadioButtonTabTest); + virtual bool init() override; +}; + +#endif /* defined(__TestCpp__UIRadioButtonTest__) */ diff --git a/tests/cpp-tests/Resources/ccs-res b/tests/cpp-tests/Resources/ccs-res index dc719c1676..37b53805de 160000 --- a/tests/cpp-tests/Resources/ccs-res +++ b/tests/cpp-tests/Resources/ccs-res @@ -1 +1 @@ -Subproject commit dc719c167623d343cd5fdaaba867e9e1a26a24d3 +Subproject commit 37b53805dedbfb1df8549a3e2417df5c47c134ff diff --git a/tests/cpp-tests/proj.android-studio/app/jni/Android.mk b/tests/cpp-tests/proj.android-studio/app/jni/Android.mk index 6179bca134..bc7073018c 100644 --- a/tests/cpp-tests/proj.android-studio/app/jni/Android.mk +++ b/tests/cpp-tests/proj.android-studio/app/jni/Android.mk @@ -161,6 +161,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../../Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp \ ../../../Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp \ ../../../Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp \ +../../../Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp \ ../../../Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp \ ../../../Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp \ ../../../Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp \ diff --git a/tests/cpp-tests/proj.android/jni/Android.mk b/tests/cpp-tests/proj.android/jni/Android.mk index de8d4678bf..29c34700cd 100644 --- a/tests/cpp-tests/proj.android/jni/Android.mk +++ b/tests/cpp-tests/proj.android/jni/Android.mk @@ -162,6 +162,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp \ ../../Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp \ ../../Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp \ +../../Classes/UITest/CocoStudioGUITest/UIRadioButtonTest/UIRadioButtonTest.cpp \ ../../Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp \ ../../Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp \ ../../Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp \ diff --git a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj index 453ad7a786..c433af3412 100644 --- a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj @@ -689,6 +689,7 @@ + @@ -752,4 +753,4 @@ - \ No newline at end of file + diff --git a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters index 5e5c39fcfb..e7927f6838 100644 --- a/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win10/cpp-tests.vcxproj.filters @@ -869,6 +869,9 @@ Classes\UITest\CocoStudioGUITest\UICheckBoxTest + + Classes\UITest\CocoStudioGUITest\UIRadioButtonTest + Classes\UITest\CocoStudioGUITest\UIFocusTest @@ -1800,4 +1803,4 @@ - \ No newline at end of file + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index 4c3788836a..be5fa255e9 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -230,6 +230,7 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y + @@ -619,4 +620,4 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y - \ No newline at end of file + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index 69529bd072..147da5417f 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -792,6 +792,9 @@ Classes\UITest\CocostudioGUISceneTest\UICheckBoxTest + + Classes\UITest\CocostudioGUISceneTest\UIRadioButtonTest + Classes\UITest\CocostudioGUISceneTest\UIFocusTest @@ -1758,4 +1761,4 @@ Classes\Scene3DTest - \ No newline at end of file + diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems index 90a5d51b74..8cbc4645b6 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems @@ -182,6 +182,7 @@ + @@ -516,4 +517,4 @@ - \ No newline at end of file + diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters index 9d1c9606fa..b245f7bcdc 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters @@ -1260,6 +1260,9 @@ Classes\UITest\CocostudioGUISceneTest\UICheckBoxTest + + Classes\UITest\CocostudioGUISceneTest\UIRadioButtonTest + Classes\UITest\CocostudioGUISceneTest\UIFocusTest @@ -1777,4 +1780,4 @@ Classes\NavMeshTest - \ No newline at end of file + diff --git a/tools/tojs/cocos2dx_ui.ini b/tools/tojs/cocos2dx_ui.ini index 8fa317061d..f655c14aa5 100644 --- a/tools/tojs/cocos2dx_ui.ini +++ b/tools/tojs/cocos2dx_ui.ini @@ -30,7 +30,7 @@ headers = %(cocosdir)s/cocos/ui/CocosGUI.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Helper Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider TextField UICCTextField ScrollView PageView ListView LayoutParameter LinearLayoutParameter RelativeLayoutParameter VideoPlayer HBox VBox RelativeBox Scale9Sprite EditBox$ LayoutComponent +classes = Helper Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider TextField UICCTextField ScrollView PageView ListView LayoutParameter LinearLayoutParameter RelativeLayoutParameter VideoPlayer HBox VBox RelativeBox Scale9Sprite EditBox$ LayoutComponent RadioButtonGroup RadioButton AbstractCheckButton classes_need_extend = Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider TextField ScrollView PageView ListView VideoPlayer HBox VBox RelativeBox Scale9Sprite EditBox$ LayoutComponent @@ -66,7 +66,7 @@ base_classes_to_skip = Ref # classes that create no constructor # Set is special and we will use a hand-written constructor -abstract_classes = Helper LayoutManager +abstract_classes = Helper LayoutManager AbstractCheckButton # Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. script_control_cpp = no