From 8d1c422ac5ab63bac5a7ba09747b3f31351bc628 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 19 Aug 2014 10:28:24 +0800 Subject: [PATCH 01/15] merge extension EditBox to ui module --- build/cocos2d_libs.xcodeproj/project.pbxproj | 72 ++ build/cocos2d_tests.xcodeproj/project.pbxproj | 8 + cocos/platform/ios/CCEAGLView.mm | 3 +- cocos/ui/Android.mk | 4 +- cocos/ui/CocosGUI.h | 2 +- cocos/ui/UIEditBox/UIEditBox.cpp | 460 ++++++++++++ cocos/ui/UIEditBox/UIEditBox.h | 462 ++++++++++++ cocos/ui/UIEditBox/UIEditBoxImpl.h | 103 +++ cocos/ui/UIEditBox/UIEditBoxImplAndroid.cpp | 319 ++++++++ cocos/ui/UIEditBox/UIEditBoxImplAndroid.h | 112 +++ cocos/ui/UIEditBox/UIEditBoxImplIOS.h | 147 ++++ cocos/ui/UIEditBox/UIEditBoxImplIOS.mm | 678 ++++++++++++++++++ cocos/ui/UIEditBox/UIEditBoxImplMac.h | 136 ++++ cocos/ui/UIEditBox/UIEditBoxImplMac.mm | 524 ++++++++++++++ cocos/ui/UIEditBox/UIEditBoxImplNone.cpp | 18 + cocos/ui/UIEditBox/UIEditBoxImplWin.cpp | 302 ++++++++ cocos/ui/UIEditBox/UIEditBoxImplWin.h | 118 +++ cocos/ui/UIEditBox/UIEditBoxImplWp8.cpp | 307 ++++++++ cocos/ui/UIEditBox/UIEditBoxImplWp8.h | 88 +++ cocos/ui/proj.win32/Win32InputBox.cpp | 383 ++++++++++ cocos/ui/proj.win32/Win32InputBox.h | 106 +++ cocos/ui/proj.win32/libui.vcxproj | 7 + cocos/ui/proj.win32/libui.vcxproj.filters | 24 + cocos/ui/proj.wp8/libGUI.vcxproj | 5 + cocos/ui/proj.wp8/libGUI.vcxproj.filters | 15 + tests/cpp-tests/Android.mk | 1 + .../CocoStudioGUITest/CocosGUIScene.cpp | 13 +- .../CocoStudioGUITest/UIEditBoxTest.cpp | 137 ++++ .../UITest/CocoStudioGUITest/UIEditBoxTest.h | 52 ++ .../UITest/CocoStudioGUITest/UIScene.h | 2 +- .../CocoStudioGUITest/UISceneManager.cpp | 4 + .../UITest/CocoStudioGUITest/UISceneManager.h | 1 + tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 2 + .../proj.win32/cpp-tests.vcxproj.filters | 6 + .../cpp-testsComponent.vcxproj | 2 + .../cpp-testsComponent.vcxproj.filters | 6 + 36 files changed, 4623 insertions(+), 6 deletions(-) create mode 100644 cocos/ui/UIEditBox/UIEditBox.cpp create mode 100644 cocos/ui/UIEditBox/UIEditBox.h create mode 100644 cocos/ui/UIEditBox/UIEditBoxImpl.h create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplAndroid.cpp create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplAndroid.h create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplIOS.h create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplIOS.mm create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplMac.h create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplMac.mm create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplNone.cpp create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplWin.cpp create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplWin.h create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplWp8.cpp create mode 100644 cocos/ui/UIEditBox/UIEditBoxImplWp8.h create mode 100644 cocos/ui/proj.win32/Win32InputBox.cpp create mode 100644 cocos/ui/proj.win32/Win32InputBox.h create mode 100644 tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp create mode 100644 tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 497aa3862f..0225d99ce9 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -638,6 +638,24 @@ 1AD71EF5180E27CF00808F54 /* CCPhysicsSprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD71EEE180E27CF00808F54 /* CCPhysicsSprite.cpp */; }; 1AD71EF6180E27CF00808F54 /* CCPhysicsSprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD71EEF180E27CF00808F54 /* CCPhysicsSprite.h */; }; 1AD71EF7180E27CF00808F54 /* CCPhysicsSprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD71EEF180E27CF00808F54 /* CCPhysicsSprite.h */; }; + 292CEFF619A18DF200E8E6A0 /* UIEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292CEFE819A18DF200E8E6A0 /* UIEditBox.cpp */; }; + 292CEFF719A18DF200E8E6A0 /* UIEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292CEFE819A18DF200E8E6A0 /* UIEditBox.cpp */; }; + 292CEFF819A18DF200E8E6A0 /* UIEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFE919A18DF200E8E6A0 /* UIEditBox.h */; }; + 292CEFF919A18DF200E8E6A0 /* UIEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFE919A18DF200E8E6A0 /* UIEditBox.h */; }; + 292CEFFA19A18DF200E8E6A0 /* UIEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFEA19A18DF200E8E6A0 /* UIEditBoxImpl.h */; }; + 292CEFFB19A18DF200E8E6A0 /* UIEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFEA19A18DF200E8E6A0 /* UIEditBoxImpl.h */; }; + 292CEFFE19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFEC19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h */; }; + 292CEFFF19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFEC19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h */; }; + 292CF00019A18DF200E8E6A0 /* UIEditBoxImplIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFED19A18DF200E8E6A0 /* UIEditBoxImplIOS.h */; }; + 292CF00119A18DF200E8E6A0 /* UIEditBoxImplIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFED19A18DF200E8E6A0 /* UIEditBoxImplIOS.h */; }; + 292CF00319A18DF200E8E6A0 /* UIEditBoxImplIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292CEFEE19A18DF200E8E6A0 /* UIEditBoxImplIOS.mm */; }; + 292CF00419A18DF200E8E6A0 /* UIEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFEF19A18DF200E8E6A0 /* UIEditBoxImplMac.h */; }; + 292CF00519A18DF200E8E6A0 /* UIEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFEF19A18DF200E8E6A0 /* UIEditBoxImplMac.h */; }; + 292CF00619A18DF200E8E6A0 /* UIEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292CEFF019A18DF200E8E6A0 /* UIEditBoxImplMac.mm */; }; + 292CF00C19A18DF200E8E6A0 /* UIEditBoxImplWin.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFF319A18DF200E8E6A0 /* UIEditBoxImplWin.h */; }; + 292CF00D19A18DF200E8E6A0 /* UIEditBoxImplWin.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFF319A18DF200E8E6A0 /* UIEditBoxImplWin.h */; }; + 292CF01019A18DF200E8E6A0 /* UIEditBoxImplWp8.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFF519A18DF200E8E6A0 /* UIEditBoxImplWp8.h */; }; + 292CF01119A18DF200E8E6A0 /* UIEditBoxImplWp8.h in Headers */ = {isa = PBXBuildFile; fileRef = 292CEFF519A18DF200E8E6A0 /* UIEditBoxImplWp8.h */; }; 2958244B19873D8E00F9746D /* UIScale9Sprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2958244919873D8E00F9746D /* UIScale9Sprite.cpp */; }; 2958244C19873D8E00F9746D /* UIScale9Sprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2958244919873D8E00F9746D /* UIScale9Sprite.cpp */; }; 2958244D19873D8E00F9746D /* UIScale9Sprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 2958244A19873D8E00F9746D /* UIScale9Sprite.h */; }; @@ -2488,6 +2506,20 @@ 2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = ""; }; 2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = ""; }; 29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = ""; }; + 292CEFE819A18DF200E8E6A0 /* UIEditBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBox.cpp; sourceTree = ""; }; + 292CEFE919A18DF200E8E6A0 /* UIEditBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBox.h; sourceTree = ""; }; + 292CEFEA19A18DF200E8E6A0 /* UIEditBoxImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImpl.h; sourceTree = ""; }; + 292CEFEB19A18DF200E8E6A0 /* UIEditBoxImplAndroid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplAndroid.cpp; sourceTree = ""; }; + 292CEFEC19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplAndroid.h; sourceTree = ""; }; + 292CEFED19A18DF200E8E6A0 /* UIEditBoxImplIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplIOS.h; sourceTree = ""; }; + 292CEFEE19A18DF200E8E6A0 /* UIEditBoxImplIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIEditBoxImplIOS.mm; sourceTree = ""; }; + 292CEFEF19A18DF200E8E6A0 /* UIEditBoxImplMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplMac.h; sourceTree = ""; }; + 292CEFF019A18DF200E8E6A0 /* UIEditBoxImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIEditBoxImplMac.mm; sourceTree = ""; }; + 292CEFF119A18DF200E8E6A0 /* UIEditBoxImplNone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplNone.cpp; sourceTree = ""; }; + 292CEFF219A18DF200E8E6A0 /* UIEditBoxImplWin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplWin.cpp; sourceTree = ""; }; + 292CEFF319A18DF200E8E6A0 /* UIEditBoxImplWin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplWin.h; sourceTree = ""; }; + 292CEFF419A18DF200E8E6A0 /* UIEditBoxImplWp8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplWp8.cpp; sourceTree = ""; }; + 292CEFF519A18DF200E8E6A0 /* UIEditBoxImplWp8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplWp8.h; sourceTree = ""; }; 2958244919873D8E00F9746D /* UIScale9Sprite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9Sprite.cpp; sourceTree = ""; }; 2958244A19873D8E00F9746D /* UIScale9Sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9Sprite.h; sourceTree = ""; }; 2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = ""; }; @@ -4371,6 +4403,7 @@ 2905F9E618CF08D000240AA3 /* ui */ = { isa = PBXGroup; children = ( + 292CEFE719A18DF200E8E6A0 /* UIEditBox */, 29CB8F531929D67D00C841D6 /* widgets */, 29CB8F521929D65500C841D6 /* experimental */, 29CB8F511929D64500C841D6 /* base */, @@ -4382,6 +4415,27 @@ path = ../cocos/ui; sourceTree = ""; }; + 292CEFE719A18DF200E8E6A0 /* UIEditBox */ = { + isa = PBXGroup; + children = ( + 292CEFE819A18DF200E8E6A0 /* UIEditBox.cpp */, + 292CEFE919A18DF200E8E6A0 /* UIEditBox.h */, + 292CEFEA19A18DF200E8E6A0 /* UIEditBoxImpl.h */, + 292CEFEB19A18DF200E8E6A0 /* UIEditBoxImplAndroid.cpp */, + 292CEFEC19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h */, + 292CEFED19A18DF200E8E6A0 /* UIEditBoxImplIOS.h */, + 292CEFEE19A18DF200E8E6A0 /* UIEditBoxImplIOS.mm */, + 292CEFEF19A18DF200E8E6A0 /* UIEditBoxImplMac.h */, + 292CEFF019A18DF200E8E6A0 /* UIEditBoxImplMac.mm */, + 292CEFF119A18DF200E8E6A0 /* UIEditBoxImplNone.cpp */, + 292CEFF219A18DF200E8E6A0 /* UIEditBoxImplWin.cpp */, + 292CEFF319A18DF200E8E6A0 /* UIEditBoxImplWin.h */, + 292CEFF419A18DF200E8E6A0 /* UIEditBoxImplWp8.cpp */, + 292CEFF519A18DF200E8E6A0 /* UIEditBoxImplWp8.h */, + ); + path = UIEditBox; + sourceTree = ""; + }; 29CB8F501929D63600C841D6 /* layout */ = { isa = PBXGroup; children = ( @@ -6120,18 +6174,24 @@ files = ( B2DB4778197665BF00411E16 /* UIHelper.h in Headers */, B2DB478A1976664400411E16 /* UISlider.h in Headers */, + 292CF00019A18DF200E8E6A0 /* UIEditBoxImplIOS.h in Headers */, + 292CEFFA19A18DF200E8E6A0 /* UIEditBoxImpl.h in Headers */, B2DB47841976661A00411E16 /* UIImageView.h in Headers */, B2DB47881976663A00411E16 /* UIRichText.h in Headers */, B2DB47801976660200411E16 /* UIButton.h in Headers */, B2DB47821976660C00411E16 /* UICheckBox.h in Headers */, B2DB47861976662D00411E16 /* UILoadingBar.h in Headers */, + 292CEFF819A18DF200E8E6A0 /* UIEditBox.h in Headers */, B2DB47681976650A00411E16 /* UIWidget.h in Headers */, 2958244D19873D8E00F9746D /* UIScale9Sprite.h in Headers */, B2DB47691976651E00411E16 /* UIHBox.h in Headers */, + 292CF01019A18DF200E8E6A0 /* UIEditBoxImplWp8.h in Headers */, + 292CF00C19A18DF200E8E6A0 /* UIEditBoxImplWin.h in Headers */, B2DB478F1976666100411E16 /* UIText.h in Headers */, B2DB47901976666100411E16 /* UITextAtlas.h in Headers */, B2DB47911976666100411E16 /* UITextBMFont.h in Headers */, B2DB47921976666100411E16 /* UITextField.h in Headers */, + 292CEFFE19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h in Headers */, B2DB476A1976653000411E16 /* UILayout.h in Headers */, B2DB477A197665D000411E16 /* UIListView.h in Headers */, B2DB477C197665DB00411E16 /* UIPageView.h in Headers */, @@ -6140,6 +6200,7 @@ B2DB476E1976655C00411E16 /* UILayoutParameter.h in Headers */, B2DB47701976657000411E16 /* UIRelativeBox.h in Headers */, B2DB47721976658000411E16 /* UIVBox.h in Headers */, + 292CF00419A18DF200E8E6A0 /* UIEditBoxImplMac.h in Headers */, B2DB47741976659800411E16 /* CocosGUI.h in Headers */, B2DB4776197665AA00411E16 /* UIDeprecated.h in Headers */, ); @@ -6152,14 +6213,18 @@ B2C59A3419777EB600B452DF /* UIListView.h in Headers */, B2C59A3519777EB600B452DF /* UILoadingBar.h in Headers */, B2C59A3619777EB600B452DF /* UIPageView.h in Headers */, + 292CF00119A18DF200E8E6A0 /* UIEditBoxImplIOS.h in Headers */, B2C59A3719777EB600B452DF /* UIRichText.h in Headers */, B2C59A3819777EB600B452DF /* UIScrollView.h in Headers */, B2C59A3919777EB600B452DF /* UISlider.h in Headers */, B2C59A3A19777EB600B452DF /* UIText.h in Headers */, + 292CF00519A18DF200E8E6A0 /* UIEditBoxImplMac.h in Headers */, B2C59A3B19777EB600B452DF /* UITextAtlas.h in Headers */, B2C59A3C19777EB600B452DF /* UITextBMFont.h in Headers */, + 292CEFFB19A18DF200E8E6A0 /* UIEditBoxImpl.h in Headers */, B2C59A3D19777EB600B452DF /* UITextField.h in Headers */, B2C59A3E19777EB600B452DF /* UIButton.h in Headers */, + 292CF01119A18DF200E8E6A0 /* UIEditBoxImplWp8.h in Headers */, B2C59A3F19777EB600B452DF /* UICheckBox.h in Headers */, B2C59A4019777EB600B452DF /* UIImageView.h in Headers */, B2C59A4119777EBC00B452DF /* UIVideoPlayer.h in Headers */, @@ -6167,10 +6232,13 @@ B2C59A4319777EC700B452DF /* UIWidget.h in Headers */, B2C59A4519777EC700B452DF /* UIHelper.h in Headers */, B2C59A4619777EC700B452DF /* GUIDefine.h in Headers */, + 292CEFF919A18DF200E8E6A0 /* UIEditBox.h in Headers */, B2C59A4719777ECF00B452DF /* UIHBox.h in Headers */, B2C59A4819777ECF00B452DF /* UIRelativeBox.h in Headers */, + 292CF00D19A18DF200E8E6A0 /* UIEditBoxImplWin.h in Headers */, B2C59A4919777ECF00B452DF /* UIVBox.h in Headers */, 2958244E19873D8E00F9746D /* UIScale9Sprite.h in Headers */, + 292CEFFF19A18DF200E8E6A0 /* UIEditBoxImplAndroid.h in Headers */, B2C59A4A19777ECF00B452DF /* UILayout.h in Headers */, B2C59A4B19777ECF00B452DF /* UILayoutParameter.h in Headers */, B2C59A4C19777ECF00B452DF /* UILayoutManager.h in Headers */, @@ -7598,10 +7666,12 @@ B2DB476F1976656D00411E16 /* UIRelativeBox.cpp in Sources */, B2DB47711976657A00411E16 /* UIVBox.cpp in Sources */, B2DB47731976658E00411E16 /* CocosGUI.cpp in Sources */, + 292CF00619A18DF200E8E6A0 /* UIEditBoxImplMac.mm in Sources */, B2DB4775197665A500411E16 /* UIDeprecated.cpp in Sources */, 2958244B19873D8E00F9746D /* UIScale9Sprite.cpp in Sources */, B2DB47891976664200411E16 /* UISlider.cpp in Sources */, B2DB4779197665CD00411E16 /* UIListView.cpp in Sources */, + 292CEFF619A18DF200E8E6A0 /* UIEditBox.cpp in Sources */, B2DB47851976662B00411E16 /* UILoadingBar.cpp in Sources */, B2DB478B1976665700411E16 /* UIText.cpp in Sources */, B2DB478C1976665700411E16 /* UITextAtlas.cpp in Sources */, @@ -7631,6 +7701,7 @@ B2C59A2419777E7500B452DF /* UITextBMFont.cpp in Sources */, B2C59A2519777E7500B452DF /* UITextField.cpp in Sources */, B2C59A2619777E7500B452DF /* UIButton.cpp in Sources */, + 292CF00319A18DF200E8E6A0 /* UIEditBoxImplIOS.mm in Sources */, B2C59ACB197782FF00B452DF /* UIVideoPlayerIOS.mm in Sources */, B2C59A2719777E7500B452DF /* UICheckBox.cpp in Sources */, B2C59A2819777E7500B452DF /* UIImageView.cpp in Sources */, @@ -7638,6 +7709,7 @@ B2C59A2B19777E8300B452DF /* UIWidget.cpp in Sources */, B2C59A2D19777E8300B452DF /* UIHelper.cpp in Sources */, B2C59A2E19777E8C00B452DF /* UIHBox.cpp in Sources */, + 292CEFF719A18DF200E8E6A0 /* UIEditBox.cpp in Sources */, B2C59A2F19777E8C00B452DF /* UIRelativeBox.cpp in Sources */, B2C59A3019777E8C00B452DF /* UIVBox.cpp in Sources */, B2C59A3119777E8C00B452DF /* UILayout.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index b75a2a309f..596da6fe3b 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -913,6 +913,8 @@ 29080DE6191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29080D8B191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp */; }; 290E94B5196FC16900694919 /* CocostudioParserTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 290E94B3196FC16900694919 /* CocostudioParserTest.cpp */; }; 290E94B6196FC16900694919 /* CocostudioParserTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 290E94B3196FC16900694919 /* CocostudioParserTest.cpp */; }; + 292CF01419A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */; }; + 292CF01519A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */; }; 295824591987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; }; 2958245A1987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; }; 29FBBBFE196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; }; @@ -3677,6 +3679,8 @@ 29080D8C191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidgetAddNodeTest_Editor.h; sourceTree = ""; }; 290E94B3196FC16900694919 /* CocostudioParserTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CocostudioParserTest.cpp; path = ../CocostudioParserTest.cpp; sourceTree = ""; }; 290E94B4196FC16900694919 /* CocostudioParserTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CocostudioParserTest.h; path = ../CocostudioParserTest.h; sourceTree = ""; }; + 292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxTest.cpp; sourceTree = ""; }; + 292CF01319A1965E00E8E6A0 /* UIEditBoxTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxTest.h; sourceTree = ""; }; 295824571987415900F9746D /* UIScale9SpriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9SpriteTest.cpp; sourceTree = ""; }; 295824581987415900F9746D /* UIScale9SpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9SpriteTest.h; sourceTree = ""; }; 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocostudioParserJsonTest.cpp; sourceTree = ""; }; @@ -7864,6 +7868,8 @@ children = ( 295824571987415900F9746D /* UIScale9SpriteTest.cpp */, 295824581987415900F9746D /* UIScale9SpriteTest.h */, + 292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */, + 292CF01319A1965E00E8E6A0 /* UIEditBoxTest.h */, 29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */, 29080D20191B595E0066F8DF /* CocosGUIScene.h */, 29080D37191B595E0066F8DF /* GUIEditorTest.cpp */, @@ -9237,6 +9243,7 @@ 1AC35B7D18CECF0C00F37B72 /* PlayerController.cpp in Sources */, 29080D9F191B595E0066F8DF /* CustomReader.cpp in Sources */, 1AC35BE718CECF0C00F37B72 /* CCControlScene.cpp in Sources */, + 292CF01419A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */, 29080DBF191B595E0066F8DF /* UIPageViewTest_Editor.cpp in Sources */, 1AC35B5F18CECF0C00F37B72 /* DataVisitorTest.cpp in Sources */, 1AC35B5D18CECF0C00F37B72 /* CurrentLanguageTest.cpp in Sources */, @@ -9418,6 +9425,7 @@ 1AC35C0618CECF0C00F37B72 /* FontTest.cpp in Sources */, 1AC35C3818CECF0C00F37B72 /* PerformanceTest.cpp in Sources */, 1F33635018E37E840074764D /* RefPtrTest.cpp in Sources */, + 292CF01519A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */, 1AC35B2818CECF0C00F37B72 /* ActionsTest.cpp in Sources */, 1AC35C4A18CECF0C00F37B72 /* ShaderTest.cpp in Sources */, 1AC35BFE18CECF0C00F37B72 /* Scale9SpriteTest.cpp in Sources */, diff --git a/cocos/platform/ios/CCEAGLView.mm b/cocos/platform/ios/CCEAGLView.mm index 3c5c1c7b37..87a02a566c 100644 --- a/cocos/platform/ios/CCEAGLView.mm +++ b/cocos/platform/ios/CCEAGLView.mm @@ -374,7 +374,8 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. for(UIView* view in subviews) { - if([view isKindOfClass:NSClassFromString(@"CCCustomUITextField")]) + if([view isKindOfClass:NSClassFromString(@"CCCustomUITextField")] || + [view isKindOfClass:NSClassFromString(@"UICustomUITextField")]) { if ([view isFirstResponder]) { diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index 40f4cb6a31..e63516d5a1 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -31,6 +31,8 @@ UIRelativeBox.cpp \ UIVideoPlayerAndroid.cpp \ UIDeprecated.cpp \ UIScale9Sprite.cpp \ +UIEditBox/UIEditBox.cpp \ +UIEditBox/UIEditBoxImplAndroid.cpp \ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \ $(LOCAL_PATH)/../editor-support @@ -43,9 +45,7 @@ $(LOCAL_PATH)/../editor-support LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static -LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static include $(BUILD_STATIC_LIBRARY) -$(call import-module,extensions) $(call import-module,.) diff --git a/cocos/ui/CocosGUI.h b/cocos/ui/CocosGUI.h index 5fc08abefc..eea8bdfa4c 100644 --- a/cocos/ui/CocosGUI.h +++ b/cocos/ui/CocosGUI.h @@ -51,7 +51,7 @@ THE SOFTWARE. #include "ui/UIDeprecated.h" #include "ui/GUIExport.h" #include "ui/UIScale9Sprite.h" - +#include "ui/UIEditBox/UIEditBox.h" NS_CC_BEGIN namespace ui { diff --git a/cocos/ui/UIEditBox/UIEditBox.cpp b/cocos/ui/UIEditBox/UIEditBox.cpp new file mode 100644 index 0000000000..12723cdb6e --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBox.cpp @@ -0,0 +1,460 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 "UIEditBox.h" +#include "UIEditBoxImpl.h" + +NS_CC_BEGIN + +namespace ui { + +static const float CHECK_EDITBOX_POSITION_INTERVAL = 0.1f; + +EditBox::EditBox(void) +: _editBoxImpl(nullptr) +, _delegate(nullptr) +, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE) +, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) +, _keyboardReturnType(KeyboardReturnType::DEFAULT) +, _fontSize(-1) +, _placeholderFontSize(-1) +, _colText(Color3B::WHITE) +, _colPlaceHolder(Color3B::GRAY) +, _maxLength(0) +, _adjustHeight(0.0f) +, _backgroundSprite(nullptr) +#if CC_ENABLE_SCRIPT_BINDING +, _scriptEditBoxHandler(0) +#endif +{ +} + +EditBox::~EditBox(void) +{ + CC_SAFE_DELETE(_editBoxImpl); +#if CC_ENABLE_SCRIPT_BINDING + unregisterScriptEditBoxHandler(); +#endif +} + + +void EditBox::touchDownAction(Ref *sender, TouchEventType controlEvent) +{ + if (controlEvent == Widget::TouchEventType::ENDED) { + _editBoxImpl->openKeyboard(); + } +} + +EditBox* EditBox::create(const Size& size, + const std::string& pNormal9SpriteBg, + TextureResType texType /*= TextureResType::LOCAL*/) +{ + EditBox* pRet = new EditBox(); + + if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, pNormal9SpriteBg, texType)) + { + pRet->autorelease(); + } + else + { + CC_SAFE_DELETE(pRet); + } + + return pRet; +} + +bool EditBox::initWithSizeAndBackgroundSprite(const Size& size, + const std::string& pNormal9SpriteBg, + TextureResType texType) +{ + if (Widget::init()) + { + _editBoxImpl = __createSystemEditBox(this); + _editBoxImpl->initWithSize(size); + _editBoxImpl->setInputMode(EditBox::InputMode::ANY); + + if (texType == Widget::TextureResType::LOCAL) + { + _backgroundSprite = Scale9Sprite::create(pNormal9SpriteBg); + } + else + { + _backgroundSprite = Scale9Sprite::createWithSpriteFrameName(pNormal9SpriteBg); + } + this->setContentSize(size); + this->setPosition(Vec2(0, 0)); + + _backgroundSprite->setPosition(Vec2(_contentSize.width/2, _contentSize.height/2)); + _backgroundSprite->setContentSize(size); + this->addProtectedChild(_backgroundSprite); + + this->setTouchEnabled(true); + + this->addTouchEventListener(CC_CALLBACK_2(EditBox::touchDownAction, this)); + + return true; + } + return false; +} + +void EditBox::setDelegate(EditBoxDelegate* pDelegate) +{ + _delegate = pDelegate; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setDelegate(pDelegate); + } +} + +EditBoxDelegate* EditBox::getDelegate() +{ + return _delegate; +} + +void EditBox::setText(const char* pText) +{ + if (pText != nullptr) + { + _text = pText; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setText(pText); + } + } +} + +const char* EditBox::getText(void) +{ + if (_editBoxImpl != nullptr) + { + const char* pText = _editBoxImpl->getText(); + if(pText != nullptr) + return pText; + } + + return ""; +} + +void EditBox::setFont(const char* pFontName, int fontSize) +{ + _fontName = pFontName; + _fontSize = fontSize; + if (pFontName != nullptr) + { + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setFont(pFontName, fontSize); + } + } +} + +void EditBox::setFontName(const char* pFontName) +{ + _fontName = pFontName; + if (_editBoxImpl != nullptr && _fontSize != -1) + { + _editBoxImpl->setFont(pFontName, _fontSize); + } +} + +void EditBox::setFontSize(int fontSize) +{ + _fontSize = fontSize; + if (_editBoxImpl != nullptr && _fontName.length() > 0) + { + _editBoxImpl->setFont(_fontName.c_str(), _fontSize); + } +} + +void EditBox::setFontColor(const Color3B& color) +{ + _colText = color; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setFontColor(color); + } +} + +void EditBox::setPlaceholderFont(const char* pFontName, int fontSize) +{ + _placeholderFontName = pFontName; + _placeholderFontSize = fontSize; + if (pFontName != nullptr) + { + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setPlaceholderFont(pFontName, fontSize); + } + } +} + +void EditBox::setPlaceholderFontName(const char* pFontName) +{ + _placeholderFontName = pFontName; + if (_editBoxImpl != nullptr && _placeholderFontSize != -1) + { + _editBoxImpl->setPlaceholderFont(pFontName, _fontSize); + } +} + +void EditBox::setPlaceholderFontSize(int fontSize) +{ + _placeholderFontSize = fontSize; + if (_editBoxImpl != nullptr && _placeholderFontName.length() > 0) + { + _editBoxImpl->setPlaceholderFont(_placeholderFontName.c_str(), _fontSize); + } +} + +void EditBox::setPlaceholderFontColor(const Color3B& color) +{ + _colText = color; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setPlaceholderFontColor(color); + } +} + +void EditBox::setPlaceHolder(const char* pText) +{ + if (pText != nullptr) + { + _placeHolder = pText; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setPlaceHolder(pText); + } + } +} + +const char* EditBox::getPlaceHolder(void) +{ + return _placeHolder.c_str(); +} + +void EditBox::setInputMode(EditBox::InputMode inputMode) +{ + _editBoxInputMode = inputMode; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setInputMode(inputMode); + } +} + +void EditBox::setMaxLength(int maxLength) +{ + _maxLength = maxLength; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setMaxLength(maxLength); + } +} + + +int EditBox::getMaxLength() +{ + return _maxLength; +} + +void EditBox::setInputFlag(EditBox::InputFlag inputFlag) +{ + _editBoxInputFlag = inputFlag; + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setInputFlag(inputFlag); + } +} + +void EditBox::setReturnType(EditBox::KeyboardReturnType returnType) +{ + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setReturnType(returnType); + } +} + +/* override function */ +void EditBox::setPosition(const Vec2& pos) +{ + Widget::setPosition(pos); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setPosition(pos); + } +} + +void EditBox::setVisible(bool visible) +{ + Widget::setVisible(visible); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setVisible(visible); + } +} + +void EditBox::setContentSize(const Size& size) +{ + Widget::setContentSize(size); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setContentSize(size); + } +} + +void EditBox::adaptRenderers() +{ + if (_contentSizeDirty) + { + _backgroundSprite->setContentSize(_contentSize); + _backgroundSprite->setPosition(Vec2(_contentSize.width/2, _contentSize.height/2)); + } +} + +void EditBox::setAnchorPoint(const Vec2& anchorPoint) +{ + Widget::setAnchorPoint(anchorPoint); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->setAnchorPoint(anchorPoint); + } +} + +void EditBox::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) +{ + Widget::visit(renderer, parentTransform, parentFlags); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->visit(); + } +} + +void EditBox::onEnter(void) +{ +#if CC_ENABLE_SCRIPT_BINDING + if (_scriptType == kScriptTypeJavascript) + { + if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) + return; + } +#endif + + Widget::onEnter(); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->onEnter(); + } +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + this->schedule(schedule_selector(EditBox::updatePosition), CHECK_EDITBOX_POSITION_INTERVAL); +#endif +} + +void EditBox::updatePosition(float dt) +{ + if (nullptr != _editBoxImpl) { + _editBoxImpl->updatePosition(dt); + } +} + + +void EditBox::onExit(void) +{ + Widget::onExit(); + if (_editBoxImpl != nullptr) + { + // remove system edit control + _editBoxImpl->closeKeyboard(); + } +} + +static Rect getRect(Node * pNode) +{ + Size contentSize = pNode->getContentSize(); + Rect rect = Rect(0, 0, contentSize.width, contentSize.height); + return RectApplyTransform(rect, pNode->getNodeToWorldTransform()); +} + +void EditBox::keyboardWillShow(IMEKeyboardNotificationInfo& info) +{ + // CCLOG("CCEditBox::keyboardWillShow"); + Rect rectTracked = getRect(this); + // some adjustment for margin between the keyboard and the edit box. + rectTracked.origin.y -= 4; + + // if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done. + if (!rectTracked.intersectsRect(info.end)) + { + CCLOG("needn't to adjust view layout."); + return; + } + + // assume keyboard at the bottom of screen, calculate the vertical adjustment. + _adjustHeight = info.end.getMaxY() - rectTracked.getMinY(); + // CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", _adjustHeight); + + if (_editBoxImpl != nullptr) + { + _editBoxImpl->doAnimationWhenKeyboardMove(info.duration, _adjustHeight); + } +} + +void EditBox::keyboardDidShow(IMEKeyboardNotificationInfo& info) +{ + +} + +void EditBox::keyboardWillHide(IMEKeyboardNotificationInfo& info) +{ + // CCLOG("CCEditBox::keyboardWillHide"); + if (_editBoxImpl != nullptr) + { + _editBoxImpl->doAnimationWhenKeyboardMove(info.duration, -_adjustHeight); + } +} + +void EditBox::keyboardDidHide(IMEKeyboardNotificationInfo& info) +{ + +} + +#if CC_ENABLE_SCRIPT_BINDING +void EditBox::registerScriptEditBoxHandler(int handler) +{ + unregisterScriptEditBoxHandler(); + _scriptEditBoxHandler = handler; +} + +void EditBox::unregisterScriptEditBoxHandler(void) +{ + if (0 != _scriptEditBoxHandler) + { + ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_scriptEditBoxHandler); + _scriptEditBoxHandler = 0; + } +} +#endif + +} + +NS_CC_END diff --git a/cocos/ui/UIEditBox/UIEditBox.h b/cocos/ui/UIEditBox/UIEditBox.h new file mode 100644 index 0000000000..335193fee8 --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBox.h @@ -0,0 +1,462 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 __UIEDITTEXT_H__ +#define __UIEDITTEXT_H__ + +#include "base/CCIMEDelegate.h" +#include "ui/GUIDefine.h" +#include "ui/UIButton.h" +#include "ui/UIScale9Sprite.h" + +NS_CC_BEGIN + +namespace ui { + + class EditBox; + class EditBoxImpl; + + + class CC_GUI_DLL EditBoxDelegate + { + public: + /** + * @js NA + * @lua NA + */ + virtual ~EditBoxDelegate() {}; + + /** + * This method is called when an edit box gains focus after keyboard is shown. + * @param editBox The edit box object that generated the event. + * @js NA + * @lua NA + */ + virtual void editBoxEditingDidBegin(EditBox* editBox) {}; + + + /** + * This method is called when an edit box loses focus after keyboard is hidden. + * @param editBox The edit box object that generated the event. + * @js NA + * @lua NA + */ + virtual void editBoxEditingDidEnd(EditBox* editBox) {}; + + /** + * This method is called when the edit box text was changed. + * @param editBox The edit box object that generated the event. + * @param text The new text. + * @js NA + * @lua NA + */ + virtual void editBoxTextChanged(EditBox* editBox, const std::string& text) {}; + + /** + * This method is called when the return button was pressed or the outside area of keyboard was touched. + * @param editBox The edit box object that generated the event. + * @js NA + * @lua NA + */ + virtual void editBoxReturn(EditBox* editBox) = 0; + + }; + + /** + * \brief Class for edit box. + * + * You can use this widget to gather small amounts of text from the user. + * + */ + + class CC_GUI_DLL EditBox + : public Widget + , public IMEDelegate + { + public: + enum class KeyboardReturnType + { + DEFAULT, + DONE, + SEND, + SEARCH, + GO + }; + + /** + * \brief The EditBox::InputMode defines the type of text that the user is allowed + * to enter. + */ + enum class InputMode + { + /** + * The user is allowed to enter any text, including line breaks. + */ + ANY, + + /** + * The user is allowed to enter an e-mail address. + */ + EMAIL_ADDRESS, + + /** + * The user is allowed to enter an integer value. + */ + NUMERIC, + + /** + * The user is allowed to enter a phone number. + */ + PHONE_NUMBER, + + /** + * The user is allowed to enter a URL. + */ + URL, + + /** + * The user is allowed to enter a real number value. + * This extends kEditBoxInputModeNumeric by allowing a decimal point. + */ + DECIMAL, + + /** + * The user is allowed to enter any text, except for line breaks. + */ + SINGLE_LINE, + }; + + /** + * \brief The EditBox::InputFlag defines how the input text is displayed/formatted. + */ + enum class InputFlag + { + /** + * Indicates that the text entered is confidential data that should be + * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. + */ + PASSWORD, + + /** + * Indicates that the text entered is sensitive data that the + * implementation must never store into a dictionary or table for use + * in predictive, auto-completing, or other accelerated input schemes. + * A credit card number is an example of sensitive data. + */ + SENSITIVE, + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each word should be capitalized. + */ + INITIAL_CAPS_WORD, + + /** + * This flag is a hint to the implementation that during text editing, + * the initial letter of each sentence should be capitalized. + */ + INITIAL_CAPS_SENTENCE, + + /** + * Capitalize all characters automatically. + */ + INTIAL_CAPS_ALL_CHARACTERS, + }; + + /** + * create a edit box with size. + * @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again. + */ + static EditBox* create(const Size& size, + const std::string& pNormal9SpriteBg, + TextureResType texType = TextureResType::LOCAL); + + /** + * Constructor. + * @js ctor + */ + EditBox(void); + + /** + * Destructor. + * @js NA + * @lua NA + */ + virtual ~EditBox(void); + + /** + * Init edit box with specified size. This method should be invoked right after constructor. + * @param size The size of edit box. + */ + bool initWithSizeAndBackgroundSprite(const Size& size, + const std::string& pNormal9SpriteBg, + TextureResType texType = TextureResType::LOCAL); + + /** + * Gets/Sets the delegate for edit box. + * @lua NA + */ + void setDelegate(EditBoxDelegate* pDelegate); + /** + * @js NA + * @lua NA + */ + EditBoxDelegate* getDelegate(); + +#if CC_ENABLE_SCRIPT_BINDING + /** + * Registers a script function that will be called for EditBox events. + * + * This handler will be removed automatically after onExit() called. + * @code + * -- lua sample + * local function editboxEventHandler(eventType) + * if eventType == "began" then + * -- triggered when an edit box gains focus after keyboard is shown + * elseif eventType == "ended" then + * -- triggered when an edit box loses focus after keyboard is hidden. + * elseif eventType == "changed" then + * -- triggered when the edit box text was changed. + * elseif eventType == "return" then + * -- triggered when the return button was pressed or the outside area of keyboard was touched. + * end + * end + * + * local editbox = EditBox:create(Size(...), Scale9Sprite:create(...)) + * editbox = registerScriptEditBoxHandler(editboxEventHandler) + * @endcode + * + * @param handler A number that indicates a lua function. + * @js NA + * @lua NA + */ + void registerScriptEditBoxHandler(int handler); + + /** + * Unregisters a script function that will be called for EditBox events. + * @js NA + * @lua NA + */ + void unregisterScriptEditBoxHandler(void); + /** + * get a script Handler + * @js NA + * @lua NA + */ + int getScriptEditBoxHandler(void){ return _scriptEditBoxHandler ;} + +#endif // #if CC_ENABLE_SCRIPT_BINDING + + /** + * Set the text entered in the edit box. + * @param pText The given text. + */ + void setText(const char* pText); + + /** + * Get the text entered in the edit box. + * @return The text entered in the edit box. + */ + const char* getText(void); + + /** + * Set the font. + * @param pFontName The font name. + * @param fontSize The font size. + */ + void setFont(const char* pFontName, int fontSize); + + /** + * Set the font name. + * @param pFontName The font name. + */ + void setFontName(const char* pFontName); + + /** + * Set the font size. + * @param fontSize The font size. + */ + void setFontSize(int fontSize); + + /** + * Set the font color of the widget's text. + */ + void setFontColor(const Color3B& color); + + /** + * Set the placeholder's font. + * @param pFontName The font name. + * @param fontSize The font size. + */ + void setPlaceholderFont(const char* pFontName, int fontSize); + + /** + * Set the placeholder's font name. + * @param pFontName The font name. + */ + void setPlaceholderFontName(const char* pFontName); + + /** + * Set the placeholder's font size. + * @param fontSize The font size. + */ + void setPlaceholderFontSize(int fontSize); + + /** + * Set the font color of the placeholder text when the edit box is empty. + * Not supported on IOS. + */ + void setPlaceholderFontColor(const Color3B& color); + + /** + * Set a text in the edit box that acts as a placeholder when an + * edit box is empty. + * @param pText The given text. + */ + void setPlaceHolder(const char* pText); + + /** + * Get a text in the edit box that acts as a placeholder when an + * edit box is empty. + */ + const char* getPlaceHolder(void); + + /** + * Set the input mode of the edit box. + * @param inputMode One of the EditBox::InputMode constants. + */ + void setInputMode(InputMode inputMode); + + /** + * Sets the maximum input length of the edit box. + * Setting this value enables multiline input mode by default. + * Available on Android, iOS and Windows Phone. + * + * @param maxLength The maximum length. + */ + void setMaxLength(int maxLength); + + /** + * Gets the maximum input length of the edit box. + * + * @return Maximum input length. + */ + int getMaxLength(); + + /** + * Set the input flags that are to be applied to the edit box. + * @param inputFlag One of the EditBox::InputFlag constants. + */ + void setInputFlag(InputFlag inputFlag); + + /** + * Set the return type that are to be applied to the edit box. + * @param returnType One of the EditBox::KeyboardReturnType constants. + */ + void setReturnType(EditBox::KeyboardReturnType returnType); + + /* override functions */ + virtual void setPosition(const Vec2& pos) override; + virtual void setVisible(bool visible) override; + virtual void setContentSize(const Size& size) override; + virtual void setAnchorPoint(const Vec2& anchorPoint) override; + /** + * @js NA + * @lua NA + */ + virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; + /** + * @js NA + * @lua NA + */ + virtual void onEnter(void) override; + /** + * @js NA + * @lua NA + */ + virtual void onExit(void) override; + /** + * @js NA + * @lua NA + */ + virtual void keyboardWillShow(IMEKeyboardNotificationInfo& info) override; + /** + * @js NA + * @lua NA + */ + virtual void keyboardDidShow(IMEKeyboardNotificationInfo& info) override; + /** + * @js NA + * @lua NA + */ + virtual void keyboardWillHide(IMEKeyboardNotificationInfo& info) override; + /** + * @js NA + * @lua NA + */ + virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) override; + + /* callback funtions + * @js NA + * @lua NA + */ + void touchDownAction(Ref *sender, TouchEventType controlEvent); + + protected: + virtual void adaptRenderers(); + + void updatePosition(float dt); + EditBoxImpl* _editBoxImpl; + EditBoxDelegate* _delegate; + + InputMode _editBoxInputMode; + InputFlag _editBoxInputFlag; + EditBox::KeyboardReturnType _keyboardReturnType; + + Scale9Sprite *_backgroundSprite; + std::string _text; + std::string _placeHolder; + + std::string _fontName; + std::string _placeholderFontName; + + int _fontSize; + int _placeholderFontSize; + + Color3B _colText; + Color3B _colPlaceHolder; + + int _maxLength; + float _adjustHeight; +#if CC_ENABLE_SCRIPT_BINDING + int _scriptEditBoxHandler; +#endif + }; +} + +NS_CC_END + +#endif /* __UIEDITTEXT_H__ */ + diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl.h b/cocos/ui/UIEditBox/UIEditBoxImpl.h new file mode 100644 index 0000000000..8413b62bae --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImpl.h @@ -0,0 +1,103 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 __UIEditBoxIMPL_H__ +#define __UIEditBoxIMPL_H__ + +#include "UIEditBox.h" + + +namespace cocos2d { + namespace ui{ + + class CC_GUI_DLL EditBoxImpl + { + public: + /** + * @js NA + */ + EditBoxImpl(EditBox* pEditBox) : _delegate(nullptr),_editBox(pEditBox) {} + /** + * @js NA + * @lua NA + */ + virtual ~EditBoxImpl() {} + + virtual bool initWithSize(const Size& size) = 0; + virtual void setFont(const char* pFontName, int fontSize) = 0; + virtual void setFontColor(const Color3B& color) = 0; + virtual void setPlaceholderFont(const char* pFontName, int fontSize) = 0; + virtual void setPlaceholderFontColor(const Color3B& color) = 0; + virtual void setInputMode(EditBox::InputMode inputMode) = 0; + virtual void setInputFlag(EditBox::InputFlag inputFlag) = 0; + virtual void setMaxLength(int maxLength) = 0; + virtual int getMaxLength() = 0; + virtual void setReturnType(EditBox::KeyboardReturnType returnType) = 0; + virtual bool isEditing() = 0; + + virtual void setText(const char* pText) = 0; + virtual const char* getText(void) = 0; + virtual void setPlaceHolder(const char* pText) = 0; + virtual void doAnimationWhenKeyboardMove(float duration, float distance) = 0; + + virtual void openKeyboard() = 0; + virtual void closeKeyboard() = 0; + + virtual void setPosition(const Vec2& pos) = 0; + virtual void setVisible(bool visible) = 0; + virtual void setContentSize(const Size& size) = 0; + virtual void setAnchorPoint(const Vec2& anchorPoint) = 0; + + /** + * check the editbox's position, update it when needed + */ + virtual void updatePosition(float dt){}; + /** + * @js NA + * @lua NA + */ + virtual void visit(void) = 0; + /** + * @js NA + * @lua NA + */ + virtual void onEnter(void) = 0; + + + void setDelegate(EditBoxDelegate* pDelegate) { _delegate = pDelegate; }; + EditBoxDelegate* getDelegate() { return _delegate; }; + EditBox* getEditBox() { return _editBox; }; + protected: + EditBoxDelegate* _delegate; + EditBox* _editBox; + }; + + // This method must be implemented at each subclass of EditBoxImpl. + extern EditBoxImpl* __createSystemEditBox(EditBox* pEditBox); + + } +} + +#endif /* __UIEditBoxIMPL_H__ */ diff --git a/cocos/ui/UIEditBox/UIEditBoxImplAndroid.cpp b/cocos/ui/UIEditBox/UIEditBoxImplAndroid.cpp new file mode 100644 index 0000000000..62251e235f --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplAndroid.cpp @@ -0,0 +1,319 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 "UIEditBoxImplAndroid.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + +#include "UIEditBox.h" +#include "jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.h" +#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h" + + +NS_CC_BEGIN + +namespace ui { + +EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) +{ + return new EditBoxImplAndroid(pEditBox); +} + +EditBoxImplAndroid::EditBoxImplAndroid(EditBox* pEditText) +: EditBoxImpl(pEditText) +, _label(nullptr) +, _labelPlaceHolder(nullptr) +, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE) +, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) +, _keyboardReturnType(EditBox::KeyboardReturnType::DEFAULT) +, _colText(Color3B::WHITE) +, _colPlaceHolder(Color3B::GRAY) +, _maxLength(-1) +{ + +} + +EditBoxImplAndroid::~EditBoxImplAndroid() +{ + +} + +void EditBoxImplAndroid::doAnimationWhenKeyboardMove(float duration, float distance) +{ // don't need to be implemented on android platform. + +} + +static const int CC_EDIT_BOX_PADDING = 5; + +bool EditBoxImplAndroid::initWithSize(const Size& size) +{ + int fontSize = getFontSizeAccordingHeightJni(size.height-12); + _label = Label::create(); + _label->setSystemFontSize(size.height-12); + // align the text vertically center + _label->setAnchorPoint(Vec2(0, 0.5f)); + _label->setPosition(Vec2(CC_EDIT_BOX_PADDING, size.height / 2.0f)); + _label->setColor(_colText); + _editBox->addChild(_label); + + _labelPlaceHolder = Label::create(); + _labelPlaceHolder->setSystemFontSize(size.height-12); + // align the text vertically center + _labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f)); + _labelPlaceHolder->setPosition(Vec2(CC_EDIT_BOX_PADDING, size.height / 2.0f)); + _labelPlaceHolder->setVisible(false); + _labelPlaceHolder->setColor(_colPlaceHolder); + _editBox->addChild(_labelPlaceHolder); + + _editSize = size; + return true; +} + +void EditBoxImplAndroid::setFont(const char* pFontName, int fontSize) +{ + if(_label != NULL) { + _label->setSystemFontName(pFontName); + _label->setSystemFontSize(fontSize); + } + + if(_labelPlaceHolder != NULL) { + _labelPlaceHolder->setSystemFontName(pFontName); + _labelPlaceHolder->setSystemFontSize(fontSize); + } +} + +void EditBoxImplAndroid::setFontColor(const Color3B& color) +{ + _colText = color; + _label->setColor(color); +} + +void EditBoxImplAndroid::setPlaceholderFont(const char* pFontName, int fontSize) +{ + if(_labelPlaceHolder != NULL) { + _labelPlaceHolder->setSystemFontName(pFontName); + _labelPlaceHolder->setSystemFontSize(fontSize); + } +} + +void EditBoxImplAndroid::setPlaceholderFontColor(const Color3B& color) +{ + _colPlaceHolder = color; + _labelPlaceHolder->setColor(color); +} + +void EditBoxImplAndroid::setInputMode(EditBox::InputMode inputMode) +{ + _editBoxInputMode = inputMode; +} + +void EditBoxImplAndroid::setMaxLength(int maxLength) +{ + _maxLength = maxLength; +} + +int EditBoxImplAndroid::getMaxLength() +{ + return _maxLength; +} + +void EditBoxImplAndroid::setInputFlag(EditBox::InputFlag inputFlag) +{ + _editBoxInputFlag = inputFlag; +} + +void EditBoxImplAndroid::setReturnType(EditBox::KeyboardReturnType returnType) +{ + _keyboardReturnType = returnType; +} + +bool EditBoxImplAndroid::isEditing() +{ + return false; +} + +void EditBoxImplAndroid::setText(const char* pText) +{ + if (pText != NULL) + { + _text = pText; + + if (_text.length() > 0) + { + _labelPlaceHolder->setVisible(false); + + std::string strToShow; + + if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) + { + long length = cc_utf8_strlen(_text.c_str(), -1); + for (long i = 0; i < length; i++) + { + strToShow.append("*"); + } + } + else + { + strToShow = _text; + } + + _label->setString(strToShow.c_str()); + + // Clip the text width to fit to the text box + + float fMaxWidth = _editSize.width - CC_EDIT_BOX_PADDING * 2; + auto labelSize = _label->getContentSize(); + if(labelSize.width > fMaxWidth) { + _label->setDimensions(fMaxWidth,labelSize.height); + } + } + else + { + _labelPlaceHolder->setVisible(true); + _label->setString(""); + } + + } +} + +const char* EditBoxImplAndroid::getText(void) +{ + return _text.c_str(); +} + +void EditBoxImplAndroid::setPlaceHolder(const char* pText) +{ + if (pText != NULL) + { + _placeHolder = pText; + if (_placeHolder.length() > 0 && _text.length() == 0) + { + _labelPlaceHolder->setVisible(true); + } + + _labelPlaceHolder->setString(_placeHolder.c_str()); + } +} + +void EditBoxImplAndroid::setPosition(const Vec2& pos) +{ // don't need to be implemented on android platform. + +} + +void EditBoxImplAndroid::setVisible(bool visible) +{ // don't need to be implemented on android platform. + +} + +void EditBoxImplAndroid::setContentSize(const Size& size) +{ // don't need to be implemented on android platform. + +} + +void EditBoxImplAndroid::setAnchorPoint(const Vec2& anchorPoint) +{ // don't need to be implemented on android platform. + +} + +void EditBoxImplAndroid::visit(void) +{ // don't need to be implemented on android platform. + +} + +void EditBoxImplAndroid::onEnter(void) +{ // don't need to be implemented on android platform. + +} + +static void editBoxCallbackFunc(const char* pText, void* ctx) +{ + EditBoxImplAndroid* thiz = (EditBoxImplAndroid*)ctx; + thiz->setText(pText); + + if (thiz->getDelegate() != NULL) + { + thiz->getDelegate()->editBoxTextChanged(thiz->getEditBox(), thiz->getText()); + thiz->getDelegate()->editBoxEditingDidEnd(thiz->getEditBox()); + thiz->getDelegate()->editBoxReturn(thiz->getEditBox()); + } + +#if CC_ENABLE_SCRIPT_BINDING + EditBox* pEditBox = thiz->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox); + ScriptEvent event(kCommonEvent,(void*)&data); + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + memset(data.eventName, 0, sizeof(data.eventName)); + strncpy(data.eventName, "ended", sizeof(data.eventName)); + event.data = (void*)&data; + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + memset(data.eventName, 0, sizeof(data.eventName)); + strncpy(data.eventName, "return", sizeof(data.eventName)); + event.data = (void*)&data; + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif +} + +void EditBoxImplAndroid::openKeyboard() +{ + if (_delegate != NULL) + { + _delegate->editBoxEditingDidBegin(_editBox); + } + +#if CC_ENABLE_SCRIPT_BINDING + EditBox* pEditBox = this->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); + ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif + + showEditTextDialogJNI( _placeHolder.c_str(), + _text.c_str(), + (int)_editBoxInputMode, + (int)_editBoxInputFlag, + (int)_keyboardReturnType, + _maxLength, + editBoxCallbackFunc, + (void*)this ); + +} + +void EditBoxImplAndroid::closeKeyboard() +{ + +} + +} + +NS_CC_END + +#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) */ + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplAndroid.h b/cocos/ui/UIEditBox/UIEditBoxImplAndroid.h new file mode 100644 index 0000000000..2b38934752 --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplAndroid.h @@ -0,0 +1,112 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 __UIEDITBOXIMPLANDROID_H__ +#define __UIEDITBOXIMPLANDROID_H__ + +#include "cocos2d.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + +#include "UIEditBoxImpl.h" + +NS_CC_BEGIN + +namespace ui { + +class EditBox; + +class EditBoxImplAndroid : public EditBoxImpl +{ +public: + /** + * @js NA + */ + EditBoxImplAndroid(EditBox* pEditText); + /** + * @js NA + * @lua NA + */ + virtual ~EditBoxImplAndroid(); + + virtual bool initWithSize(const Size& size); + virtual void setFont(const char* pFontName, int fontSize); + virtual void setFontColor(const Color3B& color); + virtual void setPlaceholderFont(const char* pFontName, int fontSize); + virtual void setPlaceholderFontColor(const Color3B& color); + virtual void setInputMode(EditBox::InputMode inputMode); + virtual void setInputFlag(EditBox::InputFlag inputFlag); + virtual void setMaxLength(int maxLength); + virtual int getMaxLength(); + virtual void setReturnType(EditBox::KeyboardReturnType returnType); + virtual bool isEditing(); + + virtual void setText(const char* pText); + virtual const char* getText(void); + virtual void setPlaceHolder(const char* pText); + virtual void setPosition(const Vec2& pos); + virtual void setVisible(bool visible); + virtual void setContentSize(const Size& size); + virtual void setAnchorPoint(const Vec2& anchorPoint); + /** + * @js NA + * @lua NA + */ + virtual void visit(void); + /** + * @js NA + * @lua NA + */ + virtual void onEnter(void); + virtual void doAnimationWhenKeyboardMove(float duration, float distance); + virtual void openKeyboard(); + virtual void closeKeyboard(); + +private: + Label* _label; + Label* _labelPlaceHolder; + EditBox::InputMode _editBoxInputMode; + EditBox::InputFlag _editBoxInputFlag; + EditBox::KeyboardReturnType _keyboardReturnType; + + std::string _text; + std::string _placeHolder; + + Color3B _colText; + Color3B _colPlaceHolder; + + int _maxLength; + Size _editSize; +}; + + +} + +NS_CC_END + +#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) */ + +#endif /* __UIEDITBOXIMPLANDROID_H__ */ + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplIOS.h b/cocos/ui/UIEditBox/UIEditBoxImplIOS.h new file mode 100644 index 0000000000..b78ce96da6 --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplIOS.h @@ -0,0 +1,147 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 __UIEditBoxIMPLIOS_H__ +#define __UIEditBoxIMPLIOS_H__ + +#include "cocos2d.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +#include "extensions/ExtensionMacros.h" +#include "UIEditBoxImpl.h" + +#import +#import + +@interface UICustomUITextField : UITextField +{ +} + +@end + + +@interface UIEditBoxImplIOS_objc : NSObject +{ + UICustomUITextField* textField_; + void* editBox_; + BOOL editState_; +} + +@property(nonatomic, retain) UITextField* textField; +@property(nonatomic, readonly, getter = isEditState) BOOL editState; +@property(nonatomic, assign) void* editBox; + +-(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox; +-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance; +-(void) setPosition:(CGPoint) pos; +-(void) setContentSize:(CGSize) size; +-(void) visit; +-(void) openKeyboard; +-(void) closeKeyboard; + +@end + +NS_CC_BEGIN + +namespace ui { + +class EditBox; + +class EditBoxImplIOS : public EditBoxImpl +{ +public: + /** + * @js NA + */ + EditBoxImplIOS(EditBox* pEditText); + /** + * @js NA + * @lua NA + */ + virtual ~EditBoxImplIOS(); + + virtual bool initWithSize(const Size& size); + virtual void setFont(const char* pFontName, int fontSize); + virtual void setFontColor(const Color3B& color); + virtual void setPlaceholderFont(const char* pFontName, int fontSize); + virtual void setPlaceholderFontColor(const Color3B& color); + virtual void setInputMode(EditBox::InputMode inputMode); + virtual void setInputFlag(EditBox::InputFlag inputFlag); + virtual void setMaxLength(int maxLength); + virtual int getMaxLength(); + virtual void setReturnType(EditBox::KeyboardReturnType returnType); + virtual bool isEditing(); + + virtual void setText(const char* pText); + virtual const char* getText(void); + virtual void refreshInactiveText(); + virtual void setPlaceHolder(const char* pText); + virtual void setPosition(const Vec2& pos); + virtual void setVisible(bool visible); + virtual void setContentSize(const Size& size); + virtual void setAnchorPoint(const Vec2& anchorPoint); + virtual void updatePosition(float dt) override; + /** + * @js NA + * @lua NA + */ + virtual void visit(void); + /** + * @js NA + * @lua NA + */ + virtual void onEnter(void); + virtual void doAnimationWhenKeyboardMove(float duration, float distance); + virtual void openKeyboard(); + virtual void closeKeyboard(); + + virtual void onEndEditing(); +private: + void initInactiveLabels(const Size& size); + void setInactiveText(const char* pText); + void adjustTextFieldPosition(); + void placeInactiveLabels(); + + Label* _label; + Label* _labelPlaceHolder; + Size _contentSize; + Vec2 _position; + Vec2 _anchorPoint; + UIEditBoxImplIOS_objc* _systemControl; + int _maxTextLength; + bool _inRetinaMode; +}; + + +} + +NS_CC_END + + +#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) */ + +#endif /* __UIEditBoxIMPLIOS_H__ */ + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplIOS.mm b/cocos/ui/UIEditBox/UIEditBoxImplIOS.mm new file mode 100644 index 0000000000..44a5b1a33e --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplIOS.mm @@ -0,0 +1,678 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 James Chen + + 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 "UIEditBoxImplIOS.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +#define kLabelZOrder 9999 + +#include "UIEditBox.h" +#import "CCEAGLView.h" + +#define getEditBoxImplIOS() ((cocos2d::ui::EditBoxImplIOS*)editBox_) + +static const int CC_EDIT_BOX_PADDING = 5; + +@implementation UICustomUITextField +- (CGRect)textRectForBounds:(CGRect)bounds +{ + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + + float padding = CC_EDIT_BOX_PADDING * glview->getScaleX() / glview->getContentScaleFactor(); + return CGRectMake(bounds.origin.x + padding, bounds.origin.y + padding, + bounds.size.width - padding*2, bounds.size.height - padding*2); +} +- (CGRect)editingRectForBounds:(CGRect)bounds { + return [self textRectForBounds:bounds]; +} +@end + + +@implementation UIEditBoxImplIOS_objc + +@synthesize textField = textField_; +@synthesize editState = editState_; +@synthesize editBox = editBox_; + +- (void)dealloc +{ + [textField_ resignFirstResponder]; + [textField_ removeFromSuperview]; + self.textField = NULL; + [super dealloc]; +} + +-(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox +{ + self = [super init]; + + if (self) + { + editState_ = NO; + self.textField = [[[UICustomUITextField alloc] initWithFrame: frameRect] autorelease]; + + [textField_ setTextColor:[UIColor whiteColor]]; + textField_.font = [UIFont systemFontOfSize:frameRect.size.height*2/3]; //TODO need to delete hard code here. + textField_.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + textField_.backgroundColor = [UIColor clearColor]; + textField_.borderStyle = UITextBorderStyleNone; + textField_.delegate = self; + textField_.hidden = true; + textField_.returnKeyType = UIReturnKeyDefault; + [textField_ addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged]; + self.editBox = editBox; + } + + return self; +} + +-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance +{ + auto view = cocos2d::Director::getInstance()->getOpenGLView(); + CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); + + [eaglview doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; +} + +-(void) setPosition:(CGPoint) pos +{ + CGRect frame = [textField_ frame]; + frame.origin = pos; + [textField_ setFrame:frame]; +} + +-(void) setContentSize:(CGSize) size +{ + CGRect frame = [textField_ frame]; + frame.size = size; + [textField_ setFrame:frame]; +} + +-(void) visit +{ + +} + +-(void) openKeyboard +{ + auto view = cocos2d::Director::getInstance()->getOpenGLView(); + CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); + + [eaglview addSubview:textField_]; + [textField_ becomeFirstResponder]; +} + +-(void) closeKeyboard +{ + [textField_ resignFirstResponder]; + [textField_ removeFromSuperview]; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)sender +{ + if (sender == textField_) { + [sender resignFirstResponder]; + } + return NO; +} + +-(void)animationSelector +{ + auto view = cocos2d::Director::getInstance()->getOpenGLView(); + CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); + + [eaglview doAnimationWhenAnotherEditBeClicked]; +} + +- (BOOL)textFieldShouldBeginEditing:(UITextField *)sender // return NO to disallow editing. +{ + CCLOG("textFieldShouldBeginEditing..."); + editState_ = YES; + + auto view = cocos2d::Director::getInstance()->getOpenGLView(); + CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); + + if ([eaglview isKeyboardShown]) + { + [self performSelector:@selector(animationSelector) withObject:nil afterDelay:0.0f]; + } + cocos2d::ui::EditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate(); + if (pDelegate != NULL) + { + pDelegate->editBoxEditingDidBegin(getEditBoxImplIOS()->getEditBox()); + } + +#if CC_ENABLE_SCRIPT_BINDING + cocos2d::ui::EditBox* pEditBox= getEditBoxImplIOS()->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); + cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif + return YES; +} + +- (BOOL)textFieldShouldEndEditing:(UITextField *)sender +{ + CCLOG("textFieldShouldEndEditing..."); + editState_ = NO; + getEditBoxImplIOS()->refreshInactiveText(); + + cocos2d::ui::EditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate(); + if (pDelegate != NULL) + { + pDelegate->editBoxEditingDidEnd(getEditBoxImplIOS()->getEditBox()); + pDelegate->editBoxReturn(getEditBoxImplIOS()->getEditBox()); + } + +#if CC_ENABLE_SCRIPT_BINDING + cocos2d::ui::EditBox* pEditBox= getEditBoxImplIOS()->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "ended",pEditBox); + cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + memset(data.eventName, 0, sizeof(data.eventName)); + strncpy(data.eventName, "return", sizeof(data.eventName)); + event.data = (void*)&data; + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif + + if(editBox_ != nil) + { + getEditBoxImplIOS()->onEndEditing(); + } + return YES; +} + +/** + * Delegate method called before the text has been changed. + * @param textField The text field containing the text. + * @param range The range of characters to be replaced. + * @param string The replacement string. + * @return YES if the specified text range should be replaced; otherwise, NO to keep the old text. + */ +- (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string +{ + if (getEditBoxImplIOS()->getMaxLength() < 0) + { + return YES; + } + + NSUInteger oldLength = [textField.text length]; + NSUInteger replacementLength = [string length]; + NSUInteger rangeLength = range.length; + + NSUInteger newLength = oldLength - rangeLength + replacementLength; + + return newLength <= getEditBoxImplIOS()->getMaxLength(); +} + +/** + * Called each time when the text field's text has changed. + */ +- (void) textChanged +{ + // NSLog(@"text is %@", self.textField.text); + cocos2d::ui::EditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate(); + if (pDelegate != NULL) + { + pDelegate->editBoxTextChanged(getEditBoxImplIOS()->getEditBox(), getEditBoxImplIOS()->getText()); + } + +#if CC_ENABLE_SCRIPT_BINDING + cocos2d::ui::EditBox* pEditBox= getEditBoxImplIOS()->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox); + cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif +} + +@end + + +NS_CC_BEGIN + +namespace ui { + +EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) +{ + return new EditBoxImplIOS(pEditBox); +} + +EditBoxImplIOS::EditBoxImplIOS(EditBox* pEditText) +: EditBoxImpl(pEditText) +, _label(nullptr) +, _labelPlaceHolder(nullptr) +, _anchorPoint(Vec2(0.5f, 0.5f)) +, _systemControl(nullptr) +, _maxTextLength(-1) +{ + auto view = cocos2d::Director::getInstance()->getOpenGLView(); + + _inRetinaMode = view->isRetinaDisplay(); +} + +EditBoxImplIOS::~EditBoxImplIOS() +{ + [_systemControl release]; +} + +void EditBoxImplIOS::doAnimationWhenKeyboardMove(float duration, float distance) +{ + if ([_systemControl isEditState] || distance < 0.0f) + { + [_systemControl doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; + } +} + +bool EditBoxImplIOS::initWithSize(const Size& size) +{ + do + { + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + + CGRect rect = CGRectMake(0, 0, size.width * glview->getScaleX(),size.height * glview->getScaleY()); + + if (_inRetinaMode) + { + rect.size.width /= 2.0f; + rect.size.height /= 2.0f; + } + + _systemControl = [[UIEditBoxImplIOS_objc alloc] initWithFrame:rect editBox:this]; + if (!_systemControl) break; + + initInactiveLabels(size); + setContentSize(size); + + return true; + }while (0); + + return false; +} + +void EditBoxImplIOS::initInactiveLabels(const Size& size) +{ + const char* pDefaultFontName = [[_systemControl.textField.font fontName] UTF8String]; + + _label = Label::create(); + _label->setAnchorPoint(Vec2(0, 0.5f)); + _label->setColor(Color3B::WHITE); + _label->setVisible(false); + _editBox->addChild(_label, kLabelZOrder); + + _labelPlaceHolder = Label::create(); + // align the text vertically center + _labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f)); + _labelPlaceHolder->setColor(Color3B::GRAY); + _editBox->addChild(_labelPlaceHolder, kLabelZOrder); + + setFont(pDefaultFontName, size.height*2/3); + setPlaceholderFont(pDefaultFontName, size.height*2/3); +} + +void EditBoxImplIOS::placeInactiveLabels() +{ + _label->setPosition(Vec2(CC_EDIT_BOX_PADDING, _contentSize.height / 2.0f)); + _labelPlaceHolder->setPosition(Vec2(CC_EDIT_BOX_PADDING, _contentSize.height / 2.0f)); +} + +void EditBoxImplIOS::setInactiveText(const char* pText) +{ + if(_systemControl.textField.secureTextEntry == YES) + { + std::string passwordString; + for(int i = 0; i < strlen(pText); ++i) + passwordString.append("\u25CF"); + _label->setString(passwordString.c_str()); + } + else + _label->setString(getText()); + + // Clip the text width to fit to the text box + float fMaxWidth = _editBox->getContentSize().width - CC_EDIT_BOX_PADDING * 2; + Size labelSize = _label->getContentSize(); + if(labelSize.width > fMaxWidth) { + _label->setDimensions(fMaxWidth,labelSize.height); + } +} + +void EditBoxImplIOS::setFont(const char* pFontName, int fontSize) +{ + bool isValidFontName = true; + if(pFontName == NULL || strlen(pFontName) == 0) { + isValidFontName = false; + } + + float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; + NSString * fntName = [NSString stringWithUTF8String:pFontName]; + + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + + float scaleFactor = glview->getScaleX(); + UIFont *textFont = nil; + if (isValidFontName) { + textFont = [UIFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor]; + } + + if (!isValidFontName || textFont == nil){ + textFont = [UIFont systemFontOfSize:fontSize * scaleFactor / retinaFactor]; + } + + if(textFont != nil) { + [_systemControl.textField setFont:textFont]; + } + + _label->setSystemFontName(pFontName); + _label->setSystemFontSize(fontSize); + _labelPlaceHolder->setSystemFontName(pFontName); + _labelPlaceHolder->setSystemFontSize(fontSize); +} + +void EditBoxImplIOS::setFontColor(const Color3B& color) +{ + _systemControl.textField.textColor = [UIColor colorWithRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:1.0f]; + _label->setColor(color); +} + +void EditBoxImplIOS::setPlaceholderFont(const char* pFontName, int fontSize) +{ + // TODO need to be implemented. +} + +void EditBoxImplIOS::setPlaceholderFontColor(const Color3B& color) +{ + _labelPlaceHolder->setColor(color); +} + +void EditBoxImplIOS::setInputMode(EditBox::InputMode inputMode) +{ + switch (inputMode) + { + case EditBox::InputMode::EMAIL_ADDRESS: + _systemControl.textField.keyboardType = UIKeyboardTypeEmailAddress; + break; + case EditBox::InputMode::NUMERIC: + _systemControl.textField.keyboardType = UIKeyboardTypeDecimalPad; + break; + case EditBox::InputMode::PHONE_NUMBER: + _systemControl.textField.keyboardType = UIKeyboardTypePhonePad; + break; + case EditBox::InputMode::URL: + _systemControl.textField.keyboardType = UIKeyboardTypeURL; + break; + case EditBox::InputMode::DECIMAL: + _systemControl.textField.keyboardType = UIKeyboardTypeDecimalPad; + break; + case EditBox::InputMode::SINGLE_LINE: + _systemControl.textField.keyboardType = UIKeyboardTypeDefault; + break; + default: + _systemControl.textField.keyboardType = UIKeyboardTypeDefault; + break; + } +} + +void EditBoxImplIOS::setMaxLength(int maxLength) +{ + _maxTextLength = maxLength; +} + +int EditBoxImplIOS::getMaxLength() +{ + return _maxTextLength; +} + +void EditBoxImplIOS::setInputFlag(EditBox::InputFlag inputFlag) +{ + switch (inputFlag) + { + case EditBox::InputFlag::PASSWORD: + _systemControl.textField.secureTextEntry = YES; + break; + case EditBox::InputFlag::INITIAL_CAPS_WORD: + _systemControl.textField.autocapitalizationType = UITextAutocapitalizationTypeWords; + break; + case EditBox::InputFlag::INITIAL_CAPS_SENTENCE: + _systemControl.textField.autocapitalizationType = UITextAutocapitalizationTypeSentences; + break; + case EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS: + _systemControl.textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters; + break; + case EditBox::InputFlag::SENSITIVE: + _systemControl.textField.autocorrectionType = UITextAutocorrectionTypeNo; + break; + default: + break; + } +} + +void EditBoxImplIOS::setReturnType(EditBox::KeyboardReturnType returnType) +{ + switch (returnType) { + case EditBox::KeyboardReturnType::DEFAULT: + _systemControl.textField.returnKeyType = UIReturnKeyDefault; + break; + case EditBox::KeyboardReturnType::DONE: + _systemControl.textField.returnKeyType = UIReturnKeyDone; + break; + case EditBox::KeyboardReturnType::SEND: + _systemControl.textField.returnKeyType = UIReturnKeySend; + break; + case EditBox::KeyboardReturnType::SEARCH: + _systemControl.textField.returnKeyType = UIReturnKeySearch; + break; + case EditBox::KeyboardReturnType::GO: + _systemControl.textField.returnKeyType = UIReturnKeyGo; + break; + default: + _systemControl.textField.returnKeyType = UIReturnKeyDefault; + break; + } +} + +bool EditBoxImplIOS::isEditing() +{ + return [_systemControl isEditState] ? true : false; +} + +void EditBoxImplIOS::refreshInactiveText() +{ + const char* text = getText(); + if(_systemControl.textField.hidden == YES) + { + setInactiveText(text); + if(strlen(text) == 0) + { + _label->setVisible(false); + _labelPlaceHolder->setVisible(true); + } + else + { + _label->setVisible(true); + _labelPlaceHolder->setVisible(false); + } + } +} + +void EditBoxImplIOS::setText(const char* text) +{ + NSString* nsText =[NSString stringWithUTF8String:text]; + if ([nsText compare:_systemControl.textField.text] != NSOrderedSame) + { + _systemControl.textField.text = nsText; + } + + refreshInactiveText(); +} + +NSString* removeSiriString(NSString* str) +{ + NSString* siriString = @"\xef\xbf\xbc"; + return [str stringByReplacingOccurrencesOfString:siriString withString:@""]; +} + +const char* EditBoxImplIOS::getText(void) +{ + return [removeSiriString(_systemControl.textField.text) UTF8String]; +} + +void EditBoxImplIOS::setPlaceHolder(const char* pText) +{ + _systemControl.textField.placeholder = [NSString stringWithUTF8String:pText]; + _labelPlaceHolder->setString(pText); +} + +static CGPoint convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode) +{ + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + CCEAGLView *eaglview = (CCEAGLView *) glview->getEAGLView(); + + float viewH = (float)[eaglview getHeight]; + + Vec2 visiblePos = Vec2(designCoord.x * glview->getScaleX(), designCoord.y * glview->getScaleY()); + Vec2 screenGLPos = visiblePos + glview->getViewPortRect().origin; + + CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y); + + if (bInRetinaMode) + { + screenPos.x = screenPos.x / 2.0f; + screenPos.y = screenPos.y / 2.0f; + } + CCLOGINFO("[EditBox] pos x = %f, y = %f", screenGLPos.x, screenGLPos.y); + return screenPos; +} + +void EditBoxImplIOS::setPosition(const Vec2& pos) +{ + _position = pos; + adjustTextFieldPosition(); +} + +void EditBoxImplIOS::setVisible(bool visible) +{ +// _systemControl.textField.hidden = !visible; +} + +void EditBoxImplIOS::setContentSize(const Size& size) +{ + _contentSize = size; + CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height); + placeInactiveLabels(); + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + CGSize controlSize = CGSizeMake(size.width * glview->getScaleX(),size.height * glview->getScaleY()); + + if (_inRetinaMode) + { + controlSize.width /= 2.0f; + controlSize.height /= 2.0f; + } + [_systemControl setContentSize:controlSize]; +} + +void EditBoxImplIOS::setAnchorPoint(const Vec2& anchorPoint) +{ + CCLOG("[Edit text] anchor point = (%f, %f)", anchorPoint.x, anchorPoint.y); + _anchorPoint = anchorPoint; + setPosition(_position); +} + +void EditBoxImplIOS::visit(void) +{ +} + +void EditBoxImplIOS::onEnter(void) +{ + adjustTextFieldPosition(); + const char* pText = getText(); + if (pText) { + setInactiveText(pText); + } +} + +void EditBoxImplIOS::updatePosition(float dt) +{ + if (nullptr != _systemControl) { + this->adjustTextFieldPosition(); + } +} + + + +void EditBoxImplIOS::adjustTextFieldPosition() +{ + Size contentSize = _editBox->getContentSize(); + Rect rect = Rect(0, 0, contentSize.width, contentSize.height); + rect = RectApplyAffineTransform(rect, _editBox->nodeToWorldTransform()); + + Vec2 designCoord = Vec2(rect.origin.x, rect.origin.y + rect.size.height); + [_systemControl setPosition:convertDesignCoordToScreenCoord(designCoord, _inRetinaMode)]; +} + +void EditBoxImplIOS::openKeyboard() +{ + _label->setVisible(false); + _labelPlaceHolder->setVisible(false); + + _systemControl.textField.hidden = NO; + [_systemControl openKeyboard]; +} + +void EditBoxImplIOS::closeKeyboard() +{ + [_systemControl closeKeyboard]; +} + +void EditBoxImplIOS::onEndEditing() +{ + _systemControl.textField.hidden = YES; + if(strlen(getText()) == 0) + { + _label->setVisible(false); + _labelPlaceHolder->setVisible(true); + } + else + { + _label->setVisible(true); + _labelPlaceHolder->setVisible(false); + setInactiveText(getText()); + } +} + +} + +NS_CC_END + +#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) */ + + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplMac.h b/cocos/ui/UIEditBox/UIEditBoxImplMac.h new file mode 100644 index 0000000000..ffb53d29ef --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplMac.h @@ -0,0 +1,136 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 Jozef Pridavok + + 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 __UIEditBoxIMPLMAC_H__ +#define __UIEditBoxIMPLMAC_H__ + +#include "cocos2d.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + +#import +#import + +#include "UIEditBoxImpl.h" + + +@interface UIEditBoxImplMac : NSObject +{ + NSTextField* textField_; + NSSecureTextField* secureTextField_; + void* editBox_; + BOOL editState_; + NSMutableDictionary* placeholderAttributes_; +} + +@property(nonatomic, retain) NSTextField* textField; +@property(nonatomic, retain) NSSecureTextField* secureTextField; +@property(nonatomic, retain) NSMutableDictionary* placeholderAttributes; +@property(nonatomic, readonly, getter = isEditState) BOOL editState; +@property(nonatomic, assign) void* editBox; + +-(id) initWithFrame: (NSRect) frameRect editBox: (void*) editBox; +-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance; +-(void) setPosition:(NSPoint) pos; +-(void) setContentSize:(NSSize) size; +-(void) visit; +-(void) openKeyboard; +-(void) closeKeyboard; + +@end + + +NS_CC_BEGIN + +namespace ui { + +class EditBox; + +class EditBoxImplMac : public EditBoxImpl +{ +public: + /** + * @js NA + */ + EditBoxImplMac(EditBox* pEditText); + /** + * @js NA + * @lua NA + */ + virtual ~EditBoxImplMac(); + + virtual bool initWithSize(const Size& size); + virtual void setFont(const char* pFontName, int fontSize); + virtual void setFontColor(const Color3B& color); + virtual void setPlaceholderFont(const char* pFontName, int fontSize); + virtual void setPlaceholderFontColor(const Color3B& color); + virtual void setInputMode(EditBox::InputMode inputMode); + virtual void setInputFlag(EditBox::InputFlag inputFlag); + virtual void setMaxLength(int maxLength); + virtual int getMaxLength(); + virtual void setReturnType(EditBox::KeyboardReturnType returnType); + virtual bool isEditing(); + + virtual void setText(const char* pText); + virtual const char* getText(void); + virtual void setPlaceHolder(const char* pText); + virtual void setPosition(const Vec2& pos); + virtual void setVisible(bool visible); + virtual void setContentSize(const Size& size); + virtual void setAnchorPoint(const Vec2& anchorPoint); + /** + * @js NA + * @lua NA + */ + virtual void visit(void); + virtual void doAnimationWhenKeyboardMove(float duration, float distance); + virtual void openKeyboard(); + virtual void closeKeyboard(); + virtual void updatePosition(float dt) override; + /** + * @js NA + * @lua NA + */ + virtual void onEnter(void); +private: + NSPoint convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode); + void adjustTextFieldPosition(); + Size _contentSize; + Vec2 _position; + Vec2 _anchorPoint; + int _maxTextLength; + bool _inRetinaMode; + UIEditBoxImplMac* _sysEdit; +}; + + +} + +NS_CC_END + +#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + +#endif /* __UIEditBoxIMPLMAC_H__ */ + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplMac.mm b/cocos/ui/UIEditBox/UIEditBoxImplMac.mm new file mode 100644 index 0000000000..b832f3d8bd --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplMac.mm @@ -0,0 +1,524 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2012 Jozef Pridavok + + 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 "UIEditBoxImplMac.h" +#include "base/CCDirector.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + +#include "UIEditBox.h" + + +#define getEditBoxImplMac() ((cocos2d::ui::EditBoxImplMac*)editBox_) + + + +@implementation UIEditBoxImplMac + +@synthesize textField = textField_; +@synthesize secureTextField = secureTextField_; +@synthesize placeholderAttributes = placeholderAttributes_; +@synthesize editState = editState_; +@synthesize editBox = editBox_; + +- (id) getNSWindow +{ + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + return glview->getCocoaWindow(); +} + +- (void)dealloc +{ + [textField_ resignFirstResponder]; + [textField_ removeFromSuperview]; + [textField_ release]; + + [secureTextField_ resignFirstResponder]; + [secureTextField_ removeFromSuperview]; + [secureTextField_ release]; + + [placeholderAttributes_ release]; + [super dealloc]; +} + +-(id) initWithFrame: (NSRect) frameRect editBox: (void*) editBox +{ + self = [super init]; + + if (self) + { + editState_ = NO; + self.textField = [[[NSTextField alloc] initWithFrame:frameRect] autorelease]; + self.secureTextField = [[[NSSecureTextField alloc] initWithFrame:frameRect] autorelease]; + + NSFont *font = [NSFont systemFontOfSize:frameRect.size.height*2/3]; //TODO need to delete hard code here. + textField_.font = font; + secureTextField_.font = font; + + [self setupTextField:textField_]; + [self setupTextField:secureTextField_]; + + self.editBox = editBox; + self.placeholderAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + [NSColor grayColor], NSForegroundColorAttributeName, + nil]; + + [[[self getNSWindow] contentView] addSubview:textField_]; + } + + return self; +} + +- (void)setupTextField:(NSTextField *)textField +{ + [textField setTextColor:[NSColor whiteColor]]; + [textField setBackgroundColor:[NSColor clearColor]]; + [textField setBordered:NO]; + [textField setHidden:NO]; + [textField setWantsLayer:YES]; + [textField setDelegate:self]; +} + +-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance +{ + [[[self getNSWindow] contentView] doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; +} + +-(void) setPosition:(NSPoint) pos +{ + NSRect frame = [textField_ frame]; + frame.origin = pos; + [textField_ setFrame:frame]; + [secureTextField_ setFrame:frame]; +} + +-(void) setContentSize:(NSSize) size +{ + +} + +-(void) visit +{ + +} + +-(void) openKeyboard +{ + if ([textField_ superview]) { + [textField_ becomeFirstResponder]; + } + else { + [secureTextField_ becomeFirstResponder]; + } +} + +-(void) closeKeyboard +{ + if ([textField_ superview]) { + [textField_ resignFirstResponder]; + [textField_ removeFromSuperview]; + } + else { + [secureTextField_ resignFirstResponder]; + [secureTextField_ removeFromSuperview]; + } +} + +- (BOOL)textFieldShouldReturn:(NSTextField *)sender +{ + if (sender == textField_ || sender == secureTextField_) { + [sender resignFirstResponder]; + } + return NO; +} + +-(void)animationSelector +{ +} + +- (void)controlTextDidBeginEditing:(NSNotification *)notification +{ + editState_ = YES; + cocos2d::ui::EditBoxDelegate* pDelegate = getEditBoxImplMac()->getDelegate(); + if (pDelegate != NULL) + { + pDelegate->editBoxEditingDidBegin(getEditBoxImplMac()->getEditBox()); + } + +#if CC_ENABLE_SCRIPT_BINDING + cocos2d::ui::EditBox* pEditBox= getEditBoxImplMac()->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); + cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif +} + +- (void)controlTextDidEndEditing:(NSNotification *)notification +{ + editState_ = NO; + cocos2d::ui::EditBoxDelegate* pDelegate = getEditBoxImplMac()->getDelegate(); + if (pDelegate != NULL) + { + pDelegate->editBoxEditingDidEnd(getEditBoxImplMac()->getEditBox()); + pDelegate->editBoxReturn(getEditBoxImplMac()->getEditBox()); + } + +#if CC_ENABLE_SCRIPT_BINDING + cocos2d::ui::EditBox* pEditBox= getEditBoxImplMac()->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "ended",pEditBox); + cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + memset(data.eventName, 0, sizeof(data.eventName)); + strncpy(data.eventName, "return", sizeof(data.eventName)); + event.data = (void*)&data; + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif +} + +/** + * Delegate method called before the text has been changed. + * @param textField The text field containing the text. + * @param range The range of characters to be replaced. + * @param string The replacement string. + * @return YES if the specified text range should be replaced; otherwise, NO to keep the old text. + */ +- (BOOL)textField:(NSTextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string +{ + if (getEditBoxImplMac()->getMaxLength() < 0) + { + return YES; + } + + NSUInteger oldLength = [[textField stringValue] length]; + NSUInteger replacementLength = [string length]; + NSUInteger rangeLength = range.length; + + NSUInteger newLength = oldLength - rangeLength + replacementLength; + + return newLength <= getEditBoxImplMac()->getMaxLength(); +} + +/** + * Called each time when the text field's text has changed. + */ +- (void)controlTextDidChange:(NSNotification *)notification +{ + cocos2d::ui::EditBoxDelegate* pDelegate = getEditBoxImplMac()->getDelegate(); + if (pDelegate != NULL) + { + pDelegate->editBoxTextChanged(getEditBoxImplMac()->getEditBox(), getEditBoxImplMac()->getText()); + } + +#if CC_ENABLE_SCRIPT_BINDING + cocos2d::ui::EditBox* pEditBox= getEditBoxImplMac()->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox); + cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); + cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif +} + +@end + +NS_CC_BEGIN + +namespace ui { + +EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) +{ + return new EditBoxImplMac(pEditBox); +} + +EditBoxImplMac::EditBoxImplMac(EditBox* pEditText) +: EditBoxImpl(pEditText) +, _anchorPoint(Vec2(0.5f, 0.5f)) +, _maxTextLength(-1) +, _sysEdit(nullptr) +{ + //! TODO: Retina on Mac + //! _inRetinaMode = [[CCEAGLView sharedEGLView] contentScaleFactor] == 2.0f ? true : false; + _inRetinaMode = false; +} + +EditBoxImplMac::~EditBoxImplMac() +{ + [_sysEdit release]; +} + +void EditBoxImplMac::doAnimationWhenKeyboardMove(float duration, float distance) +{ + if ([_sysEdit isEditState] || distance < 0.0f) + [_sysEdit doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; +} + +bool EditBoxImplMac::initWithSize(const Size& size) +{ + GLView* eglView = Director::getInstance()->getOpenGLView(); + + NSRect rect = NSMakeRect(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); + + if (_inRetinaMode) { + rect.size.width /= 2.0f; + rect.size.height /= 2.0f; + } + + _sysEdit = [[UIEditBoxImplMac alloc] initWithFrame:rect editBox:this]; + + if (!_sysEdit) + return false; + + return true; +} + +void EditBoxImplMac::setFont(const char* pFontName, int fontSize) +{ + NSString * fntName = [NSString stringWithUTF8String:pFontName]; + float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + float scaleFactor = glview->getScaleX(); + NSFont *textFont = [NSFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor]; + if (textFont != nil) { + [_sysEdit.textField setFont:textFont]; + [_sysEdit.secureTextField setFont:textFont]; + } +} + +void EditBoxImplMac::setPlaceholderFont(const char* pFontName, int fontSize) +{ + NSString *fontName = [NSString stringWithUTF8String:pFontName]; + float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; + auto glview = cocos2d::Director::getInstance()->getOpenGLView(); + float scaleFactor = glview->getScaleX(); + NSFont *font = [NSFont fontWithName:fontName size:fontSize * scaleFactor / retinaFactor]; + + if (!font) { + CCLOGWARN("Font not found: %s", pFontName); + return; + } + + [_sysEdit.placeholderAttributes setObject:font forKey:NSFontAttributeName]; + + /* reload placeholder */ + const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String; + if (placeholder) { + setPlaceHolder(placeholder); + } +} + +void EditBoxImplMac::setFontColor(const Color3B& color) +{ + NSColor *newColor = [NSColor colorWithCalibratedRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:1.0f]; + _sysEdit.textField.textColor = newColor; + _sysEdit.secureTextField.textColor = newColor; +} + +void EditBoxImplMac::setPlaceholderFontColor(const Color3B& color) +{ + NSColor *nsColor = [NSColor colorWithCalibratedRed:color.r/255.f green:color.g / 255.f blue:color.b / 255.f alpha:1.0f]; + [_sysEdit.placeholderAttributes setObject:nsColor forKey:NSForegroundColorAttributeName]; + + /* reload placeholder */ + const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String; + if (placeholder) { + setPlaceHolder(placeholder); + } +} + +void EditBoxImplMac::setInputMode(EditBox::InputMode inputMode) +{ +} + +void EditBoxImplMac::setMaxLength(int maxLength) +{ + _maxTextLength = maxLength; +} + +int EditBoxImplMac::getMaxLength() +{ + return _maxTextLength; +} + +void EditBoxImplMac::setInputFlag(EditBox::InputFlag inputFlag) +{ + switch (inputFlag) + { + case EditBox::InputFlag::PASSWORD: + [_sysEdit.textField.superview addSubview:_sysEdit.secureTextField]; + [_sysEdit.textField removeFromSuperview]; + break; + case EditBox::InputFlag::INITIAL_CAPS_WORD: + CCLOGWARN("INITIAL_CAPS_WORD not implemented"); + break; + case EditBox::InputFlag::INITIAL_CAPS_SENTENCE: + CCLOGWARN("INITIAL_CAPS_SENTENCE not implemented"); + break; + case EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS: + CCLOGWARN("INTIAL_CAPS_ALL_CHARACTERS not implemented"); + break; + case EditBox::InputFlag::SENSITIVE: + CCLOGWARN("SENSITIVE not implemented"); + break; + default: + break; + } +} + +void EditBoxImplMac::setReturnType(EditBox::KeyboardReturnType returnType) +{ +} + +bool EditBoxImplMac::isEditing() +{ + return [_sysEdit isEditState] ? true : false; +} + +void EditBoxImplMac::setText(const char* pText) +{ + NSString *string = [NSString stringWithUTF8String:pText]; + _sysEdit.textField.stringValue = string; + _sysEdit.secureTextField.stringValue = string; +} + +const char* EditBoxImplMac::getText(void) +{ + if (_sysEdit.secureTextField.superview) { + return [_sysEdit.secureTextField.stringValue UTF8String]; + } + + return [_sysEdit.textField.stringValue UTF8String]; +} + +void EditBoxImplMac::setPlaceHolder(const char* pText) +{ + NSAttributedString *as = [[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:pText] + attributes:_sysEdit.placeholderAttributes]; + + [[_sysEdit.textField cell] setPlaceholderAttributedString:as]; + [[_sysEdit.secureTextField cell] setPlaceholderAttributedString:as]; + [as release]; +} + +NSPoint EditBoxImplMac::convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode) +{ + NSRect frame = [_sysEdit.textField frame]; + CGFloat height = frame.size.height; + + GLView* eglView = Director::getInstance()->getOpenGLView(); + + Vec2 visiblePos = Vec2(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); + Vec2 screenGLPos = visiblePos + eglView->getViewPortRect().origin; + + //TODO: I don't know why here needs to substract `height`. + NSPoint screenPos = NSMakePoint(screenGLPos.x, screenGLPos.y-height); + + if (bInRetinaMode) { + screenPos.x = screenPos.x / 2.0f; + screenPos.y = screenPos.y / 2.0f; + } + + CCLOGINFO("[EditBox] pos x = %f, y = %f", screenGLPos.x, screenGLPos.y); + return screenPos; +} + +void EditBoxImplMac::updatePosition(float dt) +{ + if(nullptr != _sysEdit) + { + adjustTextFieldPosition(); + } +} + +void EditBoxImplMac::adjustTextFieldPosition() +{ + Size contentSize = _editBox->getContentSize(); + Rect rect = Rect(0, 0, contentSize.width, contentSize.height); + + rect = RectApplyAffineTransform(rect, _editBox->nodeToWorldTransform()); + + Vec2 designCoord = Vec2(rect.origin.x, rect.origin.y + rect.size.height); + [_sysEdit setPosition:convertDesignCoordToScreenCoord(designCoord, _inRetinaMode)]; +} + +void EditBoxImplMac::setPosition(const Vec2& pos) +{ + _position = pos; + adjustTextFieldPosition(); +} + +void EditBoxImplMac::setVisible(bool visible) +{ + [_sysEdit.textField setHidden:!visible]; + [_sysEdit.secureTextField setHidden:!visible]; +} + +void EditBoxImplMac::setContentSize(const Size& size) +{ + _contentSize = size; + CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height); +} + +void EditBoxImplMac::setAnchorPoint(const Vec2& anchorPoint) +{ + CCLOG("[Edit text] anchor point = (%f, %f)", anchorPoint.x, anchorPoint.y); + _anchorPoint = anchorPoint; + setPosition(_position); +} + +void EditBoxImplMac::visit(void) +{ + +} + +void EditBoxImplMac::openKeyboard() +{ + [_sysEdit openKeyboard]; +} + +void EditBoxImplMac::closeKeyboard() +{ + [_sysEdit closeKeyboard]; +} + +void EditBoxImplMac::onEnter(void) +{ + adjustTextFieldPosition(); +} + +} + +NS_CC_END + +#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) + + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplNone.cpp b/cocos/ui/UIEditBox/UIEditBoxImplNone.cpp new file mode 100644 index 0000000000..7e3899672c --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplNone.cpp @@ -0,0 +1,18 @@ +#include "UIEditBox.h" + +#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID ) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS ) && (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) && (CC_TARGET_PLATFORM != CC_PLATFORM_TIZEN) + +NS_CC_BEGIN + +namespace ui { + +EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) +{ + return NULL; +} + +} + +NS_CC_END + +#endif /* #if (..) */ diff --git a/cocos/ui/UIEditBox/UIEditBoxImplWin.cpp b/cocos/ui/UIEditBox/UIEditBoxImplWin.cpp new file mode 100644 index 0000000000..e539dabd41 --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplWin.cpp @@ -0,0 +1,302 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2013 Jozef Pridavok + + 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 "UIEditBoxImplWin.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +#include "UIEditBox.h" +#include "proj.win32/Win32InputBox.h" + +NS_CC_BEGIN + +namespace ui { + +EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) +{ + return new EditBoxImplWin(pEditBox); +} + +EditBoxImplWin::EditBoxImplWin(EditBox* pEditText) +: EditBoxImpl(pEditText) +, _label(nullptr) +, _labelPlaceHolder(nullptr) +, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE) +, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) +, _keyboardReturnType(EditBox::KeyboardReturnType::DEFAULT) +, _colText(Color3B::WHITE) +, _colPlaceHolder(Color3B::GRAY) +, _maxLength(-1) +{ + +} + +EditBoxImplWin::~EditBoxImplWin() +{ +} + +void EditBoxImplWin::doAnimationWhenKeyboardMove(float duration, float distance) +{ +} + +bool EditBoxImplWin::initWithSize(const Size& size) +{ + //! int fontSize = getFontSizeAccordingHeightJni(size.height-12); + _label = Label::create(); + _label->setSystemFontSize(size.height-12); + // align the text vertically center + _label->setAnchorPoint(Vec2(0, 0.5f)); + _label->setPosition(Vec2(5, size.height / 2.0f)); + _label->setColor(_colText); + _editBox->addChild(_label); + + _labelPlaceHolder = Label::create(); + _labelPlaceHolder->setSystemFontSize(size.height-12); + // align the text vertically center + _labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f)); + _labelPlaceHolder->setPosition(Vec2(5, size.height / 2.0f)); + _labelPlaceHolder->setVisible(false); + _labelPlaceHolder->setColor(_colPlaceHolder); + _editBox->addChild(_labelPlaceHolder); + + _editSize = size; + return true; +} + +void EditBoxImplWin::setFont(const char* pFontName, int fontSize) +{ + if(_label != nullptr) { + _label->setSystemFontName(pFontName); + _label->setSystemFontSize(fontSize); + } + + if(_labelPlaceHolder != nullptr) { + _labelPlaceHolder->setSystemFontName(pFontName); + _labelPlaceHolder->setSystemFontSize(fontSize); + } +} + +void EditBoxImplWin::setFontColor(const Color3B& color) +{ + _colText = color; + _label->setColor(color); +} + +void EditBoxImplWin::setPlaceholderFont(const char* pFontName, int fontSize) +{ + if(_labelPlaceHolder != nullptr) { + _labelPlaceHolder->setSystemFontName(pFontName); + _labelPlaceHolder->setSystemFontSize(fontSize); + } +} + +void EditBoxImplWin::setPlaceholderFontColor(const Color3B& color) +{ + _colPlaceHolder = color; + _labelPlaceHolder->setColor(color); +} + +void EditBoxImplWin::setInputMode(EditBox::InputMode inputMode) +{ + _editBoxInputMode = inputMode; +} + +void EditBoxImplWin::setMaxLength(int maxLength) +{ + _maxLength = maxLength; +} + +int EditBoxImplWin::getMaxLength() +{ + return _maxLength; +} + +void EditBoxImplWin::setInputFlag(EditBox::InputFlag inputFlag) +{ + _editBoxInputFlag = inputFlag; +} + +void EditBoxImplWin::setReturnType(EditBox::KeyboardReturnType returnType) +{ + _keyboardReturnType = returnType; +} + +bool EditBoxImplWin::isEditing() +{ + return false; +} + +void EditBoxImplWin::setText(const char* pText) +{ + if (pText != nullptr) + { + _text = pText; + + if (_text.length() > 0) + { + _labelPlaceHolder->setVisible(false); + + std::string strToShow; + + if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) + { + long length = cc_utf8_strlen(_text.c_str(), -1); + for (long i = 0; i < length; i++) + { + strToShow.append("*"); + } + } + else + { + strToShow = _text; + } + + //! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), _editSize.width, _editSize.height-12); + //! _label->setString(strWithEllipsis.c_str()); + _label->setString(strToShow.c_str()); + } + else + { + _labelPlaceHolder->setVisible(true); + _label->setString(""); + } + + } +} + +const char* EditBoxImplWin::getText(void) +{ + return _text.c_str(); +} + +void EditBoxImplWin::setPlaceHolder(const char* pText) +{ + if (pText != nullptr) + { + _placeHolder = pText; + if (_placeHolder.length() > 0 && _text.length() == 0) + { + _labelPlaceHolder->setVisible(true); + } + + _labelPlaceHolder->setString(_placeHolder.c_str()); + } +} + +void EditBoxImplWin::setPosition(const Vec2& pos) +{ + //_label->setPosition(pos); + //_labelPlaceHolder->setPosition(pos); +} + +void EditBoxImplWin::setVisible(bool visible) +{ // don't need to be implemented on win32 platform. +} + +void EditBoxImplWin::setContentSize(const Size& size) +{ +} + +void EditBoxImplWin::setAnchorPoint(const Vec2& anchorPoint) +{ // don't need to be implemented on win32 platform. + +} + +void EditBoxImplWin::visit(void) +{ +} + +void EditBoxImplWin::openKeyboard() +{ + if (_delegate != nullptr) + { + _delegate->editBoxEditingDidBegin(_editBox); + } + + EditBox* pEditBox = this->getEditBox(); + if (nullptr != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); + ScriptEvent event(kCommonEvent,(void*)&data); + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } + + std::string placeHolder = _labelPlaceHolder->getString(); + if (placeHolder.length() == 0) + placeHolder = "Enter value"; + + char pText[100]= {0}; + std::string text = getText(); + if (text.length()) + strncpy(pText, text.c_str(), 100); + auto glView = Director::getInstance()->getOpenGLView(); + HWND hwnd = glView->getWin32Window(); + bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK; + + if (didChange) + setText(pText); + + if (_delegate != nullptr) { + if (didChange) + _delegate->editBoxTextChanged(_editBox, getText()); + _delegate->editBoxEditingDidEnd(_editBox); + _delegate->editBoxReturn(_editBox); + } + +#if CC_ENABLE_SCRIPT_BINDING + if (nullptr != _editBox && 0 != _editBox->getScriptEditBoxHandler()) + { + CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed",_editBox); + ScriptEvent event(kCommonEvent,(void*)&data); + if (didChange) + { + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } + memset(data.eventName,0,sizeof(data.eventName)); + strncpy(data.eventName,"ended",sizeof(data.eventName)); + event.data = (void*)&data; + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + memset(data.eventName,0,sizeof(data.eventName)); + strncpy(data.eventName,"return",sizeof(data.eventName)); + event.data = (void*)&data; + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } +#endif // #if CC_ENABLE_SCRIPT_BINDING +} + +void EditBoxImplWin::closeKeyboard() +{ + +} + +void EditBoxImplWin::onEnter(void) +{ + +} + +} + +NS_CC_END + +#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ diff --git a/cocos/ui/UIEditBox/UIEditBoxImplWin.h b/cocos/ui/UIEditBox/UIEditBoxImplWin.h new file mode 100644 index 0000000000..b4c9cf9f47 --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplWin.h @@ -0,0 +1,118 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2013 Jozef Pridavok + + 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 __UIEditBoxIMPLWIN_H__ +#define __UIEditBoxIMPLWIN_H__ + +#include "cocos2d.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +#include "UIEditBoxImpl.h" + +NS_CC_BEGIN + +namespace ui { + +class EditBox; + +class CC_GUI_DLL EditBoxImplWin : public EditBoxImpl +{ +public: + /** + * @js NA + */ + EditBoxImplWin(EditBox* pEditText); + /** + * @js NA + * @lua NA + */ + virtual ~EditBoxImplWin(); + + virtual bool initWithSize(const Size& size); + virtual void setFont(const char* pFontName, int fontSize); + virtual void setFontColor(const Color3B& color); + virtual void setPlaceholderFont(const char* pFontName, int fontSize); + virtual void setPlaceholderFontColor(const Color3B& color); + virtual void setInputMode(EditBox::InputMode inputMode); + virtual void setInputFlag(EditBox::InputFlag inputFlag); + virtual void setMaxLength(int maxLength); + virtual int getMaxLength(); + virtual void setReturnType(EditBox::KeyboardReturnType returnType); + virtual bool isEditing(); + + virtual void setText(const char* pText); + virtual const char* getText(void); + virtual void setPlaceHolder(const char* pText); + virtual void setPosition(const Vec2& pos); + virtual void setVisible(bool visible); + virtual void setContentSize(const Size& size); + virtual void setAnchorPoint(const Vec2& anchorPoint); + /** + * @js NA + * @lua NA + */ + virtual void visit(void); + virtual void doAnimationWhenKeyboardMove(float duration, float distance); + virtual void openKeyboard(); + virtual void closeKeyboard(); + /** + * @js NA + * @lua NA + */ + virtual void onEnter(void); +private: + + Label* _label; + Label* _labelPlaceHolder; + EditBox::InputMode _editBoxInputMode; + EditBox::InputFlag _editBoxInputFlag; + EditBox::KeyboardReturnType _keyboardReturnType; + + std::string _text; + std::string _placeHolder; + + Color3B _colText; + Color3B _colPlaceHolder; + + int _maxLength; + Size _editSize; + + /* + Size _contentSize; + HWND _sysEdit; + int _maxTextLength; + */ +}; + + +} + +NS_CC_END + +#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ + +#endif /* __UIEditBoxIMPLWIN_H__ */ + diff --git a/cocos/ui/UIEditBox/UIEditBoxImplWp8.cpp b/cocos/ui/UIEditBox/UIEditBoxImplWp8.cpp new file mode 100644 index 0000000000..b8a2f23050 --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplWp8.cpp @@ -0,0 +1,307 @@ +/**************************************************************************** +Copyright (c) 2014 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. +****************************************************************************/ + +#include "UIEditBoxImplWp8.h" +#include "UIEditBox.h" +#include "CCGLViewImpl.h" +#include "base/CCScriptSupport.h" +#include "base/ccUTF8.h" + +NS_CC_BEGIN + +namespace ui { + +EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) +{ + return new UIEditBoxImplWp8(pEditBox); +} + +UIEditBoxImplWp8::UIEditBoxImplWp8( EditBox* pEditText ) + : EditBoxImpl(pEditText) + , m_pLabel(NULL) + , m_pLabelPlaceHolder(NULL) + , m_eEditBoxInputMode(EditBox::InputMode::SINGLE_LINE) + , m_eEditBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) + , m_eKeyboardReturnType(EditBox::KeyboardReturnType::DEFAULT) + , m_colText(Color3B::WHITE) + , m_colPlaceHolder(Color3B::GRAY) + , m_nMaxLength(-1) +{ + +} + +UIEditBoxImplWp8::~UIEditBoxImplWp8() +{ + +} + +void UIEditBoxImplWp8::openKeyboard() +{ + if (_delegate != NULL) + { + _delegate->editBoxEditingDidBegin(_editBox); + } + + EditBox* pEditBox = this->getEditBox(); + if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + { + CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); + ScriptEvent event(kCommonEvent,(void*)&data); + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); + } + + std::string placeHolder = m_pLabelPlaceHolder->getString(); + if (placeHolder.length() == 0) + placeHolder = "Enter value"; + + char pText[100]= {0}; + std::string text = getText(); + if (text.length()) + strncpy(pText, text.c_str(), 100); + + Windows::Foundation::EventHandler^ receiveHandler = ref new Windows::Foundation::EventHandler( + [this](Platform::Object^ sender, Platform::String^ arg) + { + setText(PlatformStringTostring(arg).c_str()); + if (_delegate != NULL) { + _delegate->editBoxTextChanged(_editBox, getText()); + _delegate->editBoxEditingDidEnd(_editBox); + _delegate->editBoxReturn(_editBox); + } + }); + + GLViewImpl::sharedOpenGLView()->OpenXamlEditBox(stringToPlatformString(placeHolder), stringToPlatformString(getText()), m_nMaxLength, (int)m_eEditBoxInputMode, (int)m_eEditBoxInputFlag, receiveHandler); +} + +bool UIEditBoxImplWp8::initWithSize( const Size& size ) +{ + //! int fontSize = getFontSizeAccordingHeightJni(size.height-12); + m_pLabel = Label::createWithSystemFont("", "", size.height-12); + // align the text vertically center + m_pLabel->setAnchorPoint(Vec2(0.0f, 0.5f)); + m_pLabel->setPosition(Vec2(5.0, size.height / 2.0f)); + m_pLabel->setColor(m_colText); + _editBox->addChild(m_pLabel); + + m_pLabelPlaceHolder = Label::createWithSystemFont("", "", size.height-12); + // align the text vertically center + m_pLabelPlaceHolder->setAnchorPoint(Vec2(0.0f, 0.5f)); + m_pLabelPlaceHolder->setPosition(Vec2(5.0f, size.height / 2.0f)); + m_pLabelPlaceHolder->setVisible(false); + m_pLabelPlaceHolder->setColor(m_colPlaceHolder); + _editBox->addChild(m_pLabelPlaceHolder); + + m_EditSize = size; + return true; +} + +void UIEditBoxImplWp8::setFont( const char* pFontName, int fontSize ) +{ + if(m_pLabel != NULL) { + m_pLabel->setSystemFontName(pFontName); + m_pLabel->setSystemFontSize(fontSize); + } + + if(m_pLabelPlaceHolder != NULL) { + m_pLabelPlaceHolder->setSystemFontName(pFontName); + m_pLabelPlaceHolder->setSystemFontSize(fontSize); + } +} + +void UIEditBoxImplWp8::setFontColor( const Color3B& color ) +{ + m_colText = color; + m_pLabel->setColor(color); +} + +void UIEditBoxImplWp8::setPlaceholderFont( const char* pFontName, int fontSize ) +{ + if(m_pLabelPlaceHolder != NULL) { + m_pLabelPlaceHolder->setSystemFontName(pFontName); + m_pLabelPlaceHolder->setSystemFontSize(fontSize); + } +} + +void UIEditBoxImplWp8::setPlaceholderFontColor( const Color3B& color ) +{ + m_colPlaceHolder = color; + m_pLabelPlaceHolder->setColor(color); +} + +void UIEditBoxImplWp8::setInputMode( EditBox::InputMode inputMode ) +{ + m_eEditBoxInputMode = inputMode; +} + +void UIEditBoxImplWp8::setInputFlag(EditBox::InputFlag inputFlag ) +{ + m_eEditBoxInputFlag = inputFlag; +} + +void UIEditBoxImplWp8::setMaxLength( int maxLength ) +{ + m_nMaxLength = maxLength; +} + +int UIEditBoxImplWp8::getMaxLength() +{ + return m_nMaxLength; +} + +void UIEditBoxImplWp8::setReturnType( EditBox::KeyboardReturnType returnType ) +{ + m_eKeyboardReturnType = returnType; +} + +bool UIEditBoxImplWp8::isEditing() +{ + return false; +} + +void UIEditBoxImplWp8::setText( const char* pText ) +{ + if (pText != NULL) + { + m_strText = pText; + + if (m_strText.length() > 0) + { + m_pLabelPlaceHolder->setVisible(false); + + std::string strToShow; + + if (EditBox::InputFlag::PASSWORD == m_eEditBoxInputFlag) + { + long length = cc_utf8_strlen(m_strText.c_str(), -1); + for (long i = 0; i < length; i++) + { + strToShow.append("*"); + } + } + else + { + strToShow = m_strText; + } + + //! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), m_EditSize.width, m_EditSize.height-12); + //! m_pLabel->setString(strWithEllipsis.c_str()); + m_pLabel->setString(strToShow.c_str()); + } + else + { + m_pLabelPlaceHolder->setVisible(true); + m_pLabel->setString(""); + } + + } +} + +const char* UIEditBoxImplWp8::getText( void ) +{ + return m_strText.c_str(); +} + +void UIEditBoxImplWp8::setPlaceHolder( const char* pText ) +{ + if (pText != NULL) + { + m_strPlaceHolder = pText; + if (m_strPlaceHolder.length() > 0 && m_strText.length() == 0) + { + m_pLabelPlaceHolder->setVisible(true); + } + + m_pLabelPlaceHolder->setString(m_strPlaceHolder.c_str()); + } +} + +void UIEditBoxImplWp8::setPosition( const Vec2& pos ) +{ + +} + +void UIEditBoxImplWp8::setVisible( bool visible ) +{ + +} + +void UIEditBoxImplWp8::setContentSize( const Size& size ) +{ + +} + +void UIEditBoxImplWp8::setAnchorPoint( const Vec2& anchorPoint ) +{ + +} + +void UIEditBoxImplWp8::visit( void ) +{ + +} + +void UIEditBoxImplWp8::doAnimationWhenKeyboardMove( float duration, float distance ) +{ + +} + +void UIEditBoxImplWp8::closeKeyboard() +{ + +} + +void UIEditBoxImplWp8::onEnter( void ) +{ + +} + +Platform::String^ UIEditBoxImplWp8::stringToPlatformString( std::string strSrc ) +{ + // to wide char + int nStrLen = MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, NULL, 0); + wchar_t* pWStr = new wchar_t[nStrLen + 1]; + memset(pWStr, 0, nStrLen + 1); + MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, pWStr, nStrLen); + Platform::String^ strDst = ref new Platform::String(pWStr); + delete[] pWStr; + return strDst; +} + +std::string UIEditBoxImplWp8::PlatformStringTostring( Platform::String^ strSrc ) +{ + const wchar_t* pWStr = strSrc->Data(); + int nStrLen = WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, NULL, 0, NULL, NULL); + char* pStr = new char[nStrLen + 1]; + memset(pStr, 0, nStrLen + 1); + WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, pStr, nStrLen, NULL, NULL); ; + + std::string strDst = std::string(pStr); + + delete[] pStr; + return strDst; +} + +} + +NS_CC_END diff --git a/cocos/ui/UIEditBox/UIEditBoxImplWp8.h b/cocos/ui/UIEditBox/UIEditBoxImplWp8.h new file mode 100644 index 0000000000..09d78167cd --- /dev/null +++ b/cocos/ui/UIEditBox/UIEditBoxImplWp8.h @@ -0,0 +1,88 @@ +/**************************************************************************** +Copyright (c) 2014 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 __UIEditBoxIMPLWP8_H__ +#define __UIEditBoxIMPLWP8_H__ + +#include "UIEditBoxImpl.h" + +NS_CC_BEGIN + +namespace ui { + class EditBox; + + class CC_GUI_DLL UIEditBoxImplWp8 : public EditBoxImpl + { + public: + UIEditBoxImplWp8(EditBox* pEditText); + virtual ~UIEditBoxImplWp8(); + + virtual bool initWithSize(const Size& size); + virtual void setFont(const char* pFontName, int fontSize); + virtual void setFontColor(const Color3B& color); + virtual void setPlaceholderFont(const char* pFontName, int fontSize); + virtual void setPlaceholderFontColor(const Color3B& color); + virtual void setInputMode(EditBox::InputMode inputMode); + virtual void setInputFlag(EditBox::InputFlag inputFlag); + virtual void setMaxLength(int maxLength); + virtual int getMaxLength(); + virtual void setReturnType(EditBox::KeyboardReturnType returnType); + virtual bool isEditing(); + + virtual void setText(const char* pText); + virtual const char* getText(void); + virtual void setPlaceHolder(const char* pText); + virtual void setPosition(const Vec2& pos); + virtual void setVisible(bool visible); + virtual void setContentSize(const Size& size); + virtual void setAnchorPoint(const Vec2& anchorPoint); + virtual void visit(void); + virtual void doAnimationWhenKeyboardMove(float duration, float distance); + virtual void openKeyboard(); + virtual void closeKeyboard(); + virtual void onEnter(void); + private: + Platform::String^ stringToPlatformString(std::string strSrc); + std::string PlatformStringTostring(Platform::String^ strSrc); + private: + + Label* m_pLabel; + Label* m_pLabelPlaceHolder; + EditBox::InputMode m_eEditBoxInputMode; + EditBox::InputFlag m_eEditBoxInputFlag; + (EditBox::KeyboardReturnType m_eKeyboardReturnType; + + std::string m_strText; + std::string m_strPlaceHolder; + + Color3B m_colText; + Color3B m_colPlaceHolder; + + int m_nMaxLength; + Size m_EditSize; + }; +} + +NS_CC_END + +#endif diff --git a/cocos/ui/proj.win32/Win32InputBox.cpp b/cocos/ui/proj.win32/Win32InputBox.cpp new file mode 100644 index 0000000000..da1cb12301 --- /dev/null +++ b/cocos/ui/proj.win32/Win32InputBox.cpp @@ -0,0 +1,383 @@ +#include "Win32InputBox.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) + +#include + +#pragma warning (disable: 4312) + +typedef struct _MSDN_DLGTEMPLATEEX +{ + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; + BYTE _rest[1]; // rest of structure +} MSDN_DLGTEMPLATEEX; + +static bool IsDlgTemplateExtended(DLGTEMPLATE *dlgTemplate) +{ + MSDN_DLGTEMPLATEEX *dgExTemplate = (MSDN_DLGTEMPLATEEX *) dlgTemplate; + + // MSDN excerpt: + //* dlgVer + // Specifies the version number of the extended dialog box template. This member must be 1. + //* signature + // Indicates whether a template is an extended dialog box template. + // If signature is 0xFFFF, this is an extended dialog box template. + // In this case, the dlgVer member specifies the template version number. + // If signature is any value other than 0xFFFF, this is a standard dialog box template that uses the DLGTEMPLATE and DLGITEMTEMPLATE structures. + + return (dgExTemplate->dlgVer == 1) && (dgExTemplate->signature == 0xFFFF); +} + +// Use alignment if supported by the compiler +#ifdef _MSC_VER + #if _MSC_VER > 1200 + __declspec(align(4)) + #endif +#endif + +// per the MSDN, the DLGTEMPLATE must be DWORD aligned +// this was generated by the DlgResToDlgTemplate tool +static unsigned char definputbox_dlg[] = +{ + 0x01,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc8,0x00,0xc8,0x00,0x06, + 0x00,0x16,0x00,0x11,0x00,0xe7,0x00,0x6d,0x00,0x00,0x00,0x00,0x00,0x57,0x00,0x69, + 0x00,0x6e,0x00,0x33,0x00,0x32,0x00,0x49,0x00,0x6e,0x00,0x70,0x00,0x75,0x00,0x74, + 0x00,0x42,0x00,0x6f,0x00,0x78,0x00,0x00,0x00,0x08,0x00,0xbc,0x02,0x00,0x00,0x4d, + 0x00,0x53,0x00,0x20,0x00,0x53,0x00,0x68,0x00,0x65,0x00,0x6c,0x00,0x6c,0x00,0x20, + 0x00,0x44,0x00,0x6c,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0x00,0x02,0x50,0x06,0x00,0x04,0x00,0x9d,0x00,0x21,0x00,0xe8, + 0x03,0x00,0x00,0xff,0xff,0x82,0x00,0x50,0x00,0x72,0x00,0x6f,0x00,0x6d,0x00,0x70, + 0x00,0x74,0x00,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x80,0x00,0x81,0x50,0x06,0x00,0x25,0x00,0xd8,0x00,0x0e,0x00,0xe9, + 0x03,0x00,0x00,0xff,0xff,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x84,0x10,0xa1,0x50,0x06,0x00,0x37,0x00,0xd8,0x00,0x31,0x00,0xea, + 0x03,0x00,0x00,0xff,0xff,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x01,0x00,0x03,0x50,0xab,0x00,0x04,0x00,0x33,0x00,0x0e,0x00,0x01, + 0x00,0x00,0x00,0xff,0xff,0x80,0x00,0x4f,0x00,0x4b,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x50,0xab,0x00,0x15,0x00,0x33, + 0x00,0x0e,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0x80,0x00,0x43,0x00,0x41,0x00,0x4e, + 0x00,0x43,0x00,0x45,0x00,0x4c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x27,0x00,0x08,0x00,0x08,0x00,0xff, + 0xff,0xff,0xff,0xff,0xff,0x82,0x00,0x00,0x00,0x00,0x00 +}; + +static LPCTSTR definputbox_buttonnames[] = { _T("OK"), _T("CANCEL") }; +static const INT_PTR definputbox_buttonids[] = { IDOK, IDCANCEL }; + +static const INT + definputbox_id_prompt = 1000, + definputbox_id_edit1 = 1001, + definputbox_id_edit2 = 1002; + +WIN32INPUTBOX_PARAM::WIN32INPUTBOX_PARAM() +{ + bMultiline = false; + hwndOwner = 0; + DlgTemplateName = 0; + hInstance = (HINSTANCE) ::GetModuleHandle(0); + DlgTemplateData = definputbox_dlg; + + bCenter = true; + + dwStylesPlus = 0; + dwExStylesPlus = 0; + dwStylesMinus = 0xFFFFFFFF; + dwExStylesMinus = 0xFFFFFFFF; + + xPos = yPos = -1; + + szResult = 0; + nResultSize = 0; +} + +CWin32InputBox::CWin32InputBox(WIN32INPUTBOX_PARAM *param) +{ + _param = param; +} + +CWin32InputBox::~CWin32InputBox() +{ + +} + +void CWin32InputBox::SetParam(WIN32INPUTBOX_PARAM *param) +{ + _param = param; +} + +WIN32INPUTBOX_PARAM *CWin32InputBox::GetParam() +{ + return _param; +} + +INT_PTR CWin32InputBox::InputBoxEx(WIN32INPUTBOX_PARAM *param) +{ + // Check mandatory parameters + if (param->szResult == 0) + { + ::SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + LPDLGTEMPLATE dlgTemplate; + + if (param->DlgTemplateName != 0) + { + HMODULE hModule = (HMODULE)param->hInstance; +#ifdef __MINGW32__ + HRSRC rcDlg = ::FindResource(hModule, (LPWSTR)(ULONG_PTR)(size_t)(param->DlgTemplateName), RT_DIALOG); +#else + HRSRC rcDlg = ::FindResource(hModule, MAKEINTRESOURCE(param->DlgTemplateName), RT_DIALOG); +#endif + if (rcDlg == nullptr) + return 0; + + HGLOBAL hglobalDlg = ::LoadResource(hModule, rcDlg); + if (hglobalDlg == nullptr) + return 0; + + dlgTemplate = (LPDLGTEMPLATE) hglobalDlg; + } + else if (param->DlgTemplateData != 0) + { + dlgTemplate = (LPDLGTEMPLATE) param->DlgTemplateData; + } + + MSDN_DLGTEMPLATEEX *dlgTemplateEx = + IsDlgTemplateExtended((LPDLGTEMPLATE) dlgTemplate) ? (MSDN_DLGTEMPLATEEX *) dlgTemplate : 0; + + if (dlgTemplateEx != 0) + { + dlgTemplateEx->exStyle |= param->dwExStylesPlus; + dlgTemplateEx->style |= param->dwStylesPlus; + dlgTemplateEx->exStyle &= param->dwExStylesMinus; + dlgTemplateEx->style &= param->dwStylesMinus; + + if (param->bCenter) + dlgTemplateEx->style |= DS_CENTER; + + if (param->xPos != -1) + dlgTemplateEx->x = param->xPos; + if (param->yPos != -1) + dlgTemplateEx->y = param->yPos; + } + else + { + dlgTemplate->dwExtendedStyle |= param->dwExStylesPlus; + dlgTemplate->style |= param->dwStylesPlus; + dlgTemplate->dwExtendedStyle &= param->dwExStylesMinus; + dlgTemplate->style &= param->dwStylesMinus; + + if (param->bCenter) + dlgTemplate->style |= DS_CENTER; + + if (param->xPos != -1) + dlgTemplate->x = param->xPos; + + if (param->yPos != -1) + dlgTemplate->y = param->yPos; + } + + CWin32InputBox inputbox(param); + + // Resize dialog and SHOW or HIDE multiline + INT_PTR r = ::DialogBoxIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)&inputbox); + + return r; +} + +INT_PTR CWin32InputBox::InputBox( + LPCSTR szTitle, + LPCSTR szPrompt, + LPSTR szResult, + DWORD nResultSize, + bool bMultiLine, + HWND hwndParent) +{ + WIN32INPUTBOX_PARAM param; + + param.szTitle = szTitle; + param.szPrompt = szPrompt; + param.szResult = szResult; + param.nResultSize = nResultSize; + param.bMultiline = bMultiLine; + param.hwndOwner = hwndParent; + return InputBoxEx(¶m); +} + +void CWin32InputBox::InitDialog() +{ + // Set the button captions + for (size_t i=0;ihDlg, (int) definputbox_buttonids[i], definputbox_buttonnames[i]); + + // Set other controls + ::SetWindowTextA(_param->hDlg, Utf8ToAnsi(_param->szTitle).c_str()); + ::SetDlgItemTextA(_param->hDlg, definputbox_id_prompt, Utf8ToAnsi(_param->szPrompt).c_str()); + + HWND hwndEdit1 = ::GetDlgItem(_param->hDlg, definputbox_id_edit1); + HWND hwndEdit2 = ::GetDlgItem(_param->hDlg, definputbox_id_edit2); + + if (_param->bMultiline) + _hwndEditCtrl = hwndEdit2; + else + _hwndEditCtrl = hwndEdit1; + + ::SetWindowTextA(_hwndEditCtrl, Utf8ToAnsi(_param->szResult).c_str()); + + RECT rectDlg, rectEdit1, rectEdit2; + + ::GetWindowRect(_param->hDlg, &rectDlg); + ::GetWindowRect(hwndEdit1, &rectEdit1); + ::GetWindowRect(hwndEdit2, &rectEdit2); + + if (_param->bMultiline) + { + ::ShowWindow(hwndEdit1, SW_HIDE); + ::SetWindowPos( + hwndEdit2, + HWND_NOTOPMOST, + rectEdit1.left - rectDlg.left, + (rectEdit1.top - rectDlg.top) - (rectEdit1.bottom - rectEdit1.top), + 0, + 0, + SWP_NOSIZE | SWP_NOZORDER); + + ::SetWindowPos( + _param->hDlg, + HWND_NOTOPMOST, + 0, + 0, + rectDlg.right - rectDlg.left, + rectDlg.bottom - rectDlg.top - (rectEdit1.bottom - rectEdit1.top), + SWP_NOMOVE); + + } + else + { + ::SetWindowPos( + _param->hDlg, + HWND_NOTOPMOST, + 0, + 0, + rectDlg.right - rectDlg.left, + rectEdit1.bottom - rectDlg.top + 5, + SWP_NOMOVE); + + ::ShowWindow(hwndEdit2, SW_HIDE); + } +} + +// Message handler for about box. +LRESULT CALLBACK CWin32InputBox::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLongPtr(hDlg, GWLP_USERDATA); + WIN32INPUTBOX_PARAM *param = _this ? _this->GetParam() : 0; + + switch (message) + { + case WM_INITDIALOG: + { + SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR) lParam); + + _this = (CWin32InputBox *) lParam; + _this->_param->hDlg = hDlg; + _this->InitDialog(); + return TRUE; + } + + case WM_COMMAND: + { +#ifdef _MY_DEBUG + CHAR buf[1024]; + static int i=0; + sprintf(buf, "WM_COMMAND: %09d wParam=%08X lParam=%08X\n", i++, wParam, lParam); + OutputDebugString(buf); +#endif + INT_PTR buttonId = LOWORD(wParam); + for (size_t i=0; + i_hwndEditCtrl, + _this->_param->szResult, + _this->_param->nResultSize); + + std::string strUtf8 = AnsiToUtf8(_this->_param->szResult); + + memset(_this->_param->szResult, 0, _this->_param->nResultSize); + strncpy(_this->_param->szResult, strUtf8.c_str(), _this->_param->nResultSize-1); + + ::EndDialog(hDlg, buttonId); + return TRUE; + } + } + } + break; + } + return FALSE; +} + + +std::string CWin32InputBox::AnsiToUtf8(std::string strAnsi) +{ + std::string ret; + if (strAnsi.length() > 0) + { + int nWideStrLength = MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, nullptr, 0); + WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength+1)*sizeof(WCHAR)); + memset(pwszBuf, 0, (nWideStrLength+1)*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, pwszBuf, (nWideStrLength+1)*sizeof(WCHAR)); + + int nUtf8Length = WideCharToMultiByte( CP_UTF8,0,pwszBuf,-1,nullptr,0,nullptr,FALSE ); + char* pszUtf8Buf = (char*)malloc((nUtf8Length+1)*sizeof(char)); + memset(pszUtf8Buf, 0, (nUtf8Length+1)*sizeof(char)); + + WideCharToMultiByte(CP_UTF8, 0, pwszBuf, -1, pszUtf8Buf, (nUtf8Length+1)*sizeof(char), nullptr, FALSE); + ret = pszUtf8Buf; + + free(pszUtf8Buf); + free(pwszBuf); + } + return ret; +} + +std::string CWin32InputBox::Utf8ToAnsi(std::string strUTF8) +{ + std::string ret; + if (strUTF8.length() > 0) + { + int nWideStrLength = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, nullptr, 0); + WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength+1)*sizeof(WCHAR)); + memset(pwszBuf, 0, (nWideStrLength+1)*sizeof(WCHAR)); + MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, pwszBuf, (nWideStrLength+1)*sizeof(WCHAR)); + + int nAnsiStrLength = WideCharToMultiByte( CP_ACP,0,pwszBuf,-1,nullptr,0,nullptr,FALSE ); + char* pszAnsiBuf = (char*)malloc((nAnsiStrLength+1)*sizeof(char)); + memset(pszAnsiBuf, 0, (nAnsiStrLength+1)*sizeof(char)); + + WideCharToMultiByte(CP_ACP, 0, pwszBuf, -1, pszAnsiBuf, (nAnsiStrLength+1)*sizeof(char), nullptr, FALSE); + ret = pszAnsiBuf; + + free(pszAnsiBuf); + free(pwszBuf); + } + + return ret; +} + + + +#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ diff --git a/cocos/ui/proj.win32/Win32InputBox.h b/cocos/ui/proj.win32/Win32InputBox.h new file mode 100644 index 0000000000..1fd46a5593 --- /dev/null +++ b/cocos/ui/proj.win32/Win32InputBox.h @@ -0,0 +1,106 @@ +#ifndef __03022006__WIN32INPUTBOX__ +#define __03022006__WIN32INPUTBOX__ + +#include "cocos2d.h" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +/* + +This library is (c) Elias Bachaalany aka lallous +You may use this library under the following license agreement: + +The zlib/libpng License. +--------------------------- +This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, including commercial applications, +and to alter it and redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; + you must not claim that you wrote the original software. + If you use this software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, + and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. + +*/ + +#include +#include + +class CWin32InputBox; + +// Structure used to orient the inputbox behavior +struct WIN32INPUTBOX_PARAM +{ + friend class CWin32InputBox; + + // + IN OPTIONAL bool bMultiline; + + // Pass this as none zero so to use this memory dlg template + IN OPTIONAL LPVOID DlgTemplateData; + + // Pass this as none ZERO so to load DLGTEMPLATE from resources + IN OPTIONAL LPCSTR DlgTemplateName; + + // passing both "DlgTemplateName" and "DlgTemplateData" ZERO will cause + // the dialog to use his default embedded resource + + // Center on monitor or owner window? + IN OPTIONAL bool bCenter; + + // Want to add more styles to the dialog? + IN OPTIONAL DWORD dwStylesPlus, dwStylesMinus; + IN OPTIONAL DWORD dwExStylesPlus, dwExStylesMinus; + + IN LPCSTR szTitle, szPrompt; + + // Return buffer + OUT LPSTR szResult; + IN DWORD nResultSize; + + // Owner window + HWND hwndOwner; + HINSTANCE hInstance; + + short xPos, yPos; + + WIN32INPUTBOX_PARAM(); +private: + HWND hDlg; +}; + +class CWin32InputBox +{ +private: + WIN32INPUTBOX_PARAM *_param; + static LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); + HWND _hwndEditCtrl; + + void InitDialog(); + void SetParam(WIN32INPUTBOX_PARAM *); + WIN32INPUTBOX_PARAM * GetParam(); + +public: + + CWin32InputBox(WIN32INPUTBOX_PARAM *); + ~CWin32InputBox(); + + static INT_PTR InputBoxEx(WIN32INPUTBOX_PARAM *); + static INT_PTR InputBox( + LPCSTR szTitle, + LPCSTR szPrompt, + LPSTR szResult, + DWORD nResultSize, + bool bMultiLine = false, + HWND hwndParent = 0); + + static std::string AnsiToUtf8(std::string strAnsi); + static std::string Utf8ToAnsi(std::string strUTF8); +}; + +#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ + +#endif diff --git a/cocos/ui/proj.win32/libui.vcxproj b/cocos/ui/proj.win32/libui.vcxproj index ed67cf90df..92003d88cd 100644 --- a/cocos/ui/proj.win32/libui.vcxproj +++ b/cocos/ui/proj.win32/libui.vcxproj @@ -16,6 +16,9 @@ + + + @@ -36,12 +39,15 @@ + + + @@ -62,6 +68,7 @@ + diff --git a/cocos/ui/proj.win32/libui.vcxproj.filters b/cocos/ui/proj.win32/libui.vcxproj.filters index c51a43c85d..2933d8b07f 100644 --- a/cocos/ui/proj.win32/libui.vcxproj.filters +++ b/cocos/ui/proj.win32/libui.vcxproj.filters @@ -16,6 +16,9 @@ {b59b178a-b7e0-4826-ba07-44c46cd29a10} + + {08fb4468-821b-4e5c-9298-8b57a3152a5b} + @@ -93,6 +96,18 @@ BaseClasses + + UIWidgets\UIEditBox + + + UIWidgets\UIEditBox + + + UIWidgets\UIEditBox + + + UIWidgets\UIEditBox + @@ -167,5 +182,14 @@ BaseClasses + + UIWidgets\UIEditBox + + + UIWidgets\UIEditBox + + + UIWidgets\UIEditBox + \ No newline at end of file diff --git a/cocos/ui/proj.wp8/libGUI.vcxproj b/cocos/ui/proj.wp8/libGUI.vcxproj index 5e2e4e6453..47ec5d9d10 100644 --- a/cocos/ui/proj.wp8/libGUI.vcxproj +++ b/cocos/ui/proj.wp8/libGUI.vcxproj @@ -184,6 +184,9 @@ + + + @@ -210,6 +213,8 @@ + + diff --git a/cocos/ui/proj.wp8/libGUI.vcxproj.filters b/cocos/ui/proj.wp8/libGUI.vcxproj.filters index 7a7b4ae6b4..c0a7f8250b 100644 --- a/cocos/ui/proj.wp8/libGUI.vcxproj.filters +++ b/cocos/ui/proj.wp8/libGUI.vcxproj.filters @@ -87,6 +87,15 @@ BaseClasses + + UIWidgets + + + UIWidgets + + + UIWidgets + @@ -161,5 +170,11 @@ BaseClasses + + UIWidgets + + + UIWidgets + \ No newline at end of file diff --git a/tests/cpp-tests/Android.mk b/tests/cpp-tests/Android.mk index c1fcaefe21..6d122eac83 100644 --- a/tests/cpp-tests/Android.mk +++ b/tests/cpp-tests/Android.mk @@ -70,6 +70,7 @@ Classes/UITest/CocoStudioGUITest/GUIEditorTest.cpp \ Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp \ Classes/UITest/CocoStudioGUITest/UIScene.cpp \ Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp \ +Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp \ Classes/UITest/CocoStudioGUITest/UISceneManager.cpp \ Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp \ Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp \ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 51fb94d967..5e0141dbd1 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -37,12 +37,23 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(KUIFocusTest_HBox); sceneManager->setMinUISceneId(KUIFocusTest_HBox); - //TODO: improve ListView focus sceneManager->setMaxUISceneId(KUIFocusTest_NestedLayout3); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } }, + { + "EditBox test", + [](Ref* sender) + { + UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); + sceneManager->setCurrentUISceneId(kUIEditBoxTest); + sceneManager->setMinUISceneId(kUIEditBoxTest); + sceneManager->setMaxUISceneId(kUIEditBoxTest); + Scene* scene = sceneManager->currentUIScene(); + Director::getInstance()->replaceScene(scene); + } + }, { "Scale9 Sprite Test", [](Ref* sender) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp new file mode 100644 index 0000000000..30d7fcc822 --- /dev/null +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** + 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 "UIEditBoxTest.h" +#include "testResource.h" + +// UIEditBoxTest +UIEditBoxTest::UIEditBoxTest() +{ + +} + +UIEditBoxTest::~UIEditBoxTest() +{ +} + +bool UIEditBoxTest::init() +{ + if (UIScene::init()) + { + auto glview = Director::getInstance()->getOpenGLView(); + auto visibleOrigin = glview->getVisibleOrigin(); + auto visibleSize = glview->getVisibleSize(); + + auto pBg = Sprite::create("Images/HelloWorld.png"); + pBg->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); + addChild(pBg); + + _TTFShowEditReturn = Label::createWithSystemFont("No edit control return!", "Arial", 30); + _TTFShowEditReturn->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y + visibleSize.height - 50)); + addChild(_TTFShowEditReturn); + + + auto editBoxSize = Size(visibleSize.width - 100, 60); + + // top + std::string pNormalSprite = "extensions/green_edit.png"; + _editName = ui::EditBox::create(editBoxSize, pNormalSprite); + _editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4)); + _editName->setFontName("Paint Boy"); + _editName->setFontSize(25); + _editName->setFontColor(Color3B::RED); + _editName->setPlaceHolder("Name:"); + _editName->setPlaceholderFontColor(Color3B::WHITE); + _editName->setMaxLength(8); + _editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE); + _editName->setDelegate(this); + addChild(_editName); + + // middle + _editPassword = ui::EditBox::create(editBoxSize, "extensions/orange_edit.png"); + _editPassword->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + _editPassword->setFont("American Typewriter", 30); +#else + _editPassword->setFont("American Typewriter", 80); + _editPassword->setPlaceholderFont("American Typewriter", 80); +#endif + _editPassword->setFontColor(Color3B::GREEN); + _editPassword->setPlaceHolder("Password:"); + _editPassword->setMaxLength(6); + _editPassword->setInputFlag(ui::EditBox::InputFlag::PASSWORD); + _editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); + _editPassword->setDelegate(this); + addChild(_editPassword); + + // bottom + _editEmail = ui::EditBox::create(Size(editBoxSize.width, editBoxSize.height), "extensions/yellow_edit.png"); + _editEmail->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4)); + _editEmail->setAnchorPoint(Vec2(0.5, 1.0f)); + _editEmail->setPlaceHolder("Email:"); + _editEmail->setInputMode(ui::EditBox::InputMode::EMAIL_ADDRESS); + _editEmail->setDelegate(this); + addChild(_editEmail); + + this->setPosition(Vec2(10, 20)); + + + + return true; + } + return false; +} + +void UIEditBoxTest::editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox) +{ + log("editBox %p DidBegin !", editBox); +} + +void UIEditBoxTest::editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox) +{ + log("editBox %p DidEnd !", editBox); +} + +void UIEditBoxTest::editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text) +{ + log("editBox %p TextChanged, text: %s ", editBox, text.c_str()); +} + +void UIEditBoxTest::editBoxReturn(ui::EditBox* editBox) +{ + log("editBox %p was returned !",editBox); + + if (_editName == editBox) + { + _TTFShowEditReturn->setString("Name EditBox return !"); + } + else if (_editPassword == editBox) + { + _TTFShowEditReturn->setString("Password EditBox return !"); + } + else if (_editEmail == editBox) + { + _TTFShowEditReturn->setString("Email EditBox return !"); + } +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h new file mode 100644 index 0000000000..3d93dd7717 --- /dev/null +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.h @@ -0,0 +1,52 @@ +/**************************************************************************** + 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 __cocos2d_tests__UIEditBoxTest__ +#define __cocos2d_tests__UIEditBoxTest__ + +#include "UIScene.h" + +class UIEditBoxTest : public UIScene, public cocos2d::ui::EditBoxDelegate +{ +public: + UIEditBoxTest(); + ~UIEditBoxTest(); + bool init(); + + virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox); + virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox); + virtual void editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text); + virtual void editBoxReturn(cocos2d::ui::EditBox* editBox); + + +protected: + cocos2d::Label* _TTFShowEditReturn; + cocos2d::ui::EditBox* _editName; + cocos2d::ui::EditBox* _editPassword; + cocos2d::ui::EditBox* _editEmail; + + UI_SCENE_CREATE_FUNC(UIEditBoxTest) +}; + +#endif /* defined(__cocos2d_tests__UIEditBoxTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h index 28a1b172e7..51aa68a126 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene.h @@ -31,7 +31,7 @@ USING_NS_CC; USING_NS_CC_EXT; -using namespace ui; +using namespace cocos2d::ui; #define UI_SCENE_CREATE_FUNC(UIScene) \ public: \ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 11e781e255..ee0ff4e5b1 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -22,6 +22,7 @@ #include "UIVideoPlayerTest/UIVideoPlayerTest.h" #endif #include "UIScale9SpriteTest.h" +#include "UIEditBoxTest.h" USING_NS_CC; @@ -35,6 +36,7 @@ static const char* s_testArray[] = "UIButtonTest_RemoveSelf", "UIButtonTestSwitchScale9", "UIButtonTestZoomScale", + "UIEditBoxTest", "UICheckBoxTest", "UISliderTest", "UISliderTest_Scale9", @@ -369,6 +371,8 @@ Scene *UISceneManager::currentUIScene() return UIS9Flip::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIS9ChangeAnchorPoint: return UIS9ChangeAnchorPoint::sceneWithTitle(s_testArray[_currentUISceneId]); + case kUIEditBoxTest: + return UIEditBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]); } return nullptr; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 4361de611f..6562a722db 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -38,6 +38,7 @@ enum kUIButtonTest_RemoveSelf, kUIButtonTestSwitchScale9, kUIButtonTestZoomScale, + kUIEditBoxTest, kUICheckBoxTest, kUISliderTest, kUISliderTest_Scale9, diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index cd2cbd3f0a..0b80cec40e 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -204,6 +204,7 @@ + @@ -392,6 +393,7 @@ + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index e815660d53..7d7fc6199c 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -867,6 +867,9 @@ Classes\Sprite3DTest + + Classes\UITest\CocostudioGUISceneTest + @@ -1601,5 +1604,8 @@ Classes\Sprite3DTest + + Classes\UITest\CocostudioGUISceneTest + \ No newline at end of file diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj index c152ba0746..9d77c284f5 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj @@ -248,6 +248,7 @@ + @@ -449,6 +450,7 @@ + diff --git a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters index 5959863578..98b5c51559 100644 --- a/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters +++ b/tests/cpp-tests/proj.wp8-xaml/cpp-testsComponent/cpp-testsComponent.vcxproj.filters @@ -858,6 +858,9 @@ Classes\UITest\CocosStudioGUITest + + Classes\UITest\CocosStudioGUITest + @@ -1590,6 +1593,9 @@ Classes\UITest\CocosStudioGUITest + + Classes\UITest\CocosStudioGUITest + From 534938d88c22fd3349dda3f94299c84dc84ce3e4 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 19 Aug 2014 15:17:48 +0800 Subject: [PATCH 02/15] fix linux compile error --- tests/cpp-tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 5dcfe748c8..81baa37543 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -82,6 +82,7 @@ set(SAMPLE_SRC Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp Classes/UITest/CocoStudioGUITest/UIScene.cpp Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp + Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp Classes/UITest/CocoStudioGUITest/UISceneManager.cpp Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.cpp Classes/UITest/CocoStudioGUITest/CocostudioParserTest.cpp From a8ab1a85b71e175bc66ff7a785d0ebce3d238418 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 19 Aug 2014 17:42:17 +0800 Subject: [PATCH 03/15] fix linux compile error --- cocos/ui/CMakeLists.txt | 4 ++++ .../Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp | 2 ++ .../Classes/UITest/CocoStudioGUITest/UISceneManager.cpp | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index 3ccdf27b25..132f7c4635 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -23,6 +23,10 @@ set(COCOS_UI_SRC UIWidget.cpp UIDeprecated.cpp UIScale9Sprite.cpp + UIEditBox/UIEditBox.cpp + UIEditBox/UIEditBoxImplAndroid.cpp + UIEditBox/UIEditBoxImplNone.cpp + UIEditBox/UIEditBoxImplWin.cpp ) include_directories( diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 5e0141dbd1..e3cd3c24fb 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -42,6 +42,7 @@ g_guisTests[] = Director::getInstance()->replaceScene(scene); } }, +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) { "EditBox test", [](Ref* sender) @@ -54,6 +55,7 @@ g_guisTests[] = Director::getInstance()->replaceScene(scene); } }, +#endif { "Scale9 Sprite Test", [](Ref* sender) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index ee0ff4e5b1..d552528b00 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -22,7 +22,9 @@ #include "UIVideoPlayerTest/UIVideoPlayerTest.h" #endif #include "UIScale9SpriteTest.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) #include "UIEditBoxTest.h" +#endif USING_NS_CC; @@ -36,7 +38,9 @@ static const char* s_testArray[] = "UIButtonTest_RemoveSelf", "UIButtonTestSwitchScale9", "UIButtonTestZoomScale", +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) "UIEditBoxTest", +#endif "UICheckBoxTest", "UISliderTest", "UISliderTest_Scale9", @@ -371,8 +375,11 @@ Scene *UISceneManager::currentUIScene() return UIS9Flip::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIS9ChangeAnchorPoint: return UIS9ChangeAnchorPoint::sceneWithTitle(s_testArray[_currentUISceneId]); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) case kUIEditBoxTest: return UIEditBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]); +#endif + } return nullptr; } From 46f3ab9b571a0d7837ffb1d026a76d69d9649144 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 20 Aug 2014 16:08:28 +0800 Subject: [PATCH 04/15] add Scale9Sprite to create method of ui::EditBox --- cocos/ui/UIEditBox/UIEditBox.cpp | 43 +++++++++++++++++++ cocos/ui/UIEditBox/UIEditBox.h | 9 ++++ .../CocoStudioGUITest/UIEditBoxTest.cpp | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/cocos/ui/UIEditBox/UIEditBox.cpp b/cocos/ui/UIEditBox/UIEditBox.cpp index 12723cdb6e..3d9034d372 100644 --- a/cocos/ui/UIEditBox/UIEditBox.cpp +++ b/cocos/ui/UIEditBox/UIEditBox.cpp @@ -84,6 +84,49 @@ EditBox* EditBox::create(const Size& size, return pRet; } + +EditBox* EditBox::create(const cocos2d::Size &size, cocos2d::ui::Scale9Sprite *pNormal9SpriteBg) +{ + EditBox* pRet = new EditBox(); + + if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, pNormal9SpriteBg)) + { + pRet->autorelease(); + } + else + { + CC_SAFE_DELETE(pRet); + } + + return pRet; +} + +bool EditBox::initWithSizeAndBackgroundSprite(const cocos2d::Size &size, cocos2d::ui::Scale9Sprite *pNormal9SpriteBg) +{ + if (Widget::init()) + { + _editBoxImpl = __createSystemEditBox(this); + _editBoxImpl->initWithSize(size); + _editBoxImpl->setInputMode(EditBox::InputMode::ANY); + + _backgroundSprite = pNormal9SpriteBg; + + this->setContentSize(size); + this->setPosition(Vec2(0, 0)); + + _backgroundSprite->setPosition(Vec2(_contentSize.width/2, _contentSize.height/2)); + _backgroundSprite->setContentSize(size); + this->addProtectedChild(_backgroundSprite); + + this->setTouchEnabled(true); + + this->addTouchEventListener(CC_CALLBACK_2(EditBox::touchDownAction, this)); + + return true; + } + return false; +} + bool EditBox::initWithSizeAndBackgroundSprite(const Size& size, const std::string& pNormal9SpriteBg, diff --git a/cocos/ui/UIEditBox/UIEditBox.h b/cocos/ui/UIEditBox/UIEditBox.h index 335193fee8..61bbeab965 100644 --- a/cocos/ui/UIEditBox/UIEditBox.h +++ b/cocos/ui/UIEditBox/UIEditBox.h @@ -185,6 +185,13 @@ namespace ui { INTIAL_CAPS_ALL_CHARACTERS, }; + /** + * create a edit box with size. + * @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again. + */ + static EditBox* create(const Size& size, + Scale9Sprite* pNormal9SpriteBg); + /** * create a edit box with size. * @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again. @@ -214,6 +221,8 @@ namespace ui { const std::string& pNormal9SpriteBg, TextureResType texType = TextureResType::LOCAL); + bool initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* pNormal9SpriteBg); + /** * Gets/Sets the delegate for edit box. * @lua NA diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp index 30d7fcc822..121f6a1fb0 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp @@ -56,7 +56,7 @@ bool UIEditBoxTest::init() // top std::string pNormalSprite = "extensions/green_edit.png"; - _editName = ui::EditBox::create(editBoxSize, pNormalSprite); + _editName = ui::EditBox::create(editBoxSize, ui::Scale9Sprite::create(pNormalSprite)); _editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4)); _editName->setFontName("Paint Boy"); _editName->setFontSize(25); From 2d8bec2ba92741056654691c738c850fa13d3de7 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 20 Aug 2014 16:20:57 +0800 Subject: [PATCH 05/15] remove Extension EditBox --- build/cocos2d_libs.xcodeproj/project.pbxproj | 62 -- extensions/GUI/CCEditBox/CCEditBox.cpp | 435 ----------- extensions/GUI/CCEditBox/CCEditBox.h | 452 ------------ extensions/GUI/CCEditBox/CCEditBoxImpl.h | 104 --- .../GUI/CCEditBox/CCEditBoxImplAndroid.cpp | 315 -------- .../GUI/CCEditBox/CCEditBoxImplAndroid.h | 109 --- extensions/GUI/CCEditBox/CCEditBoxImplIOS.h | 143 ---- extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm | 674 ------------------ extensions/GUI/CCEditBox/CCEditBoxImplMac.h | 132 ---- extensions/GUI/CCEditBox/CCEditBoxImplMac.mm | 520 -------------- .../GUI/CCEditBox/CCEditBoxImplNone.cpp | 14 - extensions/GUI/CCEditBox/CCEditBoxImplWin.cpp | 298 -------- extensions/GUI/CCEditBox/CCEditBoxImplWin.h | 116 --- extensions/GUI/CCEditBox/CCEditBoxImplWp8.cpp | 303 -------- extensions/GUI/CCEditBox/CCEditBoxImplWp8.h | 87 --- extensions/cocos-ext.h | 2 +- .../EditBoxTest/EditBoxTest.cpp | 13 +- .../ExtensionsTest/EditBoxTest/EditBoxTest.h | 16 +- 18 files changed, 16 insertions(+), 3779 deletions(-) delete mode 100644 extensions/GUI/CCEditBox/CCEditBox.cpp delete mode 100644 extensions/GUI/CCEditBox/CCEditBox.h delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImpl.h delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplIOS.h delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplMac.h delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplMac.mm delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplNone.cpp delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplWin.cpp delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplWin.h delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplWp8.cpp delete mode 100644 extensions/GUI/CCEditBox/CCEditBoxImplWp8.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 0225d99ce9..83f7a98a31 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -731,19 +731,6 @@ 460E47AC18080904000CDD6D /* CCInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1684B1807AF4E005B8026 /* CCInvocation.h */; }; 460E47AD18080904000CDD6D /* CCScale9Sprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */; }; 460E47AE18080904000CDD6D /* CCScale9Sprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */; }; - 460E47AF1808090B000CDD6D /* CCEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */; }; - 460E47B01808090B000CDD6D /* CCEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168501807AF4E005B8026 /* CCEditBox.h */; }; - 460E47B11808090B000CDD6D /* CCEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */; }; - 460E47BD1808090D000CDD6D /* CCEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */; }; - 460E47BE1808090D000CDD6D /* CCEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168501807AF4E005B8026 /* CCEditBox.h */; }; - 460E47BF1808090D000CDD6D /* CCEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */; }; - 460E47C01808090D000CDD6D /* CCEditBoxImplAndroid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168521807AF4E005B8026 /* CCEditBoxImplAndroid.cpp */; }; - 460E47C11808090D000CDD6D /* CCEditBoxImplAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168531807AF4E005B8026 /* CCEditBoxImplAndroid.h */; }; - 460E47C21808090D000CDD6D /* CCEditBoxImplIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168541807AF4E005B8026 /* CCEditBoxImplIOS.h */; }; - 460E47C31808090D000CDD6D /* CCEditBoxImplIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A168551807AF4E005B8026 /* CCEditBoxImplIOS.mm */; }; - 460E47C61808090D000CDD6D /* CCEditBoxImplNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168581807AF4E005B8026 /* CCEditBoxImplNone.cpp */; }; - 460E47C91808090D000CDD6D /* CCEditBoxImplWin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1685B1807AF4E005B8026 /* CCEditBoxImplWin.cpp */; }; - 460E47CA1808090D000CDD6D /* CCEditBoxImplWin.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1685C1807AF4E005B8026 /* CCEditBoxImplWin.h */; }; 460E47CB18080913000CDD6D /* CCScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1685E1807AF4E005B8026 /* CCScrollView.cpp */; }; 460E47CC18080913000CDD6D /* CCScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1685F1807AF4E005B8026 /* CCScrollView.h */; }; 460E47CF18080913000CDD6D /* CCTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168621807AF4E005B8026 /* CCTableView.cpp */; }; @@ -1365,8 +1352,6 @@ B276EF651988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */; }; B276EF661988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */; }; B27AEE0219768934008BD575 /* libwebsockets.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AAF5384180E35A3000584C8 /* libwebsockets.a */; }; - B282B4801980E08F00666787 /* CCEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */; }; - B282B4811980E0A300666787 /* CCEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */; }; B29594B41926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B29594B21926D5EC003EEF37 /* CCMeshCommand.cpp */; }; B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B29594B21926D5EC003EEF37 /* CCMeshCommand.cpp */; }; B29594B61926D5EC003EEF37 /* CCMeshCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = B29594B31926D5EC003EEF37 /* CCMeshCommand.h */; }; @@ -2629,16 +2614,6 @@ 46A1684B1807AF4E005B8026 /* CCInvocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCInvocation.h; sourceTree = ""; }; 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCScale9Sprite.cpp; sourceTree = ""; }; 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCScale9Sprite.h; sourceTree = ""; }; - 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBox.cpp; sourceTree = ""; }; - 46A168501807AF4E005B8026 /* CCEditBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBox.h; sourceTree = ""; }; - 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImpl.h; sourceTree = ""; }; - 46A168521807AF4E005B8026 /* CCEditBoxImplAndroid.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBoxImplAndroid.cpp; sourceTree = ""; }; - 46A168531807AF4E005B8026 /* CCEditBoxImplAndroid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplAndroid.h; sourceTree = ""; }; - 46A168541807AF4E005B8026 /* CCEditBoxImplIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplIOS.h; sourceTree = ""; }; - 46A168551807AF4E005B8026 /* CCEditBoxImplIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CCEditBoxImplIOS.mm; sourceTree = ""; }; - 46A168581807AF4E005B8026 /* CCEditBoxImplNone.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBoxImplNone.cpp; sourceTree = ""; }; - 46A1685B1807AF4E005B8026 /* CCEditBoxImplWin.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBoxImplWin.cpp; sourceTree = ""; }; - 46A1685C1807AF4E005B8026 /* CCEditBoxImplWin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplWin.h; sourceTree = ""; }; 46A1685E1807AF4E005B8026 /* CCScrollView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCScrollView.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 46A1685F1807AF4E005B8026 /* CCScrollView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCScrollView.h; sourceTree = ""; }; 46A168621807AF4E005B8026 /* CCTableView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCTableView.cpp; sourceTree = ""; }; @@ -3103,8 +3078,6 @@ B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexData.cpp; sourceTree = ""; }; B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCVertexIndexBuffer.h; sourceTree = ""; }; B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexBuffer.cpp; sourceTree = ""; }; - B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCEditBoxImplMac.mm; sourceTree = ""; }; - B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplMac.h; sourceTree = ""; }; B29594AF1926D5D9003EEF37 /* ccShader_3D_Color.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_Color.frag; sourceTree = ""; }; B29594B01926D5D9003EEF37 /* ccShader_3D_ColorTex.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_ColorTex.frag; sourceTree = ""; }; B29594B11926D5D9003EEF37 /* ccShader_3D_PositionTex.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_PositionTex.vert; sourceTree = ""; }; @@ -4596,7 +4569,6 @@ isa = PBXGroup; children = ( 46A168341807AF4E005B8026 /* CCControlExtension */, - 46A1684E1807AF4E005B8026 /* CCEditBox */, 46A1685D1807AF4E005B8026 /* CCScrollView */, ); path = GUI; @@ -4634,25 +4606,6 @@ path = CCControlExtension; sourceTree = ""; }; - 46A1684E1807AF4E005B8026 /* CCEditBox */ = { - isa = PBXGroup; - children = ( - B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */, - B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */, - 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */, - 46A168501807AF4E005B8026 /* CCEditBox.h */, - 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */, - 46A168521807AF4E005B8026 /* CCEditBoxImplAndroid.cpp */, - 46A168531807AF4E005B8026 /* CCEditBoxImplAndroid.h */, - 46A168541807AF4E005B8026 /* CCEditBoxImplIOS.h */, - 46A168551807AF4E005B8026 /* CCEditBoxImplIOS.mm */, - 46A168581807AF4E005B8026 /* CCEditBoxImplNone.cpp */, - 46A1685B1807AF4E005B8026 /* CCEditBoxImplWin.cpp */, - 46A1685C1807AF4E005B8026 /* CCEditBoxImplWin.h */, - ); - path = CCEditBox; - sourceTree = ""; - }; 46A1685D1807AF4E005B8026 /* CCScrollView */ = { isa = PBXGroup; children = ( @@ -5774,15 +5727,12 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - B282B4801980E08F00666787 /* CCEditBoxImplMac.h in Headers */, 460E478318080902000CDD6D /* CCControlExtensions.h in Headers */, 460E477E18080902000CDD6D /* CCControl.h in Headers */, - 460E47B11808090B000CDD6D /* CCEditBoxImpl.h in Headers */, 460E477B180808F5000CDD6D /* ExtensionMacros.h in Headers */, 460E479118080902000CDD6D /* CCControlUtils.h in Headers */, 460E468118080832000CDD6D /* cocos-ext.h in Headers */, 460E47CC18080913000CDD6D /* CCScrollView.h in Headers */, - 460E47B01808090B000CDD6D /* CCEditBox.h in Headers */, 460E478918080902000CDD6D /* CCControlSaturationBrightnessPicker.h in Headers */, 460E47D018080913000CDD6D /* CCTableView.h in Headers */, 460E478F18080902000CDD6D /* CCControlSwitch.h in Headers */, @@ -6044,13 +5994,10 @@ 460E47A418080904000CDD6D /* CCControlSlider.h in Headers */, 460E479E18080904000CDD6D /* CCControlHuePicker.h in Headers */, 460E468218080836000CDD6D /* cocos-ext.h in Headers */, - 460E47BF1808090D000CDD6D /* CCEditBoxImpl.h in Headers */, 460E47AE18080904000CDD6D /* CCScale9Sprite.h in Headers */, 460E477C180808F7000CDD6D /* ExtensionMacros.h in Headers */, 460E47A218080904000CDD6D /* CCControlSaturationBrightnessPicker.h in Headers */, 460E479B18080904000CDD6D /* CCControlColourPicker.h in Headers */, - 460E47C11808090D000CDD6D /* CCEditBoxImplAndroid.h in Headers */, - 460E47CA1808090D000CDD6D /* CCEditBoxImplWin.h in Headers */, 460E47AA18080904000CDD6D /* CCControlUtils.h in Headers */, 460E47A818080904000CDD6D /* CCControlSwitch.h in Headers */, 460E47D818080914000CDD6D /* CCTableView.h in Headers */, @@ -6059,8 +6006,6 @@ 460E47DA18080914000CDD6D /* CCTableViewCell.h in Headers */, 460E47AC18080904000CDD6D /* CCInvocation.h in Headers */, 460E47A018080904000CDD6D /* CCControlPotentiometer.h in Headers */, - 460E47BE1808090D000CDD6D /* CCEditBox.h in Headers */, - 460E47C21808090D000CDD6D /* CCEditBoxImplIOS.h in Headers */, 1AD71EF3180E27CF00808F54 /* CCPhysicsDebugNode.h in Headers */, 1AD71EF7180E27CF00808F54 /* CCPhysicsSprite.h in Headers */, 1AAF5356180E3060000584C8 /* AssetsManager.h in Headers */, @@ -7303,7 +7248,6 @@ buildActionMask = 2147483647; files = ( 460E477D18080902000CDD6D /* CCControl.cpp in Sources */, - B282B4811980E0A300666787 /* CCEditBoxImplMac.mm in Sources */, 460E47CB18080913000CDD6D /* CCScrollView.cpp in Sources */, 460E47D118080913000CDD6D /* CCTableViewCell.cpp in Sources */, 460E47CF18080913000CDD6D /* CCTableView.cpp in Sources */, @@ -7315,7 +7259,6 @@ 460E478E18080902000CDD6D /* CCControlSwitch.cpp in Sources */, 460E479218080902000CDD6D /* CCInvocation.cpp in Sources */, 460E477F18080902000CDD6D /* CCControlButton.cpp in Sources */, - 460E47AF1808090B000CDD6D /* CCEditBox.cpp in Sources */, 460E479418080902000CDD6D /* CCScale9Sprite.cpp in Sources */, 460E478118080902000CDD6D /* CCControlColourPicker.cpp in Sources */, 460E479018080902000CDD6D /* CCControlUtils.cpp in Sources */, @@ -7526,12 +7469,8 @@ buildActionMask = 2147483647; files = ( 460E47D918080914000CDD6D /* CCTableViewCell.cpp in Sources */, - 460E47C01808090D000CDD6D /* CCEditBoxImplAndroid.cpp in Sources */, 460E47A118080904000CDD6D /* CCControlSaturationBrightnessPicker.cpp in Sources */, - 460E47BD1808090D000CDD6D /* CCEditBox.cpp in Sources */, - 460E47C61808090D000CDD6D /* CCEditBoxImplNone.cpp in Sources */, 460E47D318080914000CDD6D /* CCScrollView.cpp in Sources */, - 460E47C91808090D000CDD6D /* CCEditBoxImplWin.cpp in Sources */, 460E47A918080904000CDD6D /* CCControlUtils.cpp in Sources */, 460E47D718080914000CDD6D /* CCTableView.cpp in Sources */, 460E479F18080904000CDD6D /* CCControlPotentiometer.cpp in Sources */, @@ -7540,7 +7479,6 @@ 460E47A318080904000CDD6D /* CCControlSlider.cpp in Sources */, 460E47AB18080904000CDD6D /* CCInvocation.cpp in Sources */, 460E47AD18080904000CDD6D /* CCScale9Sprite.cpp in Sources */, - 460E47C31808090D000CDD6D /* CCEditBoxImplIOS.mm in Sources */, 460E47A718080904000CDD6D /* CCControlSwitch.cpp in Sources */, 460E479618080904000CDD6D /* CCControl.cpp in Sources */, 460E47A518080904000CDD6D /* CCControlStepper.cpp in Sources */, diff --git a/extensions/GUI/CCEditBox/CCEditBox.cpp b/extensions/GUI/CCEditBox/CCEditBox.cpp deleted file mode 100644 index 97c34951c7..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBox.cpp +++ /dev/null @@ -1,435 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 "CCEditBox.h" -#include "CCEditBoxImpl.h" - -NS_CC_EXT_BEGIN - -static const float CHECK_EDITBOX_POSITION_INTERVAL = 0.1f; - -EditBox::EditBox(void) -: _editBoxImpl(nullptr) -, _delegate(nullptr) -, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE) -, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) -, _keyboardReturnType(KeyboardReturnType::DEFAULT) -, _fontSize(-1) -, _placeholderFontSize(-1) -, _colText(Color3B::WHITE) -, _colPlaceHolder(Color3B::GRAY) -, _maxLength(0) -, _adjustHeight(0.0f) -#if CC_ENABLE_SCRIPT_BINDING -, _scriptEditBoxHandler(0) -#endif -{ -} - -EditBox::~EditBox(void) -{ - CC_SAFE_DELETE(_editBoxImpl); -#if CC_ENABLE_SCRIPT_BINDING - unregisterScriptEditBoxHandler(); -#endif -} - - -void EditBox::touchDownAction(Ref *sender, Control::EventType controlEvent) -{ - _editBoxImpl->openKeyboard(); -} - -EditBox* EditBox::create(const Size& size, Scale9Sprite* pNormal9SpriteBg, Scale9Sprite* pPressed9SpriteBg/* = nullptr*/, Scale9Sprite* pDisabled9SpriteBg/* = nullptr*/) -{ - EditBox* pRet = new EditBox(); - - if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, pNormal9SpriteBg)) - { - if (pPressed9SpriteBg != nullptr) - { - pRet->setBackgroundSpriteForState(pPressed9SpriteBg, Control::State::HIGH_LIGHTED); - } - - if (pDisabled9SpriteBg != nullptr) - { - pRet->setBackgroundSpriteForState(pDisabled9SpriteBg, Control::State::DISABLED); - } - pRet->autorelease(); - } - else - { - CC_SAFE_DELETE(pRet); - } - - return pRet; -} - -bool EditBox::initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* pPressed9SpriteBg) -{ - if (ControlButton::initWithBackgroundSprite(pPressed9SpriteBg)) - { - _editBoxImpl = __createSystemEditBox(this); - _editBoxImpl->initWithSize(size); - _editBoxImpl->setInputMode(EditBox::InputMode::ANY); - - this->setZoomOnTouchDown(false); - this->setPreferredSize(size); - this->setPosition(Vec2(0, 0)); - this->addTargetWithActionForControlEvent(this, cccontrol_selector(EditBox::touchDownAction), Control::EventType::TOUCH_UP_INSIDE); - - return true; - } - return false; -} - -void EditBox::setDelegate(EditBoxDelegate* pDelegate) -{ - _delegate = pDelegate; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setDelegate(pDelegate); - } -} - -EditBoxDelegate* EditBox::getDelegate() -{ - return _delegate; -} - -void EditBox::setText(const char* pText) -{ - if (pText != nullptr) - { - _text = pText; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setText(pText); - } - } -} - -const char* EditBox::getText(void) -{ - if (_editBoxImpl != nullptr) - { - const char* pText = _editBoxImpl->getText(); - if(pText != nullptr) - return pText; - } - - return ""; -} - -void EditBox::setFont(const char* pFontName, int fontSize) -{ - _fontName = pFontName; - _fontSize = fontSize; - if (pFontName != nullptr) - { - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setFont(pFontName, fontSize); - } - } -} - -void EditBox::setFontName(const char* pFontName) -{ - _fontName = pFontName; - if (_editBoxImpl != nullptr && _fontSize != -1) - { - _editBoxImpl->setFont(pFontName, _fontSize); - } -} - -void EditBox::setFontSize(int fontSize) -{ - _fontSize = fontSize; - if (_editBoxImpl != nullptr && _fontName.length() > 0) - { - _editBoxImpl->setFont(_fontName.c_str(), _fontSize); - } -} - -void EditBox::setFontColor(const Color3B& color) -{ - _colText = color; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setFontColor(color); - } -} - -void EditBox::setPlaceholderFont(const char* pFontName, int fontSize) -{ - _placeholderFontName = pFontName; - _placeholderFontSize = fontSize; - if (pFontName != nullptr) - { - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setPlaceholderFont(pFontName, fontSize); - } - } -} - -void EditBox::setPlaceholderFontName(const char* pFontName) -{ - _placeholderFontName = pFontName; - if (_editBoxImpl != nullptr && _placeholderFontSize != -1) - { - _editBoxImpl->setPlaceholderFont(pFontName, _fontSize); - } -} - -void EditBox::setPlaceholderFontSize(int fontSize) -{ - _placeholderFontSize = fontSize; - if (_editBoxImpl != nullptr && _placeholderFontName.length() > 0) - { - _editBoxImpl->setPlaceholderFont(_placeholderFontName.c_str(), _fontSize); - } -} - -void EditBox::setPlaceholderFontColor(const Color3B& color) -{ - _colText = color; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setPlaceholderFontColor(color); - } -} - -void EditBox::setPlaceHolder(const char* pText) -{ - if (pText != nullptr) - { - _placeHolder = pText; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setPlaceHolder(pText); - } - } -} - -const char* EditBox::getPlaceHolder(void) -{ - return _placeHolder.c_str(); -} - -void EditBox::setInputMode(EditBox::InputMode inputMode) -{ - _editBoxInputMode = inputMode; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setInputMode(inputMode); - } -} - -void EditBox::setMaxLength(int maxLength) -{ - _maxLength = maxLength; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setMaxLength(maxLength); - } -} - - -int EditBox::getMaxLength() -{ - return _maxLength; -} - -void EditBox::setInputFlag(EditBox::InputFlag inputFlag) -{ - _editBoxInputFlag = inputFlag; - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setInputFlag(inputFlag); - } -} - -void EditBox::setReturnType(EditBox::KeyboardReturnType returnType) -{ - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setReturnType(returnType); - } -} - -/* override function */ -void EditBox::setPosition(const Vec2& pos) -{ - ControlButton::setPosition(pos); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setPosition(pos); - } -} - -void EditBox::setVisible(bool visible) -{ - ControlButton::setVisible(visible); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setVisible(visible); - } -} - -void EditBox::setContentSize(const Size& size) -{ - ControlButton::setContentSize(size); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setContentSize(size); - } -} - -void EditBox::setAnchorPoint(const Vec2& anchorPoint) -{ - ControlButton::setAnchorPoint(anchorPoint); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->setAnchorPoint(anchorPoint); - } -} - -void EditBox::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) -{ - ControlButton::visit(renderer, parentTransform, parentFlags); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->visit(); - } -} - -void EditBox::onEnter(void) -{ -#if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript) - { - if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) - return; - } -#endif - - ControlButton::onEnter(); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->onEnter(); - } -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - this->schedule(schedule_selector(EditBox::updatePosition), CHECK_EDITBOX_POSITION_INTERVAL); -#endif -} - -void EditBox::updatePosition(float dt) -{ - if (nullptr != _editBoxImpl) { - _editBoxImpl->updatePosition(dt); - } -} - - -void EditBox::onExit(void) -{ - ControlButton::onExit(); - if (_editBoxImpl != nullptr) - { - // remove system edit control - _editBoxImpl->closeKeyboard(); - } -} - -static Rect getRect(Node * pNode) -{ - Size contentSize = pNode->getContentSize(); - Rect rect = Rect(0, 0, contentSize.width, contentSize.height); - return RectApplyTransform(rect, pNode->getNodeToWorldTransform()); -} - -void EditBox::keyboardWillShow(IMEKeyboardNotificationInfo& info) -{ - // CCLOG("CCEditBox::keyboardWillShow"); - Rect rectTracked = getRect(this); - // some adjustment for margin between the keyboard and the edit box. - rectTracked.origin.y -= 4; - - // if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done. - if (!rectTracked.intersectsRect(info.end)) - { - CCLOG("needn't to adjust view layout."); - return; - } - - // assume keyboard at the bottom of screen, calculate the vertical adjustment. - _adjustHeight = info.end.getMaxY() - rectTracked.getMinY(); - // CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", _adjustHeight); - - if (_editBoxImpl != nullptr) - { - _editBoxImpl->doAnimationWhenKeyboardMove(info.duration, _adjustHeight); - } -} - -void EditBox::keyboardDidShow(IMEKeyboardNotificationInfo& info) -{ - -} - -void EditBox::keyboardWillHide(IMEKeyboardNotificationInfo& info) -{ - // CCLOG("CCEditBox::keyboardWillHide"); - if (_editBoxImpl != nullptr) - { - _editBoxImpl->doAnimationWhenKeyboardMove(info.duration, -_adjustHeight); - } -} - -void EditBox::keyboardDidHide(IMEKeyboardNotificationInfo& info) -{ - -} - -#if CC_ENABLE_SCRIPT_BINDING -void EditBox::registerScriptEditBoxHandler(int handler) -{ - unregisterScriptEditBoxHandler(); - _scriptEditBoxHandler = handler; -} - -void EditBox::unregisterScriptEditBoxHandler(void) -{ - if (0 != _scriptEditBoxHandler) - { - ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_scriptEditBoxHandler); - _scriptEditBoxHandler = 0; - } -} -#endif - -NS_CC_EXT_END diff --git a/extensions/GUI/CCEditBox/CCEditBox.h b/extensions/GUI/CCEditBox/CCEditBox.h deleted file mode 100644 index 9203cbfaac..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBox.h +++ /dev/null @@ -1,452 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 __CCEDITTEXT_H__ -#define __CCEDITTEXT_H__ - -#include "base/CCIMEDelegate.h" -#include "extensions/ExtensionMacros.h" -#include "../CCControlExtension/CCControlExtensions.h" -#include "extensions/ExtensionExport.h" - -NS_CC_EXT_BEGIN - -class EditBox; -class EditBoxImpl; - - -class CC_EX_DLL EditBoxDelegate -{ -public: - /** - * @js NA - * @lua NA - */ - virtual ~EditBoxDelegate() {}; - - /** - * This method is called when an edit box gains focus after keyboard is shown. - * @param editBox The edit box object that generated the event. - * @js NA - * @lua NA - */ - virtual void editBoxEditingDidBegin(EditBox* editBox) {}; - - - /** - * This method is called when an edit box loses focus after keyboard is hidden. - * @param editBox The edit box object that generated the event. - * @js NA - * @lua NA - */ - virtual void editBoxEditingDidEnd(EditBox* editBox) {}; - - /** - * This method is called when the edit box text was changed. - * @param editBox The edit box object that generated the event. - * @param text The new text. - * @js NA - * @lua NA - */ - virtual void editBoxTextChanged(EditBox* editBox, const std::string& text) {}; - - /** - * This method is called when the return button was pressed or the outside area of keyboard was touched. - * @param editBox The edit box object that generated the event. - * @js NA - * @lua NA - */ - virtual void editBoxReturn(EditBox* editBox) = 0; - -}; - -/** - * \brief Class for edit box. - * - * You can use this widget to gather small amounts of text from the user. - * - */ - -class CC_EX_DLL EditBox -: public ControlButton -, public IMEDelegate -{ -public: - enum class KeyboardReturnType - { - DEFAULT, - DONE, - SEND, - SEARCH, - GO - }; - - /** - * \brief The EditBox::InputMode defines the type of text that the user is allowed - * to enter. - */ - enum class InputMode - { - /** - * The user is allowed to enter any text, including line breaks. - */ - ANY, - - /** - * The user is allowed to enter an e-mail address. - */ - EMAIL_ADDRESS, - - /** - * The user is allowed to enter an integer value. - */ - NUMERIC, - - /** - * The user is allowed to enter a phone number. - */ - PHONE_NUMBER, - - /** - * The user is allowed to enter a URL. - */ - URL, - - /** - * The user is allowed to enter a real number value. - * This extends kEditBoxInputModeNumeric by allowing a decimal point. - */ - DECIMAL, - - /** - * The user is allowed to enter any text, except for line breaks. - */ - SINGLE_LINE, - }; - - /** - * \brief The EditBox::InputFlag defines how the input text is displayed/formatted. - */ - enum class InputFlag - { - /** - * Indicates that the text entered is confidential data that should be - * obscured whenever possible. This implies EDIT_BOX_INPUT_FLAG_SENSITIVE. - */ - PASSWORD, - - /** - * Indicates that the text entered is sensitive data that the - * implementation must never store into a dictionary or table for use - * in predictive, auto-completing, or other accelerated input schemes. - * A credit card number is an example of sensitive data. - */ - SENSITIVE, - - /** - * This flag is a hint to the implementation that during text editing, - * the initial letter of each word should be capitalized. - */ - INITIAL_CAPS_WORD, - - /** - * This flag is a hint to the implementation that during text editing, - * the initial letter of each sentence should be capitalized. - */ - INITIAL_CAPS_SENTENCE, - - /** - * Capitalize all characters automatically. - */ - INTIAL_CAPS_ALL_CHARACTERS, - }; - - /** - * create a edit box with size. - * @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again. - */ - static EditBox* create(const Size& size, Scale9Sprite* pNormal9SpriteBg, Scale9Sprite* pPressed9SpriteBg = NULL, Scale9Sprite* pDisabled9SpriteBg = NULL); - - /** - * Constructor. - * @js ctor - */ - EditBox(void); - - /** - * Destructor. - * @js NA - * @lua NA - */ - virtual ~EditBox(void); - - /** - * Init edit box with specified size. This method should be invoked right after constructor. - * @param size The size of edit box. - */ - bool initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* pNormal9SpriteBg); - - /** - * Gets/Sets the delegate for edit box. - * @lua NA - */ - void setDelegate(EditBoxDelegate* pDelegate); - /** - * @js NA - * @lua NA - */ - EditBoxDelegate* getDelegate(); - -#if CC_ENABLE_SCRIPT_BINDING - /** - * Registers a script function that will be called for EditBox events. - * - * This handler will be removed automatically after onExit() called. - * @code - * -- lua sample - * local function editboxEventHandler(eventType) - * if eventType == "began" then - * -- triggered when an edit box gains focus after keyboard is shown - * elseif eventType == "ended" then - * -- triggered when an edit box loses focus after keyboard is hidden. - * elseif eventType == "changed" then - * -- triggered when the edit box text was changed. - * elseif eventType == "return" then - * -- triggered when the return button was pressed or the outside area of keyboard was touched. - * end - * end - * - * local editbox = EditBox:create(Size(...), Scale9Sprite:create(...)) - * editbox = registerScriptEditBoxHandler(editboxEventHandler) - * @endcode - * - * @param handler A number that indicates a lua function. - * @js NA - * @lua NA - */ - void registerScriptEditBoxHandler(int handler); - - /** - * Unregisters a script function that will be called for EditBox events. - * @js NA - * @lua NA - */ - void unregisterScriptEditBoxHandler(void); - /** - * get a script Handler - * @js NA - * @lua NA - */ - int getScriptEditBoxHandler(void){ return _scriptEditBoxHandler ;} - -#endif // #if CC_ENABLE_SCRIPT_BINDING - - /** - * Set the text entered in the edit box. - * @param pText The given text. - */ - void setText(const char* pText); - - /** - * Get the text entered in the edit box. - * @return The text entered in the edit box. - */ - const char* getText(void); - - /** - * Set the font. - * @param pFontName The font name. - * @param fontSize The font size. - */ - void setFont(const char* pFontName, int fontSize); - - /** - * Set the font name. - * @param pFontName The font name. - */ - void setFontName(const char* pFontName); - - /** - * Set the font size. - * @param fontSize The font size. - */ - void setFontSize(int fontSize); - - /** - * Set the font color of the widget's text. - */ - void setFontColor(const Color3B& color); - - /** - * Set the placeholder's font. - * @param pFontName The font name. - * @param fontSize The font size. - */ - void setPlaceholderFont(const char* pFontName, int fontSize); - - /** - * Set the placeholder's font name. - * @param pFontName The font name. - */ - void setPlaceholderFontName(const char* pFontName); - - /** - * Set the placeholder's font size. - * @param fontSize The font size. - */ - void setPlaceholderFontSize(int fontSize); - - /** - * Set the font color of the placeholder text when the edit box is empty. - * Not supported on IOS. - */ - void setPlaceholderFontColor(const Color3B& color); - - /** - * Set a text in the edit box that acts as a placeholder when an - * edit box is empty. - * @param pText The given text. - */ - void setPlaceHolder(const char* pText); - - /** - * Get a text in the edit box that acts as a placeholder when an - * edit box is empty. - */ - const char* getPlaceHolder(void); - - /** - * Set the input mode of the edit box. - * @param inputMode One of the EditBox::InputMode constants. - */ - void setInputMode(InputMode inputMode); - - /** - * Sets the maximum input length of the edit box. - * Setting this value enables multiline input mode by default. - * Available on Android, iOS and Windows Phone. - * - * @param maxLength The maximum length. - */ - void setMaxLength(int maxLength); - - /** - * Gets the maximum input length of the edit box. - * - * @return Maximum input length. - */ - int getMaxLength(); - - /** - * Set the input flags that are to be applied to the edit box. - * @param inputFlag One of the EditBox::InputFlag constants. - */ - void setInputFlag(InputFlag inputFlag); - - /** - * Set the return type that are to be applied to the edit box. - * @param returnType One of the EditBox::KeyboardReturnType constants. - */ - void setReturnType(EditBox::KeyboardReturnType returnType); - - /* override functions */ - virtual void setPosition(const Vec2& pos) override; - virtual void setVisible(bool visible) override; - virtual void setContentSize(const Size& size) override; - virtual void setAnchorPoint(const Vec2& anchorPoint) override; - /** - * @js NA - * @lua NA - */ - virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; - /** - * @js NA - * @lua NA - */ - virtual void onEnter(void) override; - /** - * @js NA - * @lua NA - */ - virtual void onExit(void) override; - /** - * @js NA - * @lua NA - */ - virtual void keyboardWillShow(IMEKeyboardNotificationInfo& info) override; - /** - * @js NA - * @lua NA - */ - virtual void keyboardDidShow(IMEKeyboardNotificationInfo& info) override; - /** - * @js NA - * @lua NA - */ - virtual void keyboardWillHide(IMEKeyboardNotificationInfo& info) override; - /** - * @js NA - * @lua NA - */ - virtual void keyboardDidHide(IMEKeyboardNotificationInfo& info) override; - - /* callback funtions - * @js NA - * @lua NA - */ - void touchDownAction(Ref *sender, Control::EventType controlEvent); - -protected: - void updatePosition(float dt); - EditBoxImpl* _editBoxImpl; - EditBoxDelegate* _delegate; - - InputMode _editBoxInputMode; - InputFlag _editBoxInputFlag; - EditBox::KeyboardReturnType _keyboardReturnType; - - std::string _text; - std::string _placeHolder; - - std::string _fontName; - std::string _placeholderFontName; - - int _fontSize; - int _placeholderFontSize; - - Color3B _colText; - Color3B _colPlaceHolder; - - int _maxLength; - float _adjustHeight; -#if CC_ENABLE_SCRIPT_BINDING - int _scriptEditBoxHandler; -#endif -}; - -NS_CC_EXT_END - -#endif /* __CCEDITTEXT_H__ */ - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImpl.h b/extensions/GUI/CCEditBox/CCEditBoxImpl.h deleted file mode 100644 index 79d3d8f3fa..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImpl.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 __CCEditBoxIMPL_H__ -#define __CCEditBoxIMPL_H__ - -#include "extensions/ExtensionMacros.h" -#include "CCEditBox.h" -#include "extensions/ExtensionExport.h" - -NS_CC_EXT_BEGIN - - -class CC_EX_DLL EditBoxImpl -{ -public: - /** - * @js NA - */ - EditBoxImpl(EditBox* pEditBox) : _delegate(nullptr),_editBox(pEditBox) {} - /** - * @js NA - * @lua NA - */ - virtual ~EditBoxImpl() {} - - virtual bool initWithSize(const Size& size) = 0; - virtual void setFont(const char* pFontName, int fontSize) = 0; - virtual void setFontColor(const Color3B& color) = 0; - virtual void setPlaceholderFont(const char* pFontName, int fontSize) = 0; - virtual void setPlaceholderFontColor(const Color3B& color) = 0; - virtual void setInputMode(EditBox::InputMode inputMode) = 0; - virtual void setInputFlag(EditBox::InputFlag inputFlag) = 0; - virtual void setMaxLength(int maxLength) = 0; - virtual int getMaxLength() = 0; - virtual void setReturnType(EditBox::KeyboardReturnType returnType) = 0; - virtual bool isEditing() = 0; - - virtual void setText(const char* pText) = 0; - virtual const char* getText(void) = 0; - virtual void setPlaceHolder(const char* pText) = 0; - virtual void doAnimationWhenKeyboardMove(float duration, float distance) = 0; - - virtual void openKeyboard() = 0; - virtual void closeKeyboard() = 0; - - virtual void setPosition(const Vec2& pos) = 0; - virtual void setVisible(bool visible) = 0; - virtual void setContentSize(const Size& size) = 0; - virtual void setAnchorPoint(const Vec2& anchorPoint) = 0; - - /** - * check the editbox's position, update it when needed - */ - virtual void updatePosition(float dt){}; - /** - * @js NA - * @lua NA - */ - virtual void visit(void) = 0; - /** - * @js NA - * @lua NA - */ - virtual void onEnter(void) = 0; - - - void setDelegate(EditBoxDelegate* pDelegate) { _delegate = pDelegate; }; - EditBoxDelegate* getDelegate() { return _delegate; }; - EditBox* getEditBox() { return _editBox; }; -protected: - EditBoxDelegate* _delegate; - EditBox* _editBox; -}; - -// This method must be implemented at each subclass of EditBoxImpl. -extern EditBoxImpl* __createSystemEditBox(EditBox* pEditBox); - - -NS_CC_EXT_END - -#endif /* __CCEditBoxIMPL_H__ */ diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp b/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp deleted file mode 100644 index e610819d17..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 "CCEditBoxImplAndroid.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - -#include "CCEditBox.h" -#include "jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.h" -#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h" - - -NS_CC_EXT_BEGIN - -EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) -{ - return new EditBoxImplAndroid(pEditBox); -} - -EditBoxImplAndroid::EditBoxImplAndroid(EditBox* pEditText) -: EditBoxImpl(pEditText) -, _label(nullptr) -, _labelPlaceHolder(nullptr) -, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE) -, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) -, _keyboardReturnType(EditBox::KeyboardReturnType::DEFAULT) -, _colText(Color3B::WHITE) -, _colPlaceHolder(Color3B::GRAY) -, _maxLength(-1) -{ - -} - -EditBoxImplAndroid::~EditBoxImplAndroid() -{ - -} - -void EditBoxImplAndroid::doAnimationWhenKeyboardMove(float duration, float distance) -{ // don't need to be implemented on android platform. - -} - -static const int CC_EDIT_BOX_PADDING = 5; - -bool EditBoxImplAndroid::initWithSize(const Size& size) -{ - int fontSize = getFontSizeAccordingHeightJni(size.height-12); - _label = Label::create(); - _label->setSystemFontSize(size.height-12); - // align the text vertically center - _label->setAnchorPoint(Vec2(0, 0.5f)); - _label->setPosition(Vec2(CC_EDIT_BOX_PADDING, size.height / 2.0f)); - _label->setColor(_colText); - _editBox->addChild(_label); - - _labelPlaceHolder = Label::create(); - _labelPlaceHolder->setSystemFontSize(size.height-12); - // align the text vertically center - _labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f)); - _labelPlaceHolder->setPosition(Vec2(CC_EDIT_BOX_PADDING, size.height / 2.0f)); - _labelPlaceHolder->setVisible(false); - _labelPlaceHolder->setColor(_colPlaceHolder); - _editBox->addChild(_labelPlaceHolder); - - _editSize = size; - return true; -} - -void EditBoxImplAndroid::setFont(const char* pFontName, int fontSize) -{ - if(_label != NULL) { - _label->setSystemFontName(pFontName); - _label->setSystemFontSize(fontSize); - } - - if(_labelPlaceHolder != NULL) { - _labelPlaceHolder->setSystemFontName(pFontName); - _labelPlaceHolder->setSystemFontSize(fontSize); - } -} - -void EditBoxImplAndroid::setFontColor(const Color3B& color) -{ - _colText = color; - _label->setColor(color); -} - -void EditBoxImplAndroid::setPlaceholderFont(const char* pFontName, int fontSize) -{ - if(_labelPlaceHolder != NULL) { - _labelPlaceHolder->setSystemFontName(pFontName); - _labelPlaceHolder->setSystemFontSize(fontSize); - } -} - -void EditBoxImplAndroid::setPlaceholderFontColor(const Color3B& color) -{ - _colPlaceHolder = color; - _labelPlaceHolder->setColor(color); -} - -void EditBoxImplAndroid::setInputMode(EditBox::InputMode inputMode) -{ - _editBoxInputMode = inputMode; -} - -void EditBoxImplAndroid::setMaxLength(int maxLength) -{ - _maxLength = maxLength; -} - -int EditBoxImplAndroid::getMaxLength() -{ - return _maxLength; -} - -void EditBoxImplAndroid::setInputFlag(EditBox::InputFlag inputFlag) -{ - _editBoxInputFlag = inputFlag; -} - -void EditBoxImplAndroid::setReturnType(EditBox::KeyboardReturnType returnType) -{ - _keyboardReturnType = returnType; -} - -bool EditBoxImplAndroid::isEditing() -{ - return false; -} - -void EditBoxImplAndroid::setText(const char* pText) -{ - if (pText != NULL) - { - _text = pText; - - if (_text.length() > 0) - { - _labelPlaceHolder->setVisible(false); - - std::string strToShow; - - if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) - { - long length = cc_utf8_strlen(_text.c_str(), -1); - for (long i = 0; i < length; i++) - { - strToShow.append("*"); - } - } - else - { - strToShow = _text; - } - - _label->setString(strToShow.c_str()); - - // Clip the text width to fit to the text box - - float fMaxWidth = _editSize.width - CC_EDIT_BOX_PADDING * 2; - auto labelSize = _label->getContentSize(); - if(labelSize.width > fMaxWidth) { - _label->setDimensions(fMaxWidth,labelSize.height); - } - } - else - { - _labelPlaceHolder->setVisible(true); - _label->setString(""); - } - - } -} - -const char* EditBoxImplAndroid::getText(void) -{ - return _text.c_str(); -} - -void EditBoxImplAndroid::setPlaceHolder(const char* pText) -{ - if (pText != NULL) - { - _placeHolder = pText; - if (_placeHolder.length() > 0 && _text.length() == 0) - { - _labelPlaceHolder->setVisible(true); - } - - _labelPlaceHolder->setString(_placeHolder.c_str()); - } -} - -void EditBoxImplAndroid::setPosition(const Vec2& pos) -{ // don't need to be implemented on android platform. - -} - -void EditBoxImplAndroid::setVisible(bool visible) -{ // don't need to be implemented on android platform. - -} - -void EditBoxImplAndroid::setContentSize(const Size& size) -{ // don't need to be implemented on android platform. - -} - -void EditBoxImplAndroid::setAnchorPoint(const Vec2& anchorPoint) -{ // don't need to be implemented on android platform. - -} - -void EditBoxImplAndroid::visit(void) -{ // don't need to be implemented on android platform. - -} - -void EditBoxImplAndroid::onEnter(void) -{ // don't need to be implemented on android platform. - -} - -static void editBoxCallbackFunc(const char* pText, void* ctx) -{ - EditBoxImplAndroid* thiz = (EditBoxImplAndroid*)ctx; - thiz->setText(pText); - - if (thiz->getDelegate() != NULL) - { - thiz->getDelegate()->editBoxTextChanged(thiz->getEditBox(), thiz->getText()); - thiz->getDelegate()->editBoxEditingDidEnd(thiz->getEditBox()); - thiz->getDelegate()->editBoxReturn(thiz->getEditBox()); - } - -#if CC_ENABLE_SCRIPT_BINDING - EditBox* pEditBox = thiz->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox); - ScriptEvent event(kCommonEvent,(void*)&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - memset(data.eventName, 0, sizeof(data.eventName)); - strncpy(data.eventName, "ended", sizeof(data.eventName)); - event.data = (void*)&data; - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - memset(data.eventName, 0, sizeof(data.eventName)); - strncpy(data.eventName, "return", sizeof(data.eventName)); - event.data = (void*)&data; - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif -} - -void EditBoxImplAndroid::openKeyboard() -{ - if (_delegate != NULL) - { - _delegate->editBoxEditingDidBegin(_editBox); - } - -#if CC_ENABLE_SCRIPT_BINDING - EditBox* pEditBox = this->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); - ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif - - showEditTextDialogJNI( _placeHolder.c_str(), - _text.c_str(), - (int)_editBoxInputMode, - (int)_editBoxInputFlag, - (int)_keyboardReturnType, - _maxLength, - editBoxCallbackFunc, - (void*)this ); - -} - -void EditBoxImplAndroid::closeKeyboard() -{ - -} - -NS_CC_EXT_END - -#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) */ - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h b/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h deleted file mode 100644 index 8f4d6a1e95..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplAndroid.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 __CCEDITBOXIMPLANDROID_H__ -#define __CCEDITBOXIMPLANDROID_H__ - -#include "cocos2d.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - -#include "extensions/ExtensionMacros.h" -#include "CCEditBoxImpl.h" - -NS_CC_EXT_BEGIN - -class EditBox; - -class EditBoxImplAndroid : public EditBoxImpl -{ -public: - /** - * @js NA - */ - EditBoxImplAndroid(EditBox* pEditText); - /** - * @js NA - * @lua NA - */ - virtual ~EditBoxImplAndroid(); - - virtual bool initWithSize(const Size& size); - virtual void setFont(const char* pFontName, int fontSize); - virtual void setFontColor(const Color3B& color); - virtual void setPlaceholderFont(const char* pFontName, int fontSize); - virtual void setPlaceholderFontColor(const Color3B& color); - virtual void setInputMode(EditBox::InputMode inputMode); - virtual void setInputFlag(EditBox::InputFlag inputFlag); - virtual void setMaxLength(int maxLength); - virtual int getMaxLength(); - virtual void setReturnType(EditBox::KeyboardReturnType returnType); - virtual bool isEditing(); - - virtual void setText(const char* pText); - virtual const char* getText(void); - virtual void setPlaceHolder(const char* pText); - virtual void setPosition(const Vec2& pos); - virtual void setVisible(bool visible); - virtual void setContentSize(const Size& size); - virtual void setAnchorPoint(const Vec2& anchorPoint); - /** - * @js NA - * @lua NA - */ - virtual void visit(void); - /** - * @js NA - * @lua NA - */ - virtual void onEnter(void); - virtual void doAnimationWhenKeyboardMove(float duration, float distance); - virtual void openKeyboard(); - virtual void closeKeyboard(); - -private: - Label* _label; - Label* _labelPlaceHolder; - EditBox::InputMode _editBoxInputMode; - EditBox::InputFlag _editBoxInputFlag; - EditBox::KeyboardReturnType _keyboardReturnType; - - std::string _text; - std::string _placeHolder; - - Color3B _colText; - Color3B _colPlaceHolder; - - int _maxLength; - Size _editSize; -}; - - -NS_CC_EXT_END - -#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) */ - -#endif /* __CCEDITBOXIMPLANDROID_H__ */ - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h deleted file mode 100644 index 0e666ee6ed..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 __CCEditBoxIMPLIOS_H__ -#define __CCEditBoxIMPLIOS_H__ - -#include "cocos2d.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - -#include "extensions/ExtensionMacros.h" -#include "CCEditBoxImpl.h" - -#import -#import - -@interface CCCustomUITextField : UITextField -{ -} - -@end - - -@interface CCEditBoxImplIOS_objc : NSObject -{ - CCCustomUITextField* textField_; - void* editBox_; - BOOL editState_; -} - -@property(nonatomic, retain) UITextField* textField; -@property(nonatomic, readonly, getter = isEditState) BOOL editState; -@property(nonatomic, assign) void* editBox; - --(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox; --(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance; --(void) setPosition:(CGPoint) pos; --(void) setContentSize:(CGSize) size; --(void) visit; --(void) openKeyboard; --(void) closeKeyboard; - -@end - -NS_CC_EXT_BEGIN - -class EditBox; - -class EditBoxImplIOS : public EditBoxImpl -{ -public: - /** - * @js NA - */ - EditBoxImplIOS(EditBox* pEditText); - /** - * @js NA - * @lua NA - */ - virtual ~EditBoxImplIOS(); - - virtual bool initWithSize(const Size& size); - virtual void setFont(const char* pFontName, int fontSize); - virtual void setFontColor(const Color3B& color); - virtual void setPlaceholderFont(const char* pFontName, int fontSize); - virtual void setPlaceholderFontColor(const Color3B& color); - virtual void setInputMode(EditBox::InputMode inputMode); - virtual void setInputFlag(EditBox::InputFlag inputFlag); - virtual void setMaxLength(int maxLength); - virtual int getMaxLength(); - virtual void setReturnType(EditBox::KeyboardReturnType returnType); - virtual bool isEditing(); - - virtual void setText(const char* pText); - virtual const char* getText(void); - virtual void refreshInactiveText(); - virtual void setPlaceHolder(const char* pText); - virtual void setPosition(const Vec2& pos); - virtual void setVisible(bool visible); - virtual void setContentSize(const Size& size); - virtual void setAnchorPoint(const Vec2& anchorPoint); - virtual void updatePosition(float dt) override; - /** - * @js NA - * @lua NA - */ - virtual void visit(void); - /** - * @js NA - * @lua NA - */ - virtual void onEnter(void); - virtual void doAnimationWhenKeyboardMove(float duration, float distance); - virtual void openKeyboard(); - virtual void closeKeyboard(); - - virtual void onEndEditing(); -private: - void initInactiveLabels(const Size& size); - void setInactiveText(const char* pText); - void adjustTextFieldPosition(); - void placeInactiveLabels(); - - Label* _label; - Label* _labelPlaceHolder; - Size _contentSize; - Vec2 _position; - Vec2 _anchorPoint; - CCEditBoxImplIOS_objc* _systemControl; - int _maxTextLength; - bool _inRetinaMode; -}; - - -NS_CC_EXT_END - - -#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) */ - -#endif /* __CCEditBoxIMPLIOS_H__ */ - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm deleted file mode 100644 index edab22c826..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm +++ /dev/null @@ -1,674 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 James Chen - - 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 "CCEditBoxImplIOS.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - -#define kLabelZOrder 9999 - -#include "CCEditBox.h" -#import "CCEAGLView.h" - -#define getEditBoxImplIOS() ((cocos2d::extension::EditBoxImplIOS*)editBox_) - -static const int CC_EDIT_BOX_PADDING = 5; - -@implementation CCCustomUITextField -- (CGRect)textRectForBounds:(CGRect)bounds -{ - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - - float padding = CC_EDIT_BOX_PADDING * glview->getScaleX() / glview->getContentScaleFactor(); - return CGRectMake(bounds.origin.x + padding, bounds.origin.y + padding, - bounds.size.width - padding*2, bounds.size.height - padding*2); -} -- (CGRect)editingRectForBounds:(CGRect)bounds { - return [self textRectForBounds:bounds]; -} -@end - - -@implementation CCEditBoxImplIOS_objc - -@synthesize textField = textField_; -@synthesize editState = editState_; -@synthesize editBox = editBox_; - -- (void)dealloc -{ - [textField_ resignFirstResponder]; - [textField_ removeFromSuperview]; - self.textField = NULL; - [super dealloc]; -} - --(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox -{ - self = [super init]; - - if (self) - { - editState_ = NO; - self.textField = [[[CCCustomUITextField alloc] initWithFrame: frameRect] autorelease]; - - [textField_ setTextColor:[UIColor whiteColor]]; - textField_.font = [UIFont systemFontOfSize:frameRect.size.height*2/3]; //TODO need to delete hard code here. - textField_.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - textField_.backgroundColor = [UIColor clearColor]; - textField_.borderStyle = UITextBorderStyleNone; - textField_.delegate = self; - textField_.hidden = true; - textField_.returnKeyType = UIReturnKeyDefault; - [textField_ addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged]; - self.editBox = editBox; - } - - return self; -} - --(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance -{ - auto view = cocos2d::Director::getInstance()->getOpenGLView(); - CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); - - [eaglview doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; -} - --(void) setPosition:(CGPoint) pos -{ - CGRect frame = [textField_ frame]; - frame.origin = pos; - [textField_ setFrame:frame]; -} - --(void) setContentSize:(CGSize) size -{ - CGRect frame = [textField_ frame]; - frame.size = size; - [textField_ setFrame:frame]; -} - --(void) visit -{ - -} - --(void) openKeyboard -{ - auto view = cocos2d::Director::getInstance()->getOpenGLView(); - CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); - - [eaglview addSubview:textField_]; - [textField_ becomeFirstResponder]; -} - --(void) closeKeyboard -{ - [textField_ resignFirstResponder]; - [textField_ removeFromSuperview]; -} - -- (BOOL)textFieldShouldReturn:(UITextField *)sender -{ - if (sender == textField_) { - [sender resignFirstResponder]; - } - return NO; -} - --(void)animationSelector -{ - auto view = cocos2d::Director::getInstance()->getOpenGLView(); - CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); - - [eaglview doAnimationWhenAnotherEditBeClicked]; -} - -- (BOOL)textFieldShouldBeginEditing:(UITextField *)sender // return NO to disallow editing. -{ - CCLOG("textFieldShouldBeginEditing..."); - editState_ = YES; - - auto view = cocos2d::Director::getInstance()->getOpenGLView(); - CCEAGLView *eaglview = (CCEAGLView *) view->getEAGLView(); - - if ([eaglview isKeyboardShown]) - { - [self performSelector:@selector(animationSelector) withObject:nil afterDelay:0.0f]; - } - cocos2d::extension::EditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate(); - if (pDelegate != NULL) - { - pDelegate->editBoxEditingDidBegin(getEditBoxImplIOS()->getEditBox()); - } - -#if CC_ENABLE_SCRIPT_BINDING - cocos2d::extension::EditBox* pEditBox= getEditBoxImplIOS()->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif - return YES; -} - -- (BOOL)textFieldShouldEndEditing:(UITextField *)sender -{ - CCLOG("textFieldShouldEndEditing..."); - editState_ = NO; - getEditBoxImplIOS()->refreshInactiveText(); - - cocos2d::extension::EditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate(); - if (pDelegate != NULL) - { - pDelegate->editBoxEditingDidEnd(getEditBoxImplIOS()->getEditBox()); - pDelegate->editBoxReturn(getEditBoxImplIOS()->getEditBox()); - } - -#if CC_ENABLE_SCRIPT_BINDING - cocos2d::extension::EditBox* pEditBox= getEditBoxImplIOS()->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "ended",pEditBox); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - memset(data.eventName, 0, sizeof(data.eventName)); - strncpy(data.eventName, "return", sizeof(data.eventName)); - event.data = (void*)&data; - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif - - if(editBox_ != nil) - { - getEditBoxImplIOS()->onEndEditing(); - } - return YES; -} - -/** - * Delegate method called before the text has been changed. - * @param textField The text field containing the text. - * @param range The range of characters to be replaced. - * @param string The replacement string. - * @return YES if the specified text range should be replaced; otherwise, NO to keep the old text. - */ -- (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string -{ - if (getEditBoxImplIOS()->getMaxLength() < 0) - { - return YES; - } - - NSUInteger oldLength = [textField.text length]; - NSUInteger replacementLength = [string length]; - NSUInteger rangeLength = range.length; - - NSUInteger newLength = oldLength - rangeLength + replacementLength; - - return newLength <= getEditBoxImplIOS()->getMaxLength(); -} - -/** - * Called each time when the text field's text has changed. - */ -- (void) textChanged -{ - // NSLog(@"text is %@", self.textField.text); - cocos2d::extension::EditBoxDelegate* pDelegate = getEditBoxImplIOS()->getDelegate(); - if (pDelegate != NULL) - { - pDelegate->editBoxTextChanged(getEditBoxImplIOS()->getEditBox(), getEditBoxImplIOS()->getText()); - } - -#if CC_ENABLE_SCRIPT_BINDING - cocos2d::extension::EditBox* pEditBox= getEditBoxImplIOS()->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif -} - -@end - - -NS_CC_EXT_BEGIN - -EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) -{ - return new EditBoxImplIOS(pEditBox); -} - -EditBoxImplIOS::EditBoxImplIOS(EditBox* pEditText) -: EditBoxImpl(pEditText) -, _label(nullptr) -, _labelPlaceHolder(nullptr) -, _anchorPoint(Vec2(0.5f, 0.5f)) -, _systemControl(nullptr) -, _maxTextLength(-1) -{ - auto view = cocos2d::Director::getInstance()->getOpenGLView(); - - _inRetinaMode = view->isRetinaDisplay(); -} - -EditBoxImplIOS::~EditBoxImplIOS() -{ - [_systemControl release]; -} - -void EditBoxImplIOS::doAnimationWhenKeyboardMove(float duration, float distance) -{ - if ([_systemControl isEditState] || distance < 0.0f) - { - [_systemControl doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; - } -} - -bool EditBoxImplIOS::initWithSize(const Size& size) -{ - do - { - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - - CGRect rect = CGRectMake(0, 0, size.width * glview->getScaleX(),size.height * glview->getScaleY()); - - if (_inRetinaMode) - { - rect.size.width /= 2.0f; - rect.size.height /= 2.0f; - } - - _systemControl = [[CCEditBoxImplIOS_objc alloc] initWithFrame:rect editBox:this]; - if (!_systemControl) break; - - initInactiveLabels(size); - setContentSize(size); - - return true; - }while (0); - - return false; -} - -void EditBoxImplIOS::initInactiveLabels(const Size& size) -{ - const char* pDefaultFontName = [[_systemControl.textField.font fontName] UTF8String]; - - _label = Label::create(); - _label->setAnchorPoint(Vec2(0, 0.5f)); - _label->setColor(Color3B::WHITE); - _label->setVisible(false); - _editBox->addChild(_label, kLabelZOrder); - - _labelPlaceHolder = Label::create(); - // align the text vertically center - _labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f)); - _labelPlaceHolder->setColor(Color3B::GRAY); - _editBox->addChild(_labelPlaceHolder, kLabelZOrder); - - setFont(pDefaultFontName, size.height*2/3); - setPlaceholderFont(pDefaultFontName, size.height*2/3); -} - -void EditBoxImplIOS::placeInactiveLabels() -{ - _label->setPosition(Vec2(CC_EDIT_BOX_PADDING, _contentSize.height / 2.0f)); - _labelPlaceHolder->setPosition(Vec2(CC_EDIT_BOX_PADDING, _contentSize.height / 2.0f)); -} - -void EditBoxImplIOS::setInactiveText(const char* pText) -{ - if(_systemControl.textField.secureTextEntry == YES) - { - std::string passwordString; - for(int i = 0; i < strlen(pText); ++i) - passwordString.append("\u25CF"); - _label->setString(passwordString.c_str()); - } - else - _label->setString(getText()); - - // Clip the text width to fit to the text box - float fMaxWidth = _editBox->getContentSize().width - CC_EDIT_BOX_PADDING * 2; - Size labelSize = _label->getContentSize(); - if(labelSize.width > fMaxWidth) { - _label->setDimensions(fMaxWidth,labelSize.height); - } -} - -void EditBoxImplIOS::setFont(const char* pFontName, int fontSize) -{ - bool isValidFontName = true; - if(pFontName == NULL || strlen(pFontName) == 0) { - isValidFontName = false; - } - - float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; - NSString * fntName = [NSString stringWithUTF8String:pFontName]; - - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - - float scaleFactor = glview->getScaleX(); - UIFont *textFont = nil; - if (isValidFontName) { - textFont = [UIFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor]; - } - - if (!isValidFontName || textFont == nil){ - textFont = [UIFont systemFontOfSize:fontSize * scaleFactor / retinaFactor]; - } - - if(textFont != nil) { - [_systemControl.textField setFont:textFont]; - } - - _label->setSystemFontName(pFontName); - _label->setSystemFontSize(fontSize); - _labelPlaceHolder->setSystemFontName(pFontName); - _labelPlaceHolder->setSystemFontSize(fontSize); -} - -void EditBoxImplIOS::setFontColor(const Color3B& color) -{ - _systemControl.textField.textColor = [UIColor colorWithRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:1.0f]; - _label->setColor(color); -} - -void EditBoxImplIOS::setPlaceholderFont(const char* pFontName, int fontSize) -{ - // TODO need to be implemented. -} - -void EditBoxImplIOS::setPlaceholderFontColor(const Color3B& color) -{ - _labelPlaceHolder->setColor(color); -} - -void EditBoxImplIOS::setInputMode(EditBox::InputMode inputMode) -{ - switch (inputMode) - { - case EditBox::InputMode::EMAIL_ADDRESS: - _systemControl.textField.keyboardType = UIKeyboardTypeEmailAddress; - break; - case EditBox::InputMode::NUMERIC: - _systemControl.textField.keyboardType = UIKeyboardTypeDecimalPad; - break; - case EditBox::InputMode::PHONE_NUMBER: - _systemControl.textField.keyboardType = UIKeyboardTypePhonePad; - break; - case EditBox::InputMode::URL: - _systemControl.textField.keyboardType = UIKeyboardTypeURL; - break; - case EditBox::InputMode::DECIMAL: - _systemControl.textField.keyboardType = UIKeyboardTypeDecimalPad; - break; - case EditBox::InputMode::SINGLE_LINE: - _systemControl.textField.keyboardType = UIKeyboardTypeDefault; - break; - default: - _systemControl.textField.keyboardType = UIKeyboardTypeDefault; - break; - } -} - -void EditBoxImplIOS::setMaxLength(int maxLength) -{ - _maxTextLength = maxLength; -} - -int EditBoxImplIOS::getMaxLength() -{ - return _maxTextLength; -} - -void EditBoxImplIOS::setInputFlag(EditBox::InputFlag inputFlag) -{ - switch (inputFlag) - { - case EditBox::InputFlag::PASSWORD: - _systemControl.textField.secureTextEntry = YES; - break; - case EditBox::InputFlag::INITIAL_CAPS_WORD: - _systemControl.textField.autocapitalizationType = UITextAutocapitalizationTypeWords; - break; - case EditBox::InputFlag::INITIAL_CAPS_SENTENCE: - _systemControl.textField.autocapitalizationType = UITextAutocapitalizationTypeSentences; - break; - case EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS: - _systemControl.textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters; - break; - case EditBox::InputFlag::SENSITIVE: - _systemControl.textField.autocorrectionType = UITextAutocorrectionTypeNo; - break; - default: - break; - } -} - -void EditBoxImplIOS::setReturnType(EditBox::KeyboardReturnType returnType) -{ - switch (returnType) { - case EditBox::KeyboardReturnType::DEFAULT: - _systemControl.textField.returnKeyType = UIReturnKeyDefault; - break; - case EditBox::KeyboardReturnType::DONE: - _systemControl.textField.returnKeyType = UIReturnKeyDone; - break; - case EditBox::KeyboardReturnType::SEND: - _systemControl.textField.returnKeyType = UIReturnKeySend; - break; - case EditBox::KeyboardReturnType::SEARCH: - _systemControl.textField.returnKeyType = UIReturnKeySearch; - break; - case EditBox::KeyboardReturnType::GO: - _systemControl.textField.returnKeyType = UIReturnKeyGo; - break; - default: - _systemControl.textField.returnKeyType = UIReturnKeyDefault; - break; - } -} - -bool EditBoxImplIOS::isEditing() -{ - return [_systemControl isEditState] ? true : false; -} - -void EditBoxImplIOS::refreshInactiveText() -{ - const char* text = getText(); - if(_systemControl.textField.hidden == YES) - { - setInactiveText(text); - if(strlen(text) == 0) - { - _label->setVisible(false); - _labelPlaceHolder->setVisible(true); - } - else - { - _label->setVisible(true); - _labelPlaceHolder->setVisible(false); - } - } -} - -void EditBoxImplIOS::setText(const char* text) -{ - NSString* nsText =[NSString stringWithUTF8String:text]; - if ([nsText compare:_systemControl.textField.text] != NSOrderedSame) - { - _systemControl.textField.text = nsText; - } - - refreshInactiveText(); -} - -NSString* removeSiriString(NSString* str) -{ - NSString* siriString = @"\xef\xbf\xbc"; - return [str stringByReplacingOccurrencesOfString:siriString withString:@""]; -} - -const char* EditBoxImplIOS::getText(void) -{ - return [removeSiriString(_systemControl.textField.text) UTF8String]; -} - -void EditBoxImplIOS::setPlaceHolder(const char* pText) -{ - _systemControl.textField.placeholder = [NSString stringWithUTF8String:pText]; - _labelPlaceHolder->setString(pText); -} - -static CGPoint convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode) -{ - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - CCEAGLView *eaglview = (CCEAGLView *) glview->getEAGLView(); - - float viewH = (float)[eaglview getHeight]; - - Vec2 visiblePos = Vec2(designCoord.x * glview->getScaleX(), designCoord.y * glview->getScaleY()); - Vec2 screenGLPos = visiblePos + glview->getViewPortRect().origin; - - CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y); - - if (bInRetinaMode) - { - screenPos.x = screenPos.x / 2.0f; - screenPos.y = screenPos.y / 2.0f; - } - CCLOGINFO("[EditBox] pos x = %f, y = %f", screenGLPos.x, screenGLPos.y); - return screenPos; -} - -void EditBoxImplIOS::setPosition(const Vec2& pos) -{ - _position = pos; - adjustTextFieldPosition(); -} - -void EditBoxImplIOS::setVisible(bool visible) -{ -// _systemControl.textField.hidden = !visible; -} - -void EditBoxImplIOS::setContentSize(const Size& size) -{ - _contentSize = size; - CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height); - placeInactiveLabels(); - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - CGSize controlSize = CGSizeMake(size.width * glview->getScaleX(),size.height * glview->getScaleY()); - - if (_inRetinaMode) - { - controlSize.width /= 2.0f; - controlSize.height /= 2.0f; - } - [_systemControl setContentSize:controlSize]; -} - -void EditBoxImplIOS::setAnchorPoint(const Vec2& anchorPoint) -{ - CCLOG("[Edit text] anchor point = (%f, %f)", anchorPoint.x, anchorPoint.y); - _anchorPoint = anchorPoint; - setPosition(_position); -} - -void EditBoxImplIOS::visit(void) -{ -} - -void EditBoxImplIOS::onEnter(void) -{ - adjustTextFieldPosition(); - const char* pText = getText(); - if (pText) { - setInactiveText(pText); - } -} - -void EditBoxImplIOS::updatePosition(float dt) -{ - if (nullptr != _systemControl) { - this->adjustTextFieldPosition(); - } -} - - - -void EditBoxImplIOS::adjustTextFieldPosition() -{ - Size contentSize = _editBox->getContentSize(); - Rect rect = Rect(0, 0, contentSize.width, contentSize.height); - rect = RectApplyAffineTransform(rect, _editBox->nodeToWorldTransform()); - - Vec2 designCoord = Vec2(rect.origin.x, rect.origin.y + rect.size.height); - [_systemControl setPosition:convertDesignCoordToScreenCoord(designCoord, _inRetinaMode)]; -} - -void EditBoxImplIOS::openKeyboard() -{ - _label->setVisible(false); - _labelPlaceHolder->setVisible(false); - - _systemControl.textField.hidden = NO; - [_systemControl openKeyboard]; -} - -void EditBoxImplIOS::closeKeyboard() -{ - [_systemControl closeKeyboard]; -} - -void EditBoxImplIOS::onEndEditing() -{ - _systemControl.textField.hidden = YES; - if(strlen(getText()) == 0) - { - _label->setVisible(false); - _labelPlaceHolder->setVisible(true); - } - else - { - _label->setVisible(true); - _labelPlaceHolder->setVisible(false); - setInactiveText(getText()); - } -} - -NS_CC_EXT_END - -#endif /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) */ - - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplMac.h b/extensions/GUI/CCEditBox/CCEditBoxImplMac.h deleted file mode 100644 index 34085e8278..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplMac.h +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 Jozef Pridavok - - 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 __CCEditBoxIMPLMAC_H__ -#define __CCEditBoxIMPLMAC_H__ - -#include "cocos2d.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - -#import -#import - -#include "extensions/ExtensionMacros.h" -#include "CCEditBoxImpl.h" - - -@interface CCEditBoxImplMac : NSObject -{ - NSTextField* textField_; - NSSecureTextField* secureTextField_; - void* editBox_; - BOOL editState_; - NSMutableDictionary* placeholderAttributes_; -} - -@property(nonatomic, retain) NSTextField* textField; -@property(nonatomic, retain) NSSecureTextField* secureTextField; -@property(nonatomic, retain) NSMutableDictionary* placeholderAttributes; -@property(nonatomic, readonly, getter = isEditState) BOOL editState; -@property(nonatomic, assign) void* editBox; - --(id) initWithFrame: (NSRect) frameRect editBox: (void*) editBox; --(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance; --(void) setPosition:(NSPoint) pos; --(void) setContentSize:(NSSize) size; --(void) visit; --(void) openKeyboard; --(void) closeKeyboard; - -@end - -NS_CC_EXT_BEGIN - -class EditBox; - -class EditBoxImplMac : public EditBoxImpl -{ -public: - /** - * @js NA - */ - EditBoxImplMac(EditBox* pEditText); - /** - * @js NA - * @lua NA - */ - virtual ~EditBoxImplMac(); - - virtual bool initWithSize(const Size& size); - virtual void setFont(const char* pFontName, int fontSize); - virtual void setFontColor(const Color3B& color); - virtual void setPlaceholderFont(const char* pFontName, int fontSize); - virtual void setPlaceholderFontColor(const Color3B& color); - virtual void setInputMode(EditBox::InputMode inputMode); - virtual void setInputFlag(EditBox::InputFlag inputFlag); - virtual void setMaxLength(int maxLength); - virtual int getMaxLength(); - virtual void setReturnType(EditBox::KeyboardReturnType returnType); - virtual bool isEditing(); - - virtual void setText(const char* pText); - virtual const char* getText(void); - virtual void setPlaceHolder(const char* pText); - virtual void setPosition(const Vec2& pos); - virtual void setVisible(bool visible); - virtual void setContentSize(const Size& size); - virtual void setAnchorPoint(const Vec2& anchorPoint); - /** - * @js NA - * @lua NA - */ - virtual void visit(void); - virtual void doAnimationWhenKeyboardMove(float duration, float distance); - virtual void openKeyboard(); - virtual void closeKeyboard(); - virtual void updatePosition(float dt) override; - /** - * @js NA - * @lua NA - */ - virtual void onEnter(void); -private: - NSPoint convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode); - void adjustTextFieldPosition(); - Size _contentSize; - Vec2 _position; - Vec2 _anchorPoint; - int _maxTextLength; - bool _inRetinaMode; - CCEditBoxImplMac* _sysEdit; -}; - - -NS_CC_EXT_END - -#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - -#endif /* __CCEditBoxIMPLMAC_H__ */ - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm b/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm deleted file mode 100644 index 47063b2907..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplMac.mm +++ /dev/null @@ -1,520 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2012 Jozef Pridavok - - 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 "CCEditBoxImplMac.h" -#include "base/CCDirector.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - -#include "CCEditBox.h" - - -#define getEditBoxImplMac() ((cocos2d::extension::EditBoxImplMac*)editBox_) - - - -@implementation CCEditBoxImplMac - -@synthesize textField = textField_; -@synthesize secureTextField = secureTextField_; -@synthesize placeholderAttributes = placeholderAttributes_; -@synthesize editState = editState_; -@synthesize editBox = editBox_; - -- (id) getNSWindow -{ - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - return glview->getCocoaWindow(); -} - -- (void)dealloc -{ - [textField_ resignFirstResponder]; - [textField_ removeFromSuperview]; - [textField_ release]; - - [secureTextField_ resignFirstResponder]; - [secureTextField_ removeFromSuperview]; - [secureTextField_ release]; - - [placeholderAttributes_ release]; - [super dealloc]; -} - --(id) initWithFrame: (NSRect) frameRect editBox: (void*) editBox -{ - self = [super init]; - - if (self) - { - editState_ = NO; - self.textField = [[[NSTextField alloc] initWithFrame:frameRect] autorelease]; - self.secureTextField = [[[NSSecureTextField alloc] initWithFrame:frameRect] autorelease]; - - NSFont *font = [NSFont systemFontOfSize:frameRect.size.height*2/3]; //TODO need to delete hard code here. - textField_.font = font; - secureTextField_.font = font; - - [self setupTextField:textField_]; - [self setupTextField:secureTextField_]; - - self.editBox = editBox; - self.placeholderAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys: - font, NSFontAttributeName, - [NSColor grayColor], NSForegroundColorAttributeName, - nil]; - - [[[self getNSWindow] contentView] addSubview:textField_]; - } - - return self; -} - -- (void)setupTextField:(NSTextField *)textField -{ - [textField setTextColor:[NSColor whiteColor]]; - [textField setBackgroundColor:[NSColor clearColor]]; - [textField setBordered:NO]; - [textField setHidden:NO]; - [textField setWantsLayer:YES]; - [textField setDelegate:self]; -} - --(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance -{ - [[[self getNSWindow] contentView] doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; -} - --(void) setPosition:(NSPoint) pos -{ - NSRect frame = [textField_ frame]; - frame.origin = pos; - [textField_ setFrame:frame]; - [secureTextField_ setFrame:frame]; -} - --(void) setContentSize:(NSSize) size -{ - -} - --(void) visit -{ - -} - --(void) openKeyboard -{ - if ([textField_ superview]) { - [textField_ becomeFirstResponder]; - } - else { - [secureTextField_ becomeFirstResponder]; - } -} - --(void) closeKeyboard -{ - if ([textField_ superview]) { - [textField_ resignFirstResponder]; - [textField_ removeFromSuperview]; - } - else { - [secureTextField_ resignFirstResponder]; - [secureTextField_ removeFromSuperview]; - } -} - -- (BOOL)textFieldShouldReturn:(NSTextField *)sender -{ - if (sender == textField_ || sender == secureTextField_) { - [sender resignFirstResponder]; - } - return NO; -} - --(void)animationSelector -{ -} - -- (void)controlTextDidBeginEditing:(NSNotification *)notification -{ - editState_ = YES; - cocos2d::extension::EditBoxDelegate* pDelegate = getEditBoxImplMac()->getDelegate(); - if (pDelegate != NULL) - { - pDelegate->editBoxEditingDidBegin(getEditBoxImplMac()->getEditBox()); - } - -#if CC_ENABLE_SCRIPT_BINDING - cocos2d::extension::EditBox* pEditBox= getEditBoxImplMac()->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif -} - -- (void)controlTextDidEndEditing:(NSNotification *)notification -{ - editState_ = NO; - cocos2d::extension::EditBoxDelegate* pDelegate = getEditBoxImplMac()->getDelegate(); - if (pDelegate != NULL) - { - pDelegate->editBoxEditingDidEnd(getEditBoxImplMac()->getEditBox()); - pDelegate->editBoxReturn(getEditBoxImplMac()->getEditBox()); - } - -#if CC_ENABLE_SCRIPT_BINDING - cocos2d::extension::EditBox* pEditBox= getEditBoxImplMac()->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "ended",pEditBox); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - memset(data.eventName, 0, sizeof(data.eventName)); - strncpy(data.eventName, "return", sizeof(data.eventName)); - event.data = (void*)&data; - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif -} - -/** - * Delegate method called before the text has been changed. - * @param textField The text field containing the text. - * @param range The range of characters to be replaced. - * @param string The replacement string. - * @return YES if the specified text range should be replaced; otherwise, NO to keep the old text. - */ -- (BOOL)textField:(NSTextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string -{ - if (getEditBoxImplMac()->getMaxLength() < 0) - { - return YES; - } - - NSUInteger oldLength = [[textField stringValue] length]; - NSUInteger replacementLength = [string length]; - NSUInteger rangeLength = range.length; - - NSUInteger newLength = oldLength - rangeLength + replacementLength; - - return newLength <= getEditBoxImplMac()->getMaxLength(); -} - -/** - * Called each time when the text field's text has changed. - */ -- (void)controlTextDidChange:(NSNotification *)notification -{ - cocos2d::extension::EditBoxDelegate* pDelegate = getEditBoxImplMac()->getDelegate(); - if (pDelegate != NULL) - { - pDelegate->editBoxTextChanged(getEditBoxImplMac()->getEditBox(), getEditBoxImplMac()->getText()); - } - -#if CC_ENABLE_SCRIPT_BINDING - cocos2d::extension::EditBox* pEditBox= getEditBoxImplMac()->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - cocos2d::CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox); - cocos2d::ScriptEvent event(cocos2d::kCommonEvent,(void*)&data); - cocos2d::ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif -} - -@end - -NS_CC_EXT_BEGIN - -EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) -{ - return new EditBoxImplMac(pEditBox); -} - -EditBoxImplMac::EditBoxImplMac(EditBox* pEditText) -: EditBoxImpl(pEditText) -, _anchorPoint(Vec2(0.5f, 0.5f)) -, _maxTextLength(-1) -, _sysEdit(nullptr) -{ - //! TODO: Retina on Mac - //! _inRetinaMode = [[CCEAGLView sharedEGLView] contentScaleFactor] == 2.0f ? true : false; - _inRetinaMode = false; -} - -EditBoxImplMac::~EditBoxImplMac() -{ - [_sysEdit release]; -} - -void EditBoxImplMac::doAnimationWhenKeyboardMove(float duration, float distance) -{ - if ([_sysEdit isEditState] || distance < 0.0f) - [_sysEdit doAnimationWhenKeyboardMoveWithDuration:duration distance:distance]; -} - -bool EditBoxImplMac::initWithSize(const Size& size) -{ - GLView* eglView = Director::getInstance()->getOpenGLView(); - - NSRect rect = NSMakeRect(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); - - if (_inRetinaMode) { - rect.size.width /= 2.0f; - rect.size.height /= 2.0f; - } - - _sysEdit = [[CCEditBoxImplMac alloc] initWithFrame:rect editBox:this]; - - if (!_sysEdit) - return false; - - return true; -} - -void EditBoxImplMac::setFont(const char* pFontName, int fontSize) -{ - NSString * fntName = [NSString stringWithUTF8String:pFontName]; - float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - float scaleFactor = glview->getScaleX(); - NSFont *textFont = [NSFont fontWithName:fntName size:fontSize * scaleFactor / retinaFactor]; - if (textFont != nil) { - [_sysEdit.textField setFont:textFont]; - [_sysEdit.secureTextField setFont:textFont]; - } -} - -void EditBoxImplMac::setPlaceholderFont(const char* pFontName, int fontSize) -{ - NSString *fontName = [NSString stringWithUTF8String:pFontName]; - float retinaFactor = _inRetinaMode ? 2.0f : 1.0f; - auto glview = cocos2d::Director::getInstance()->getOpenGLView(); - float scaleFactor = glview->getScaleX(); - NSFont *font = [NSFont fontWithName:fontName size:fontSize * scaleFactor / retinaFactor]; - - if (!font) { - CCLOGWARN("Font not found: %s", pFontName); - return; - } - - [_sysEdit.placeholderAttributes setObject:font forKey:NSFontAttributeName]; - - /* reload placeholder */ - const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String; - if (placeholder) { - setPlaceHolder(placeholder); - } -} - -void EditBoxImplMac::setFontColor(const Color3B& color) -{ - NSColor *newColor = [NSColor colorWithCalibratedRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:1.0f]; - _sysEdit.textField.textColor = newColor; - _sysEdit.secureTextField.textColor = newColor; -} - -void EditBoxImplMac::setPlaceholderFontColor(const Color3B& color) -{ - NSColor *nsColor = [NSColor colorWithCalibratedRed:color.r/255.f green:color.g / 255.f blue:color.b / 255.f alpha:1.0f]; - [_sysEdit.placeholderAttributes setObject:nsColor forKey:NSForegroundColorAttributeName]; - - /* reload placeholder */ - const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String; - if (placeholder) { - setPlaceHolder(placeholder); - } -} - -void EditBoxImplMac::setInputMode(EditBox::InputMode inputMode) -{ -} - -void EditBoxImplMac::setMaxLength(int maxLength) -{ - _maxTextLength = maxLength; -} - -int EditBoxImplMac::getMaxLength() -{ - return _maxTextLength; -} - -void EditBoxImplMac::setInputFlag(EditBox::InputFlag inputFlag) -{ - switch (inputFlag) - { - case EditBox::InputFlag::PASSWORD: - [_sysEdit.textField.superview addSubview:_sysEdit.secureTextField]; - [_sysEdit.textField removeFromSuperview]; - break; - case EditBox::InputFlag::INITIAL_CAPS_WORD: - CCLOGWARN("INITIAL_CAPS_WORD not implemented"); - break; - case EditBox::InputFlag::INITIAL_CAPS_SENTENCE: - CCLOGWARN("INITIAL_CAPS_SENTENCE not implemented"); - break; - case EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS: - CCLOGWARN("INTIAL_CAPS_ALL_CHARACTERS not implemented"); - break; - case EditBox::InputFlag::SENSITIVE: - CCLOGWARN("SENSITIVE not implemented"); - break; - default: - break; - } -} - -void EditBoxImplMac::setReturnType(EditBox::KeyboardReturnType returnType) -{ -} - -bool EditBoxImplMac::isEditing() -{ - return [_sysEdit isEditState] ? true : false; -} - -void EditBoxImplMac::setText(const char* pText) -{ - NSString *string = [NSString stringWithUTF8String:pText]; - _sysEdit.textField.stringValue = string; - _sysEdit.secureTextField.stringValue = string; -} - -const char* EditBoxImplMac::getText(void) -{ - if (_sysEdit.secureTextField.superview) { - return [_sysEdit.secureTextField.stringValue UTF8String]; - } - - return [_sysEdit.textField.stringValue UTF8String]; -} - -void EditBoxImplMac::setPlaceHolder(const char* pText) -{ - NSAttributedString *as = [[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:pText] - attributes:_sysEdit.placeholderAttributes]; - - [[_sysEdit.textField cell] setPlaceholderAttributedString:as]; - [[_sysEdit.secureTextField cell] setPlaceholderAttributedString:as]; - [as release]; -} - -NSPoint EditBoxImplMac::convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode) -{ - NSRect frame = [_sysEdit.textField frame]; - CGFloat height = frame.size.height; - - GLView* eglView = Director::getInstance()->getOpenGLView(); - - Vec2 visiblePos = Vec2(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); - Vec2 screenGLPos = visiblePos + eglView->getViewPortRect().origin; - - //TODO: I don't know why here needs to substract `height`. - NSPoint screenPos = NSMakePoint(screenGLPos.x, screenGLPos.y-height); - - if (bInRetinaMode) { - screenPos.x = screenPos.x / 2.0f; - screenPos.y = screenPos.y / 2.0f; - } - - CCLOGINFO("[EditBox] pos x = %f, y = %f", screenGLPos.x, screenGLPos.y); - return screenPos; -} - -void EditBoxImplMac::updatePosition(float dt) -{ - if(nullptr != _sysEdit) - { - adjustTextFieldPosition(); - } -} - -void EditBoxImplMac::adjustTextFieldPosition() -{ - Size contentSize = _editBox->getContentSize(); - Rect rect = Rect(0, 0, contentSize.width, contentSize.height); - - rect = RectApplyAffineTransform(rect, _editBox->nodeToWorldTransform()); - - Vec2 designCoord = Vec2(rect.origin.x, rect.origin.y + rect.size.height); - [_sysEdit setPosition:convertDesignCoordToScreenCoord(designCoord, _inRetinaMode)]; -} - -void EditBoxImplMac::setPosition(const Vec2& pos) -{ - _position = pos; - adjustTextFieldPosition(); -} - -void EditBoxImplMac::setVisible(bool visible) -{ - [_sysEdit.textField setHidden:!visible]; - [_sysEdit.secureTextField setHidden:!visible]; -} - -void EditBoxImplMac::setContentSize(const Size& size) -{ - _contentSize = size; - CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height); -} - -void EditBoxImplMac::setAnchorPoint(const Vec2& anchorPoint) -{ - CCLOG("[Edit text] anchor point = (%f, %f)", anchorPoint.x, anchorPoint.y); - _anchorPoint = anchorPoint; - setPosition(_position); -} - -void EditBoxImplMac::visit(void) -{ - -} - -void EditBoxImplMac::openKeyboard() -{ - [_sysEdit openKeyboard]; -} - -void EditBoxImplMac::closeKeyboard() -{ - [_sysEdit closeKeyboard]; -} - -void EditBoxImplMac::onEnter(void) -{ - adjustTextFieldPosition(); -} - -NS_CC_EXT_END - -#endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplNone.cpp b/extensions/GUI/CCEditBox/CCEditBoxImplNone.cpp deleted file mode 100644 index 5cac865d3d..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplNone.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "CCEditBox.h" - -#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID ) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS ) && (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) && (CC_TARGET_PLATFORM != CC_PLATFORM_TIZEN) - -NS_CC_EXT_BEGIN - -EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) -{ - return NULL; -} - -NS_CC_EXT_END - -#endif /* #if (..) */ diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplWin.cpp b/extensions/GUI/CCEditBox/CCEditBoxImplWin.cpp deleted file mode 100644 index 2259e4dda0..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplWin.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2013 Jozef Pridavok - - 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 "CCEditBoxImplWin.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - -#include "CCEditBox.h" -#include "proj.win32/Win32InputBox.h" - -NS_CC_EXT_BEGIN - -EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) -{ - return new EditBoxImplWin(pEditBox); -} - -EditBoxImplWin::EditBoxImplWin(EditBox* pEditText) -: EditBoxImpl(pEditText) -, _label(nullptr) -, _labelPlaceHolder(nullptr) -, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE) -, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) -, _keyboardReturnType(EditBox::KeyboardReturnType::DEFAULT) -, _colText(Color3B::WHITE) -, _colPlaceHolder(Color3B::GRAY) -, _maxLength(-1) -{ - -} - -EditBoxImplWin::~EditBoxImplWin() -{ -} - -void EditBoxImplWin::doAnimationWhenKeyboardMove(float duration, float distance) -{ -} - -bool EditBoxImplWin::initWithSize(const Size& size) -{ - //! int fontSize = getFontSizeAccordingHeightJni(size.height-12); - _label = Label::create(); - _label->setSystemFontSize(size.height-12); - // align the text vertically center - _label->setAnchorPoint(Vec2(0, 0.5f)); - _label->setPosition(Vec2(5, size.height / 2.0f)); - _label->setColor(_colText); - _editBox->addChild(_label); - - _labelPlaceHolder = Label::create(); - _labelPlaceHolder->setSystemFontSize(size.height-12); - // align the text vertically center - _labelPlaceHolder->setAnchorPoint(Vec2(0, 0.5f)); - _labelPlaceHolder->setPosition(Vec2(5, size.height / 2.0f)); - _labelPlaceHolder->setVisible(false); - _labelPlaceHolder->setColor(_colPlaceHolder); - _editBox->addChild(_labelPlaceHolder); - - _editSize = size; - return true; -} - -void EditBoxImplWin::setFont(const char* pFontName, int fontSize) -{ - if(_label != nullptr) { - _label->setSystemFontName(pFontName); - _label->setSystemFontSize(fontSize); - } - - if(_labelPlaceHolder != nullptr) { - _labelPlaceHolder->setSystemFontName(pFontName); - _labelPlaceHolder->setSystemFontSize(fontSize); - } -} - -void EditBoxImplWin::setFontColor(const Color3B& color) -{ - _colText = color; - _label->setColor(color); -} - -void EditBoxImplWin::setPlaceholderFont(const char* pFontName, int fontSize) -{ - if(_labelPlaceHolder != nullptr) { - _labelPlaceHolder->setSystemFontName(pFontName); - _labelPlaceHolder->setSystemFontSize(fontSize); - } -} - -void EditBoxImplWin::setPlaceholderFontColor(const Color3B& color) -{ - _colPlaceHolder = color; - _labelPlaceHolder->setColor(color); -} - -void EditBoxImplWin::setInputMode(EditBox::InputMode inputMode) -{ - _editBoxInputMode = inputMode; -} - -void EditBoxImplWin::setMaxLength(int maxLength) -{ - _maxLength = maxLength; -} - -int EditBoxImplWin::getMaxLength() -{ - return _maxLength; -} - -void EditBoxImplWin::setInputFlag(EditBox::InputFlag inputFlag) -{ - _editBoxInputFlag = inputFlag; -} - -void EditBoxImplWin::setReturnType(EditBox::KeyboardReturnType returnType) -{ - _keyboardReturnType = returnType; -} - -bool EditBoxImplWin::isEditing() -{ - return false; -} - -void EditBoxImplWin::setText(const char* pText) -{ - if (pText != nullptr) - { - _text = pText; - - if (_text.length() > 0) - { - _labelPlaceHolder->setVisible(false); - - std::string strToShow; - - if (EditBox::InputFlag::PASSWORD == _editBoxInputFlag) - { - long length = cc_utf8_strlen(_text.c_str(), -1); - for (long i = 0; i < length; i++) - { - strToShow.append("*"); - } - } - else - { - strToShow = _text; - } - - //! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), _editSize.width, _editSize.height-12); - //! _label->setString(strWithEllipsis.c_str()); - _label->setString(strToShow.c_str()); - } - else - { - _labelPlaceHolder->setVisible(true); - _label->setString(""); - } - - } -} - -const char* EditBoxImplWin::getText(void) -{ - return _text.c_str(); -} - -void EditBoxImplWin::setPlaceHolder(const char* pText) -{ - if (pText != nullptr) - { - _placeHolder = pText; - if (_placeHolder.length() > 0 && _text.length() == 0) - { - _labelPlaceHolder->setVisible(true); - } - - _labelPlaceHolder->setString(_placeHolder.c_str()); - } -} - -void EditBoxImplWin::setPosition(const Vec2& pos) -{ - //_label->setPosition(pos); - //_labelPlaceHolder->setPosition(pos); -} - -void EditBoxImplWin::setVisible(bool visible) -{ // don't need to be implemented on win32 platform. -} - -void EditBoxImplWin::setContentSize(const Size& size) -{ -} - -void EditBoxImplWin::setAnchorPoint(const Vec2& anchorPoint) -{ // don't need to be implemented on win32 platform. - -} - -void EditBoxImplWin::visit(void) -{ -} - -void EditBoxImplWin::openKeyboard() -{ - if (_delegate != nullptr) - { - _delegate->editBoxEditingDidBegin(_editBox); - } - - EditBox* pEditBox = this->getEditBox(); - if (nullptr != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); - ScriptEvent event(kCommonEvent,(void*)&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } - - std::string placeHolder = _labelPlaceHolder->getString(); - if (placeHolder.length() == 0) - placeHolder = "Enter value"; - - char pText[100]= {0}; - std::string text = getText(); - if (text.length()) - strncpy(pText, text.c_str(), 100); - auto glView = Director::getInstance()->getOpenGLView(); - HWND hwnd = glView->getWin32Window(); - bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK; - - if (didChange) - setText(pText); - - if (_delegate != nullptr) { - if (didChange) - _delegate->editBoxTextChanged(_editBox, getText()); - _delegate->editBoxEditingDidEnd(_editBox); - _delegate->editBoxReturn(_editBox); - } - -#if CC_ENABLE_SCRIPT_BINDING - if (nullptr != _editBox && 0 != _editBox->getScriptEditBoxHandler()) - { - CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed",_editBox); - ScriptEvent event(kCommonEvent,(void*)&data); - if (didChange) - { - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } - memset(data.eventName,0,sizeof(data.eventName)); - strncpy(data.eventName,"ended",sizeof(data.eventName)); - event.data = (void*)&data; - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - memset(data.eventName,0,sizeof(data.eventName)); - strncpy(data.eventName,"return",sizeof(data.eventName)); - event.data = (void*)&data; - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } -#endif // #if CC_ENABLE_SCRIPT_BINDING -} - -void EditBoxImplWin::closeKeyboard() -{ - -} - -void EditBoxImplWin::onEnter(void) -{ - -} - -NS_CC_EXT_END - -#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplWin.h b/extensions/GUI/CCEditBox/CCEditBoxImplWin.h deleted file mode 100644 index 4d04fb6cce..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplWin.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2013 Jozef Pridavok - - 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 __CCEditBoxIMPLWIN_H__ -#define __CCEditBoxIMPLWIN_H__ - -#include "cocos2d.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - -#include "extensions/ExtensionMacros.h" -#include "CCEditBoxImpl.h" -#include "extensions/ExtensionExport.h" - -NS_CC_EXT_BEGIN - -class EditBox; - -class CC_EX_DLL EditBoxImplWin : public EditBoxImpl -{ -public: - /** - * @js NA - */ - EditBoxImplWin(EditBox* pEditText); - /** - * @js NA - * @lua NA - */ - virtual ~EditBoxImplWin(); - - virtual bool initWithSize(const Size& size); - virtual void setFont(const char* pFontName, int fontSize); - virtual void setFontColor(const Color3B& color); - virtual void setPlaceholderFont(const char* pFontName, int fontSize); - virtual void setPlaceholderFontColor(const Color3B& color); - virtual void setInputMode(EditBox::InputMode inputMode); - virtual void setInputFlag(EditBox::InputFlag inputFlag); - virtual void setMaxLength(int maxLength); - virtual int getMaxLength(); - virtual void setReturnType(EditBox::KeyboardReturnType returnType); - virtual bool isEditing(); - - virtual void setText(const char* pText); - virtual const char* getText(void); - virtual void setPlaceHolder(const char* pText); - virtual void setPosition(const Vec2& pos); - virtual void setVisible(bool visible); - virtual void setContentSize(const Size& size); - virtual void setAnchorPoint(const Vec2& anchorPoint); - /** - * @js NA - * @lua NA - */ - virtual void visit(void); - virtual void doAnimationWhenKeyboardMove(float duration, float distance); - virtual void openKeyboard(); - virtual void closeKeyboard(); - /** - * @js NA - * @lua NA - */ - virtual void onEnter(void); -private: - - Label* _label; - Label* _labelPlaceHolder; - EditBox::InputMode _editBoxInputMode; - EditBox::InputFlag _editBoxInputFlag; - EditBox::KeyboardReturnType _keyboardReturnType; - - std::string _text; - std::string _placeHolder; - - Color3B _colText; - Color3B _colPlaceHolder; - - int _maxLength; - Size _editSize; - - /* - Size _contentSize; - HWND _sysEdit; - int _maxTextLength; - */ -}; - - -NS_CC_EXT_END - -#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */ - -#endif /* __CCEditBoxIMPLWIN_H__ */ - diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplWp8.cpp b/extensions/GUI/CCEditBox/CCEditBoxImplWp8.cpp deleted file mode 100644 index 245149d164..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplWp8.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/**************************************************************************** -Copyright (c) 2014 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. -****************************************************************************/ - -#include "CCEditBoxImplWp8.h" -#include "CCEditBox.h" -#include "CCGLViewImpl.h" -#include "base/CCScriptSupport.h" -#include "base/ccUTF8.h" - -NS_CC_EXT_BEGIN - -EditBoxImpl* __createSystemEditBox(EditBox* pEditBox) -{ - return new CCEditBoxImplWp8(pEditBox); -} - -CCEditBoxImplWp8::CCEditBoxImplWp8( EditBox* pEditText ) - : EditBoxImpl(pEditText) - , m_pLabel(NULL) - , m_pLabelPlaceHolder(NULL) - , m_eEditBoxInputMode(EditBox::InputMode::SINGLE_LINE) - , m_eEditBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS) - , m_eKeyboardReturnType(EditBox::KeyboardReturnType::DEFAULT) - , m_colText(Color3B::WHITE) - , m_colPlaceHolder(Color3B::GRAY) - , m_nMaxLength(-1) -{ - -} - -CCEditBoxImplWp8::~CCEditBoxImplWp8() -{ - -} - -void CCEditBoxImplWp8::openKeyboard() -{ - if (_delegate != NULL) - { - _delegate->editBoxEditingDidBegin(_editBox); - } - - EditBox* pEditBox = this->getEditBox(); - if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) - { - CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); - ScriptEvent event(kCommonEvent,(void*)&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); - } - - std::string placeHolder = m_pLabelPlaceHolder->getString(); - if (placeHolder.length() == 0) - placeHolder = "Enter value"; - - char pText[100]= {0}; - std::string text = getText(); - if (text.length()) - strncpy(pText, text.c_str(), 100); - - Windows::Foundation::EventHandler^ receiveHandler = ref new Windows::Foundation::EventHandler( - [this](Platform::Object^ sender, Platform::String^ arg) - { - setText(PlatformStringTostring(arg).c_str()); - if (_delegate != NULL) { - _delegate->editBoxTextChanged(_editBox, getText()); - _delegate->editBoxEditingDidEnd(_editBox); - _delegate->editBoxReturn(_editBox); - } - }); - - GLViewImpl::sharedOpenGLView()->OpenXamlEditBox(stringToPlatformString(placeHolder), stringToPlatformString(getText()), m_nMaxLength, (int)m_eEditBoxInputMode, (int)m_eEditBoxInputFlag, receiveHandler); -} - -bool CCEditBoxImplWp8::initWithSize( const Size& size ) -{ - //! int fontSize = getFontSizeAccordingHeightJni(size.height-12); - m_pLabel = Label::createWithSystemFont("", "", size.height-12); - // align the text vertically center - m_pLabel->setAnchorPoint(Vec2(0.0f, 0.5f)); - m_pLabel->setPosition(Vec2(5.0, size.height / 2.0f)); - m_pLabel->setColor(m_colText); - _editBox->addChild(m_pLabel); - - m_pLabelPlaceHolder = Label::createWithSystemFont("", "", size.height-12); - // align the text vertically center - m_pLabelPlaceHolder->setAnchorPoint(Vec2(0.0f, 0.5f)); - m_pLabelPlaceHolder->setPosition(Vec2(5.0f, size.height / 2.0f)); - m_pLabelPlaceHolder->setVisible(false); - m_pLabelPlaceHolder->setColor(m_colPlaceHolder); - _editBox->addChild(m_pLabelPlaceHolder); - - m_EditSize = size; - return true; -} - -void CCEditBoxImplWp8::setFont( const char* pFontName, int fontSize ) -{ - if(m_pLabel != NULL) { - m_pLabel->setSystemFontName(pFontName); - m_pLabel->setSystemFontSize(fontSize); - } - - if(m_pLabelPlaceHolder != NULL) { - m_pLabelPlaceHolder->setSystemFontName(pFontName); - m_pLabelPlaceHolder->setSystemFontSize(fontSize); - } -} - -void CCEditBoxImplWp8::setFontColor( const Color3B& color ) -{ - m_colText = color; - m_pLabel->setColor(color); -} - -void CCEditBoxImplWp8::setPlaceholderFont( const char* pFontName, int fontSize ) -{ - if(m_pLabelPlaceHolder != NULL) { - m_pLabelPlaceHolder->setSystemFontName(pFontName); - m_pLabelPlaceHolder->setSystemFontSize(fontSize); - } -} - -void CCEditBoxImplWp8::setPlaceholderFontColor( const Color3B& color ) -{ - m_colPlaceHolder = color; - m_pLabelPlaceHolder->setColor(color); -} - -void CCEditBoxImplWp8::setInputMode( EditBox::InputMode inputMode ) -{ - m_eEditBoxInputMode = inputMode; -} - -void CCEditBoxImplWp8::setInputFlag(EditBox::InputFlag inputFlag ) -{ - m_eEditBoxInputFlag = inputFlag; -} - -void CCEditBoxImplWp8::setMaxLength( int maxLength ) -{ - m_nMaxLength = maxLength; -} - -int CCEditBoxImplWp8::getMaxLength() -{ - return m_nMaxLength; -} - -void CCEditBoxImplWp8::setReturnType( EditBox::KeyboardReturnType returnType ) -{ - m_eKeyboardReturnType = returnType; -} - -bool CCEditBoxImplWp8::isEditing() -{ - return false; -} - -void CCEditBoxImplWp8::setText( const char* pText ) -{ - if (pText != NULL) - { - m_strText = pText; - - if (m_strText.length() > 0) - { - m_pLabelPlaceHolder->setVisible(false); - - std::string strToShow; - - if (EditBox::InputFlag::PASSWORD == m_eEditBoxInputFlag) - { - long length = cc_utf8_strlen(m_strText.c_str(), -1); - for (long i = 0; i < length; i++) - { - strToShow.append("*"); - } - } - else - { - strToShow = m_strText; - } - - //! std::string strWithEllipsis = getStringWithEllipsisJni(strToShow.c_str(), m_EditSize.width, m_EditSize.height-12); - //! m_pLabel->setString(strWithEllipsis.c_str()); - m_pLabel->setString(strToShow.c_str()); - } - else - { - m_pLabelPlaceHolder->setVisible(true); - m_pLabel->setString(""); - } - - } -} - -const char* CCEditBoxImplWp8::getText( void ) -{ - return m_strText.c_str(); -} - -void CCEditBoxImplWp8::setPlaceHolder( const char* pText ) -{ - if (pText != NULL) - { - m_strPlaceHolder = pText; - if (m_strPlaceHolder.length() > 0 && m_strText.length() == 0) - { - m_pLabelPlaceHolder->setVisible(true); - } - - m_pLabelPlaceHolder->setString(m_strPlaceHolder.c_str()); - } -} - -void CCEditBoxImplWp8::setPosition( const Vec2& pos ) -{ - -} - -void CCEditBoxImplWp8::setVisible( bool visible ) -{ - -} - -void CCEditBoxImplWp8::setContentSize( const Size& size ) -{ - -} - -void CCEditBoxImplWp8::setAnchorPoint( const Vec2& anchorPoint ) -{ - -} - -void CCEditBoxImplWp8::visit( void ) -{ - -} - -void CCEditBoxImplWp8::doAnimationWhenKeyboardMove( float duration, float distance ) -{ - -} - -void CCEditBoxImplWp8::closeKeyboard() -{ - -} - -void CCEditBoxImplWp8::onEnter( void ) -{ - -} - -Platform::String^ CCEditBoxImplWp8::stringToPlatformString( std::string strSrc ) -{ - // to wide char - int nStrLen = MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, NULL, 0); - wchar_t* pWStr = new wchar_t[nStrLen + 1]; - memset(pWStr, 0, nStrLen + 1); - MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, pWStr, nStrLen); - Platform::String^ strDst = ref new Platform::String(pWStr); - delete[] pWStr; - return strDst; -} - -std::string CCEditBoxImplWp8::PlatformStringTostring( Platform::String^ strSrc ) -{ - const wchar_t* pWStr = strSrc->Data(); - int nStrLen = WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, NULL, 0, NULL, NULL); - char* pStr = new char[nStrLen + 1]; - memset(pStr, 0, nStrLen + 1); - WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, pStr, nStrLen, NULL, NULL); ; - - std::string strDst = std::string(pStr); - - delete[] pStr; - return strDst; -} - -NS_CC_EXT_END diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplWp8.h b/extensions/GUI/CCEditBox/CCEditBoxImplWp8.h deleted file mode 100644 index 4513ec6dfd..0000000000 --- a/extensions/GUI/CCEditBox/CCEditBoxImplWp8.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -Copyright (c) 2014 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 __CCEditBoxIMPLWP8_H__ -#define __CCEditBoxIMPLWP8_H__ - -#include "ExtensionMacros.h" -#include "CCEditBoxImpl.h" - -NS_CC_EXT_BEGIN - -class CCEditBox; - -class CCEditBoxImplWp8 : public EditBoxImpl -{ -public: - CCEditBoxImplWp8(EditBox* pEditText); - virtual ~CCEditBoxImplWp8(); - - virtual bool initWithSize(const Size& size); - virtual void setFont(const char* pFontName, int fontSize); - virtual void setFontColor(const Color3B& color); - virtual void setPlaceholderFont(const char* pFontName, int fontSize); - virtual void setPlaceholderFontColor(const Color3B& color); - virtual void setInputMode(EditBox::InputMode inputMode); - virtual void setInputFlag(EditBox::InputFlag inputFlag); - virtual void setMaxLength(int maxLength); - virtual int getMaxLength(); - virtual void setReturnType(EditBox::KeyboardReturnType returnType); - virtual bool isEditing(); - - virtual void setText(const char* pText); - virtual const char* getText(void); - virtual void setPlaceHolder(const char* pText); - virtual void setPosition(const Vec2& pos); - virtual void setVisible(bool visible); - virtual void setContentSize(const Size& size); - virtual void setAnchorPoint(const Vec2& anchorPoint); - virtual void visit(void); - virtual void doAnimationWhenKeyboardMove(float duration, float distance); - virtual void openKeyboard(); - virtual void closeKeyboard(); - virtual void onEnter(void); -private: - Platform::String^ stringToPlatformString(std::string strSrc); - std::string PlatformStringTostring(Platform::String^ strSrc); -private: - - Label* m_pLabel; - Label* m_pLabelPlaceHolder; - EditBox::InputMode m_eEditBoxInputMode; - EditBox::InputFlag m_eEditBoxInputFlag; - (EditBox::KeyboardReturnType m_eKeyboardReturnType; - - std::string m_strText; - std::string m_strPlaceHolder; - - Color3B m_colText; - Color3B m_colPlaceHolder; - - int m_nMaxLength; - Size m_EditSize; -}; - -NS_CC_EXT_END - -#endif diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index a204f40e43..695077d628 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -7,7 +7,7 @@ #include "GUI/CCControlExtension/CCControlExtensions.h" #include "GUI/CCScrollView/CCScrollView.h" #include "GUI/CCScrollView/CCTableView.h" -#include "GUI/CCEditBox/CCEditBox.h" +#include "ui/UIEditBox/UIEditBox.h" // Physics integration #include "physics-nodes/CCPhysicsDebugNode.h" diff --git a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp index b54a42aa32..a84855b7b8 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp @@ -11,6 +11,7 @@ USING_NS_CC; USING_NS_CC_EXT; +using namespace ui; EditBoxTest::EditBoxTest() @@ -37,7 +38,7 @@ EditBoxTest::EditBoxTest() auto editBoxSize = Size(visibleSize.width - 100, 60); // top - _editName = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/green_edit.png")); + _editName = EditBox::create(editBoxSize, ui::Scale9Sprite::create("extensions/green_edit.png")); _editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4)); _editName->setFontName("Paint Boy"); _editName->setFontSize(25); @@ -50,7 +51,7 @@ EditBoxTest::EditBoxTest() addChild(_editName); // middle - _editPassword = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/orange_edit.png")); + _editPassword = EditBox::create(editBoxSize, ui::Scale9Sprite::create("extensions/orange_edit.png")); _editPassword->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) _editPassword->setFont("American Typewriter", 30); @@ -67,7 +68,7 @@ EditBoxTest::EditBoxTest() addChild(_editPassword); // bottom - _editEmail = EditBox::create(Size(editBoxSize.width, editBoxSize.height), Scale9Sprite::create("extensions/yellow_edit.png")); + _editEmail = EditBox::create(Size(editBoxSize.width, editBoxSize.height), ui::Scale9Sprite::create("extensions/yellow_edit.png")); _editEmail->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4)); _editEmail->setAnchorPoint(Vec2(0.5, 1.0f)); _editEmail->setPlaceHolder("Email:"); @@ -90,17 +91,17 @@ void EditBoxTest::toExtensionsMainLayer(cocos2d::Ref *sender) scene->release(); } -void EditBoxTest::editBoxEditingDidBegin(cocos2d::extension::EditBox* editBox) +void EditBoxTest::editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox) { log("editBox %p DidBegin !", editBox); } -void EditBoxTest::editBoxEditingDidEnd(cocos2d::extension::EditBox* editBox) +void EditBoxTest::editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox) { log("editBox %p DidEnd !", editBox); } -void EditBoxTest::editBoxTextChanged(cocos2d::extension::EditBox* editBox, const std::string& text) +void EditBoxTest::editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text) { log("editBox %p TextChanged, text: %s ", editBox, text.c_str()); } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h index 3cef026dbd..2de0e0642f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h @@ -12,22 +12,22 @@ #include "cocos2d.h" #include "extensions/cocos-ext.h" -class EditBoxTest : public cocos2d::Layer, public cocos2d::extension::EditBoxDelegate +class EditBoxTest : public cocos2d::Layer, public cocos2d::ui::EditBoxDelegate { public: EditBoxTest(); virtual ~EditBoxTest(); void toExtensionsMainLayer(cocos2d::Ref *sender); - virtual void editBoxEditingDidBegin(cocos2d::extension::EditBox* editBox); - virtual void editBoxEditingDidEnd(cocos2d::extension::EditBox* editBox); - virtual void editBoxTextChanged(cocos2d::extension::EditBox* editBox, const std::string& text); - virtual void editBoxReturn(cocos2d::extension::EditBox* editBox); + virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox); + virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox); + virtual void editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text); + virtual void editBoxReturn(cocos2d::ui::EditBox* editBox); private: cocos2d::Label* _TTFShowEditReturn; - cocos2d::extension::EditBox* _editName; - cocos2d::extension::EditBox* _editPassword; - cocos2d::extension::EditBox* _editEmail; + cocos2d::ui::EditBox* _editName; + cocos2d::ui::EditBox* _editPassword; + cocos2d::ui::EditBox* _editEmail; }; void runEditBoxTest(); From 0076953f97f8fec2dee2ca679cffc3b53eb929f5 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 1 Sep 2014 15:55:09 +0800 Subject: [PATCH 06/15] fix iOS compile error --- build/cocos2d_libs.xcodeproj/project.pbxproj | 120 ++++++++++-------- .../CocoStudioGUITest/CocosGUIScene.cpp | 12 ++ 2 files changed, 80 insertions(+), 52 deletions(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index c49581a417..6e12365842 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1008,16 +1008,6 @@ 15AE1C0419AAE01E00C27E9E /* CCTableView.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168631807AF4E005B8026 /* CCTableView.h */; }; 15AE1C0519AAE01E00C27E9E /* CCTableViewCell.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168641807AF4E005B8026 /* CCTableViewCell.cpp */; }; 15AE1C0619AAE01E00C27E9E /* CCTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168651807AF4E005B8026 /* CCTableViewCell.h */; }; - 15AE1C0719AAE02500C27E9E /* CCEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */; }; - 15AE1C0819AAE02500C27E9E /* CCEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168501807AF4E005B8026 /* CCEditBox.h */; }; - 15AE1C0919AAE02500C27E9E /* CCEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */; }; - 15AE1C0A19AAE02500C27E9E /* CCEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168501807AF4E005B8026 /* CCEditBox.h */; }; - 15AE1C0B19AAE02D00C27E9E /* CCEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */; }; - 15AE1C0C19AAE02D00C27E9E /* CCEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */; }; - 15AE1C0D19AAE03400C27E9E /* CCEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */; }; - 15AE1C0E19AAE03400C27E9E /* CCEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */; }; - 15AE1C0F19AAE03E00C27E9E /* CCEditBoxImplIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168541807AF4E005B8026 /* CCEditBoxImplIOS.h */; }; - 15AE1C1019AAE03E00C27E9E /* CCEditBoxImplIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46A168551807AF4E005B8026 /* CCEditBoxImplIOS.mm */; }; 15AE1C1119AAE2C600C27E9E /* CCPhysicsDebugNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD71EEC180E27CF00808F54 /* CCPhysicsDebugNode.cpp */; }; 15AE1C1219AAE2C600C27E9E /* CCPhysicsDebugNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AD71EED180E27CF00808F54 /* CCPhysicsDebugNode.h */; }; 15AE1C1319AAE2C600C27E9E /* CCPhysicsSprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AD71EEE180E27CF00808F54 /* CCPhysicsSprite.cpp */; }; @@ -1350,6 +1340,26 @@ 1ABA68B11888D700007D1BB4 /* CCFontCharMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABA68AD1888D700007D1BB4 /* CCFontCharMap.h */; }; 1AC0269C1914068200FA920D /* ConvertUTF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC026991914068200FA920D /* ConvertUTF.h */; }; 1AC0269D1914068200FA920D /* ConvertUTF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC026991914068200FA920D /* ConvertUTF.h */; }; + 292DB13D19B4574100A80320 /* UIEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB12F19B4574100A80320 /* UIEditBox.cpp */; }; + 292DB13E19B4574100A80320 /* UIEditBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB12F19B4574100A80320 /* UIEditBox.cpp */; }; + 292DB13F19B4574100A80320 /* UIEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13019B4574100A80320 /* UIEditBox.h */; }; + 292DB14019B4574100A80320 /* UIEditBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13019B4574100A80320 /* UIEditBox.h */; }; + 292DB14119B4574100A80320 /* UIEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13119B4574100A80320 /* UIEditBoxImpl.h */; }; + 292DB14219B4574100A80320 /* UIEditBoxImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13119B4574100A80320 /* UIEditBoxImpl.h */; }; + 292DB14319B4574100A80320 /* UIEditBoxImplAndroid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13219B4574100A80320 /* UIEditBoxImplAndroid.cpp */; }; + 292DB14419B4574100A80320 /* UIEditBoxImplAndroid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13219B4574100A80320 /* UIEditBoxImplAndroid.cpp */; }; + 292DB14519B4574100A80320 /* UIEditBoxImplAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13319B4574100A80320 /* UIEditBoxImplAndroid.h */; }; + 292DB14619B4574100A80320 /* UIEditBoxImplAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13319B4574100A80320 /* UIEditBoxImplAndroid.h */; }; + 292DB14719B4574100A80320 /* UIEditBoxImplIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13419B4574100A80320 /* UIEditBoxImplIOS.h */; }; + 292DB14819B4574100A80320 /* UIEditBoxImplIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13419B4574100A80320 /* UIEditBoxImplIOS.h */; }; + 292DB14919B4574100A80320 /* UIEditBoxImplIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13519B4574100A80320 /* UIEditBoxImplIOS.mm */; }; + 292DB14A19B4574100A80320 /* UIEditBoxImplIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13519B4574100A80320 /* UIEditBoxImplIOS.mm */; }; + 292DB14B19B4574100A80320 /* UIEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13619B4574100A80320 /* UIEditBoxImplMac.h */; }; + 292DB14C19B4574100A80320 /* UIEditBoxImplMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB13619B4574100A80320 /* UIEditBoxImplMac.h */; }; + 292DB14D19B4574100A80320 /* UIEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13719B4574100A80320 /* UIEditBoxImplMac.mm */; }; + 292DB14E19B4574100A80320 /* UIEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13719B4574100A80320 /* UIEditBoxImplMac.mm */; }; + 292DB14F19B4574100A80320 /* UIEditBoxImplNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */; }; + 292DB15019B4574100A80320 /* UIEditBoxImplNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */; }; 29394CF019B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; }; 29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; }; 29394CF219B01DBA00D2DE1A /* UIWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CED19B01DBA00D2DE1A /* UIWebView.mm */; }; @@ -2304,6 +2314,16 @@ 2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = ""; }; 2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = ""; }; 29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = ""; }; + 292DB12F19B4574100A80320 /* UIEditBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBox.cpp; sourceTree = ""; }; + 292DB13019B4574100A80320 /* UIEditBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBox.h; sourceTree = ""; }; + 292DB13119B4574100A80320 /* UIEditBoxImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImpl.h; sourceTree = ""; }; + 292DB13219B4574100A80320 /* UIEditBoxImplAndroid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplAndroid.cpp; sourceTree = ""; }; + 292DB13319B4574100A80320 /* UIEditBoxImplAndroid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplAndroid.h; sourceTree = ""; }; + 292DB13419B4574100A80320 /* UIEditBoxImplIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplIOS.h; sourceTree = ""; }; + 292DB13519B4574100A80320 /* UIEditBoxImplIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIEditBoxImplIOS.mm; sourceTree = ""; }; + 292DB13619B4574100A80320 /* UIEditBoxImplMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplMac.h; sourceTree = ""; }; + 292DB13719B4574100A80320 /* UIEditBoxImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIEditBoxImplMac.mm; sourceTree = ""; }; + 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplNone.cpp; sourceTree = ""; }; 29394CEC19B01DBA00D2DE1A /* UIWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebView.h; sourceTree = ""; }; 29394CED19B01DBA00D2DE1A /* UIWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWebView.mm; sourceTree = ""; }; 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebViewImpl_iOS.h; sourceTree = ""; }; @@ -2407,16 +2427,6 @@ 46A1684B1807AF4E005B8026 /* CCInvocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCInvocation.h; sourceTree = ""; }; 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCScale9Sprite.cpp; sourceTree = ""; }; 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCScale9Sprite.h; sourceTree = ""; }; - 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBox.cpp; sourceTree = ""; }; - 46A168501807AF4E005B8026 /* CCEditBox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBox.h; sourceTree = ""; }; - 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImpl.h; sourceTree = ""; }; - 46A168521807AF4E005B8026 /* CCEditBoxImplAndroid.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBoxImplAndroid.cpp; sourceTree = ""; }; - 46A168531807AF4E005B8026 /* CCEditBoxImplAndroid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplAndroid.h; sourceTree = ""; }; - 46A168541807AF4E005B8026 /* CCEditBoxImplIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplIOS.h; sourceTree = ""; }; - 46A168551807AF4E005B8026 /* CCEditBoxImplIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CCEditBoxImplIOS.mm; sourceTree = ""; }; - 46A168581807AF4E005B8026 /* CCEditBoxImplNone.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBoxImplNone.cpp; sourceTree = ""; }; - 46A1685B1807AF4E005B8026 /* CCEditBoxImplWin.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCEditBoxImplWin.cpp; sourceTree = ""; }; - 46A1685C1807AF4E005B8026 /* CCEditBoxImplWin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplWin.h; sourceTree = ""; }; 46A1685E1807AF4E005B8026 /* CCScrollView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCScrollView.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 46A1685F1807AF4E005B8026 /* CCScrollView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCScrollView.h; sourceTree = ""; }; 46A168621807AF4E005B8026 /* CCTableView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCTableView.cpp; sourceTree = ""; }; @@ -2867,8 +2877,6 @@ B276EF5C1988D1D500CD400F /* CCVertexIndexData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexData.cpp; sourceTree = ""; }; B276EF5D1988D1D500CD400F /* CCVertexIndexBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCVertexIndexBuffer.h; sourceTree = ""; }; B276EF5E1988D1D500CD400F /* CCVertexIndexBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCVertexIndexBuffer.cpp; sourceTree = ""; }; - B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCEditBoxImplMac.mm; sourceTree = ""; }; - B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEditBoxImplMac.h; sourceTree = ""; }; B29594AF1926D5D9003EEF37 /* ccShader_3D_Color.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_Color.frag; sourceTree = ""; }; B29594B01926D5D9003EEF37 /* ccShader_3D_ColorTex.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_ColorTex.frag; sourceTree = ""; }; B29594B11926D5D9003EEF37 /* ccShader_3D_PositionTex.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_PositionTex.vert; sourceTree = ""; }; @@ -3979,6 +3987,23 @@ path = ../cocos/ui; sourceTree = ""; }; + 292DB12E19B4574100A80320 /* UIEditBox */ = { + isa = PBXGroup; + children = ( + 292DB12F19B4574100A80320 /* UIEditBox.cpp */, + 292DB13019B4574100A80320 /* UIEditBox.h */, + 292DB13119B4574100A80320 /* UIEditBoxImpl.h */, + 292DB13219B4574100A80320 /* UIEditBoxImplAndroid.cpp */, + 292DB13319B4574100A80320 /* UIEditBoxImplAndroid.h */, + 292DB13419B4574100A80320 /* UIEditBoxImplIOS.h */, + 292DB13519B4574100A80320 /* UIEditBoxImplIOS.mm */, + 292DB13619B4574100A80320 /* UIEditBoxImplMac.h */, + 292DB13719B4574100A80320 /* UIEditBoxImplMac.mm */, + 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */, + ); + path = UIEditBox; + sourceTree = ""; + }; 29CB8F501929D63600C841D6 /* layout */ = { isa = PBXGroup; children = ( @@ -4030,6 +4055,7 @@ 29CB8F531929D67D00C841D6 /* widgets */ = { isa = PBXGroup; children = ( + 292DB12E19B4574100A80320 /* UIEditBox */, 2905F9FE18CF08D000240AA3 /* UIListView.cpp */, 2905F9FF18CF08D000240AA3 /* UIListView.h */, 2905FA0018CF08D000240AA3 /* UILoadingBar.cpp */, @@ -4143,7 +4169,6 @@ isa = PBXGroup; children = ( 46A168341807AF4E005B8026 /* CCControlExtension */, - 46A1684E1807AF4E005B8026 /* CCEditBox */, 46A1685D1807AF4E005B8026 /* CCScrollView */, ); path = GUI; @@ -4181,25 +4206,6 @@ path = CCControlExtension; sourceTree = ""; }; - 46A1684E1807AF4E005B8026 /* CCEditBox */ = { - isa = PBXGroup; - children = ( - B282B47C1980E02B00666787 /* CCEditBoxImplMac.mm */, - B282B47D1980E02B00666787 /* CCEditBoxImplMac.h */, - 46A1684F1807AF4E005B8026 /* CCEditBox.cpp */, - 46A168501807AF4E005B8026 /* CCEditBox.h */, - 46A168511807AF4E005B8026 /* CCEditBoxImpl.h */, - 46A168521807AF4E005B8026 /* CCEditBoxImplAndroid.cpp */, - 46A168531807AF4E005B8026 /* CCEditBoxImplAndroid.h */, - 46A168541807AF4E005B8026 /* CCEditBoxImplIOS.h */, - 46A168551807AF4E005B8026 /* CCEditBoxImplIOS.mm */, - 46A168581807AF4E005B8026 /* CCEditBoxImplNone.cpp */, - 46A1685B1807AF4E005B8026 /* CCEditBoxImplWin.cpp */, - 46A1685C1807AF4E005B8026 /* CCEditBoxImplWin.h */, - ); - path = CCEditBox; - sourceTree = ""; - }; 46A1685D1807AF4E005B8026 /* CCScrollView */ = { isa = PBXGroup; children = ( @@ -4943,9 +4949,11 @@ 50ABBE851925AB6F00A911A9 /* ccFPSImages.h in Headers */, 15AE1A5319AAD40300C27E9E /* b2Draw.h in Headers */, 5034CA39191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */, + 292DB14B19B4574100A80320 /* UIEditBoxImplMac.h in Headers */, 50ABBE891925AB6F00A911A9 /* CCMap.h in Headers */, 50ABBE8D1925AB6F00A911A9 /* CCNS.h in Headers */, 50ABBEA51925AB6F00A911A9 /* CCScriptSupport.h in Headers */, + 292DB14519B4574100A80320 /* UIEditBoxImplAndroid.h in Headers */, 15AE1B9A19AADFDF00C27E9E /* UIHBox.h in Headers */, 15AE18EB19AAD35000C27E9E /* CCActionNode.h in Headers */, 15AE1A3819AAD3D500C27E9E /* b2Shape.h in Headers */, @@ -5020,7 +5028,6 @@ 15AE199919AAD39600C27E9E /* LoadingBarReader.h in Headers */, 15AE1A8F19AAD40300C27E9E /* b2RopeJoint.h in Headers */, 15AE18ED19AAD35000C27E9E /* CCActionObject.h in Headers */, - 15AE1C0C19AAE02D00C27E9E /* CCEditBoxImpl.h in Headers */, ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */, 15AE18A719AAD33D00C27E9E /* CCScrollViewLoader.h in Headers */, 15AE184819AAD2F700C27E9E /* cocos3d.h in Headers */, @@ -5175,6 +5182,7 @@ 15AE188519AAD33D00C27E9E /* CCBSequence.h in Headers */, 15AE1AE219AAD42500C27E9E /* cpDampedRotarySpring.h in Headers */, 5034CA49191D591100CE6051 /* ccShader_Label_df.frag in Headers */, + 292DB14119B4574100A80320 /* UIEditBoxImpl.h in Headers */, 1A01C68C18F57BE800EFE3A6 /* CCDeprecated.h in Headers */, 50ABBD561925AB0000A911A9 /* TransformUtils.h in Headers */, 299754F6193EC95400A54AC3 /* ObjectFactory.h in Headers */, @@ -5183,6 +5191,7 @@ 15AE18FB19AAD35000C27E9E /* CCColliderDetector.h in Headers */, 15AE19E119AAD3A700C27E9E /* Skeleton.h in Headers */, 1A570280180BCC900088DEC7 /* CCSprite.h in Headers */, + 292DB14719B4574100A80320 /* UIEditBoxImplIOS.h in Headers */, 15AE1A9119AAD40300C27E9E /* b2WeldJoint.h in Headers */, 15AE1A5419AAD40300C27E9E /* b2GrowableStack.h in Headers */, 15AE1B4E19AADA9900C27E9E /* UIListView.h in Headers */, @@ -5286,7 +5295,6 @@ 15AE1BCA19AAE01E00C27E9E /* CCControl.h in Headers */, 50ABBDBF1925AB4100A911A9 /* CCTextureCache.h in Headers */, 15AE186719AAD31D00C27E9E /* CDXMacOSXSupport.h in Headers */, - 15AE1C0A19AAE02500C27E9E /* CCEditBox.h in Headers */, B37510741823AC9F00B3BA6A /* CCPhysicsContactInfo_chipmunk.h in Headers */, 15AE1ADF19AAD42500C27E9E /* chipmunk_types.h in Headers */, 5034CA35191D591100CE6051 /* ccShader_PositionTexture.frag in Headers */, @@ -5365,6 +5373,7 @@ 15AE1AEC19AAD42500C27E9E /* util.h in Headers */, 15AE19DD19AAD3A700C27E9E /* Json.h in Headers */, 15AE191A19AAD35000C27E9E /* CCSSceneReader.h in Headers */, + 292DB13F19B4574100A80320 /* UIEditBox.h in Headers */, 50ABBE671925AB6F00A911A9 /* CCEventListenerCustom.h in Headers */, 15AE18E219AAD35000C27E9E /* TriggerMng.h in Headers */, 15AE1B2B19AAD43700C27E9E /* prime.h in Headers */, @@ -5417,7 +5426,6 @@ 50ABBE771925AB6F00A911A9 /* CCEventListenerTouch.h in Headers */, 5034CA33191D591100CE6051 /* ccShader_PositionTexture_uColor.frag in Headers */, 50ABC0171926664800A911A9 /* CCImage.h in Headers */, - 15AE1C0E19AAE03400C27E9E /* CCEditBoxImplMac.h in Headers */, 15AE1AED19AAD42500C27E9E /* cpArbiter.h in Headers */, 50ABBDA91925AB4100A911A9 /* CCRenderCommand.h in Headers */, 50ABBD951925AB4100A911A9 /* CCGLProgramState.h in Headers */, @@ -5448,6 +5456,7 @@ 15AE183319AAD2F700C27E9E /* CCOBB.h in Headers */, 15AE18B119AAD33D00C27E9E /* CCBMemberVariableAssigner.h in Headers */, 15AE1AFA19AAD42500C27E9E /* cpConstraint.h in Headers */, + 292DB14019B4574100A80320 /* UIEditBox.h in Headers */, 50ABBD3B1925AB0000A911A9 /* CCAffineTransform.h in Headers */, 15AE1A0A19AAD3A700C27E9E /* CCSkeleton.h in Headers */, 5034CA38191D591100CE6051 /* ccShader_PositionColorLengthTexture.vert in Headers */, @@ -5543,6 +5552,7 @@ 15AE19F819AAD3A700C27E9E /* Animation.h in Headers */, 1A5700A1180BC5D20088DEC7 /* CCNode.h in Headers */, 15AE181919AAD2F700C27E9E /* CCAttachNode.h in Headers */, + 292DB14C19B4574100A80320 /* UIEditBoxImplMac.h in Headers */, 15AE1BF019AAE01E00C27E9E /* CCControlHuePicker.h in Headers */, 15AE18B819AAD33D00C27E9E /* CCBSequenceProperty.h in Headers */, 503DD8E41926736A00CD74DD /* CCDirectorCaller.h in Headers */, @@ -5572,6 +5582,7 @@ 50ABBD5B1925AB0000A911A9 /* Vec2.h in Headers */, 50ABBD411925AB0000A911A9 /* CCMath.h in Headers */, 1A5701A0180BCB590088DEC7 /* CCFont.h in Headers */, + 292DB14819B4574100A80320 /* UIEditBoxImplIOS.h in Headers */, 15AE1A0819AAD3A700C27E9E /* BoneData.h in Headers */, 50ABBD9A1925AB4100A911A9 /* CCGLProgramStateCache.h in Headers */, 15AE181D19AAD2F700C27E9E /* CCBundle3D.h in Headers */, @@ -5603,6 +5614,7 @@ 15AE196B19AAD35100C27E9E /* DictionaryHelper.h in Headers */, 15AE1AA619AAD40300C27E9E /* b2Fixture.h in Headers */, 15AE1BBA19AADFF000C27E9E /* HttpClient.h in Headers */, + 292DB14619B4574100A80320 /* UIEditBoxImplAndroid.h in Headers */, 15AE1AF819AAD42500C27E9E /* chipmunk_types.h in Headers */, 15AE1B9419AADA9A00C27E9E /* GUIDefine.h in Headers */, 15AE183B19AAD2F700C27E9E /* CCRay.h in Headers */, @@ -5745,6 +5757,7 @@ 15AE1B8D19AADA9A00C27E9E /* UIScale9Sprite.h in Headers */, 15AE18AC19AAD33D00C27E9E /* CCBAnimationManager.h in Headers */, 15AE1A1A19AAD3A700C27E9E /* Skin.h in Headers */, + 292DB14219B4574100A80320 /* UIEditBoxImpl.h in Headers */, 1A570303180BCE890088DEC7 /* CCParallaxNode.h in Headers */, 50ABBE2A1925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */, 1A57030F180BCF190088DEC7 /* CCComponent.h in Headers */, @@ -5766,7 +5779,6 @@ 15AE1BFE19AAE01E00C27E9E /* CCInvocation.h in Headers */, 15AE1A9E19AAD40300C27E9E /* b2StackAllocator.h in Headers */, 1A570357180BD0B00088DEC7 /* ioapi.h in Headers */, - 15AE1C0F19AAE03E00C27E9E /* CCEditBoxImplIOS.h in Headers */, 15AE1A1619AAD3A700C27E9E /* SkeletonData.h in Headers */, 50ABBD4B1925AB0000A911A9 /* Mat4.h in Headers */, 15AE1BBE19AADFF000C27E9E /* SocketIO.h in Headers */, @@ -5883,13 +5895,11 @@ B276EF641988D1D500CD400F /* CCVertexIndexBuffer.h in Headers */, 15AE1A0619AAD3A700C27E9E /* Bone.h in Headers */, ED9C6A9718599AD8000A5232 /* CCNodeGrid.h in Headers */, - 15AE1C0819AAE02500C27E9E /* CCEditBox.h in Headers */, 50ABC0201926664800A911A9 /* CCThread.h in Headers */, 15AE1B8519AADA9A00C27E9E /* UITextField.h in Headers */, 1A01C69318F57BE800EFE3A6 /* CCDouble.h in Headers */, 15AE184B19AAD30500C27E9E /* Export.h in Headers */, 15AE196019AAD35100C27E9E /* CCSpriteFrameCacheHelper.h in Headers */, - 15AE1C0B19AAE02D00C27E9E /* CCEditBoxImpl.h in Headers */, 50ABBE221925AB6F00A911A9 /* atitc.h in Headers */, 15AE1AB719AAD40300C27E9E /* b2ContactSolver.h in Headers */, 15AE193319AAD35100C27E9E /* CCActionNode.h in Headers */, @@ -6002,6 +6012,7 @@ 15AE1B1E19AAD43700C27E9E /* cpBody.c in Sources */, 15AE1BDE19AAE01E00C27E9E /* CCInvocation.cpp in Sources */, 3EA3EDBC1991CDFA00645534 /* CCCamera.cpp in Sources */, + 292DB14F19B4574100A80320 /* UIEditBoxImplNone.cpp in Sources */, 15AE199419AAD39600C27E9E /* LayoutReader.cpp in Sources */, 1A01C68A18F57BE800EFE3A6 /* CCDeprecated.cpp in Sources */, 1A1645B0191B726C008C7C7F /* ConvertUTF.c in Sources */, @@ -6033,7 +6044,6 @@ 15AE186319AAD31D00C27E9E /* CDAudioManager.m in Sources */, 15AE1B2219AAD43700C27E9E /* cpShape.c in Sources */, ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */, - 15AE1C0D19AAE03400C27E9E /* CCEditBoxImplMac.mm in Sources */, 15AE1A2C19AAD3D500C27E9E /* b2DynamicTree.cpp in Sources */, 15AE184019AAD2F700C27E9E /* CCSprite3D.cpp in Sources */, 46A170E61807CECA005B8026 /* CCPhysicsBody.cpp in Sources */, @@ -6045,7 +6055,6 @@ 50ABBEBB1925AB6F00A911A9 /* ccUtils.cpp in Sources */, 15AE186A19AAD31D00C27E9E /* CocosDenshion.m in Sources */, 15AE198C19AAD36E00C27E9E /* CheckBoxReader.cpp in Sources */, - 15AE1C0919AAE02500C27E9E /* CCEditBox.cpp in Sources */, 15AE1B6319AADA9900C27E9E /* UICheckBox.cpp in Sources */, 15EFA211198A2BB5000C57D3 /* CCProtectedNode.cpp in Sources */, 50ABBEB71925AB6F00A911A9 /* ccUTF8.cpp in Sources */, @@ -6122,6 +6131,7 @@ 50ABBE391925AB6F00A911A9 /* CCData.cpp in Sources */, 1A57010E180BC8EE0088DEC7 /* CCDrawingPrimitives.cpp in Sources */, 50ABBED71925AB6F00A911A9 /* ZipUtils.cpp in Sources */, + 292DB14919B4574100A80320 /* UIEditBoxImplIOS.mm in Sources */, 15AE181019AAD2F700C27E9E /* CCAnimation3D.cpp in Sources */, 1A01C68418F57BE800EFE3A6 /* CCArray.cpp in Sources */, 1A570112180BC8EE0088DEC7 /* CCDrawNode.cpp in Sources */, @@ -6152,6 +6162,7 @@ 15AE1B5319AADA9900C27E9E /* UIRichText.cpp in Sources */, 15AE19DC19AAD3A700C27E9E /* Json.cpp in Sources */, 15AE1B2419AAD43700C27E9E /* cpSpaceComponent.c in Sources */, + 292DB13D19B4574100A80320 /* UIEditBox.cpp in Sources */, 50ABBE551925AB6F00A911A9 /* CCEventFocus.cpp in Sources */, 15AE1A8819AAD40300C27E9E /* b2PrismaticJoint.cpp in Sources */, 50ABBE491925AB6F00A911A9 /* CCEventAcceleration.cpp in Sources */, @@ -6200,6 +6211,7 @@ 1A570202180BCBD40088DEC7 /* CCClippingNode.cpp in Sources */, 1A570208180BCBDF0088DEC7 /* CCMotionStreak.cpp in Sources */, 1A570210180BCBF40088DEC7 /* CCProgressTimer.cpp in Sources */, + 292DB14D19B4574100A80320 /* UIEditBoxImplMac.mm in Sources */, 50ABBDB51925AB4100A911A9 /* CCTexture2D.cpp in Sources */, 1A570214180BCBF40088DEC7 /* CCRenderTexture.cpp in Sources */, 15AE1BD019AAE01E00C27E9E /* CCControlHuePicker.cpp in Sources */, @@ -6338,6 +6350,7 @@ 50ABC0631926664800A911A9 /* CCDevice.mm in Sources */, 15AE1A2819AAD3D500C27E9E /* b2Collision.cpp in Sources */, 15AE1B6719AADA9900C27E9E /* UIScale9Sprite.cpp in Sources */, + 292DB14319B4574100A80320 /* UIEditBoxImplAndroid.cpp in Sources */, 15AE1A5219AAD40300C27E9E /* b2Draw.cpp in Sources */, 50ABBE1F1925AB6F00A911A9 /* atitc.cpp in Sources */, 1A01C69818F57BE800EFE3A6 /* CCSet.cpp in Sources */, @@ -6451,6 +6464,7 @@ 46A171031807CECB005B8026 /* CCPhysicsShape.cpp in Sources */, 50ABC0161926664800A911A9 /* CCImage.cpp in Sources */, 1A01C6A518F58F7500EFE3A6 /* CCNotificationCenter.cpp in Sources */, + 292DB14E19B4574100A80320 /* UIEditBoxImplMac.mm in Sources */, 15AE1BFB19AAE01E00C27E9E /* CCControlUtils.cpp in Sources */, 15AE1B9019AADA9A00C27E9E /* UIWidget.cpp in Sources */, ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */, @@ -6502,6 +6516,7 @@ 15AE198E19AAD36E00C27E9E /* CheckBoxReader.cpp in Sources */, 50ABBE621925AB6F00A911A9 /* CCEventListenerAcceleration.cpp in Sources */, 15AE1AB619AAD40300C27E9E /* b2ContactSolver.cpp in Sources */, + 292DB13E19B4574100A80320 /* UIEditBox.cpp in Sources */, 3E6176681960F89B00DE83F5 /* CCController-iOS.mm in Sources */, 15AE19EF19AAD3A700C27E9E /* SkeletonBounds.cpp in Sources */, 15AE18B219AAD33D00C27E9E /* CCBReader.cpp in Sources */, @@ -6547,6 +6562,7 @@ 15AE1B4319AAD43700C27E9E /* cpSpaceHash.c in Sources */, 15AE1A1D19AAD3A700C27E9E /* SlotData.cpp in Sources */, 50ABBD551925AB0000A911A9 /* TransformUtils.cpp in Sources */, + 292DB14419B4574100A80320 /* UIEditBoxImplAndroid.cpp in Sources */, 15AE193619AAD35100C27E9E /* CCArmature.cpp in Sources */, 1A57007A180BC5A10088DEC7 /* CCActionInstant.cpp in Sources */, 15AE1AC419AAD40300C27E9E /* b2FrictionJoint.cpp in Sources */, @@ -6566,7 +6582,6 @@ 1A570086180BC5A10088DEC7 /* CCActionPageTurn3D.cpp in Sources */, 15AE1AB819AAD40300C27E9E /* b2EdgeAndCircleContact.cpp in Sources */, 15AE19FF19AAD3A700C27E9E /* AtlasAttachmentLoader.cpp in Sources */, - 15AE1C0719AAE02500C27E9E /* CCEditBox.cpp in Sources */, 1A57008A180BC5A10088DEC7 /* CCActionProgressTimer.cpp in Sources */, 15AE18AF19AAD33D00C27E9E /* CCBKeyframe.cpp in Sources */, 15AE19FB19AAD3A700C27E9E /* AnimationStateData.cpp in Sources */, @@ -6596,6 +6611,7 @@ 15AE195F19AAD35100C27E9E /* CCSpriteFrameCacheHelper.cpp in Sources */, 15AE193019AAD35100C27E9E /* CCActionManagerEx.cpp in Sources */, 503DD8E21926736A00CD74DD /* CCCommon.mm in Sources */, + 292DB14A19B4574100A80320 /* UIEditBoxImplIOS.mm in Sources */, 15AE1A9419AAD40300C27E9E /* b2BlockAllocator.cpp in Sources */, 15AE1B4419AAD43700C27E9E /* cpSpaceQuery.c in Sources */, 15AE1A4D19AAD3D500C27E9E /* b2PolygonShape.cpp in Sources */, @@ -6672,6 +6688,7 @@ 15AE194019AAD35100C27E9E /* CCBone.cpp in Sources */, 1A570215180BCBF40088DEC7 /* CCRenderTexture.cpp in Sources */, 1A570222180BCC1A0088DEC7 /* CCParticleBatchNode.cpp in Sources */, + 292DB15019B4574100A80320 /* UIEditBoxImplNone.cpp in Sources */, 15AE19F119AAD3A700C27E9E /* Event.cpp in Sources */, 15AE185F19AAD31200C27E9E /* SimpleAudioEngine.mm in Sources */, 15AE1BE819AAE01E00C27E9E /* CCControl.cpp in Sources */, @@ -6715,7 +6732,6 @@ 15AE19AE19AAD39700C27E9E /* PageViewReader.cpp in Sources */, 3EA3EDBD1991CDFA00645534 /* CCCamera.cpp in Sources */, 1A570297180BCCAB0088DEC7 /* CCAnimationCache.cpp in Sources */, - 15AE1C1019AAE03E00C27E9E /* CCEditBoxImplIOS.mm in Sources */, 50ABBE321925AB6F00A911A9 /* CCConfiguration.cpp in Sources */, 15AE1A9F19AAD40300C27E9E /* b2Timer.cpp in Sources */, 15AE1AD419AAD40300C27E9E /* b2WeldJoint.cpp in Sources */, diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 6905ba7701..de96938730 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -44,6 +44,18 @@ g_guisTests[] = } }, #endif + { + "EditBox Test", + [](Ref* sender) + { + UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); + sceneManager->setCurrentUISceneId(kUIEditBoxTest); + sceneManager->setMinUISceneId(kUIEditBoxTest); + sceneManager->setMaxUISceneId(kUIEditBoxTest); + Scene* scene = sceneManager->currentUIScene(); + Director::getInstance()->replaceScene(scene); + } + }, { "focus test", [](Ref* sender) From 85ce801fdd37dfe72f22ab6b06bc28e8f87ad4ac Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 1 Sep 2014 17:06:22 +0800 Subject: [PATCH 07/15] remove ccscale9sprite , cceditBox --- build/cocos2d_libs.xcodeproj/project.pbxproj | 26 +- build/cocos2d_tests.xcodeproj/project.pbxproj | 32 - .../cocosbuilder/CCScale9SpriteLoader.cpp | 16 +- .../cocosbuilder/CCScale9SpriteLoader.h | 6 +- cocos/ui/Android.mk | 3 + cocos/ui/UIScale9Sprite.cpp | 19 +- cocos/ui/UIScale9Sprite.h | 6 + extensions/ExtensionDeprecated.cpp | 25 + extensions/ExtensionDeprecated.h | 39 + .../CCControlExtension/CCControlButton.cpp | 1 - .../GUI/CCControlExtension/CCControlButton.h | 3 +- .../CCControlExtension/CCControlExtensions.h | 1 - .../GUI/CCControlExtension/CCScale9Sprite.cpp | 816 ------------------ .../GUI/CCControlExtension/CCScale9Sprite.h | 323 ------- extensions/cocos-ext.h | 2 +- .../EditBoxTest/EditBoxTest.cpp | 135 --- .../ExtensionsTest/EditBoxTest/EditBoxTest.h | 35 - .../Classes/ExtensionsTest/ExtensionsTest.cpp | 19 +- .../Scale9SpriteTest/Scale9SpriteTest.cpp | 784 ----------------- .../Scale9SpriteTest/Scale9SpriteTest.h | 255 ------ 20 files changed, 118 insertions(+), 2428 deletions(-) create mode 100644 extensions/ExtensionDeprecated.cpp create mode 100644 extensions/ExtensionDeprecated.h delete mode 100644 extensions/GUI/CCControlExtension/CCScale9Sprite.cpp delete mode 100644 extensions/GUI/CCControlExtension/CCScale9Sprite.h delete mode 100644 tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp delete mode 100644 tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h delete mode 100644 tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp delete mode 100644 tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 6e12365842..9482485163 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -948,7 +948,7 @@ 15AE1BC819AAE00000C27E9E /* AssetsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AAF5352180E3060000584C8 /* AssetsManager.h */; }; 15AE1BC919AAE01E00C27E9E /* CCControl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168351807AF4E005B8026 /* CCControl.cpp */; }; 15AE1BCA19AAE01E00C27E9E /* CCControl.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168361807AF4E005B8026 /* CCControl.h */; }; - 15AE1BCB19AAE01E00C27E9E /* CCControlButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168371807AF4E005B8026 /* CCControlButton.cpp */; }; + 15AE1BCB19AAE01E00C27E9E /* CCControlButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168371807AF4E005B8026 /* CCControlButton.cpp */; settings = {COMPILER_FLAGS = "-w -Xanalyzer -analyzer-disable-checker"; }; }; 15AE1BCC19AAE01E00C27E9E /* CCControlButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168381807AF4E005B8026 /* CCControlButton.h */; }; 15AE1BCD19AAE01E00C27E9E /* CCControlColourPicker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168391807AF4E005B8026 /* CCControlColourPicker.cpp */; }; 15AE1BCE19AAE01E00C27E9E /* CCControlColourPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1683A1807AF4E005B8026 /* CCControlColourPicker.h */; }; @@ -969,8 +969,6 @@ 15AE1BDD19AAE01E00C27E9E /* CCControlUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168491807AF4E005B8026 /* CCControlUtils.h */; }; 15AE1BDE19AAE01E00C27E9E /* CCInvocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684A1807AF4E005B8026 /* CCInvocation.cpp */; }; 15AE1BDF19AAE01E00C27E9E /* CCInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1684B1807AF4E005B8026 /* CCInvocation.h */; }; - 15AE1BE019AAE01E00C27E9E /* CCScale9Sprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */; }; - 15AE1BE119AAE01E00C27E9E /* CCScale9Sprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */; }; 15AE1BE219AAE01E00C27E9E /* CCScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1685E1807AF4E005B8026 /* CCScrollView.cpp */; }; 15AE1BE319AAE01E00C27E9E /* CCScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1685F1807AF4E005B8026 /* CCScrollView.h */; }; 15AE1BE419AAE01E00C27E9E /* CCTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168621807AF4E005B8026 /* CCTableView.cpp */; }; @@ -1000,8 +998,6 @@ 15AE1BFC19AAE01E00C27E9E /* CCControlUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168491807AF4E005B8026 /* CCControlUtils.h */; }; 15AE1BFD19AAE01E00C27E9E /* CCInvocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684A1807AF4E005B8026 /* CCInvocation.cpp */; }; 15AE1BFE19AAE01E00C27E9E /* CCInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1684B1807AF4E005B8026 /* CCInvocation.h */; }; - 15AE1BFF19AAE01E00C27E9E /* CCScale9Sprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */; }; - 15AE1C0019AAE01E00C27E9E /* CCScale9Sprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */; }; 15AE1C0119AAE01E00C27E9E /* CCScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A1685E1807AF4E005B8026 /* CCScrollView.cpp */; }; 15AE1C0219AAE01E00C27E9E /* CCScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A1685F1807AF4E005B8026 /* CCScrollView.h */; }; 15AE1C0319AAE01E00C27E9E /* CCTableView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A168621807AF4E005B8026 /* CCTableView.cpp */; }; @@ -1360,6 +1356,10 @@ 292DB14E19B4574100A80320 /* UIEditBoxImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13719B4574100A80320 /* UIEditBoxImplMac.mm */; }; 292DB14F19B4574100A80320 /* UIEditBoxImplNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */; }; 292DB15019B4574100A80320 /* UIEditBoxImplNone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */; }; + 292DB15F19B461CA00A80320 /* ExtensionDeprecated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB15D19B461CA00A80320 /* ExtensionDeprecated.cpp */; }; + 292DB16019B461CA00A80320 /* ExtensionDeprecated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 292DB15D19B461CA00A80320 /* ExtensionDeprecated.cpp */; }; + 292DB16119B461CA00A80320 /* ExtensionDeprecated.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB15E19B461CA00A80320 /* ExtensionDeprecated.h */; }; + 292DB16219B461CA00A80320 /* ExtensionDeprecated.h in Headers */ = {isa = PBXBuildFile; fileRef = 292DB15E19B461CA00A80320 /* ExtensionDeprecated.h */; }; 29394CF019B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; }; 29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; }; 29394CF219B01DBA00D2DE1A /* UIWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CED19B01DBA00D2DE1A /* UIWebView.mm */; }; @@ -2324,6 +2324,8 @@ 292DB13619B4574100A80320 /* UIEditBoxImplMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImplMac.h; sourceTree = ""; }; 292DB13719B4574100A80320 /* UIEditBoxImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIEditBoxImplMac.mm; sourceTree = ""; }; 292DB13819B4574100A80320 /* UIEditBoxImplNone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBoxImplNone.cpp; sourceTree = ""; }; + 292DB15D19B461CA00A80320 /* ExtensionDeprecated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtensionDeprecated.cpp; sourceTree = ""; }; + 292DB15E19B461CA00A80320 /* ExtensionDeprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtensionDeprecated.h; sourceTree = ""; }; 29394CEC19B01DBA00D2DE1A /* UIWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebView.h; sourceTree = ""; }; 29394CED19B01DBA00D2DE1A /* UIWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWebView.mm; sourceTree = ""; }; 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebViewImpl_iOS.h; sourceTree = ""; }; @@ -2425,8 +2427,6 @@ 46A168491807AF4E005B8026 /* CCControlUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCControlUtils.h; sourceTree = ""; }; 46A1684A1807AF4E005B8026 /* CCInvocation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCInvocation.cpp; sourceTree = ""; }; 46A1684B1807AF4E005B8026 /* CCInvocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCInvocation.h; sourceTree = ""; }; - 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCScale9Sprite.cpp; sourceTree = ""; }; - 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCScale9Sprite.h; sourceTree = ""; }; 46A1685E1807AF4E005B8026 /* CCScrollView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCScrollView.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 46A1685F1807AF4E005B8026 /* CCScrollView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCScrollView.h; sourceTree = ""; }; 46A168621807AF4E005B8026 /* CCTableView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCTableView.cpp; sourceTree = ""; }; @@ -4155,6 +4155,8 @@ 46A167981807AF4D005B8026 /* extensions */ = { isa = PBXGroup; children = ( + 292DB15D19B461CA00A80320 /* ExtensionDeprecated.cpp */, + 292DB15E19B461CA00A80320 /* ExtensionDeprecated.h */, 46A167D21807AF4D005B8026 /* cocos-ext.h */, 46A168321807AF4E005B8026 /* ExtensionMacros.h */, 1AAF5350180E305F000584C8 /* assets-manager */, @@ -4200,8 +4202,6 @@ 46A168491807AF4E005B8026 /* CCControlUtils.h */, 46A1684A1807AF4E005B8026 /* CCInvocation.cpp */, 46A1684B1807AF4E005B8026 /* CCInvocation.h */, - 46A1684C1807AF4E005B8026 /* CCScale9Sprite.cpp */, - 46A1684D1807AF4E005B8026 /* CCScale9Sprite.h */, ); path = CCControlExtension; sourceTree = ""; @@ -5037,7 +5037,6 @@ 50ABBEA11925AB6F00A911A9 /* CCScheduler.h in Headers */, 15AE1B6219AADA9900C27E9E /* UIButton.h in Headers */, 50ABBDB71925AB4100A911A9 /* CCTexture2D.h in Headers */, - 15AE1BE119AAE01E00C27E9E /* CCScale9Sprite.h in Headers */, 50ABBE811925AB6F00A911A9 /* CCEventType.h in Headers */, 1A57008F180BC5A10088DEC7 /* CCActionTiledGrid.h in Headers */, 15AE19A319AAD39600C27E9E /* TextBMFontReader.h in Headers */, @@ -5344,6 +5343,7 @@ 15AE18A919AAD33D00C27E9E /* CCSpriteLoader.h in Headers */, 15AE198419AAD36400C27E9E /* WidgetReaderProtocol.h in Headers */, 50ABBEC91925AB6F00A911A9 /* firePngData.h in Headers */, + 292DB16119B461CA00A80320 /* ExtensionDeprecated.h in Headers */, 503DD8F51926B0DB00CD74DD /* CCIMEDelegate.h in Headers */, 50ABBD5A1925AB0000A911A9 /* Vec2.h in Headers */, 15AE1BDB19AAE01E00C27E9E /* CCControlSwitch.h in Headers */, @@ -5465,6 +5465,7 @@ 46A171011807CECB005B8026 /* CCPhysicsJoint.h in Headers */, 46A170FD1807CECB005B8026 /* CCPhysicsBody.h in Headers */, 50ABBE9C1925AB6F00A911A9 /* CCRef.h in Headers */, + 292DB16219B461CA00A80320 /* ExtensionDeprecated.h in Headers */, 50ABBD961925AB4100A911A9 /* CCGLProgramState.h in Headers */, 46A171061807CECB005B8026 /* CCPhysicsWorld.h in Headers */, 50ABBDB41925AB4100A911A9 /* ccShaders.h in Headers */, @@ -5839,7 +5840,6 @@ 15AE198019AAD35700C27E9E /* CCTimeLine.h in Headers */, 50ABBD4F1925AB0000A911A9 /* MathUtil.h in Headers */, 1A01C69718F57BE800EFE3A6 /* CCInteger.h in Headers */, - 15AE1C0019AAE01E00C27E9E /* CCScale9Sprite.h in Headers */, 15AE1C0619AAE01E00C27E9E /* CCTableViewCell.h in Headers */, 15AE19AB19AAD39700C27E9E /* ListViewReader.h in Headers */, 50ABBEBE1925AB6F00A911A9 /* ccUtils.h in Headers */, @@ -6211,6 +6211,7 @@ 1A570202180BCBD40088DEC7 /* CCClippingNode.cpp in Sources */, 1A570208180BCBDF0088DEC7 /* CCMotionStreak.cpp in Sources */, 1A570210180BCBF40088DEC7 /* CCProgressTimer.cpp in Sources */, + 292DB15F19B461CA00A80320 /* ExtensionDeprecated.cpp in Sources */, 292DB14D19B4574100A80320 /* UIEditBoxImplMac.mm in Sources */, 50ABBDB51925AB4100A911A9 /* CCTexture2D.cpp in Sources */, 1A570214180BCBF40088DEC7 /* CCRenderTexture.cpp in Sources */, @@ -6230,7 +6231,6 @@ 1A570286180BCC900088DEC7 /* CCSpriteFrame.cpp in Sources */, B24AA989195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */, 15AE199619AAD39600C27E9E /* ListViewReader.cpp in Sources */, - 15AE1BE019AAE01E00C27E9E /* CCScale9Sprite.cpp in Sources */, 50ABC0191926664800A911A9 /* CCSAXParser.cpp in Sources */, 15AE1B1419AAD43700C27E9E /* cpPinJoint.c in Sources */, 15AE189219AAD33D00C27E9E /* CCLayerGradientLoader.cpp in Sources */, @@ -6628,6 +6628,7 @@ 15AE1AB019AAD40300C27E9E /* b2ChainAndPolygonContact.cpp in Sources */, 1A5701B2180BCB590088DEC7 /* CCFontFNT.cpp in Sources */, 1A5701B6180BCB590088DEC7 /* CCFontFreeType.cpp in Sources */, + 292DB16019B461CA00A80320 /* ExtensionDeprecated.cpp in Sources */, 50ABBEAC1925AB6F00A911A9 /* ccTypes.cpp in Sources */, 15AE196A19AAD35100C27E9E /* DictionaryHelper.cpp in Sources */, 15AE1A3F19AAD3D500C27E9E /* b2Collision.cpp in Sources */, @@ -6698,7 +6699,6 @@ 15AE182919AAD2F700C27E9E /* CCMeshSkin.cpp in Sources */, 15AE1BBD19AADFF000C27E9E /* SocketIO.cpp in Sources */, 15AE1A4319AAD3D500C27E9E /* b2DynamicTree.cpp in Sources */, - 15AE1BFF19AAE01E00C27E9E /* CCScale9Sprite.cpp in Sources */, 15AE1A3A19AAD3D500C27E9E /* b2BroadPhase.cpp in Sources */, 15AE19B619AAD39700C27E9E /* TextBMFontReader.cpp in Sources */, 15AE1BFD19AAE01E00C27E9E /* CCInvocation.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index cd6916594b..dec67dde2c 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -472,8 +472,6 @@ 1AC35BEE18CECF0C00F37B72 /* CCControlStepperTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7318CECF0B00F37B72 /* CCControlStepperTest.cpp */; }; 1AC35BEF18CECF0C00F37B72 /* CCControlSwitchTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7618CECF0B00F37B72 /* CCControlSwitchTest.cpp */; }; 1AC35BF018CECF0C00F37B72 /* CCControlSwitchTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7618CECF0B00F37B72 /* CCControlSwitchTest.cpp */; }; - 1AC35BF118CECF0C00F37B72 /* EditBoxTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7918CECF0B00F37B72 /* EditBoxTest.cpp */; }; - 1AC35BF218CECF0C00F37B72 /* EditBoxTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7918CECF0B00F37B72 /* EditBoxTest.cpp */; }; 1AC35BF318CECF0C00F37B72 /* ExtensionsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7B18CECF0B00F37B72 /* ExtensionsTest.cpp */; }; 1AC35BF418CECF0C00F37B72 /* ExtensionsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7B18CECF0B00F37B72 /* ExtensionsTest.cpp */; }; 1AC35BF518CECF0C00F37B72 /* HttpClientTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A7E18CECF0B00F37B72 /* HttpClientTest.cpp */; }; @@ -484,8 +482,6 @@ 1AC35BFA18CECF0C00F37B72 /* WebSocketTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8218CECF0B00F37B72 /* WebSocketTest.cpp */; }; 1AC35BFB18CECF0C00F37B72 /* NotificationCenterTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8518CECF0B00F37B72 /* NotificationCenterTest.cpp */; }; 1AC35BFC18CECF0C00F37B72 /* NotificationCenterTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8518CECF0B00F37B72 /* NotificationCenterTest.cpp */; }; - 1AC35BFD18CECF0C00F37B72 /* Scale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8818CECF0B00F37B72 /* Scale9SpriteTest.cpp */; }; - 1AC35BFE18CECF0C00F37B72 /* Scale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8818CECF0B00F37B72 /* Scale9SpriteTest.cpp */; }; 1AC35BFF18CECF0C00F37B72 /* CustomTableViewCell.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8B18CECF0B00F37B72 /* CustomTableViewCell.cpp */; }; 1AC35C0018CECF0C00F37B72 /* CustomTableViewCell.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8B18CECF0B00F37B72 /* CustomTableViewCell.cpp */; }; 1AC35C0118CECF0C00F37B72 /* TableViewTestScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC35A8D18CECF0B00F37B72 /* TableViewTestScene.cpp */; }; @@ -2557,8 +2553,6 @@ 1AC35A7418CECF0B00F37B72 /* CCControlStepperTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCControlStepperTest.h; sourceTree = ""; }; 1AC35A7618CECF0B00F37B72 /* CCControlSwitchTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCControlSwitchTest.cpp; sourceTree = ""; }; 1AC35A7718CECF0B00F37B72 /* CCControlSwitchTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCControlSwitchTest.h; sourceTree = ""; }; - 1AC35A7918CECF0B00F37B72 /* EditBoxTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditBoxTest.cpp; sourceTree = ""; }; - 1AC35A7A18CECF0B00F37B72 /* EditBoxTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditBoxTest.h; sourceTree = ""; }; 1AC35A7B18CECF0B00F37B72 /* ExtensionsTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtensionsTest.cpp; sourceTree = ""; }; 1AC35A7C18CECF0B00F37B72 /* ExtensionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtensionsTest.h; sourceTree = ""; }; 1AC35A7E18CECF0B00F37B72 /* HttpClientTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HttpClientTest.cpp; sourceTree = ""; }; @@ -2569,8 +2563,6 @@ 1AC35A8318CECF0B00F37B72 /* WebSocketTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketTest.h; sourceTree = ""; }; 1AC35A8518CECF0B00F37B72 /* NotificationCenterTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NotificationCenterTest.cpp; sourceTree = ""; }; 1AC35A8618CECF0B00F37B72 /* NotificationCenterTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotificationCenterTest.h; sourceTree = ""; }; - 1AC35A8818CECF0B00F37B72 /* Scale9SpriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Scale9SpriteTest.cpp; sourceTree = ""; }; - 1AC35A8918CECF0B00F37B72 /* Scale9SpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scale9SpriteTest.h; sourceTree = ""; }; 1AC35A8B18CECF0B00F37B72 /* CustomTableViewCell.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomTableViewCell.cpp; sourceTree = ""; }; 1AC35A8C18CECF0B00F37B72 /* CustomTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomTableViewCell.h; sourceTree = ""; }; 1AC35A8D18CECF0B00F37B72 /* TableViewTestScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TableViewTestScene.cpp; sourceTree = ""; }; @@ -5777,12 +5769,10 @@ 1AC359DF18CECF0B00F37B72 /* CocoStudioComponentsTest */, 1AC35A5818CECF0B00F37B72 /* CocoStudioSceneTest */, 1AC35A6118CECF0B00F37B72 /* ControlExtensionTest */, - 1AC35A7818CECF0B00F37B72 /* EditBoxTest */, 1AC35A7B18CECF0B00F37B72 /* ExtensionsTest.cpp */, 1AC35A7C18CECF0B00F37B72 /* ExtensionsTest.h */, 1AC35A7D18CECF0B00F37B72 /* NetworkTest */, 1AC35A8418CECF0B00F37B72 /* NotificationCenterTest */, - 1AC35A8718CECF0B00F37B72 /* Scale9SpriteTest */, 1AC35A8A18CECF0B00F37B72 /* TableViewTest */, ); path = ExtensionsTest; @@ -6024,15 +6014,6 @@ path = CCControlSwitchTest; sourceTree = ""; }; - 1AC35A7818CECF0B00F37B72 /* EditBoxTest */ = { - isa = PBXGroup; - children = ( - 1AC35A7918CECF0B00F37B72 /* EditBoxTest.cpp */, - 1AC35A7A18CECF0B00F37B72 /* EditBoxTest.h */, - ); - path = EditBoxTest; - sourceTree = ""; - }; 1AC35A7D18CECF0B00F37B72 /* NetworkTest */ = { isa = PBXGroup; children = ( @@ -6055,15 +6036,6 @@ path = NotificationCenterTest; sourceTree = ""; }; - 1AC35A8718CECF0B00F37B72 /* Scale9SpriteTest */ = { - isa = PBXGroup; - children = ( - 1AC35A8818CECF0B00F37B72 /* Scale9SpriteTest.cpp */, - 1AC35A8918CECF0B00F37B72 /* Scale9SpriteTest.h */, - ); - path = Scale9SpriteTest; - sourceTree = ""; - }; 1AC35A8A18CECF0B00F37B72 /* TableViewTest */ = { isa = PBXGroup; children = ( @@ -7976,7 +7948,6 @@ 1AC35B6718CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */, 29080DB7191B595E0066F8DF /* UIListViewTest_Editor.cpp in Sources */, 1AC35BF918CECF0C00F37B72 /* WebSocketTest.cpp in Sources */, - 1AC35BF118CECF0C00F37B72 /* EditBoxTest.cpp in Sources */, 1AC35B3918CECF0C00F37B72 /* Bug-1174.cpp in Sources */, 1AC35BE318CECF0C00F37B72 /* CCControlColourPickerTest.cpp in Sources */, 29080DB1191B595E0066F8DF /* UILayoutTest.cpp in Sources */, @@ -8027,7 +7998,6 @@ 29080DD1191B595E0066F8DF /* UISliderTest_Editor.cpp in Sources */, 1AC35B2718CECF0C00F37B72 /* ActionsTest.cpp in Sources */, 1AC35C4918CECF0C00F37B72 /* ShaderTest.cpp in Sources */, - 1AC35BFD18CECF0C00F37B72 /* Scale9SpriteTest.cpp in Sources */, 1AC35B4318CECF0C00F37B72 /* Bug-624.cpp in Sources */, 1AC35BF718CECF0C00F37B72 /* SocketIOTest.cpp in Sources */, 1AC35C4F18CECF0C00F37B72 /* SpriteTest.cpp in Sources */, @@ -8173,7 +8143,6 @@ 1AC35B6818CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */, 29080D8E191B595E0066F8DF /* CocosGUIScene.cpp in Sources */, 1AC35BFA18CECF0C00F37B72 /* WebSocketTest.cpp in Sources */, - 1AC35BF218CECF0C00F37B72 /* EditBoxTest.cpp in Sources */, 38FA2E74194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp in Sources */, 2958245A1987415900F9746D /* UIScale9SpriteTest.cpp in Sources */, 1AC35B3A18CECF0C00F37B72 /* Bug-1174.cpp in Sources */, @@ -8231,7 +8200,6 @@ 292CF01519A1965E00E8E6A0 /* UIEditBoxTest.cpp in Sources */, 1AC35B2818CECF0C00F37B72 /* ActionsTest.cpp in Sources */, 1AC35C4A18CECF0C00F37B72 /* ShaderTest.cpp in Sources */, - 1AC35BFE18CECF0C00F37B72 /* Scale9SpriteTest.cpp in Sources */, C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */, 1AC35B4418CECF0C00F37B72 /* Bug-624.cpp in Sources */, 1AC35BF818CECF0C00F37B72 /* SocketIOTest.cpp in Sources */, diff --git a/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.cpp b/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.cpp index 2089898058..186708fc34 100644 --- a/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.cpp @@ -19,7 +19,7 @@ namespace cocosbuilder { void Scale9SpriteLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char * pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) { if(strcmp(pPropertyName, PROPERTY_SPRITEFRAME) == 0) { - ((Scale9Sprite *)pNode)->setSpriteFrame(pSpriteFrame); + ((cocos2d::ui::Scale9Sprite *)pNode)->setSpriteFrame(pSpriteFrame); } else { NodeLoader::onHandlePropTypeSpriteFrame(pNode, pParent, pPropertyName, pSpriteFrame, ccbReader); } @@ -27,7 +27,7 @@ void Scale9SpriteLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParen void Scale9SpriteLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char * pPropertyName, Color3B pColor3B, CCBReader * ccbReader) { if(strcmp(pPropertyName, PROPERTY_COLOR) == 0) { - ((Scale9Sprite *)pNode)->setColor(pColor3B); + ((cocos2d::ui::Scale9Sprite *)pNode)->setColor(pColor3B); } else { NodeLoader::onHandlePropTypeColor3(pNode, pParent, pPropertyName, pColor3B, ccbReader); } @@ -35,7 +35,7 @@ void Scale9SpriteLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, co void Scale9SpriteLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const char * pPropertyName, unsigned char pByte, CCBReader * ccbReader) { if(strcmp(pPropertyName, PROPERTY_OPACITY) == 0) { - ((Scale9Sprite *)pNode)->setOpacity(pByte); + ((cocos2d::ui::Scale9Sprite *)pNode)->setOpacity(pByte); } else { NodeLoader::onHandlePropTypeByte(pNode, pParent, pPropertyName, pByte, ccbReader); } @@ -54,7 +54,7 @@ void Scale9SpriteLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, cons if(strcmp(pPropertyName, PROPERTY_CONTENTSIZE) == 0) { //((Scale9Sprite *)pNode)->setContentSize(pSize); } else if(strcmp(pPropertyName, PROPERTY_PREFEREDSIZE) == 0) { - ((Scale9Sprite *)pNode)->setPreferredSize(pSize); + ((cocos2d::ui::Scale9Sprite *)pNode)->setPreferredSize(pSize); } else { NodeLoader::onHandlePropTypeSize(pNode, pParent, pPropertyName, pSize, ccbReader); } @@ -62,13 +62,13 @@ void Scale9SpriteLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, cons void Scale9SpriteLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const char * pPropertyName, float pFloat, CCBReader * ccbReader) { if(strcmp(pPropertyName, PROPERTY_INSETLEFT) == 0) { - ((Scale9Sprite *)pNode)->setInsetLeft(pFloat); + ((cocos2d::ui::Scale9Sprite *)pNode)->setInsetLeft(pFloat); } else if(strcmp(pPropertyName, PROPERTY_INSETTOP) == 0) { - ((Scale9Sprite *)pNode)->setInsetTop(pFloat); + ((cocos2d::ui::Scale9Sprite *)pNode)->setInsetTop(pFloat); } else if(strcmp(pPropertyName, PROPERTY_INSETRIGHT) == 0) { - ((Scale9Sprite *)pNode)->setInsetRight(pFloat); + ((cocos2d::ui::Scale9Sprite *)pNode)->setInsetRight(pFloat); } else if(strcmp(pPropertyName, PROPERTY_INSETBOTTOM) == 0) { - ((Scale9Sprite *)pNode)->setInsetBottom(pFloat); + ((cocos2d::ui::Scale9Sprite *)pNode)->setInsetBottom(pFloat); } else { NodeLoader::onHandlePropTypeFloat(pNode, pParent, pPropertyName, pFloat, ccbReader); } diff --git a/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.h b/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.h index 70f7e1816b..35bf229776 100644 --- a/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.h +++ b/cocos/editor-support/cocosbuilder/CCScale9SpriteLoader.h @@ -3,7 +3,7 @@ #include "CCNodeLoader.h" #include "CCScale9SpriteLoader.h" -#include "extensions/GUI/CCControlExtension/CCScale9Sprite.h" +#include "ui/UIScale9Sprite.h" namespace cocosbuilder { @@ -28,8 +28,8 @@ protected: * @js NA * @lua NA */ - virtual cocos2d::extension::Scale9Sprite * createNode(cocos2d::Node * pParent, cocosbuilder::CCBReader * ccbReader) { - cocos2d::extension::Scale9Sprite* pNode = cocos2d::extension::Scale9Sprite::create(); + virtual cocos2d::ui::Scale9Sprite * createNode(cocos2d::Node * pParent, cocosbuilder::CCBReader * ccbReader) { + cocos2d::ui::Scale9Sprite* pNode = cocos2d::ui::Scale9Sprite::create(); pNode->setAnchorPoint(cocos2d::Vec2::ZERO); diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index 221315e578..a76af6d91a 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -33,6 +33,9 @@ UIDeprecated.cpp \ UIScale9Sprite.cpp \ UIWebView.cpp \ UIWebViewImpl_android.cpp \ +UIEditBox/UIEditBox.cpp \ +UIEditBox/UIEditBoxImplAndroid.cpp \ + LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \ $(LOCAL_PATH)/../editor-support diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index a7071c3729..13f6f2f92d 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -140,11 +140,28 @@ namespace ui { return true; } + bool Scale9Sprite::initWithBatchNode(cocos2d::SpriteBatchNode *batchnode, const cocos2d::Rect &rect, bool rotated, const cocos2d::Rect &capInsets) + { + Sprite *sprite = Sprite::createWithTexture(batchnode->getTexture()); + return init(sprite, rect, rotated, capInsets); + } + + bool Scale9Sprite::initWithBatchNode(cocos2d::SpriteBatchNode *batchnode, const cocos2d::Rect &rect, const cocos2d::Rect &capInsets) + { + return initWithBatchNode(batchnode, rect, false, capInsets); + } + #define TRANSLATE_X(x, y, xtranslate) \ x+=xtranslate; \ #define TRANSLATE_Y(x, y, ytranslate) \ -y+=ytranslate; \ +y+=ytranslate; \ + + bool Scale9Sprite::updateWithBatchNode(cocos2d::SpriteBatchNode *batchnode, const cocos2d::Rect &originalRect, bool rotated, const cocos2d::Rect &capInsets) + { + Sprite *sprite = Sprite::createWithTexture(batchnode->getTexture()); + return this->updateWithSprite(sprite, originalRect, rotated, capInsets); + } bool Scale9Sprite::updateWithSprite(Sprite* sprite, const Rect& originalRect, bool rotated, const Rect& capInsets) { diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index da54df5de0..6a0d8b7e4f 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -69,6 +69,7 @@ namespace ui { */ static Scale9Sprite* create(const std::string& file, const Rect& rect, const Rect& capInsets); + /** * Creates a 9-slice sprite with a texture file. The whole texture will be * broken down into a 3×3 grid of equal blocks. @@ -233,6 +234,9 @@ namespace ui { virtual bool init(); virtual bool init(Sprite* sprite, const Rect& rect, bool rotated, const Rect& capInsets); virtual bool init(Sprite* sprite, const Rect& rect, const Rect& capInsets); + CC_DEPRECATED_ATTRIBUTE virtual bool initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, bool rotated, const Rect& capInsets); + CC_DEPRECATED_ATTRIBUTE virtual bool initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, const Rect& capInsets); + /** * Creates and returns a new sprite object with the specified cap insets. * You use this method to add cap insets to a sprite or to change the existing @@ -244,6 +248,8 @@ namespace ui { Scale9Sprite* resizableSpriteWithCapInsets(const Rect& capInsets); virtual bool updateWithSprite(Sprite* sprite, const Rect& rect, bool rotated, const Rect& capInsets); + CC_DEPRECATED_ATTRIBUTE bool updateWithBatchNode(SpriteBatchNode* batchnode, const Rect& originalRect, bool rotated, const Rect& capInsets); + virtual void setSpriteFrame(SpriteFrame * spriteFrame); // overrides diff --git a/extensions/ExtensionDeprecated.cpp b/extensions/ExtensionDeprecated.cpp new file mode 100644 index 0000000000..d3e3e65e5d --- /dev/null +++ b/extensions/ExtensionDeprecated.cpp @@ -0,0 +1,25 @@ +/**************************************************************************** + 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 "ExtensionDeprecated.h" diff --git a/extensions/ExtensionDeprecated.h b/extensions/ExtensionDeprecated.h new file mode 100644 index 0000000000..8abdf919b6 --- /dev/null +++ b/extensions/ExtensionDeprecated.h @@ -0,0 +1,39 @@ +/**************************************************************************** + 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 __cocos2d_libs__ExtensionDeprecated__ +#define __cocos2d_libs__ExtensionDeprecated__ + +#include "ui/UIEditBox/UIEditBox.h" +#include "ExtensionMacros.h" + +NS_CC_EXT_BEGIN + +CC_DEPRECATED_ATTRIBUTE typedef ui::EditBox EditBox; +CC_DEPRECATED_ATTRIBUTE typedef ui::EditBoxDelegate EditBoxDelegate; +CC_DEPRECATED_ATTRIBUTE typedef ui::Scale9Sprite Scale9Sprite; + +NS_CC_EXT_END + +#endif /* defined(__cocos2d_libs__ExtensionDeprecated__) */ diff --git a/extensions/GUI/CCControlExtension/CCControlButton.cpp b/extensions/GUI/CCControlExtension/CCControlButton.cpp index f7cc5b71b6..91599ae386 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.cpp +++ b/extensions/GUI/CCControlExtension/CCControlButton.cpp @@ -26,7 +26,6 @@ */ #include "CCControlButton.h" -#include "CCScale9Sprite.h" #include "2d/CCLabel.h" #include "2d/CCAction.h" #include "2d/CCActionInterval.h" diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index f7484e2172..2c58a59311 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -32,9 +32,8 @@ #include "CCControl.h" #include "CCInvocation.h" -#include "CCScale9Sprite.h" +#include "ExtensionDeprecated.h" #include "base/CCMap.h" -#include "extensions/ExtensionExport.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCControlExtension/CCControlExtensions.h b/extensions/GUI/CCControlExtension/CCControlExtensions.h index c4548bf535..2cbae97035 100644 --- a/extensions/GUI/CCControlExtension/CCControlExtensions.h +++ b/extensions/GUI/CCControlExtension/CCControlExtensions.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __CCCONTROL_EXTENSIONS_H__ #define __CCCONTROL_EXTENSIONS_H__ -#include "CCScale9Sprite.h" #include "CCControl.h" #include "CCControlButton.h" #include "CCControlColourPicker.h" diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp deleted file mode 100644 index 021de0489e..0000000000 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ /dev/null @@ -1,816 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012 cocos2d-x.org - -http://www.cocos2d-x.org - -Created by Jung Sang-Taik on 12. 3. 16.. -Copyright (c) 2012 Neofect. All rights reserved. - -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 "CCScale9Sprite.h" -#include "base/CCPlatformMacros.h" -#include "2d/CCSprite.h" -#include "2d/CCSpriteFrameCache.h" - -NS_CC_EXT_BEGIN - -Scale9Sprite::Scale9Sprite() -: _spritesGenerated(false) -, _spriteFrameRotated(false) -, _positionsAreDirty(false) -, _scale9Image(nullptr) -, _topLeft(nullptr) -, _top(nullptr) -, _topRight(nullptr) -, _left(nullptr) -, _centre(nullptr) -, _right(nullptr) -, _bottomLeft(nullptr) -, _bottom(nullptr) -, _bottomRight(nullptr) -, _opacityModifyRGB(false) -, _insetLeft(0) -, _insetTop(0) -, _insetRight(0) -, _insetBottom(0) -{ - -} - -Scale9Sprite::~Scale9Sprite() -{ - CC_SAFE_RELEASE(_topLeft); - CC_SAFE_RELEASE(_top); - CC_SAFE_RELEASE(_topRight); - CC_SAFE_RELEASE(_left); - CC_SAFE_RELEASE(_centre); - CC_SAFE_RELEASE(_right); - CC_SAFE_RELEASE(_bottomLeft); - CC_SAFE_RELEASE(_bottom); - CC_SAFE_RELEASE(_bottomRight); - CC_SAFE_RELEASE(_scale9Image); -} - -bool Scale9Sprite::init() -{ - return this->initWithBatchNode(nullptr, Rect::ZERO, Rect::ZERO); -} - -bool Scale9Sprite::initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, const Rect& capInsets) -{ - return this->initWithBatchNode(batchnode, rect, false, capInsets); -} - -bool Scale9Sprite::initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, bool rotated, const Rect& capInsets) -{ - if(batchnode) - { - this->updateWithBatchNode(batchnode, rect, rotated, capInsets); - } - this->setCascadeColorEnabled(true); - this->setCascadeOpacityEnabled(true); - this->setAnchorPoint(Vec2(0.5f, 0.5f)); - this->_positionsAreDirty = true; - - return true; -} - -#define TRANSLATE_X(x, y, xtranslate) \ - x+=xtranslate; \ - -#define TRANSLATE_Y(x, y, ytranslate) \ - y+=ytranslate; \ - -bool Scale9Sprite::updateWithBatchNode(SpriteBatchNode* batchnode, const Rect& originalRect, bool rotated, const Rect& capInsets) -{ - GLubyte opacity = getOpacity(); - Color3B color = getColor(); - Rect rect(originalRect); - - // Release old sprites - this->removeAllChildrenWithCleanup(true); - - CC_SAFE_RELEASE(this->_centre); - CC_SAFE_RELEASE(this->_top); - CC_SAFE_RELEASE(this->_topLeft); - CC_SAFE_RELEASE(this->_topRight); - CC_SAFE_RELEASE(this->_left); - CC_SAFE_RELEASE(this->_right); - CC_SAFE_RELEASE(this->_bottomLeft); - CC_SAFE_RELEASE(this->_bottom); - CC_SAFE_RELEASE(this->_bottomRight); - - - if(this->_scale9Image != batchnode) - { - CC_SAFE_RELEASE(this->_scale9Image); - _scale9Image = batchnode; - CC_SAFE_RETAIN(_scale9Image); - } - - if (!_scale9Image) - { - return false; - } - - _capInsets = capInsets; - _spriteFrameRotated = rotated; - - // If there is no given rect - if ( rect.equals(Rect::ZERO) ) - { - // Get the texture size as original - Size textureSize = _scale9Image->getTextureAtlas()->getTexture()->getContentSize(); - - rect = Rect(0, 0, textureSize.width, textureSize.height); - } - - // Set the given rect's size as original size - _spriteRect = rect; - _originalSize = rect.size; - _preferredSize = _originalSize; - _capInsetsInternal = capInsets; - - float w = rect.size.width; - float h = rect.size.height; - - // If there is no specified center region - if ( _capInsetsInternal.equals(Rect::ZERO) ) - { - // log("... cap insets not specified : using default cap insets ..."); - _capInsetsInternal = Rect(w/3, h/3, w/3, h/3); - } - - float left_w = _capInsetsInternal.origin.x; - float center_w = _capInsetsInternal.size.width; - float right_w = rect.size.width - (left_w + center_w); - - float top_h = _capInsetsInternal.origin.y; - float center_h = _capInsetsInternal.size.height; - float bottom_h = rect.size.height - (top_h + center_h); - - // calculate rects - - // ... top row - float x = 0.0; - float y = 0.0; - - // top left - Rect lefttopbounds = Rect(x, y, left_w, top_h); - - // top center - TRANSLATE_X(x, y, left_w); - Rect centertopbounds = Rect(x, y, center_w, top_h); - - // top right - TRANSLATE_X(x, y, center_w); - Rect righttopbounds = Rect(x, y, right_w, top_h); - - // ... center row - x = 0.0; - y = 0.0; - TRANSLATE_Y(x, y, top_h); - - // center left - Rect leftcenterbounds = Rect(x, y, left_w, center_h); - - // center center - TRANSLATE_X(x, y, left_w); - Rect centerbounds = Rect(x, y, center_w, center_h); - - // center right - TRANSLATE_X(x, y, center_w); - Rect rightcenterbounds = Rect(x, y, right_w, center_h); - - // ... bottom row - x = 0.0; - y = 0.0; - TRANSLATE_Y(x, y, top_h); - TRANSLATE_Y(x, y, center_h); - - // bottom left - Rect leftbottombounds = Rect(x, y, left_w, bottom_h); - - // bottom center - TRANSLATE_X(x, y, left_w); - Rect centerbottombounds = Rect(x, y, center_w, bottom_h); - - // bottom right - TRANSLATE_X(x, y, center_w); - Rect rightbottombounds = Rect(x, y, right_w, bottom_h); - - if (!rotated) { - // log("!rotated"); - - AffineTransform t = AffineTransform::IDENTITY; - t = AffineTransformTranslate(t, rect.origin.x, rect.origin.y); - - centerbounds = RectApplyAffineTransform(centerbounds, t); - rightbottombounds = RectApplyAffineTransform(rightbottombounds, t); - leftbottombounds = RectApplyAffineTransform(leftbottombounds, t); - righttopbounds = RectApplyAffineTransform(righttopbounds, t); - lefttopbounds = RectApplyAffineTransform(lefttopbounds, t); - rightcenterbounds = RectApplyAffineTransform(rightcenterbounds, t); - leftcenterbounds = RectApplyAffineTransform(leftcenterbounds, t); - centerbottombounds = RectApplyAffineTransform(centerbottombounds, t); - centertopbounds = RectApplyAffineTransform(centertopbounds, t); - - // Centre - _centre = Sprite::createWithTexture(_scale9Image->getTexture(), centerbounds); - _centre->retain(); - this->addChild(_centre); - - - // Top - _top = Sprite::createWithTexture(_scale9Image->getTexture(), centertopbounds); - _top->retain(); - this->addChild(_top); - - // Bottom - _bottom = Sprite::createWithTexture(_scale9Image->getTexture(), centerbottombounds); - _bottom->retain(); - this->addChild(_bottom); - - // Left - _left = Sprite::createWithTexture(_scale9Image->getTexture(), leftcenterbounds); - _left->retain(); - this->addChild(_left); - - // Right - _right = Sprite::createWithTexture(_scale9Image->getTexture(), rightcenterbounds); - _right->retain(); - this->addChild(_right); - - // Top left - _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), lefttopbounds); - _topLeft->retain(); - this->addChild(_topLeft); - - // Top right - _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), righttopbounds); - _topRight->retain(); - this->addChild(_topRight); - - // Bottom left - _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), leftbottombounds); - _bottomLeft->retain(); - this->addChild(_bottomLeft); - - // Bottom right - _bottomRight = Sprite::createWithTexture(_scale9Image->getTexture(), rightbottombounds); - _bottomRight->retain(); - this->addChild(_bottomRight); - } else { - // set up transformation of coordinates - // to handle the case where the sprite is stored rotated - // in the spritesheet - // log("rotated"); - - AffineTransform t = AffineTransform::IDENTITY; - - Rect rotatedcenterbounds = centerbounds; - Rect rotatedrightbottombounds = rightbottombounds; - Rect rotatedleftbottombounds = leftbottombounds; - Rect rotatedrighttopbounds = righttopbounds; - Rect rotatedlefttopbounds = lefttopbounds; - Rect rotatedrightcenterbounds = rightcenterbounds; - Rect rotatedleftcenterbounds = leftcenterbounds; - Rect rotatedcenterbottombounds = centerbottombounds; - Rect rotatedcentertopbounds = centertopbounds; - - t = AffineTransformTranslate(t, rect.size.height+rect.origin.x, rect.origin.y); - t = AffineTransformRotate(t, 1.57079633f); - - centerbounds = RectApplyAffineTransform(centerbounds, t); - rightbottombounds = RectApplyAffineTransform(rightbottombounds, t); - leftbottombounds = RectApplyAffineTransform(leftbottombounds, t); - righttopbounds = RectApplyAffineTransform(righttopbounds, t); - lefttopbounds = RectApplyAffineTransform(lefttopbounds, t); - rightcenterbounds = RectApplyAffineTransform(rightcenterbounds, t); - leftcenterbounds = RectApplyAffineTransform(leftcenterbounds, t); - centerbottombounds = RectApplyAffineTransform(centerbottombounds, t); - centertopbounds = RectApplyAffineTransform(centertopbounds, t); - - rotatedcenterbounds.origin = centerbounds.origin; - rotatedrightbottombounds.origin = rightbottombounds.origin; - rotatedleftbottombounds.origin = leftbottombounds.origin; - rotatedrighttopbounds.origin = righttopbounds.origin; - rotatedlefttopbounds.origin = lefttopbounds.origin; - rotatedrightcenterbounds.origin = rightcenterbounds.origin; - rotatedleftcenterbounds.origin = leftcenterbounds.origin; - rotatedcenterbottombounds.origin = centerbottombounds.origin; - rotatedcentertopbounds.origin = centertopbounds.origin; - - // Centre - _centre = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, true); - _centre->retain(); - this->addChild(_centre, 0); - - // Top - _top = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, true); - _top->retain(); - this->addChild(_top); - - // Bottom - _bottom = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, true); - _bottom->retain(); - this->addChild(_bottom); - - // Left - _left = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, true); - _left->retain(); - this->addChild(_left); - - // Right - _right = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, true); - _right->retain(); - this->addChild(_right); - - // Top left - _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, true); - _topLeft->retain(); - this->addChild(_topLeft); - - // Top right - _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, true); - _topRight->retain(); - this->addChild(_topRight); - - // Bottom left - _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, true); - _bottomLeft->retain(); - this->addChild(_bottomLeft); - - // Bottom right - _bottomRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightbottombounds, true); - _bottomRight->retain(); - this->addChild(_bottomRight); - } - - this->setContentSize(rect.size); -// this->addChild(_scale9Image); - - if (_spritesGenerated) - { - // Restore color and opacity - this->setOpacity(opacity); - this->setColor(color); - } - _spritesGenerated = true; - - return true; -} - -void Scale9Sprite::setContentSize(const Size &size) -{ - Node::setContentSize(size); - this->_positionsAreDirty = true; -} - -void Scale9Sprite::updatePositions() -{ - // Check that instances are non-nullptr - if(!((_topLeft) && - (_topRight) && - (_bottomRight) && - (_bottomLeft) && - (_centre))) { - // if any of the above sprites are nullptr, return - return; - } - - Size size = this->_contentSize; - - float sizableWidth = size.width - _topLeft->getContentSize().width - _topRight->getContentSize().width; - float sizableHeight = size.height - _topLeft->getContentSize().height - _bottomRight->getContentSize().height; - - float horizontalScale = sizableWidth/_centre->getContentSize().width; - float verticalScale = sizableHeight/_centre->getContentSize().height; - - _centre->setScaleX(horizontalScale); - _centre->setScaleY(verticalScale); - - float rescaledWidth = _centre->getContentSize().width * horizontalScale; - float rescaledHeight = _centre->getContentSize().height * verticalScale; - - float leftWidth = _bottomLeft->getContentSize().width; - float bottomHeight = _bottomLeft->getContentSize().height; - - _bottomLeft->setAnchorPoint(Vec2(0,0)); - _bottomRight->setAnchorPoint(Vec2(0,0)); - _topLeft->setAnchorPoint(Vec2(0,0)); - _topRight->setAnchorPoint(Vec2(0,0)); - _left->setAnchorPoint(Vec2(0,0)); - _right->setAnchorPoint(Vec2(0,0)); - _top->setAnchorPoint(Vec2(0,0)); - _bottom->setAnchorPoint(Vec2(0,0)); - _centre->setAnchorPoint(Vec2(0,0)); - - // Position corners - _bottomLeft->setPosition(0,0); - _bottomRight->setPosition(leftWidth+rescaledWidth,0); - _topLeft->setPosition(0, bottomHeight+rescaledHeight); - _topRight->setPosition(leftWidth+rescaledWidth, bottomHeight+rescaledHeight); - - // Scale and position borders - _left->setPosition(0, bottomHeight); - _left->setScaleY(verticalScale); - _right->setPosition(leftWidth+rescaledWidth,bottomHeight); - _right->setScaleY(verticalScale); - _bottom->setPosition(leftWidth,0); - _bottom->setScaleX(horizontalScale); - _top->setPosition(leftWidth,bottomHeight+rescaledHeight); - _top->setScaleX(horizontalScale); - - // Position centre - _centre->setPosition(leftWidth, bottomHeight); -} - -bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets) -{ - SpriteBatchNode *batchnode = SpriteBatchNode::create(file, 9); - bool pReturn = this->initWithBatchNode(batchnode, rect, capInsets); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect, const Rect& capInsets) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithFile(file, rect, capInsets) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect) -{ - bool pReturn = this->initWithFile(file, rect, Rect::ZERO); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithFile(file, rect) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - - -bool Scale9Sprite::initWithFile(const Rect& capInsets, const std::string& file) -{ - bool pReturn = this->initWithFile(file, Rect::ZERO, capInsets); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const std::string& file) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithFile(capInsets, file) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -bool Scale9Sprite::initWithFile(const std::string& file) -{ - bool pReturn = this->initWithFile(file, Rect::ZERO); - return pReturn; - -} - -Scale9Sprite* Scale9Sprite::create(const std::string& file) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithFile(file) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -bool Scale9Sprite::initWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) -{ - Texture2D* texture = spriteFrame->getTexture(); - CCASSERT(texture != nullptr, "CCTexture must be not nil"); - - SpriteBatchNode *batchnode = SpriteBatchNode::createWithTexture(texture, 9); - CCASSERT(batchnode != nullptr, "CCSpriteBatchNode must be not nil"); - - bool pReturn = this->initWithBatchNode(batchnode, spriteFrame->getRect(), spriteFrame->isRotated(), capInsets); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame, capInsets) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} -bool Scale9Sprite::initWithSpriteFrame(SpriteFrame* spriteFrame) -{ - CCASSERT(spriteFrame != nullptr, "Invalid spriteFrame for sprite"); - bool pReturn = this->initWithSpriteFrame(spriteFrame, Rect::ZERO); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) -{ - CCASSERT((SpriteFrameCache::getInstance()) != nullptr, "SpriteFrameCache::getInstance() must be non-nullptr"); - - SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); - CCASSERT(frame != nullptr, "CCSpriteFrame must be non-nullptr"); - - if (nullptr == frame) return false; - - bool pReturn = this->initWithSpriteFrame(frame, capInsets); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName, capInsets) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) -{ - bool pReturn = this->initWithSpriteFrameName(spriteFrameName, Rect::ZERO); - return pReturn; -} - -Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - - log("Could not allocate Scale9Sprite()"); - return nullptr; - -} - -Scale9Sprite* Scale9Sprite::resizableSpriteWithCapInsets(const Rect& capInsets) -{ - Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); - if ( pReturn && pReturn->initWithBatchNode(_scale9Image, _spriteRect, capInsets) ) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -Scale9Sprite* Scale9Sprite::create() -{ - Scale9Sprite *pReturn = new (std::nothrow) Scale9Sprite(); - if (pReturn && pReturn->init()) - { - pReturn->autorelease(); - return pReturn; - } - CC_SAFE_DELETE(pReturn); - return nullptr; -} - -/** sets the opacity. - @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed. - Values goes from 0 to 255, where 255 means fully opaque. - */ - -void Scale9Sprite::setPreferredSize(Size preferedSize) -{ - this->setContentSize(preferedSize); - this->_preferredSize = preferedSize; -} - -Size Scale9Sprite::getPreferredSize() -{ - return this->_preferredSize; -} - -void Scale9Sprite::setCapInsets(Rect capInsets) -{ - Size contentSize = this->_contentSize; - this->updateWithBatchNode(this->_scale9Image, this->_spriteRect, _spriteFrameRotated, capInsets); - this->setContentSize(contentSize); -} - -Rect Scale9Sprite::getCapInsets() -{ - return _capInsets; -} - -void Scale9Sprite::updateCapInset() -{ - Rect insets; - if (this->_insetLeft == 0 && this->_insetTop == 0 && this->_insetRight == 0 && this->_insetBottom == 0) - { - insets = Rect::ZERO; - } - else - { - insets = Rect(_insetLeft, - _insetTop, - _spriteRect.size.width-_insetLeft-_insetRight, - _spriteRect.size.height-_insetTop-_insetBottom); - } - this->setCapInsets(insets); -} - -void Scale9Sprite::setOpacityModifyRGB(bool var) -{ - if (!_scale9Image) - { - return; - } - _opacityModifyRGB = var; - - for(auto child : _scale9Image->getChildren()){ - child->setOpacityModifyRGB(_opacityModifyRGB); - } -} - -bool Scale9Sprite::isOpacityModifyRGB() const -{ - return _opacityModifyRGB; -} - -void Scale9Sprite::setSpriteFrame(SpriteFrame * spriteFrame) -{ - SpriteBatchNode * batchnode = SpriteBatchNode::createWithTexture(spriteFrame->getTexture(), 9); - this->updateWithBatchNode(batchnode, spriteFrame->getRect(), spriteFrame->isRotated(), Rect::ZERO); - - // Reset insets - this->_insetLeft = 0; - this->_insetTop = 0; - this->_insetRight = 0; - this->_insetBottom = 0; -} - -float Scale9Sprite::getInsetLeft() -{ - return this->_insetLeft; -} - -float Scale9Sprite::getInsetTop() -{ - return this->_insetTop; -} - -float Scale9Sprite::getInsetRight() -{ - return this->_insetRight; -} - -float Scale9Sprite::getInsetBottom() -{ - return this->_insetBottom; -} - -void Scale9Sprite::setInsetLeft(float insetLeft) -{ - this->_insetLeft = insetLeft; - this->updateCapInset(); -} - -void Scale9Sprite::setInsetTop(float insetTop) -{ - this->_insetTop = insetTop; - this->updateCapInset(); -} - -void Scale9Sprite::setInsetRight(float insetRight) -{ - this->_insetRight = insetRight; - this->updateCapInset(); -} - -void Scale9Sprite::setInsetBottom(float insetBottom) -{ - this->_insetBottom = insetBottom; - this->updateCapInset(); -} - -void Scale9Sprite::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) -{ - if(this->_positionsAreDirty) - { - this->updatePositions(); - this->_positionsAreDirty = false; - } - Node::visit(renderer, parentTransform, parentFlags); -} - -void Scale9Sprite::setColor(const Color3B& color) -{ - if (!_scale9Image) - { - return; - } - - Node::setColor(color); - - for(auto child : _scale9Image->getChildren()){ - child->setColor(color); - } -} - -void Scale9Sprite::setOpacity(GLubyte opacity) -{ - if (!_scale9Image) - { - return; - } - Node::setOpacity(opacity); - - for(auto child : _scale9Image->getChildren()){ - child->setOpacity(opacity); - } -} - -void Scale9Sprite::updateDisplayedColor(const cocos2d::Color3B &parentColor) -{ - if (!_scale9Image) - { - return; - } - Node::updateDisplayedColor(parentColor); - - for(auto child : _scale9Image->getChildren()){ - child->updateDisplayedColor(parentColor); - } -} - -void Scale9Sprite::updateDisplayedOpacity(GLubyte parentOpacity) -{ - if (!_scale9Image) - { - return; - } - Node::updateDisplayedOpacity(parentOpacity); - - for(auto child : _scale9Image->getChildren()){ - child->updateDisplayedOpacity(parentOpacity); - } -} - -NS_CC_EXT_END diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.h b/extensions/GUI/CCControlExtension/CCScale9Sprite.h deleted file mode 100644 index fc1dea95ba..0000000000 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.h +++ /dev/null @@ -1,323 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012 cocos2d-x.org - -http://www.cocos2d-x.org - -Created by Jung Sang-Taik on 12. 3. 16.. -Copyright (c) 2012 Neofect. All rights reserved. - -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 __CCScale9Sprite_H__ -#define __CCScale9Sprite_H__ - -#include "2d/CCNode.h" -#include "2d/CCSpriteFrame.h" -#include "2d/CCSpriteBatchNode.h" -#include "extensions/ExtensionExport.h" -#include "../../ExtensionMacros.h" - -NS_CC_EXT_BEGIN - -/** - * @addtogroup GUI - * @{ - * @addtogroup control_extension - * @{ - */ - -/** - * A 9-slice sprite for cocos2d. - * - * 9-slice scaling allows you to specify how scaling is applied - * to specific areas of a sprite. With 9-slice scaling (3x3 grid), - * you can ensure that the sprite does not become distorted when - * scaled. - * - * @see http://yannickloriot.com/library/ios/cccontrolextension/Classes/CCScale9Sprite.html - */ -class CC_EX_DLL Scale9Sprite : public Node -{ -public: - /** - * @js ctor - */ - Scale9Sprite(); - /** - * @js NA - * @lua NA - */ - virtual ~Scale9Sprite(); - -public: - static Scale9Sprite* create(); - - /** - * Creates a 9-slice sprite with a texture file, a delimitation zone and - * with the specified cap insets. - * - * @see initWithFile(const char *file, const Rect& rect, const Rect& capInsets) - */ - static Scale9Sprite* create(const std::string& file, const Rect& rect, const Rect& capInsets); - - /** - * Creates a 9-slice sprite with a texture file. The whole texture will be - * broken down into a 3×3 grid of equal blocks. - * - * @see initWithFile(const Rect& capInsets, const char *file) - */ - static Scale9Sprite* create(const Rect& capInsets, const std::string& file); - - /** - * Creates a 9-slice sprite with a texture file and a delimitation zone. The - * texture will be broken down into a 3×3 grid of equal blocks. - * - * @see initWithFile(const char *file, const Rect& rect) - */ - static Scale9Sprite* create(const std::string& file, const Rect& rect); - - /** - * Creates a 9-slice sprite with a texture file. The whole texture will be - * broken down into a 3×3 grid of equal blocks. - * - * @see initWithFile(const char *file) - */ - static Scale9Sprite* create(const std::string& file); - - /** - * Creates a 9-slice sprite with an sprite frame. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @see initWithSpriteFrame(SpriteFrame *spriteFrame) - */ - static Scale9Sprite* createWithSpriteFrame(SpriteFrame* spriteFrame); - - /** - * Creates a 9-slice sprite with an sprite frame and the centre of its zone. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @see initWithSpriteFrame(SpriteFrame *spriteFrame, const Rect& capInsets) - */ - static Scale9Sprite* createWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets); - - /** - * Creates a 9-slice sprite with an sprite frame name. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @see initWithSpriteFrameName(const char *spriteFrameName) - */ - static Scale9Sprite* createWithSpriteFrameName(const std::string& spriteFrameName); - - /** - * Creates a 9-slice sprite with an sprite frame name and the centre of its - * zone. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @see initWithSpriteFrameName(const char *spriteFrameName, const Rect& capInsets) - */ - static Scale9Sprite* createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets); - - /** - * Initializes a 9-slice sprite with a texture file, a delimitation zone and - * with the specified cap insets. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param file The name of the texture file. - * @param rect The rectangle that describes the sub-part of the texture that - * is the whole image. If the shape is the whole texture, set this to the - * texture's full rect. - * @param capInsets The values to use for the cap insets. - */ - virtual bool initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets); - - /** - * Initializes a 9-slice sprite with a texture file and a delimitation zone. The - * texture will be broken down into a 3×3 grid of equal blocks. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param file The name of the texture file. - * @param rect The rectangle that describes the sub-part of the texture that - * is the whole image. If the shape is the whole texture, set this to the - * texture's full rect. - */ - virtual bool initWithFile(const std::string& file, const Rect& rect); - - /** - * Initializes a 9-slice sprite with a texture file and with the specified cap - * insets. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param file The name of the texture file. - * @param capInsets The values to use for the cap insets. - */ - virtual bool initWithFile(const Rect& capInsets, const std::string& file); - - /** - * Initializes a 9-slice sprite with a texture file. The whole texture will be - * broken down into a 3×3 grid of equal blocks. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param file The name of the texture file. - */ - virtual bool initWithFile(const std::string& file); - - /** - * Initializes a 9-slice sprite with an sprite frame and with the specified - * cap insets. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param spriteFrame The sprite frame object. - * @param capInsets The values to use for the cap insets. - */ - virtual bool initWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets); - - /** - * Initializes a 9-slice sprite with an sprite frame. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param spriteFrame The sprite frame object. - */ - virtual bool initWithSpriteFrame(SpriteFrame* spriteFrame); - - /** - * Initializes a 9-slice sprite with an sprite frame name and with the specified - * cap insets. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param spriteFrameName The sprite frame name. - * @param capInsets The values to use for the cap insets. - */ - virtual bool initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets); - - /** - * Initializes a 9-slice sprite with an sprite frame name. - * Once the sprite is created, you can then call its "setContentSize:" method - * to resize the sprite will all it's 9-slice goodness intract. - * It respects the anchorPoint too. - * - * @param spriteFrameName The sprite frame name. - */ - virtual bool initWithSpriteFrameName(const std::string& spriteFrameName); - - virtual bool init(); - virtual bool initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, bool rotated, const Rect& capInsets); - virtual bool initWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, const Rect& capInsets); - - /** - * Creates and returns a new sprite object with the specified cap insets. - * You use this method to add cap insets to a sprite or to change the existing - * cap insets of a sprite. In both cases, you get back a new image and the - * original sprite remains untouched. - * - * @param capInsets The values to use for the cap insets. - */ - Scale9Sprite* resizableSpriteWithCapInsets(const Rect& capInsets); - - virtual bool updateWithBatchNode(SpriteBatchNode* batchnode, const Rect& rect, bool rotated, const Rect& capInsets); - virtual void setSpriteFrame(SpriteFrame * spriteFrame); - - // overrides - virtual void setContentSize(const Size & size) override; - /** - * @js NA - * @lua NA - */ - virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; - virtual void setOpacityModifyRGB(bool bValue) override; - virtual bool isOpacityModifyRGB(void) const override; - virtual void setOpacity(GLubyte opacity) override; - virtual void setColor(const Color3B& color) override; - virtual void updateDisplayedOpacity(GLubyte parentOpacity) override; - virtual void updateDisplayedColor(const Color3B& parentColor) override; - -protected: - void updateCapInset(); - void updatePositions(); - - bool _spritesGenerated; - Rect _spriteRect; - bool _spriteFrameRotated; - Rect _capInsetsInternal; - bool _positionsAreDirty; - - SpriteBatchNode* _scale9Image; - Sprite* _topLeft; - Sprite* _top; - Sprite* _topRight; - Sprite* _left; - Sprite* _centre; - Sprite* _right; - Sprite* _bottomLeft; - Sprite* _bottom; - Sprite* _bottomRight; - - bool _opacityModifyRGB; - - /** Original sprite's size. */ - CC_SYNTHESIZE_READONLY(Size, _originalSize, OriginalSize); - /** Prefered sprite's size. By default the prefered size is the original size. */ - - //if the preferredSize component is given as -1, it is ignored - CC_PROPERTY(Size, _preferredSize, PreferredSize); - /** - * The end-cap insets. - * On a non-resizeable sprite, this property is set to CGRect::ZERO; the sprite - * does not use end caps and the entire sprite is subject to stretching. - */ - CC_PROPERTY(Rect, _capInsets, CapInsets); - /** Sets the left side inset */ - CC_PROPERTY(float, _insetLeft, InsetLeft); - /** Sets the top side inset */ - CC_PROPERTY(float, _insetTop, InsetTop); - /** Sets the right side inset */ - CC_PROPERTY(float, _insetRight, InsetRight); - /** Sets the bottom side inset */ - CC_PROPERTY(float, _insetBottom, InsetBottom); -}; - -// end of GUI group -/// @} -/// @} - -NS_CC_EXT_END - -#endif // __CCScale9Sprite_H__ diff --git a/extensions/cocos-ext.h b/extensions/cocos-ext.h index 695077d628..6f742b7046 100644 --- a/extensions/cocos-ext.h +++ b/extensions/cocos-ext.h @@ -7,12 +7,12 @@ #include "GUI/CCControlExtension/CCControlExtensions.h" #include "GUI/CCScrollView/CCScrollView.h" #include "GUI/CCScrollView/CCTableView.h" -#include "ui/UIEditBox/UIEditBox.h" // Physics integration #include "physics-nodes/CCPhysicsDebugNode.h" #include "physics-nodes/CCPhysicsSprite.h" #include "assets-manager/AssetsManager.h" +#include "ExtensionDeprecated.h" #endif /* __COCOS2D_EXT_H__ */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp deleted file mode 100644 index dfa40086aa..0000000000 --- a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp +++ /dev/null @@ -1,135 +0,0 @@ -// -// EditBoxTest.cpp -// TestCpp -// -// Created by James on 8/14/12. -// -// - -#include "EditBoxTest.h" -#include "../ExtensionsTest.h" - -USING_NS_CC; -USING_NS_CC_EXT; -using namespace ui; - - -EditBoxTest::EditBoxTest() -{ - auto glview = Director::getInstance()->getOpenGLView(); - auto visibleOrigin = glview->getVisibleOrigin(); - auto visibleSize = glview->getVisibleSize(); - - auto pBg = Sprite::create("Images/HelloWorld.png"); - pBg->setPosition(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2); - addChild(pBg); - - _TTFShowEditReturn = Label::createWithSystemFont("No edit control return!", "", 30); - _TTFShowEditReturn->setPosition(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y + visibleSize.height - 50); - addChild(_TTFShowEditReturn); - - // Back Menu - auto itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(EditBoxTest::toExtensionsMainLayer, this)); - itemBack->setPosition(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25); - auto menuBack = Menu::create(itemBack, nullptr); - menuBack->setPosition(Vec2::ZERO); - addChild(menuBack); - - auto editBoxSize = Size(visibleSize.width - 100, 60); - - // top - _editName = EditBox::create(editBoxSize, ui::Scale9Sprite::create("extensions/green_edit.png")); - _editName->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4)); - _editName->setFontName("Paint Boy"); - _editName->setFontSize(25); - _editName->setFontColor(Color3B::RED); - _editName->setPlaceHolder("Name:"); - _editName->setPlaceholderFontColor(Color3B::WHITE); - _editName->setMaxLength(8); - _editName->setReturnType(EditBox::KeyboardReturnType::DONE); - _editName->setDelegate(this); - addChild(_editName); - - // middle - _editPassword = EditBox::create(editBoxSize, ui::Scale9Sprite::create("extensions/orange_edit.png")); - _editPassword->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - _editPassword->setFont("American Typewriter", 30); -#else - _editPassword->setFont("American Typewriter", 80); - _editPassword->setPlaceholderFont("American Typewriter", 80); -#endif - _editPassword->setFontColor(Color3B::GREEN); - _editPassword->setPlaceHolder("Password:"); - _editPassword->setMaxLength(6); - _editPassword->setInputFlag(EditBox::InputFlag::PASSWORD); - _editPassword->setInputMode(EditBox::InputMode::SINGLE_LINE); - _editPassword->setDelegate(this); - addChild(_editPassword); - - // bottom - _editEmail = EditBox::create(Size(editBoxSize.width, editBoxSize.height), ui::Scale9Sprite::create("extensions/yellow_edit.png")); - _editEmail->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4)); - _editEmail->setAnchorPoint(Vec2(0.5, 1.0f)); - _editEmail->setPlaceHolder("Email:"); - _editEmail->setInputMode(EditBox::InputMode::EMAIL_ADDRESS); - _editEmail->setDelegate(this); - addChild(_editEmail); - - this->setPosition(10, 20); -} - -EditBoxTest::~EditBoxTest() -{ - -} - -void EditBoxTest::toExtensionsMainLayer(cocos2d::Ref *sender) -{ - auto scene = new (std::nothrow) ExtensionsTestScene(); - scene->runThisTest(); - scene->release(); -} - -void EditBoxTest::editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox) -{ - log("editBox %p DidBegin !", editBox); -} - -void EditBoxTest::editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox) -{ - log("editBox %p DidEnd !", editBox); -} - -void EditBoxTest::editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text) -{ - log("editBox %p TextChanged, text: %s ", editBox, text.c_str()); -} - -void EditBoxTest::editBoxReturn(EditBox* editBox) -{ - log("editBox %p was returned !",editBox); - - if (_editName == editBox) - { - _TTFShowEditReturn->setString("Name EditBox return !"); - } - else if (_editPassword == editBox) - { - _TTFShowEditReturn->setString("Password EditBox return !"); - } - else if (_editEmail == editBox) - { - _TTFShowEditReturn->setString("Email EditBox return !"); - } -} - -void runEditBoxTest() -{ - auto scene = Scene::create(); - EditBoxTest *layer = new (std::nothrow) EditBoxTest(); - scene->addChild(layer); - - Director::getInstance()->replaceScene(scene); - layer->release(); -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h b/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h deleted file mode 100644 index 2de0e0642f..0000000000 --- a/tests/cpp-tests/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// EditBoxTest.h -// TestCpp -// -// Created by James on 8/14/12. -// -// - -#ifndef __TestCpp__CCEditBoxTest__ -#define __TestCpp__CCEditBoxTest__ - -#include "cocos2d.h" -#include "extensions/cocos-ext.h" - -class EditBoxTest : public cocos2d::Layer, public cocos2d::ui::EditBoxDelegate -{ -public: - EditBoxTest(); - virtual ~EditBoxTest(); - void toExtensionsMainLayer(cocos2d::Ref *sender); - - virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox); - virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox); - virtual void editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text); - virtual void editBoxReturn(cocos2d::ui::EditBox* editBox); -private: - cocos2d::Label* _TTFShowEditReturn; - cocos2d::ui::EditBox* _editName; - cocos2d::ui::EditBox* _editPassword; - cocos2d::ui::EditBox* _editEmail; -}; - -void runEditBoxTest(); - -#endif /* defined(__TestCpp__CCEditBoxTest__) */ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp index 3a09e2da85..10d31a2900 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/ExtensionsTest.cpp @@ -18,11 +18,6 @@ #include "NetworkTest/SocketIOTest.h" #endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) -#include "EditBoxTest/EditBoxTest.h" -#endif - -#include "Scale9SpriteTest/Scale9SpriteTest.h" enum { @@ -36,15 +31,6 @@ static struct { } g_extensionsTests[] = { { "NotificationCenterTest", [](Ref* sender) { runNotificationCenterTest(); } }, - { "Scale9SpriteTest", [](Ref* sender) { - auto scene = new (std::nothrow) S9SpriteTestScene(); - if (scene) - { - scene->runThisTest(); - scene->release(); - } - } - }, { "CCControlButtonTest", [](Ref *sender){ ControlSceneManager* pManager = ControlSceneManager::sharedControlSceneManager(); auto scene = pManager->currentControlScene(); @@ -68,10 +54,7 @@ static struct { { "SocketIOTest", [](Ref *sender){ runSocketIOTest();} }, #endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) - { "EditBoxTest", [](Ref *sender){ runEditBoxTest();} - }, -#endif + { "TableViewTest", [](Ref *sender){ runTableViewTest();} }, { "CocoStudioArmatureTest", [](Ref *sender) { ArmatureTestScene *scene = new (std::nothrow) ArmatureTestScene(); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp deleted file mode 100644 index c8cc71acbf..0000000000 --- a/tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp +++ /dev/null @@ -1,784 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011 Zynga Inc. - Copyright (c) 2013 Surith Thekkiam - - 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 "Scale9SpriteTest.h" -#include "testResource.h" -#include "cocos2d.h" -#include "extensions/cocos-ext.h" - -USING_NS_CC_EXT; - -static std::function createFunctions[] = { - CL(S9BatchNodeBasic), - CL(S9FrameNameSpriteSheet), - CL(S9FrameNameSpriteSheetRotated), - CL(S9BatchNodeScaledNoInsets), - CL(S9FrameNameSpriteSheetScaledNoInsets), - CL(S9FrameNameSpriteSheetRotatedScaledNoInsets), - CL(S9BatchNodeScaleWithCapInsets), - CL(S9FrameNameSpriteSheetInsets), - CL(S9FrameNameSpriteSheetInsetsScaled), - CL(S9FrameNameSpriteSheetRotatedInsets), - CL(S9_TexturePacker), - CL(S9FrameNameSpriteSheetRotatedInsetsScaled), - CL(S9FrameNameSpriteSheetRotatedSetCapInsetLater), - CL(S9CascadeOpacityAndColor), - CL(S9ZOrder), - CL(S9Flip) -}; - -static int sceneIdx=-1; -#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) - -static Layer* nextAction() -{ - sceneIdx++; - sceneIdx = sceneIdx % MAX_LAYER; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* backAction() -{ - sceneIdx--; - int total = MAX_LAYER; - if( sceneIdx < 0 ) - sceneIdx += total; - - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -static Layer* restartAction() -{ - auto layer = (createFunctions[sceneIdx])(); - return layer; -} - -void S9SpriteTestScene::runThisTest() -{ - sceneIdx = -1; - addChild(nextAction()); - - Director::getInstance()->replaceScene(this); -} - -//------------------------------------------------------------------ -// -// S9SpriteTestDemo -// -//------------------------------------------------------------------ - -void S9SpriteTestDemo::onEnter() -{ - BaseTest::onEnter(); - SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_blocks9_plist); - CCLOG("sprite frames added to sprite frame cache..."); -} - -void S9SpriteTestDemo::restartCallback(Ref* sender) -{ - auto s = new (std::nothrow) S9SpriteTestScene(); - s->addChild( restartAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void S9SpriteTestDemo::nextCallback(Ref* sender) -{ - auto s = new (std::nothrow) S9SpriteTestScene(); - s->addChild( nextAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - -void S9SpriteTestDemo::backCallback(Ref* sender) -{ - auto s = new (std::nothrow) S9SpriteTestScene(); - s->addChild( backAction() ); - Director::getInstance()->replaceScene(s); - s->release(); -} - - -// S9BatchNodeBasic - -void S9BatchNodeBasic::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9BatchNodeBasic ..."); - - auto batchNode = SpriteBatchNode::create("Images/blocks9.png"); - log("batchNode created with : Images/blocks9.png"); - - auto blocks = Scale9Sprite::create(); - log("... created"); - - blocks->updateWithBatchNode(batchNode, Rect(0, 0, 96, 96), false, Rect(0, 0, 96, 96)); - log("... updateWithBatchNode"); - - blocks->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks); - log("this->addChild"); - - log("... S9BatchNodeBasic done."); -} - -std::string S9BatchNodeBasic::title() const -{ - return "Scale9Sprite created empty and updated from SpriteBatchNode"; -} - -std::string S9BatchNodeBasic::subtitle() const -{ - return "updateWithBatchNode(); capInsets=full size"; -} - - -// S9FrameNameSpriteSheet - -void S9FrameNameSpriteSheet::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheet ..."); - - auto blocks = Scale9Sprite::createWithSpriteFrameName("blocks9.png"); - log("... created"); - - blocks->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks); - log("this->addChild"); - - log("... S9FrameNameSpriteSheet done."); -} - -std::string S9FrameNameSpriteSheet::title() const -{ - return "Scale9Sprite from sprite sheet"; -} - -std::string S9FrameNameSpriteSheet::subtitle() const -{ - return "createWithSpriteFrameName(); default cap insets"; -} - -// -//// S9FrameNameSpriteSheetRotated -// -void S9FrameNameSpriteSheetRotated::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetRotated ..."); - - auto blocks = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - log("... created"); - - blocks->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetRotated done."); -} - -std::string S9FrameNameSpriteSheetRotated::title() const -{ - return "Scale9Sprite from sprite sheet (stored rotated)"; -} - -std::string S9FrameNameSpriteSheetRotated::subtitle() const -{ - return "createWithSpriteFrameName(); default cap insets"; -} - -// -//// S9BatchNodeScaledNoInsets -// - -void S9BatchNodeScaledNoInsets::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9BatchNodeScaledNoInsets ..."); - - // scaled without insets - auto batchNode_scaled = SpriteBatchNode::create("Images/blocks9.png"); - log("batchNode_scaled created with : Images/blocks9.png"); - - auto blocks_scaled = Scale9Sprite::create(); - log("... created"); - blocks_scaled->updateWithBatchNode(batchNode_scaled, Rect(0, 0, 96, 96), false, Rect(0, 0, 96, 96)); - log("... updateWithBatchNode"); - - blocks_scaled->setPosition(Vec2(x, y)); - log("... setPosition"); - - blocks_scaled->setContentSize(Size(96 * 4, 96*2)); - log("... setContentSize"); - - this->addChild(blocks_scaled); - log("this->addChild"); - - log("... S9BtchNodeScaledNoInsets done."); -} - -std::string S9BatchNodeScaledNoInsets::title() const -{ - return "Scale9Sprite created empty and updated from SpriteBatchNode"; -} - -std::string S9BatchNodeScaledNoInsets::subtitle() const -{ - return "updateWithBatchNode(); capInsets=full size; rendered 4 X width, 2 X height"; -} - -// -//// S9FrameNameSpriteSheetScaledNoInsets -// - -void S9FrameNameSpriteSheetScaledNoInsets::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetScaledNoInsets ..."); - - auto blocks_scaled = Scale9Sprite::createWithSpriteFrameName("blocks9.png"); - log("... created"); - - blocks_scaled->setPosition(Vec2(x, y)); - log("... setPosition"); - - blocks_scaled->setContentSize(Size(96 * 4, 96*2)); - log("... setContentSize"); - - this->addChild(blocks_scaled); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetScaledNoInsets done."); -} - -std::string S9FrameNameSpriteSheetScaledNoInsets::title() const -{ - return "Scale9Sprite from sprite sheet"; -} - -std::string S9FrameNameSpriteSheetScaledNoInsets::subtitle() const -{ - return "createWithSpriteFrameName(); default cap insets; rendered 4 X width, 2 X height"; -} - - -// -//// S9FrameNameSpriteSheetRotatedScaledNoInsets -// - -void S9FrameNameSpriteSheetRotatedScaledNoInsets::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetRotatedScaledNoInsets ..."); - - auto blocks_scaled = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - log("... created"); - - blocks_scaled->setPosition(Vec2(x, y)); - log("... setPosition"); - - blocks_scaled->setContentSize(Size(96 * 4, 96*2)); - log("... setContentSize"); - - this->addChild(blocks_scaled); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetRotatedScaledNoInsets done."); -} - -std::string S9FrameNameSpriteSheetRotatedScaledNoInsets::title() const -{ - return "Scale9Sprite from sprite sheet (stored rotated)"; -} - -std::string S9FrameNameSpriteSheetRotatedScaledNoInsets::subtitle() const -{ - return "createWithSpriteFrameName(); default cap insets; rendered 4 X width, 2 X height"; -} - -// -// -//// S9BatchNodeScaleWithCapInsets -// - -void S9BatchNodeScaleWithCapInsets::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9BatchNodeScaleWithCapInsets ..."); - - auto batchNode_scaled_with_insets = SpriteBatchNode::create("Images/blocks9.png"); - log("batchNode_scaled_with_insets created with : Images/blocks9.png"); - - auto blocks_scaled_with_insets = Scale9Sprite::create(); - log("... created"); - - blocks_scaled_with_insets->updateWithBatchNode(batchNode_scaled_with_insets, Rect(0, 0, 96, 96), false, Rect(32, 32, 32, 32)); - log("... updateWithBatchNode"); - - blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5)); - log("... setContentSize"); - - blocks_scaled_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks_scaled_with_insets); - log("this->addChild"); - - log("... S9BatchNodeScaleWithCapInsets done."); -} - -std::string S9BatchNodeScaleWithCapInsets::title() const -{ - return "Scale9Sprite created empty and updated from SpriteBatchNode"; -} - -std::string S9BatchNodeScaleWithCapInsets::subtitle() const -{ - return "updateWithBatchNode(); capInsets=(32, 32, 32, 32)"; -} - -// -//// S9FrameNameSpriteSheetInsets -// - -void S9FrameNameSpriteSheetInsets::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetInsets ..."); - - auto blocks_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32)); - log("... created"); - - blocks_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks_with_insets); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetInsets done."); -} - -std::string S9FrameNameSpriteSheetInsets::title() const -{ - return "Scale9Sprite scaled with insets sprite sheet"; -} - -std::string S9FrameNameSpriteSheetInsets::subtitle() const -{ - return "createWithSpriteFrameName(); cap insets=(32, 32, 32, 32)"; -} - -// -//// S9FrameNameSpriteSheetInsetsScaled -// -void S9FrameNameSpriteSheetInsetsScaled::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetInsetsScaled ..."); - - auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32)); - log("... created"); - - blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5)); - log("... setContentSize"); - - blocks_scaled_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks_scaled_with_insets); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetInsetsScaled done."); -} - -std::string S9FrameNameSpriteSheetInsetsScaled::title() const -{ - return "Scale9Sprite scaled with insets sprite sheet"; -} - -std::string S9FrameNameSpriteSheetInsetsScaled::subtitle() const -{ - return "createWithSpriteFrameName(); default cap insets; rendered scaled 4.5 X width, 2.5 X height"; -} - -//// S9FrameNameSpriteSheetRotatedInsets -// - -void S9FrameNameSpriteSheetRotatedInsets::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetRotatedInsets ..."); - - auto blocks_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png", Rect(32, 32, 32, 32)); - log("... created"); - - blocks_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks_with_insets); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetRotatedInsets done."); -} - -std::string S9FrameNameSpriteSheetRotatedInsets::title() const -{ - return "Scale9Sprite scaled with insets sprite sheet (stored rotated)"; -} - -std::string S9FrameNameSpriteSheetRotatedInsets::subtitle() const -{ - return "createWithSpriteFrameName(); cap insets=(32, 32, 32, 32)"; -} - -// -//// S9_TexturePacker -// - -void S9_TexturePacker::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_ui_plist); - - float x = winSize.width / 4; - float y = 0 + (winSize.height / 2); - - log("S9_TexturePacker ..."); - - auto s = Scale9Sprite::createWithSpriteFrameName("button_normal.png"); - log("... created"); - - s->setPosition(Vec2(x, y)); - log("... setPosition"); - - s->setContentSize(Size(14 * 16, 10 * 16)); - log("... setContentSize"); - - this->addChild(s); - log("this->addChild"); - - x = winSize.width * 3/4; - - auto s2 = Scale9Sprite::createWithSpriteFrameName("button_actived.png"); - log("... created"); - - s2->setPosition(Vec2(x, y)); - log("... setPosition"); - - s2->setContentSize(Size(14 * 16, 10 * 16)); - log("... setContentSize"); - - this->addChild(s2); - log("this->addChild"); - - log("... S9_TexturePacker done."); -} - -std::string S9_TexturePacker::title() const -{ - return "Scale9Sprite from a spritesheet created with TexturePacker"; -} - -std::string S9_TexturePacker::subtitle() const -{ - return "createWithSpriteFrameName('button_normal.png');createWithSpriteFrameName('button_actived.png');"; -} - -// -//// S9FrameNameSpriteSheetRotatedInsetsScaled -// - -void S9FrameNameSpriteSheetRotatedInsetsScaled::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("S9FrameNameSpriteSheetRotatedInsetsScaled ..."); - - auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32)); - log("... created"); - - blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5)); - log("... setContentSize"); - - blocks_scaled_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks_scaled_with_insets); - log("this->addChild"); - - log("... S9FrameNameSpriteSheetRotatedInsetsScaled done."); -} - -std::string S9FrameNameSpriteSheetRotatedInsetsScaled::title() const -{ - return "Scale9Sprite scaled with insets sprite sheet (stored rotated)"; -} - -std::string S9FrameNameSpriteSheetRotatedInsetsScaled::subtitle() const -{ - return "createWithSpriteFrameName(); default cap insets; rendered scaled 4.5 X width, 2.5 X height"; -} - -// -//// Scale9FrameNameSpriteSheetRotatedSetCapInsetLater -// - -void S9FrameNameSpriteSheetRotatedSetCapInsetLater::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - log("Scale9FrameNameSpriteSheetRotatedSetCapInsetLater ..."); - - auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - log("... created"); - - blocks_scaled_with_insets->setInsetLeft(32); - blocks_scaled_with_insets->setInsetRight(32); - - blocks_scaled_with_insets->setPreferredSize(Size(32*5.5f, 32*4)); - blocks_scaled_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - this->addChild(blocks_scaled_with_insets); - log("this->addChild"); - - log("... Scale9FrameNameSpriteSheetRotatedSetCapInsetLater done."); -} - -std::string S9FrameNameSpriteSheetRotatedSetCapInsetLater::title() const -{ - return "Scale9Sprite from sprite sheet (stored rotated), with setting CapInset later"; -} - -std::string S9FrameNameSpriteSheetRotatedSetCapInsetLater::subtitle() const -{ - return "createWithSpriteFrameName(); setInsetLeft(32); setInsetRight(32);"; -} - -// -//// S9CascadeOpacityAndColor -// - -void S9CascadeOpacityAndColor::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - auto rgba = Layer::create(); - rgba->setCascadeColorEnabled(true); - rgba->setCascadeOpacityEnabled(true); - this->addChild(rgba); - - log("S9CascadeOpacityAndColor ..."); - - auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - log("... created"); - - blocks_scaled_with_insets->setPosition(Vec2(x, y)); - log("... setPosition"); - - rgba->addChild(blocks_scaled_with_insets); - auto actions = Sequence::create(FadeIn::create(1), - TintTo::create(1, 0, 255, 0), - TintTo::create(1, 255, 255, 255), - FadeOut::create(1), - nullptr); - auto repeat = RepeatForever::create(actions); - rgba->runAction(repeat); - log("this->addChild"); - - log("... S9CascadeOpacityAndColor done."); -} - -std::string S9CascadeOpacityAndColor::title() const -{ - return "Scale9Sprite and a Layer parent with setCascadeOpacityEnable(true) and setCascadeColorEnable(true)"; -} - -std::string S9CascadeOpacityAndColor::subtitle() const -{ - return "when parent change color/opacity, Scale9Sprite should also change"; -} - -// -//// S9ZOrder -// - -void S9ZOrder::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - - blocks_scaled_with_insets->setPosition(Vec2(x, y)); - this->addChild(blocks_scaled_with_insets); - - Sprite *normalSprite = Sprite::createWithSpriteFrameName("blocks9r.png"); - normalSprite->setColor(Color3B::RED); - blocks_scaled_with_insets->addChild(normalSprite); - - auto topLabel = Label::createWithSystemFont("I Must be On the Top", "Arial", 15); - topLabel->setPosition(Vec2(20,20)); - blocks_scaled_with_insets->addChild(topLabel); - - auto bottomLabel = Label::createWithSystemFont("I Must be On the Bottom", "Arial", 15); - bottomLabel->setPosition(Vec2(80,80)); - bottomLabel->setColor(Color3B::BLUE); - blocks_scaled_with_insets->addChild(bottomLabel,-1); - -} - -std::string S9ZOrder::title() const -{ - return "Scale9Sprite ZOrder issue"; -} - -std::string S9ZOrder::subtitle() const -{ - return "When adding nodes to Scale9Sprite, it should be added on top itself"; -} - -// -//// S9Flip -// - -void S9Flip::onEnter() -{ - S9SpriteTestDemo::onEnter(); - auto winSize = Director::getInstance()->getWinSize(); - float x = winSize.width / 2; - float y = 0 + (winSize.height / 2); - - - auto normalSprite = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - - normalSprite->setPosition(Vec2(x, y )); - this->addChild(normalSprite); - - - auto normalLabel = Label::createWithSystemFont("Normal Sprite","Airal",10); - normalLabel->setPosition(normalSprite->getPosition() + Vec2(0, normalSprite->getContentSize().height/2 + 10)); - this->addChild(normalLabel); - - - - auto flipXSprite = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - - flipXSprite->setPosition(Vec2(x - 120, y )); - this->addChild(flipXSprite); - - flipXSprite->setScaleX(-1); - - auto flipXLabel = Label::createWithSystemFont("Sprite FlipX","Airal",10); - flipXLabel->setPosition(flipXSprite->getPosition() + Vec2(0, flipXSprite->getContentSize().height/2 + 10)); - this->addChild(flipXLabel); - - - auto flipYSprite = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); - - flipYSprite->setPosition(Vec2(x + 120, y)); - this->addChild(flipYSprite); - - flipYSprite->setScaleY(-1); - - auto flipYLabel = Label::createWithSystemFont("Sprite FlipY","Airal",10); - flipYLabel->setPosition(flipYSprite->getPosition() + Vec2(0, flipYSprite->getContentSize().height/2 + 10)); - this->addChild(flipYLabel); - - -} - -std::string S9Flip::title() const -{ - return "Scale9Sprite Flip issue"; -} - -std::string S9Flip::subtitle() const -{ - return "When Flipped, the scale9Sprite should behavior like a normal node"; -} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h b/tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h deleted file mode 100644 index a5448fb86e..0000000000 --- a/tests/cpp-tests/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011 Zynga Inc. - Copyright (c) 2013 Surith Thekkiam - - 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 "testBasic.h" -#include "BaseTest.h" - - -class S9SpriteTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - -class S9SpriteTestDemo : public BaseTest -{ -public: - virtual void onEnter() override; - - virtual void restartCallback(Ref* sender); - virtual void nextCallback(Ref* sender); - virtual void backCallback(Ref* sender); -}; - -// S9BatchNodeBasic - -class S9BatchNodeBasic : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9BatchNodeBasic); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheet - -class S9FrameNameSpriteSheet : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheet); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetRotated - -class S9FrameNameSpriteSheetRotated : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetRotated); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9BatchNodeScaledNoInsets - -class S9BatchNodeScaledNoInsets : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9BatchNodeScaledNoInsets); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetScaledNoInsets - -class S9FrameNameSpriteSheetScaledNoInsets : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetScaledNoInsets); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetRotatedScaledNoInsets - -class S9FrameNameSpriteSheetRotatedScaledNoInsets : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetRotatedScaledNoInsets); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - - -// S9BatchNodeScaleWithCapInsets - -class S9BatchNodeScaleWithCapInsets : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9BatchNodeScaleWithCapInsets); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetInsets - -class S9FrameNameSpriteSheetInsets : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetInsets); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetInsetsScaled - -class S9FrameNameSpriteSheetInsetsScaled : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetInsetsScaled); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetRotatedInsets - -class S9FrameNameSpriteSheetRotatedInsets : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetRotatedInsets); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9_TexturePacker - -class S9_TexturePacker : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9_TexturePacker); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetRotatedInsetsScaled - -class S9FrameNameSpriteSheetRotatedInsetsScaled : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetRotatedInsetsScaled); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9FrameNameSpriteSheetRotatedInsetsScaled - -class S9FrameNameSpriteSheetRotatedSetCapInsetLater : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9FrameNameSpriteSheetRotatedSetCapInsetLater); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// S9CascadeOpacityAndColor - -class S9CascadeOpacityAndColor : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9CascadeOpacityAndColor); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// Scale9Sprite ZOrder - -class S9ZOrder : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9ZOrder); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; - -// Scale9Sprite Flip - -class S9Flip : public S9SpriteTestDemo -{ -public: - CREATE_FUNC(S9Flip); - - virtual void onEnter() override; - - virtual std::string title() const override; - virtual std::string subtitle() const override; -}; From ffee7b27d43e93798607bd7a07c879b68ec4a91c Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 1 Sep 2014 17:43:40 +0800 Subject: [PATCH 08/15] fix linux and android compile error --- cocos/CMakeLists.txt | 3 -- cocos/ui/CMakeLists.txt | 50 ------------------- extensions/Android.mk | 9 ++-- .../GUI/CCControlExtension/CCControlButton.h | 2 +- tests/cpp-tests/Android.mk | 2 - 5 files changed, 5 insertions(+), 61 deletions(-) delete mode 100644 cocos/ui/CMakeLists.txt diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c454b4f63a..ac588ab6a9 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -90,9 +90,6 @@ list(REMOVE_ITEM cocos2d_source_files "${CMAKE_CURRENT_SOURCE_DIR}/storage/local-storage/LocalStorageAndroid.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/base/CCEventController.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/base/CCEventListenerController.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../extensions/GUI/CCEditBox/CCEditBoxImplAndroid.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../extensions/GUI/CCEditBox/CCEditBoxImplWin.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../extensions/GUI/CCEditBox/CCEditBoxImplWp8.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/editor-support/cocostudio/proj.wp8/pch.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../extensions/proj.wp8/pch.cpp") diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt deleted file mode 100644 index 132f7c4635..0000000000 --- a/cocos/ui/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -set(COCOS_UI_SRC - CocosGUI.cpp - UIButton.cpp - UICheckBox.cpp - UIHBox.cpp - UIHelper.cpp - UIImageView.cpp - UILayout.cpp - UILayoutParameter.cpp - UILayoutManager.cpp - UIListView.cpp - UILoadingBar.cpp - UIPageView.cpp - UIRelativeBox.cpp - UIRichText.cpp - UIScrollView.cpp - UISlider.cpp - UITextAtlas.cpp - UITextBMFont.cpp - UIText.cpp - UITextField.cpp - UIVBox.cpp - UIWidget.cpp - UIDeprecated.cpp - UIScale9Sprite.cpp - UIEditBox/UIEditBox.cpp - UIEditBox/UIEditBoxImplAndroid.cpp - UIEditBox/UIEditBoxImplNone.cpp - UIEditBox/UIEditBoxImplWin.cpp -) - -include_directories( - ui - ../../base -) - - -add_library(ui STATIC - ${COCOS_UI_SRC} -) - -target_link_libraries(ui - cocos2d -) - -set_target_properties(ui - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" -) diff --git a/extensions/Android.mk b/extensions/Android.mk index 89877aa54d..2603f2f3d2 100644 --- a/extensions/Android.mk +++ b/extensions/Android.mk @@ -18,11 +18,6 @@ GUI/CCControlExtension/CCControlStepper.cpp \ GUI/CCControlExtension/CCControlSwitch.cpp \ GUI/CCControlExtension/CCControlUtils.cpp \ GUI/CCControlExtension/CCInvocation.cpp \ -GUI/CCControlExtension/CCScale9Sprite.cpp \ -GUI/CCEditBox/CCEditBox.cpp \ -GUI/CCEditBox/CCEditBoxImplAndroid.cpp \ -GUI/CCEditBox/CCEditBoxImplNone.cpp \ -GUI/CCEditBox/CCEditBoxImplWin.cpp \ GUI/CCScrollView/CCScrollView.cpp \ GUI/CCScrollView/CCTableView.cpp \ GUI/CCScrollView/CCTableViewCell.cpp \ @@ -33,6 +28,10 @@ LOCAL_STATIC_LIBRARIES := cocos2dx_internal_static LOCAL_STATIC_LIBRARIES += cocos_curl_static LOCAL_STATIC_LIBRARIES += box2d_static +GU/CCEditBox/CCEditBox.cpp \ +GUI/CCEditBox/CCEditBoxImplAndroid.cpp \ +GUI/CCEditBox/CCEditBoxImplNone.cpp \ +GUI/CCEditBox/CCEditBoxImplWin.cpp \ LOCAL_CXXFLAGS += -fexceptions LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. \ diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index 2c58a59311..758c61d363 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -32,7 +32,7 @@ #include "CCControl.h" #include "CCInvocation.h" -#include "ExtensionDeprecated.h" +#include "extensions/ExtensionDeprecated.h" #include "base/CCMap.h" NS_CC_EXT_BEGIN diff --git a/tests/cpp-tests/Android.mk b/tests/cpp-tests/Android.mk index d09e7895e0..dba250329b 100644 --- a/tests/cpp-tests/Android.mk +++ b/tests/cpp-tests/Android.mk @@ -124,12 +124,10 @@ Classes/ExtensionsTest/ControlExtensionTest/CCControlPotentiometerTest/CCControl Classes/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.cpp \ Classes/ExtensionsTest/ControlExtensionTest/CCControlStepperTest/CCControlStepperTest.cpp \ Classes/ExtensionsTest/ControlExtensionTest/CCControlSwitchTest/CCControlSwitchTest.cpp \ -Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp \ Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \ Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp \ Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp \ Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp \ -Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp \ Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.cpp \ Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp \ Classes/FileUtilsTest/FileUtilsTest.cpp \ From e24192aeb2502656387b441c6635539f62b621a6 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 1 Sep 2014 18:06:21 +0800 Subject: [PATCH 09/15] fix linux compile --- tests/cpp-tests/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index ec798974c6..d1ca2a1ee1 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -2,7 +2,6 @@ set(APP_NAME cpp-tests) if(WIN32) set(PLATFORM_SRC - Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp Classes/ExtensionsTest/NetworkTest/SocketIOTest.cpp proj.win32/main.cpp @@ -125,7 +124,6 @@ set(SAMPLE_SRC Classes/UITest/CocoStudioGUITest/CustomWidget/CustomReader.cpp Classes/UITest/CocoStudioGUITest/CustomTest/CustomImageTest/CustomImageTest.cpp Classes/UITest/CocoStudioGUITest/CustomTest/CustomParticleWidgetTest/CustomParticleWidgetTest.cpp - Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp Classes/NewRendererTest/NewRendererTest.cpp Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp Classes/FontTest/FontTest.cpp From fa33ab76fcd0f1409a5248cc67f5f60a8b6e760c Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 1 Sep 2014 18:23:45 +0800 Subject: [PATCH 10/15] remove UIEditBox test --- tests/cpp-tests/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index d1ca2a1ee1..815cfb7e43 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -81,7 +81,6 @@ set(SAMPLE_SRC Classes/UITest/CocoStudioGUITest/CustomGUIScene.cpp Classes/UITest/CocoStudioGUITest/UIScene.cpp Classes/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp - Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp Classes/UITest/CocoStudioGUITest/UISceneManager.cpp Classes/UITest/CocoStudioGUITest/CocostudioParserTest/CocostudioParserJsonTest.cpp Classes/UITest/CocoStudioGUITest/CocostudioParserTest.cpp From 6dc45f86e41b1eb254c1b814a09d929fac1bc665 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 2 Sep 2014 10:05:22 +0800 Subject: [PATCH 11/15] fix windows compile error --- cocos/2d/libcocos2d.vcxproj | 16 +- cocos/2d/libcocos2d.vcxproj.filters | 198 +++++++++--------- tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 4 - .../proj.win32/cpp-tests.vcxproj.filters | 18 -- 4 files changed, 103 insertions(+), 133 deletions(-) diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 9fdc34eb21..69e5434274 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -192,15 +192,11 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\spine\prebuilt\release-l - - - - @@ -409,9 +405,12 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\spine\prebuilt\release-l + + + @@ -516,16 +515,11 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\spine\prebuilt\release-l - - - - - @@ -786,9 +780,13 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\spine\prebuilt\release-l + + + + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index 1a5d9f9b25..d918da6cc1 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -76,15 +76,9 @@ {b27aba95-51a2-413c-8570-0aff9adf2b6b} - - {220cf2ee-61b0-40cf-a88a-8627e4e609f1} - {a1f539bc-d5be-4224-a4d2-01c0b6f17d6e} - - {dc45cd54-4576-4401-87b7-a276f91a45bd} - {1de7fce7-0dee-4571-8fcd-43eb617aaf8b} @@ -211,6 +205,12 @@ {8579ed15-b266-4f80-818d-a3a9251c4248} + + {89eb6312-dc7f-4fda-b9b2-ab67c31ddd55} + + + {118d80ca-ccf2-480c-b87d-25220af23440} + @@ -787,42 +787,6 @@ extension\AssetsManager - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - extension\GUI\CCScrollView @@ -832,15 +796,6 @@ extension\GUI\CCScrollView - - extension\GUI\CCEditBox - - - extension\GUI\CCEditBox - - - extension\GUI\CCEditBox - extension\physics_nodes @@ -1165,6 +1120,48 @@ cocosbuilder\Source Files + + ui\UIWidgets\EditBox + + + ui\UIWidgets\EditBox + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + ui\UIWidgets\EditBox + @@ -1825,45 +1822,6 @@ extension\AssetsManager - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - - - extension\GUI\CCControlExtension - extension\GUI\CCScrollView @@ -1873,18 +1831,6 @@ extension\GUI\CCScrollView - - extension\GUI\CCEditBox - - - extension\GUI\CCEditBox - - - extension\GUI\CCEditBox - - - extension\GUI\CCEditBox - extension\physics_nodes @@ -2290,6 +2236,54 @@ cocosbuilder\Header Files + + ui\UIWidgets\EditBox + + + ui\UIWidgets\EditBox + + + ui\UIWidgets\EditBox + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + extension\GUI\CCControlExtensions + + + ui\UIWidgets\EditBox + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index ed6a45c59c..8667753fd4 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -161,11 +161,9 @@ - - @@ -350,11 +348,9 @@ - - diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index 7d7fc6199c..f0e771d566 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -202,9 +202,6 @@ {a4c2111f-cf9f-492c-884d-3de24715adce} - - {18a69e7e-8ca7-475a-bfbb-7296baab16ce} - {0ef55f53-411a-4661-b5d5-13930da52e68} @@ -220,9 +217,6 @@ {81ec2355-7efd-49e0-b6cb-b1bba23fbbc8} - - {3d73aa04-d66e-43d3-921f-b867a753c113} - {a6e7d28e-46a3-46c4-9735-b39e96f776f0} @@ -594,9 +588,6 @@ Classes\FileUtilsTest - - Classes\ExtensionsTest\EditBoxTest - Classes\ExtensionsTest\CocosBuilderTest\TimelineCallbackTest @@ -618,9 +609,6 @@ Classes - - Classes\ExtensionsTest\Scale9SpriteTest - Classes\ExtensionsTest\NetworkTest @@ -1310,9 +1298,6 @@ Classes\FileUtilsTest - - Classes\ExtensionsTest\EditBoxTest - Classes\ExtensionsTest\CocosBuilderTest\TimelineCallbackTest @@ -1337,9 +1322,6 @@ Classes - - Classes\ExtensionsTest\Scale9SpriteTest - Classes\ExtensionsTest\NetworkTest From 2deeee2109b535d0203153e659dc80afe5594204 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 2 Sep 2014 01:11:50 -0700 Subject: [PATCH 12/15] remove extension luabindings --- tools/tolua/cocos2dx_extension.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/tolua/cocos2dx_extension.ini b/tools/tolua/cocos2dx_extension.ini index 03e0829edb..3b474c792f 100644 --- a/tools/tolua/cocos2dx_extension.ini +++ b/tools/tolua/cocos2dx_extension.ini @@ -27,7 +27,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.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 = AssetsManager.* Scale9Sprite Control.* ControlButton.* EditBox$ ScrollView$ TableView$ TableViewCell$ +classes = AssetsManager.* Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -39,7 +39,6 @@ classes = AssetsManager.* Scale9Sprite Control.* ControlButton.* EditBox$ Scroll skip = .*Delegate::[*], .*Loader.*::[*], *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate .*HSV], - EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler], AssetsManager::[(g|s)etDelegate], AssetsManagerDelegateProtocol::[*], Control::[removeHandleOfControlEvent addHandleOfControlEvent], From a0c28e49ac592adf223a68a7dec467fd7361a956 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 2 Sep 2014 16:14:07 +0800 Subject: [PATCH 13/15] remove exteion edtibox --- extensions/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index b3c609beb5..427452a0b0 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -11,11 +11,6 @@ set(EXTENSIONS_SRC GUI/CCControlExtension/CCControlSwitch.cpp GUI/CCControlExtension/CCControlUtils.cpp GUI/CCControlExtension/CCInvocation.cpp - GUI/CCControlExtension/CCScale9Sprite.cpp - GUI/CCEditBox/CCEditBox.cpp - GUI/CCEditBox/CCEditBoxImplAndroid.cpp - GUI/CCEditBox/CCEditBoxImplNone.cpp - GUI/CCEditBox/CCEditBoxImplWin.cpp GUI/CCScrollView/CCScrollView.cpp GUI/CCScrollView/CCTableView.cpp GUI/CCScrollView/CCTableViewCell.cpp From 51e160beffc08d16ef56c35c7b402232291605b8 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 2 Sep 2014 17:37:55 +0800 Subject: [PATCH 14/15] fix EditBox lua compile error --- cocos/ui/UIEditBox/UIEditBox.cpp | 9 +++++---- cocos/ui/UIEditBox/UIEditBox.h | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cocos/ui/UIEditBox/UIEditBox.cpp b/cocos/ui/UIEditBox/UIEditBox.cpp index b5eed33b68..27e4ccc95b 100644 --- a/cocos/ui/UIEditBox/UIEditBox.cpp +++ b/cocos/ui/UIEditBox/UIEditBox.cpp @@ -68,12 +68,12 @@ void EditBox::touchDownAction(Ref *sender, TouchEventType controlEvent) } EditBox* EditBox::create(const Size& size, - const std::string& pNormal9SpriteBg, + const std::string& normalSprite, TextureResType texType /*= TextureResType::LOCAL*/) { EditBox* pRet = new EditBox(); - if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, pNormal9SpriteBg, texType)) + if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, normalSprite, texType)) { pRet->autorelease(); } @@ -85,11 +85,12 @@ EditBox* EditBox::create(const Size& size, return pRet; } -EditBox* EditBox::create(const cocos2d::Size &size, cocos2d::ui::Scale9Sprite *pNormal9SpriteBg) + +EditBox* EditBox::create(const cocos2d::Size &size, cocos2d::ui::Scale9Sprite *normalSprite, ui::Scale9Sprite *pressedSprite, Scale9Sprite* disabledSprite) { EditBox* pRet = new (std::nothrow) EditBox(); - if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, pNormal9SpriteBg)) + if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, normalSprite)) { pRet->autorelease(); } diff --git a/cocos/ui/UIEditBox/UIEditBox.h b/cocos/ui/UIEditBox/UIEditBox.h index 61bbeab965..72af4a2627 100644 --- a/cocos/ui/UIEditBox/UIEditBox.h +++ b/cocos/ui/UIEditBox/UIEditBox.h @@ -190,7 +190,10 @@ namespace ui { * @return An autorelease pointer of EditBox, you don't need to release it only if you retain it again. */ static EditBox* create(const Size& size, - Scale9Sprite* pNormal9SpriteBg); + Scale9Sprite* normalSprite, + Scale9Sprite* pressedSprite = nullptr, + Scale9Sprite* disabledSprite = nullptr); + /** * create a edit box with size. From a429959e65b90b32a92eee85bd3195942ac30e83 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 2 Sep 2014 01:31:02 -0700 Subject: [PATCH 15/15] fix lua compile error --- .../manual/extension/lua_cocos2dx_extension_manual.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp index b2f2e1c8a8..80498ab073 100644 --- a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp @@ -1045,7 +1045,7 @@ static void extendTableView(lua_State* L) int register_all_cocos2dx_extension_manual(lua_State* tolua_S) { extendControl(tolua_S); - extendEditBox(tolua_S); + /* extendEditBox(tolua_S); */ extendAssetsManager(tolua_S); extendScrollView(tolua_S); extendTableView(tolua_S);