mirror of https://github.com/axmolengine/axmol.git
add Mac Editbox multiline support.
1. It also refactor the original logic and optimize the iOS EditBox implementation.
This commit is contained in:
parent
ad756cf6bb
commit
a93bc88d31
|
@ -1185,6 +1185,8 @@
|
|||
291901441B05895600F8B4BA /* CCNinePatchImageParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 291901411B05895600F8B4BA /* CCNinePatchImageParser.h */; };
|
||||
291901451B05895600F8B4BA /* CCNinePatchImageParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 291901421B05895600F8B4BA /* CCNinePatchImageParser.cpp */; };
|
||||
291901461B05895600F8B4BA /* CCNinePatchImageParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 291901421B05895600F8B4BA /* CCNinePatchImageParser.cpp */; };
|
||||
291A09241C5F06A60068C1D2 /* CCUIEditBoxMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 291A09221C5F06A60068C1D2 /* CCUIEditBoxMac.h */; };
|
||||
291A09251C5F06A60068C1D2 /* CCUIEditBoxMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 291A09231C5F06A60068C1D2 /* CCUIEditBoxMac.mm */; };
|
||||
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 */; };
|
||||
|
@ -1222,6 +1224,15 @@
|
|||
29394CF519B01DBA00D2DE1A /* UIWebViewImpl-ios.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl-ios.h */; };
|
||||
29394CF619B01DBA00D2DE1A /* UIWebViewImpl-ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl-ios.mm */; };
|
||||
29394CF719B01DBA00D2DE1A /* UIWebViewImpl-ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl-ios.mm */; };
|
||||
2962D5E81C61CBF9004821A3 /* CCUITextInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 2962D5E71C61CBF9004821A3 /* CCUITextInput.h */; };
|
||||
2962D5EF1C61CF3F004821A3 /* CCUISingleLineTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = 2962D5ED1C61CF3F004821A3 /* CCUISingleLineTextField.h */; };
|
||||
2962D5F01C61CF3F004821A3 /* CCUISingleLineTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 2962D5EE1C61CF3F004821A3 /* CCUISingleLineTextField.m */; };
|
||||
2962D5F71C61DBBF004821A3 /* CCUIPasswordTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = 2962D5F51C61DBBF004821A3 /* CCUIPasswordTextField.h */; };
|
||||
2962D5F81C61DBBF004821A3 /* CCUIPasswordTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 2962D5F61C61DBBF004821A3 /* CCUIPasswordTextField.m */; };
|
||||
2962D5FF1C61DF1A004821A3 /* CCUIMultilineTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = 2962D5FD1C61DF1A004821A3 /* CCUIMultilineTextField.h */; };
|
||||
2962D6001C61DF1A004821A3 /* CCUIMultilineTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 2962D5FE1C61DF1A004821A3 /* CCUIMultilineTextField.m */; };
|
||||
2962D6031C61F02E004821A3 /* CCUITextFieldFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 2962D6011C61F02E004821A3 /* CCUITextFieldFormatter.h */; };
|
||||
2962D6041C61F02E004821A3 /* CCUITextFieldFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2962D6021C61F02E004821A3 /* CCUITextFieldFormatter.m */; };
|
||||
2980F0221BA9A5550059E678 /* CCUIEditBoxIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 2980F0171BA9A5550059E678 /* CCUIEditBoxIOS.h */; };
|
||||
2980F0231BA9A5550059E678 /* CCUIEditBoxIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2980F0181BA9A5550059E678 /* CCUIEditBoxIOS.mm */; };
|
||||
2980F0241BA9A5550059E678 /* CCUIMultilineTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = 2980F0191BA9A5550059E678 /* CCUIMultilineTextField.h */; };
|
||||
|
@ -5959,6 +5970,8 @@
|
|||
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
|
||||
291901411B05895600F8B4BA /* CCNinePatchImageParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCNinePatchImageParser.h; path = ../base/CCNinePatchImageParser.h; sourceTree = "<group>"; };
|
||||
291901421B05895600F8B4BA /* CCNinePatchImageParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCNinePatchImageParser.cpp; path = ../base/CCNinePatchImageParser.cpp; sourceTree = "<group>"; };
|
||||
291A09221C5F06A60068C1D2 /* CCUIEditBoxMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUIEditBoxMac.h; sourceTree = "<group>"; };
|
||||
291A09231C5F06A60068C1D2 /* CCUIEditBoxMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCUIEditBoxMac.mm; sourceTree = "<group>"; };
|
||||
292DB12F19B4574100A80320 /* UIEditBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEditBox.cpp; sourceTree = "<group>"; };
|
||||
292DB13019B4574100A80320 /* UIEditBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBox.h; sourceTree = "<group>"; };
|
||||
292DB13119B4574100A80320 /* UIEditBoxImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIEditBoxImpl.h; sourceTree = "<group>"; };
|
||||
|
@ -5983,6 +5996,15 @@
|
|||
29394CEF19B01DBA00D2DE1A /* UIWebViewImpl-ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIWebViewImpl-ios.mm"; sourceTree = "<group>"; };
|
||||
2958244919873D8E00F9746D /* UIScale9Sprite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9Sprite.cpp; sourceTree = "<group>"; };
|
||||
2958244A19873D8E00F9746D /* UIScale9Sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9Sprite.h; sourceTree = "<group>"; };
|
||||
2962D5E71C61CBF9004821A3 /* CCUITextInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUITextInput.h; sourceTree = "<group>"; };
|
||||
2962D5ED1C61CF3F004821A3 /* CCUISingleLineTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUISingleLineTextField.h; sourceTree = "<group>"; };
|
||||
2962D5EE1C61CF3F004821A3 /* CCUISingleLineTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCUISingleLineTextField.m; sourceTree = "<group>"; };
|
||||
2962D5F51C61DBBF004821A3 /* CCUIPasswordTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUIPasswordTextField.h; sourceTree = "<group>"; };
|
||||
2962D5F61C61DBBF004821A3 /* CCUIPasswordTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCUIPasswordTextField.m; sourceTree = "<group>"; };
|
||||
2962D5FD1C61DF1A004821A3 /* CCUIMultilineTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUIMultilineTextField.h; sourceTree = "<group>"; };
|
||||
2962D5FE1C61DF1A004821A3 /* CCUIMultilineTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCUIMultilineTextField.m; sourceTree = "<group>"; };
|
||||
2962D6011C61F02E004821A3 /* CCUITextFieldFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUITextFieldFormatter.h; sourceTree = "<group>"; };
|
||||
2962D6021C61F02E004821A3 /* CCUITextFieldFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCUITextFieldFormatter.m; sourceTree = "<group>"; };
|
||||
2980F0171BA9A5550059E678 /* CCUIEditBoxIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUIEditBoxIOS.h; sourceTree = "<group>"; };
|
||||
2980F0181BA9A5550059E678 /* CCUIEditBoxIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCUIEditBoxIOS.mm; sourceTree = "<group>"; };
|
||||
2980F0191BA9A5550059E678 /* CCUIMultilineTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUIMultilineTextField.h; sourceTree = "<group>"; };
|
||||
|
@ -8742,9 +8764,28 @@
|
|||
path = ../cocos/ui;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
291A091F1C5F06530068C1D2 /* Mac */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
291A09221C5F06A60068C1D2 /* CCUIEditBoxMac.h */,
|
||||
291A09231C5F06A60068C1D2 /* CCUIEditBoxMac.mm */,
|
||||
2962D5FD1C61DF1A004821A3 /* CCUIMultilineTextField.h */,
|
||||
2962D5FE1C61DF1A004821A3 /* CCUIMultilineTextField.m */,
|
||||
2962D5ED1C61CF3F004821A3 /* CCUISingleLineTextField.h */,
|
||||
2962D5EE1C61CF3F004821A3 /* CCUISingleLineTextField.m */,
|
||||
2962D5F51C61DBBF004821A3 /* CCUIPasswordTextField.h */,
|
||||
2962D5F61C61DBBF004821A3 /* CCUIPasswordTextField.m */,
|
||||
2962D5E71C61CBF9004821A3 /* CCUITextInput.h */,
|
||||
2962D6011C61F02E004821A3 /* CCUITextFieldFormatter.h */,
|
||||
2962D6021C61F02E004821A3 /* CCUITextFieldFormatter.m */,
|
||||
);
|
||||
path = Mac;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
292DB12E19B4574100A80320 /* UIEditBox */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
291A091F1C5F06530068C1D2 /* Mac */,
|
||||
2980F0161BA9A5550059E678 /* iOS */,
|
||||
A0E749F51BA8FD7F001A8332 /* UIEditBoxImpl-common.cpp */,
|
||||
A0E749F61BA8FD7F001A8332 /* UIEditBoxImpl-common.h */,
|
||||
|
@ -11129,6 +11170,7 @@
|
|||
B6CAB4F31AF9AA1A00B9B856 /* btAabbUtil2.h in Headers */,
|
||||
ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */,
|
||||
B6CAB4151AF9AA1A00B9B856 /* btMultiBodyPoint2Point.h in Headers */,
|
||||
2962D5F71C61DBBF004821A3 /* CCUIPasswordTextField.h in Headers */,
|
||||
B6CAB4491AF9AA1A00B9B856 /* btThreadSupportInterface.h in Headers */,
|
||||
15AE18A719AAD33D00C27E9E /* CCScrollViewLoader.h in Headers */,
|
||||
15FB20891AE7C57D00C31518 /* shapes.h in Headers */,
|
||||
|
@ -11242,6 +11284,7 @@
|
|||
B6CAB2771AF9AA1A00B9B856 /* btUnionFind.h in Headers */,
|
||||
B6CAB2111AF9AA1A00B9B856 /* btSimpleBroadphase.h in Headers */,
|
||||
15AE1BD919AAE01E00C27E9E /* CCControlStepper.h in Headers */,
|
||||
291A09241C5F06A60068C1D2 /* CCUIEditBoxMac.h in Headers */,
|
||||
15AE192119AAD35000C27E9E /* CocoStudio.h in Headers */,
|
||||
B6CAB3891AF9AA1A00B9B856 /* btPointCollector.h in Headers */,
|
||||
15AE18A119AAD33D00C27E9E /* CCNodeLoaderListener.h in Headers */,
|
||||
|
@ -11338,6 +11381,8 @@
|
|||
1A5701FD180BCBAD0088DEC7 /* CCMenuItem.h in Headers */,
|
||||
B6CAB2AD1AF9AA1A00B9B856 /* btConvexPointCloudShape.h in Headers */,
|
||||
1A570204180BCBD40088DEC7 /* CCClippingNode.h in Headers */,
|
||||
2962D5EF1C61CF3F004821A3 /* CCUISingleLineTextField.h in Headers */,
|
||||
2962D5FF1C61DF1A004821A3 /* CCUIMultilineTextField.h in Headers */,
|
||||
15AE1A7B19AAD40300C27E9E /* b2PolygonContact.h in Headers */,
|
||||
15AE1A2919AAD3D500C27E9E /* b2Collision.h in Headers */,
|
||||
182C5CE71A9D725400C30D34 /* UserCameraReader.h in Headers */,
|
||||
|
@ -11474,6 +11519,7 @@
|
|||
1A57028C180BCC900088DEC7 /* CCSpriteFrameCache.h in Headers */,
|
||||
B6CAB21D1AF9AA1A00B9B856 /* btBoxBoxCollisionAlgorithm.h in Headers */,
|
||||
B6CAAFEC1AF9A9E100B9B856 /* CCPhysics3DConstraint.h in Headers */,
|
||||
2962D6031C61F02E004821A3 /* CCUITextFieldFormatter.h in Headers */,
|
||||
C503066E1B60B583001E6D43 /* CCSkinNode.h in Headers */,
|
||||
5027253A190BF1B900AAF4ED /* cocos2d.h in Headers */,
|
||||
B665E3041AA80A6500DDB1C5 /* CCPUMeshSurfaceEmitter.h in Headers */,
|
||||
|
@ -11637,6 +11683,7 @@
|
|||
B6CAB2B51AF9AA1A00B9B856 /* btConvexShape.h in Headers */,
|
||||
B60C5BD619AC68B10056FBDE /* CCBillBoard.h in Headers */,
|
||||
15AE1BA419AADFDF00C27E9E /* UILayoutManager.h in Headers */,
|
||||
2962D5E81C61CBF9004821A3 /* CCUITextInput.h in Headers */,
|
||||
1A01C69418F57BE800EFE3A6 /* CCFloat.h in Headers */,
|
||||
1A57034D180BD09B0088DEC7 /* tinyxml2.h in Headers */,
|
||||
B6CAB4C31AF9AA1A00B9B856 /* Box.h in Headers */,
|
||||
|
@ -14234,12 +14281,14 @@
|
|||
B665E32A1AA80A6500DDB1C5 /* CCPUOnCountObserver.cpp in Sources */,
|
||||
15AE1B5F19AADA9900C27E9E /* UITextField.cpp in Sources */,
|
||||
B6CAB29B1AF9AA1A00B9B856 /* btConeShape.cpp in Sources */,
|
||||
2962D5F01C61CF3F004821A3 /* CCUISingleLineTextField.m in Sources */,
|
||||
15AE187C19AAD33D00C27E9E /* CCBFileLoader.cpp in Sources */,
|
||||
B6CAB3B31AF9AA1A00B9B856 /* btGearConstraint.cpp in Sources */,
|
||||
B6CAB4031AF9AA1A00B9B856 /* btMultiBodyDynamicsWorld.cpp in Sources */,
|
||||
B665E3F21AA80A6600DDB1C5 /* CCPUSlaveEmitter.cpp in Sources */,
|
||||
A045F6D61BA81577005076C7 /* CCTextureCube.cpp in Sources */,
|
||||
50ABBE651925AB6F00A911A9 /* CCEventListenerCustom.cpp in Sources */,
|
||||
2962D5F81C61DBBF004821A3 /* CCUIPasswordTextField.m in Sources */,
|
||||
D0FD034B1A3B51AA00825BB5 /* CCAllocatorDiagnostics.cpp in Sources */,
|
||||
B6CAB3E11AF9AA1A00B9B856 /* btUniversalConstraint.cpp in Sources */,
|
||||
15AE189B19AAD33D00C27E9E /* CCNode+CCBRelativePositioning.cpp in Sources */,
|
||||
|
@ -14542,6 +14591,7 @@
|
|||
50ABBE691925AB6F00A911A9 /* CCEventListenerFocus.cpp in Sources */,
|
||||
15AE18EA19AAD35000C27E9E /* CCActionNode.cpp in Sources */,
|
||||
B6CAB2391AF9AA1A00B9B856 /* btCompoundCompoundCollisionAlgorithm.cpp in Sources */,
|
||||
2962D6001C61DF1A004821A3 /* CCUIMultilineTextField.m in Sources */,
|
||||
15AE1A7819AAD40300C27E9E /* b2PolygonAndCircleContact.cpp in Sources */,
|
||||
15AE1A3419AAD3D500C27E9E /* b2EdgeShape.cpp in Sources */,
|
||||
B6CAB1F91AF9AA1A00B9B856 /* btDbvtBroadphase.cpp in Sources */,
|
||||
|
@ -14754,6 +14804,7 @@
|
|||
15AE199E19AAD39600C27E9E /* SliderReader.cpp in Sources */,
|
||||
B6CAB49F1AF9AA1A00B9B856 /* PosixThreadSupport.cpp in Sources */,
|
||||
50ABBE451925AB6F00A911A9 /* CCEvent.cpp in Sources */,
|
||||
291A09251C5F06A60068C1D2 /* CCUIEditBoxMac.mm in Sources */,
|
||||
D0FD034F1A3B51AA00825BB5 /* CCAllocatorGlobal.cpp in Sources */,
|
||||
50ABBE611925AB6F00A911A9 /* CCEventListenerAcceleration.cpp in Sources */,
|
||||
50ABBD9F1925AB4100A911A9 /* CCGroupCommand.cpp in Sources */,
|
||||
|
@ -14852,6 +14903,7 @@
|
|||
B6CAB2131AF9AA1A00B9B856 /* btActivatingCollisionAlgorithm.cpp in Sources */,
|
||||
15AE18A419AAD33D00C27E9E /* CCScale9SpriteLoader.cpp in Sources */,
|
||||
B6CAB2ED1AF9AA1A00B9B856 /* btStridingMeshInterface.cpp in Sources */,
|
||||
2962D6041C61F02E004821A3 /* CCUITextFieldFormatter.m in Sources */,
|
||||
182C5CD61A98F30500C30D34 /* Sprite3DReader.cpp in Sources */,
|
||||
38D9629D1ACA9721007C6FAF /* CocoStudio.cpp in Sources */,
|
||||
B6CAB24D1AF9AA1A00B9B856 /* btDefaultCollisionConfiguration.cpp in Sources */,
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#include "UIEditboxImpl-mac.h"
|
||||
#include "CCUITextInput.h"
|
||||
|
||||
#pragma mark - UIEditBox mac implementation
|
||||
|
||||
@interface UIEditBoxImplMac : NSObject <NSTextFieldDelegate, NSTextViewDelegate>
|
||||
|
||||
@property (nonatomic, retain) NSView<CCUITextInput> *textInput;
|
||||
@property (nonatomic, readonly) NSWindow *window;
|
||||
|
||||
@property (nonatomic, readonly, getter = isEditState) BOOL editState;
|
||||
@property (nonatomic, assign) void *editBox;
|
||||
@property (nonatomic, assign) NSString *text;
|
||||
@property (nonatomic, assign) CGRect frameRect;
|
||||
@property (nonatomic, assign) cocos2d::ui::EditBox::InputFlag dataInputMode;
|
||||
@property (nonatomic, assign) cocos2d::ui::EditBox::KeyboardReturnType keyboardReturnType;
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect editBox:(void *)editBox;
|
||||
- (void)setMaxLength:(int)maxLength;
|
||||
- (void)updateFrame:(CGRect)rect;
|
||||
|
||||
- (void)openKeyboard;
|
||||
- (void)closeKeyboard;
|
||||
|
||||
- (NSString *)getDefaultFontName;
|
||||
|
||||
- (void)setInputMode:(cocos2d::ui::EditBox::InputMode)inputMode;
|
||||
- (void)setInputFlag:(cocos2d::ui::EditBox::InputFlag)inputFlag;
|
||||
- (void)setReturnType:(cocos2d::ui::EditBox::KeyboardReturnType)returnType;
|
||||
|
||||
- (void)setPlaceHolder:(const char *)text;
|
||||
- (void)setVisible:(BOOL)visible;
|
||||
- (void)setTextColor:(NSColor*)color;
|
||||
- (void)setFont:(NSFont *)font;
|
||||
- (void)setPlaceholderFontColor:(NSColor*)color;
|
||||
- (void)setPlaceholderFont:(NSFont*)font;
|
||||
@end
|
|
@ -0,0 +1,345 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import "CCUIEditBoxMac.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "CCUISingleLineTextField.h"
|
||||
#include "CCUIPasswordTextField.h"
|
||||
#include "CCUIMultilineTextField.h"
|
||||
|
||||
#define getEditBoxImplMac() ((cocos2d::ui::EditBoxImplMac *)_editBox)
|
||||
|
||||
|
||||
@implementation UIEditBoxImplMac
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect editBox:(void *)editBox
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
|
||||
_editState = NO;
|
||||
self.frameRect = frameRect;
|
||||
|
||||
self.editBox = editBox;
|
||||
self.dataInputMode = cocos2d::ui::EditBox::InputFlag::INITIAL_CAPS_ALL_CHARACTERS;
|
||||
self.keyboardReturnType = cocos2d::ui::EditBox::KeyboardReturnType::DEFAULT;
|
||||
|
||||
[self createMultiLineTextField];
|
||||
[self.window.contentView addSubview:self.textInput];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSingleLineTextField
|
||||
{
|
||||
CCUISingleLineTextField *textField = [[[CCUISingleLineTextField alloc] initWithFrame:self.frameRect] autorelease];
|
||||
|
||||
self.textInput = textField;
|
||||
}
|
||||
|
||||
- (void)createMultiLineTextField
|
||||
{
|
||||
CCUIMultilineTextField *textView = [[[CCUIMultilineTextField alloc] initWithFrame:self.frameRect] autorelease];
|
||||
self.textInput = textView;
|
||||
}
|
||||
|
||||
- (void)createPasswordTextField
|
||||
{
|
||||
CCUIPasswordTextField *textField = [[[CCUIPasswordTextField alloc] initWithFrame:self.frameRect] autorelease];
|
||||
|
||||
self.textInput = textField;
|
||||
}
|
||||
|
||||
- (void)setTextInput:(NSView<CCUITextInput> *)textInput
|
||||
{
|
||||
if (_textInput == textInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Migrate properties
|
||||
textInput.ccui_textColor = _textInput.ccui_textColor ?: [NSColor whiteColor];
|
||||
textInput.ccui_text = _textInput.ccui_text ?: @"";
|
||||
textInput.ccui_placeholder = _textInput.ccui_placeholder ?: @"";
|
||||
textInput.ccui_font = _textInput.ccui_font ?: [NSFont systemFontOfSize:self.frameRect.size.height*3/2];
|
||||
textInput.ccui_maxLength = getEditBoxImplMac()->getMaxLength();
|
||||
|
||||
[_textInput removeFromSuperview];
|
||||
[_textInput release];
|
||||
|
||||
_textInput = [textInput retain];
|
||||
|
||||
[_textInput performSelector:@selector(setTextColor:) withObject:_textInput.ccui_textColor];
|
||||
[_textInput performSelector:@selector(setBackgroundColor:) withObject:[NSColor clearColor]];
|
||||
|
||||
if (![_textInput isKindOfClass:[NSTextView class]]) {
|
||||
[_textInput performSelector:@selector(setBordered:) withObject:[NSNumber numberWithBool:NO]];
|
||||
}
|
||||
_textInput.hidden = NO;
|
||||
_textInput.wantsLayer = YES;
|
||||
|
||||
[_textInput ccui_setDelegate:self];
|
||||
|
||||
[self setInputFlag:self.dataInputMode];
|
||||
[self setReturnType:self.keyboardReturnType];
|
||||
}
|
||||
|
||||
- (void)updateFrame:(CGRect)rect
|
||||
{
|
||||
NSRect frame = self.textInput.frame;
|
||||
frame.origin = rect.origin;
|
||||
frame.size = rect.size;
|
||||
|
||||
self.textInput.frame = frame;
|
||||
[self.window makeFirstResponder:self.window.contentView];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.textInput = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSWindow *)window
|
||||
{
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
return glview->getCocoaWindow();
|
||||
}
|
||||
|
||||
- (void)openKeyboard
|
||||
{
|
||||
[self.window.contentView addSubview:self.textInput];
|
||||
if (![self.textInput isKindOfClass:[NSTextView class]]) {
|
||||
[self.textInput becomeFirstResponder];
|
||||
}else {
|
||||
[self.window makeFirstResponder:self.textInput];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)closeKeyboard
|
||||
{
|
||||
if (![self.textInput isKindOfClass:[NSTextView class]]) {
|
||||
[self.textInput resignFirstResponder];
|
||||
}
|
||||
|
||||
[self.textInput removeFromSuperview];
|
||||
}
|
||||
|
||||
|
||||
- (const char*) getText
|
||||
{
|
||||
return [self.textInput.ccui_text UTF8String];
|
||||
}
|
||||
|
||||
- (void)controlTextDidBeginEditing:(NSNotification *)notification
|
||||
{
|
||||
_editState = YES;
|
||||
|
||||
getEditBoxImplMac()->editBoxEditingDidBegin();
|
||||
}
|
||||
|
||||
- (void)controlTextDidEndEditing:(NSNotification *)notification
|
||||
{
|
||||
_editState = NO;
|
||||
|
||||
getEditBoxImplMac()->editBoxEditingDidEnd([self getText]);
|
||||
}
|
||||
|
||||
- (void)setMaxLength:(int)length
|
||||
{
|
||||
self.textInput.ccui_maxLength = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each time when the text field's text has changed.
|
||||
*/
|
||||
- (void)controlTextDidChange:(NSNotification *)notification
|
||||
{
|
||||
getEditBoxImplMac()->editBoxEditingChanged([self getText]);
|
||||
}
|
||||
|
||||
- (NSString *)getDefaultFontName
|
||||
{
|
||||
return self.textInput.ccui_font.fontName ?: @"";
|
||||
}
|
||||
|
||||
- (void) hackingCodeForRefreshPosition
|
||||
{
|
||||
[self.window.contentView addSubview:self.textInput];
|
||||
if (![self.textInput isKindOfClass:[NSTextView class]]) {
|
||||
[self.textInput becomeFirstResponder];
|
||||
}else {
|
||||
[self.window makeFirstResponder:self.textInput];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setInputMode:(cocos2d::ui::EditBox::InputMode)inputMode
|
||||
{
|
||||
//multiline input
|
||||
if (inputMode == cocos2d::ui::EditBox::InputMode::ANY) {
|
||||
if (![self.textInput isKindOfClass:[NSTextView class]]) {
|
||||
[self createMultiLineTextField];
|
||||
[self hackingCodeForRefreshPosition];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (self.dataInputMode != cocos2d::ui::EditBox::InputFlag::PASSWORD) {
|
||||
if (![self.textInput isKindOfClass:[NSTextField class]]) {
|
||||
[self createSingleLineTextField];
|
||||
[self hackingCodeForRefreshPosition];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setInputFlag:(cocos2d::ui::EditBox::InputFlag)inputFlag
|
||||
{
|
||||
if (self.dataInputMode == inputFlag) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.dataInputMode == cocos2d::ui::EditBox::InputFlag::PASSWORD
|
||||
&& inputFlag != cocos2d::ui::EditBox::InputFlag::PASSWORD) {
|
||||
[self createSingleLineTextField];
|
||||
}
|
||||
|
||||
if (self.dataInputMode != cocos2d::ui::EditBox::InputFlag::PASSWORD
|
||||
&& inputFlag == cocos2d::ui::EditBox::InputFlag::PASSWORD) {
|
||||
[self createPasswordTextField];
|
||||
}
|
||||
|
||||
switch (inputFlag)
|
||||
{
|
||||
case cocos2d::ui::EditBox::InputFlag::PASSWORD:
|
||||
self.dataInputMode = inputFlag;
|
||||
break;
|
||||
case cocos2d::ui::EditBox::InputFlag::INITIAL_CAPS_WORD:
|
||||
CCLOG("INITIAL_CAPS_WORD not implemented");
|
||||
break;
|
||||
case cocos2d::ui::EditBox::InputFlag::INITIAL_CAPS_SENTENCE:
|
||||
CCLOG("INITIAL_CAPS_SENTENCE not implemented");
|
||||
break;
|
||||
case cocos2d::ui::EditBox::InputFlag::INITIAL_CAPS_ALL_CHARACTERS:
|
||||
CCLOG("INITIAL_CAPS_ALL_CHARACTERS not implemented");
|
||||
break;
|
||||
case cocos2d::ui::EditBox::InputFlag::SENSITIVE:
|
||||
CCLOG("SENSITIVE not implemented");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setReturnType:(cocos2d::ui::EditBox::KeyboardReturnType)returnType
|
||||
{
|
||||
CCLOG("setReturnType not implemented");
|
||||
}
|
||||
|
||||
- (void)setPlaceHolder:(const char *)text
|
||||
{
|
||||
self.textInput.ccui_placeholder = [NSString stringWithUTF8String:text];
|
||||
}
|
||||
|
||||
- (void)setVisible:(BOOL)visible
|
||||
{
|
||||
self.textInput.hidden = !visible;
|
||||
}
|
||||
|
||||
- (void)setTextColor:(NSColor*)color
|
||||
{
|
||||
self.textInput.ccui_textColor = color;
|
||||
}
|
||||
|
||||
- (void)setFont:(NSFont *)font
|
||||
{
|
||||
if (font != nil) {
|
||||
self.textInput.ccui_font = font;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setPlaceholderFontColor:(NSColor *)color
|
||||
{
|
||||
self.textInput.ccui_placeholderColor = color;
|
||||
}
|
||||
|
||||
- (void)setPlaceholderFont:(NSFont*)font
|
||||
{
|
||||
self.textInput.ccui_placeholderFont = font;
|
||||
}
|
||||
- (void)setText:(NSString *)text
|
||||
{
|
||||
self.textInput.ccui_text = text;
|
||||
}
|
||||
|
||||
- (BOOL)textShouldBeginEditing:(NSText *)textObject; // YES means do it
|
||||
{
|
||||
_editState = YES;
|
||||
|
||||
getEditBoxImplMac()->editBoxEditingDidBegin();
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)textDidEndEditing:(NSNotification *)notification
|
||||
{
|
||||
_editState = NO;
|
||||
|
||||
getEditBoxImplMac()->editBoxEditingDidEnd([self getText]);
|
||||
}
|
||||
|
||||
- (void)textDidChange:(NSNotification *)notification
|
||||
{
|
||||
NSTextView* textView = notification.object;
|
||||
|
||||
const char* inputText = [textView.string UTF8String];
|
||||
|
||||
getEditBoxImplMac()->editBoxEditingChanged(inputText);
|
||||
}
|
||||
|
||||
- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString
|
||||
{
|
||||
int maxLength = getEditBoxImplMac()->getMaxLength();
|
||||
if (maxLength < 0)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (affectedCharRange.length + affectedCharRange.location > textView.string.length) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSUInteger oldLength = textView.string.length;
|
||||
NSUInteger replacementLength = replacementString.length;
|
||||
NSUInteger rangeLength = affectedCharRange.length;
|
||||
|
||||
NSUInteger newLength = oldLength - rangeLength + replacementLength;
|
||||
|
||||
return newLength <= maxLength;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
|
@ -0,0 +1,31 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#include "CCUITextInput.h"
|
||||
|
||||
@interface CCUIMultilineTextField : NSTextView <CCUITextInput>
|
||||
|
||||
@end
|
|
@ -0,0 +1,121 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import "CCUIMultilineTextField.h"
|
||||
|
||||
@interface CCUIMultilineTextField()
|
||||
@property(nonatomic, copy)NSString* placeHolder;
|
||||
@end
|
||||
|
||||
@implementation CCUIMultilineTextField
|
||||
{
|
||||
NSString* _placeHolder;
|
||||
}
|
||||
@synthesize placeHolder = _placeHolder;
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
self.placeHolder = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholderFont:(NSFont *)font
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
-(NSFont*)ccui_placeholderFont
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholder:(NSString *)text
|
||||
{
|
||||
self.placeHolder = text;
|
||||
}
|
||||
|
||||
-(NSString*)ccui_placeholder
|
||||
{
|
||||
return self.placeHolder;
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholderColor:(NSColor *)color
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
-(NSColor*)ccui_placeholderColor
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - CCUITextInput
|
||||
- (NSString *)ccui_text
|
||||
{
|
||||
return self.string;
|
||||
}
|
||||
|
||||
- (void)ccui_setText:(NSString *)ccui_text
|
||||
{
|
||||
self.string = ccui_text;
|
||||
}
|
||||
|
||||
- (NSColor *)ccui_textColor
|
||||
{
|
||||
return self.textColor;
|
||||
}
|
||||
|
||||
- (void)ccui_setTextColor:(NSColor *)ccui_textColor
|
||||
{
|
||||
self.textColor = ccui_textColor;
|
||||
}
|
||||
|
||||
- (NSFont *)ccui_font
|
||||
{
|
||||
return self.font;
|
||||
}
|
||||
|
||||
- (void)ccui_setFont:(NSFont *)ccui_font
|
||||
{
|
||||
self.font = ccui_font;
|
||||
}
|
||||
|
||||
|
||||
- (void)ccui_setDelegate:(id<NSTextFieldDelegate,NSTextViewDelegate>)delegate
|
||||
{
|
||||
self.delegate = delegate;
|
||||
}
|
||||
|
||||
- (void)ccui_setMaxLength:(int)ccui_maxLength
|
||||
{
|
||||
//noop
|
||||
}
|
||||
-(int)ccui_maxLength
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@end
|
|
@ -0,0 +1,33 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#include "CCUITextInput.h"
|
||||
|
||||
@interface CCUIPasswordTextField : NSSecureTextField<CCUITextInput>
|
||||
|
||||
@end
|
||||
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import "CCUIPasswordTextField.h"
|
||||
#include "CCUITextFieldFormatter.h"
|
||||
|
||||
@interface CCUIPasswordTextField()
|
||||
@property (nonatomic, retain) NSMutableDictionary *placeholderAttributes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CCUIPasswordTextField
|
||||
{
|
||||
NSMutableDictionary* _placeholderAttributes;
|
||||
}
|
||||
@synthesize placeholderAttributes = _placeholderAttributes;
|
||||
|
||||
-(id) initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ([super initWithFrame:frameRect]) {
|
||||
NSFont* font = [NSFont systemFontOfSize:frameRect.size.height * 3 /2];
|
||||
self.placeholderAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||
font, NSFontAttributeName,
|
||||
[NSColor grayColor], NSForegroundColorAttributeName,
|
||||
nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.placeholderAttributes = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholderFont:(NSFont *)font
|
||||
{
|
||||
[self.placeholderAttributes setObject:font forKey:NSFontAttributeName];
|
||||
}
|
||||
|
||||
-(NSString*)ccui_placeholder
|
||||
{
|
||||
return self.placeholderString;
|
||||
}
|
||||
|
||||
-(NSFont*)ccui_placeholderFont
|
||||
{
|
||||
return [self.placeholderAttributes objectForKey:NSFontAttributeName];
|
||||
}
|
||||
|
||||
-(NSColor*)ccui_placeholderColor
|
||||
{
|
||||
return [self.placeholderAttributes objectForKey:NSForegroundColorAttributeName];
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholder:(NSString *)text
|
||||
{
|
||||
NSAttributedString *as = [[NSAttributedString alloc] initWithString:text
|
||||
attributes:self.placeholderAttributes];
|
||||
|
||||
[[self cell] setPlaceholderAttributedString:as];
|
||||
|
||||
[as release];
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholderColor:(NSColor *)color
|
||||
{
|
||||
[self.placeholderAttributes setObject:color forKey:NSForegroundColorAttributeName];
|
||||
}
|
||||
|
||||
#pragma mark - CCUITextInput
|
||||
- (NSString *)ccui_text
|
||||
{
|
||||
return self.stringValue;
|
||||
}
|
||||
|
||||
- (void)ccui_setText:(NSString *)ccui_text
|
||||
{
|
||||
self.stringValue = ccui_text;
|
||||
}
|
||||
|
||||
- (NSColor *)ccui_textColor
|
||||
{
|
||||
return self.textColor;
|
||||
}
|
||||
|
||||
- (void)ccui_setTextColor:(NSColor *)ccui_textColor
|
||||
{
|
||||
self.textColor = ccui_textColor;
|
||||
}
|
||||
|
||||
- (NSFont *)ccui_font
|
||||
{
|
||||
return self.font;
|
||||
}
|
||||
|
||||
- (void)ccui_setFont:(NSFont *)ccui_font
|
||||
{
|
||||
self.font = ccui_font;
|
||||
}
|
||||
|
||||
|
||||
- (void)ccui_setDelegate:(id<NSTextFieldDelegate,NSTextViewDelegate>)delegate
|
||||
{
|
||||
self.delegate = delegate;
|
||||
}
|
||||
|
||||
- (void)ccui_setMaxLength:(int)length
|
||||
{
|
||||
id formater = [[[CCUITextFieldFormatter alloc]init] autorelease];
|
||||
[formater setMaximumLength:length];
|
||||
[self setFormatter:formater];
|
||||
}
|
||||
|
||||
- (int)ccui_maxLength
|
||||
{
|
||||
return [self.formatter maximumLength];
|
||||
}
|
||||
@end
|
|
@ -0,0 +1,33 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#include "CCUITextInput.h"
|
||||
|
||||
@interface CCUISingleLineTextField : NSTextField<CCUITextInput>
|
||||
|
||||
@end
|
||||
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import "CCUISingleLineTextField.h"
|
||||
#include "CCUITextFieldFormatter.h"
|
||||
|
||||
@interface CCUISingleLineTextField()
|
||||
@property (nonatomic, retain) NSMutableDictionary *placeholderAttributes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CCUISingleLineTextField
|
||||
{
|
||||
NSMutableDictionary* _placeholderAttributes;
|
||||
}
|
||||
|
||||
@synthesize placeholderAttributes = _placeholderAttributes;
|
||||
|
||||
-(id) initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ([super initWithFrame:frameRect]) {
|
||||
NSFont* font = [NSFont systemFontOfSize:frameRect.size.height * 3 /2];
|
||||
self.placeholderAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||
font, NSFontAttributeName,
|
||||
[NSColor grayColor], NSForegroundColorAttributeName,
|
||||
nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
self.placeholderAttributes = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholderFont:(NSFont *)font
|
||||
{
|
||||
[self.placeholderAttributes setObject:font forKey:NSFontAttributeName];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)ccui_setPlaceholder:(NSString *)text
|
||||
{
|
||||
NSAttributedString *as = [[NSAttributedString alloc] initWithString:text
|
||||
attributes:self.placeholderAttributes];
|
||||
|
||||
[[self cell] setPlaceholderAttributedString:as];
|
||||
|
||||
[as release];
|
||||
}
|
||||
|
||||
-(NSString*)ccui_placeholder
|
||||
{
|
||||
return self.placeholderString;
|
||||
}
|
||||
|
||||
-(NSFont*)ccui_placeholderFont
|
||||
{
|
||||
return [self.placeholderAttributes objectForKey:NSFontAttributeName];
|
||||
}
|
||||
|
||||
-(NSColor*)ccui_placeholderColor
|
||||
{
|
||||
return [self.placeholderAttributes objectForKey:NSForegroundColorAttributeName];
|
||||
}
|
||||
|
||||
-(void)ccui_setPlaceholderColor:(NSColor *)color
|
||||
{
|
||||
[self.placeholderAttributes setObject:color forKey:NSForegroundColorAttributeName];
|
||||
}
|
||||
|
||||
- (NSString *)ccui_text
|
||||
{
|
||||
return self.stringValue;
|
||||
}
|
||||
|
||||
- (void)ccui_setText:(NSString *)ccui_text
|
||||
{
|
||||
self.stringValue = ccui_text;
|
||||
}
|
||||
|
||||
- (NSColor *)ccui_textColor
|
||||
{
|
||||
return self.textColor;
|
||||
}
|
||||
|
||||
- (void)ccui_setTextColor:(NSColor *)ccui_textColor
|
||||
{
|
||||
self.textColor = ccui_textColor;
|
||||
}
|
||||
|
||||
- (NSFont *)ccui_font
|
||||
{
|
||||
return self.font;
|
||||
}
|
||||
|
||||
- (void)ccui_setFont:(NSFont *)ccui_font
|
||||
{
|
||||
self.font = ccui_font;
|
||||
}
|
||||
|
||||
|
||||
- (void)ccui_setDelegate:(id<NSTextFieldDelegate,NSTextViewDelegate>)delegate
|
||||
{
|
||||
self.delegate = delegate;
|
||||
}
|
||||
|
||||
- (void)ccui_setMaxLength:(int)length
|
||||
{
|
||||
id formater = [[[CCUITextFieldFormatter alloc]init] autorelease];
|
||||
[formater setMaximumLength:length];
|
||||
[self setFormatter:formater];
|
||||
}
|
||||
|
||||
- (int)ccui_maxLength
|
||||
{
|
||||
return [self.formatter maximumLength];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,31 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface CCUITextFieldFormatter : NSFormatter
|
||||
@property (nonatomic, assign) int maximumLength;
|
||||
|
||||
@end
|
|
@ -0,0 +1,69 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#import "CCUITextFieldFormatter.h"
|
||||
|
||||
@implementation CCUITextFieldFormatter
|
||||
{
|
||||
int _maximumLength;
|
||||
}
|
||||
|
||||
@synthesize maximumLength = _maximumLength;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_maximumLength = INT_MAX;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)stringForObjectValue:(id)object
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
|
||||
{
|
||||
*object = string;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
|
||||
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
|
||||
originalString:(NSString *)origString
|
||||
originalSelectedRange:(NSRange)origSelRange
|
||||
errorDescription:(NSString **)error
|
||||
{
|
||||
return (*partialStringPtr).length <= self.maximumLength;
|
||||
}
|
||||
|
||||
- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
@end
|
|
@ -0,0 +1,47 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 zilongshanren
|
||||
|
||||
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 CCUITextInput_h
|
||||
#define CCUITextInput_h
|
||||
|
||||
/**
|
||||
This protocol provides a common interface for consolidating text input method calls
|
||||
*/
|
||||
@protocol CCUITextInput <NSObject>
|
||||
|
||||
@property (nonatomic, retain, setter=ccui_setText:) NSString *ccui_text;
|
||||
@property (nonatomic, retain, setter=ccui_setTextColor:) NSColor *ccui_textColor;
|
||||
@property (nonatomic, retain, setter=ccui_setFont:) NSFont *ccui_font;
|
||||
@property (nonatomic, assign, setter=ccui_setMaxLength:)int ccui_maxLength;
|
||||
@property (nonatomic, retain, setter=ccui_setPlaceholder:) NSString *ccui_placeholder;
|
||||
@property (nonatomic, retain, setter=ccui_setPlaceholderColor:) NSColor *ccui_placeholderColor;
|
||||
@property (nonatomic, retain, setter=ccui_setPlaceholderFont:) NSFont *ccui_placeholderFont;
|
||||
|
||||
/* can only set. and not get, since the getter will only return one delegate implementation */
|
||||
- (void)ccui_setDelegate:(id<NSTextFieldDelegate, NSTextViewDelegate>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* CCUITextInput_h */
|
|
@ -67,16 +67,12 @@ public:
|
|||
virtual void setNativePlaceHolder(const char* pText) override;
|
||||
virtual void setNativeVisible(bool visible) override;
|
||||
virtual void updateNativeFrame(const Rect& rect) override;
|
||||
virtual void setNativeContentSize(const Size& size) override {};
|
||||
virtual const char* getNativeDefaultFontName() override;
|
||||
virtual void nativeOpenKeyboard() override;
|
||||
virtual void nativeCloseKeyboard() override;
|
||||
virtual void setNativeMaxLength(int maxLength);
|
||||
|
||||
|
||||
private:
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance)override {}
|
||||
|
||||
int _editBoxIndex;
|
||||
};
|
||||
|
||||
|
|
|
@ -246,13 +246,6 @@ void EditBoxImplCommon::setContentSize(const Size& size)
|
|||
_contentSize = size;
|
||||
CCLOG("[Edit text] content size = (%f, %f)", size.width, size.height);
|
||||
placeInactiveLabels();
|
||||
|
||||
auto director = cocos2d::Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
Size controlSize = Size(size.width * glview->getScaleX() * _label->getNodeToWorldAffineTransform().a,size.height * glview->getScaleY() * _label->getNodeToWorldAffineTransform().a);
|
||||
|
||||
this->setNativeContentSize(controlSize);
|
||||
|
||||
}
|
||||
|
||||
void EditBoxImplCommon::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
|
|
|
@ -107,7 +107,6 @@ public:
|
|||
virtual void setNativePlaceHolder(const char* pText) = 0;
|
||||
virtual void setNativeVisible(bool visible) = 0;
|
||||
virtual void updateNativeFrame(const Rect& rect) = 0;
|
||||
virtual void setNativeContentSize(const Size& size) = 0;
|
||||
virtual const char* getNativeDefaultFontName() = 0;
|
||||
virtual void nativeOpenKeyboard() = 0;
|
||||
virtual void nativeCloseKeyboard() = 0;
|
||||
|
@ -118,6 +117,7 @@ private:
|
|||
void initInactiveLabels(const Size& size);
|
||||
void setInactiveText(const char* pText);
|
||||
void placeInactiveLabels();
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance)override {};
|
||||
|
||||
Label* _label;
|
||||
Label* _labelPlaceHolder;
|
||||
|
|
|
@ -53,9 +53,6 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual ~EditBoxImplIOS();
|
||||
virtual void setPosition(const Vec2& pos) override;
|
||||
virtual void setAnchorPoint(const Vec2& anchorPoint) override;
|
||||
virtual void updatePosition(float dt) override;
|
||||
|
||||
virtual bool isEditing() override;
|
||||
virtual void createNativeControl(const Rect& frame) override;
|
||||
|
@ -70,7 +67,6 @@ public:
|
|||
virtual void setNativePlaceHolder(const char* pText) override;
|
||||
virtual void setNativeVisible(bool visible) override;
|
||||
virtual void updateNativeFrame(const Rect& rect) override;
|
||||
virtual void setNativeContentSize(const Size& size) override;
|
||||
virtual const char* getNativeDefaultFontName() override;
|
||||
virtual void nativeOpenKeyboard() override;
|
||||
virtual void nativeCloseKeyboard() override;
|
||||
|
@ -81,11 +77,8 @@ public:
|
|||
virtual void doAnimationWhenKeyboardMove(float duration, float distance) override;
|
||||
private:
|
||||
UIFont* constructFont(const char* fontName, int fontSize);
|
||||
void adjustTextFieldPosition();
|
||||
|
||||
UIEditBoxImplIOS_objc* _systemControl;
|
||||
Vec2 _position;
|
||||
Vec2 _anchorPoint;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ EditBoxImpl* __createSystemEditBox(EditBox* pEditBox)
|
|||
EditBoxImplIOS::EditBoxImplIOS(EditBox* pEditText)
|
||||
: EditBoxImplCommon(pEditText)
|
||||
, _systemControl(nullptr)
|
||||
, _anchorPoint(Vec2(0.5f, 0.5f))
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -126,6 +125,10 @@ void EditBoxImplIOS::setNativePlaceholderFontColor(const Color4B& color)
|
|||
void EditBoxImplIOS::setNativeInputMode(EditBox::InputMode inputMode)
|
||||
{
|
||||
[_systemControl setInputMode:inputMode];
|
||||
|
||||
auto oldPos = _editBox->getPosition();
|
||||
_editBox->setPosition(oldPos + Vec2(10,10));
|
||||
_editBox->setPosition(oldPos);
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::setNativeInputFlag(EditBox::InputFlag inputFlag)
|
||||
|
@ -170,17 +173,16 @@ void EditBoxImplIOS::setNativeVisible(bool visible)
|
|||
|
||||
void EditBoxImplIOS::updateNativeFrame(const Rect& rect)
|
||||
{
|
||||
//no-op
|
||||
}
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
CCEAGLView *eaglview = (CCEAGLView *) glview->getEAGLView();
|
||||
|
||||
void EditBoxImplIOS::setNativeContentSize(const Size& size)
|
||||
{
|
||||
auto director = cocos2d::Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
CCEAGLView *eaglview = static_cast<CCEAGLView *>(glview->getEAGLView());
|
||||
float factor = eaglview.contentScaleFactor;
|
||||
|
||||
[_systemControl setContentSize:CGSizeMake(size.width / factor, size.height / factor)];
|
||||
[_systemControl updateFrame:CGRectMake(rect.origin.x / factor,
|
||||
rect.origin.y / factor,
|
||||
rect.size.width / factor,
|
||||
rect.size.height / factor)];
|
||||
|
||||
}
|
||||
|
||||
const char* EditBoxImplIOS::getNativeDefaultFontName()
|
||||
|
@ -230,58 +232,6 @@ UIFont* EditBoxImplIOS::constructFont(const char *fontName, int fontSize)
|
|||
}
|
||||
return textFont;
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::setPosition(const Vec2& pos)
|
||||
{
|
||||
_position = pos;
|
||||
adjustTextFieldPosition();
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::setAnchorPoint(const Vec2& anchorPoint)
|
||||
{
|
||||
CCLOG("[Edit text] anchor point = (%f, %f)", anchorPoint.x, anchorPoint.y);
|
||||
_anchorPoint = anchorPoint;
|
||||
setPosition(_position);
|
||||
}
|
||||
|
||||
void EditBoxImplIOS::updatePosition(float dt)
|
||||
{
|
||||
if (nullptr != _systemControl) {
|
||||
this->adjustTextFieldPosition();
|
||||
}
|
||||
}
|
||||
|
||||
static CGPoint convertDesignCoordToScreenCoord(const Vec2& designCoord)
|
||||
{
|
||||
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);
|
||||
|
||||
float factor = eaglview.contentScaleFactor;
|
||||
screenPos.x = screenPos.x / factor;
|
||||
screenPos.y = screenPos.y / factor;
|
||||
|
||||
CCLOGINFO("[EditBox] pos x = %f, y = %f", screenGLPos.x, screenGLPos.y);
|
||||
return screenPos;
|
||||
}
|
||||
|
||||
|
||||
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)];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
|
||||
#include "UIEditBoxImpl.h"
|
||||
#include "UIEditBoxImpl-common.h"
|
||||
|
||||
@class UIEditBoxImplMac;
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace ui {
|
|||
|
||||
class EditBox;
|
||||
|
||||
class EditBoxImplMac : public EditBoxImpl
|
||||
class EditBoxImplMac : public EditBoxImplCommon
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -53,47 +53,27 @@ public:
|
|||
*/
|
||||
virtual ~EditBoxImplMac();
|
||||
|
||||
virtual bool initWithSize(const Size& size) override;
|
||||
virtual void setFont(const char* pFontName, int fontSize) override;
|
||||
virtual void setFontColor(const Color4B& color) override;
|
||||
virtual void setPlaceholderFont(const char* pFontName, int fontSize) override;
|
||||
virtual void setPlaceholderFontColor(const Color4B& color) override;
|
||||
virtual void setInputMode(EditBox::InputMode inputMode) override;
|
||||
virtual void setInputFlag(EditBox::InputFlag inputFlag) override;
|
||||
virtual void setMaxLength(int maxLength) override;
|
||||
virtual int getMaxLength() override;
|
||||
virtual void setReturnType(EditBox::KeyboardReturnType returnType) override;
|
||||
virtual bool isEditing() override;
|
||||
|
||||
virtual void setText(const char* pText) override;
|
||||
virtual const char* getText(void) override;
|
||||
virtual void setPlaceHolder(const char* pText) override;
|
||||
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 draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)override;
|
||||
virtual void doAnimationWhenKeyboardMove(float duration, float distance) override;
|
||||
virtual void openKeyboard() override;
|
||||
virtual void closeKeyboard() override;
|
||||
virtual void updatePosition(float dt) override;
|
||||
/**
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual void onEnter(void) override;
|
||||
virtual void createNativeControl(const Rect& frame) override;
|
||||
virtual void setNativeFont(const char* pFontName, int fontSize) override;
|
||||
virtual void setNativeFontColor(const Color4B& color) override;
|
||||
virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) override;
|
||||
virtual void setNativePlaceholderFontColor(const Color4B& color) override;
|
||||
virtual void setNativeInputMode(EditBox::InputMode inputMode) override;
|
||||
virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) override;
|
||||
virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType)override;
|
||||
virtual void setNativeText(const char* pText) override;
|
||||
virtual void setNativePlaceHolder(const char* pText) override;
|
||||
virtual void setNativeVisible(bool visible) override;
|
||||
virtual void updateNativeFrame(const Rect& rect) override;
|
||||
virtual const char* getNativeDefaultFontName() override;
|
||||
virtual void nativeOpenKeyboard() override;
|
||||
virtual void nativeCloseKeyboard() override;
|
||||
virtual void setNativeMaxLength(int maxLength) override;
|
||||
|
||||
private:
|
||||
NSPoint convertDesignCoordToScreenCoord(const Vec2& designCoord, bool bInRetinaMode);
|
||||
void adjustTextFieldPosition();
|
||||
NSFont* constructFont(const char* fontName, int fontSize);
|
||||
Size _contentSize;
|
||||
Vec2 _position;
|
||||
Vec2 _anchorPoint;
|
||||
int _maxTextLength;
|
||||
|
||||
bool _inRetinaMode;
|
||||
UIEditBoxImplMac* _sysEdit;
|
||||
};
|
||||
|
|
|
@ -30,299 +30,7 @@
|
|||
#include "base/CCDirector.h"
|
||||
#include "UIEditBox.h"
|
||||
#include "deprecated/CCString.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#define getEditBoxImplMac() ((cocos2d::ui::EditBoxImplMac *)_editBox)
|
||||
|
||||
#pragma mark - internal classes
|
||||
|
||||
/** TODO: Missing doc - What does "CustomTextFieldFormatter" do?
|
||||
*/
|
||||
@interface CustomTextFieldFormatter : NSFormatter
|
||||
{
|
||||
int _maximumLength;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) int maximumLength;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CustomTextFieldFormatter
|
||||
@synthesize maximumLength = _maximumLength;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_maximumLength = INT_MAX;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)stringForObjectValue:(id)object
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
|
||||
{
|
||||
*object = string;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
|
||||
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
|
||||
originalString:(NSString *)origString
|
||||
originalSelectedRange:(NSRange)origSelRange
|
||||
errorDescription:(NSString **)error
|
||||
{
|
||||
return (*partialStringPtr).length <= self.maximumLength;
|
||||
}
|
||||
|
||||
- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - UIEditBox mac implementation
|
||||
|
||||
@interface UIEditBoxImplMac : NSObject <NSTextFieldDelegate>
|
||||
{
|
||||
NSTextField* _textField;
|
||||
NSSecureTextField* _secureTextField;
|
||||
NSMutableDictionary* _placeholderAttributes;
|
||||
NSWindow* _window;
|
||||
|
||||
BOOL _editState;
|
||||
BOOL _secure;
|
||||
void* _editBox;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSTextField* textField;
|
||||
@property (nonatomic, retain) NSSecureTextField *secureTextField;
|
||||
@property (nonatomic, retain) NSMutableDictionary *placeholderAttributes;
|
||||
@property (nonatomic, readonly) NSWindow *window;
|
||||
|
||||
@property (nonatomic, readonly, getter = isEditState) BOOL editState;
|
||||
@property (nonatomic, assign, getter = isSecure) BOOL secure;
|
||||
@property (nonatomic, assign) void *editBox;
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect editBox:(void *)editBox;
|
||||
|
||||
- (void)doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance;
|
||||
- (void)setPosition:(NSPoint)pos;
|
||||
|
||||
- (void)openKeyboard;
|
||||
- (void)closeKeyboard;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UIEditBoxImplMac
|
||||
@synthesize textField = _textField;
|
||||
@synthesize secureTextField = _secureTextField;
|
||||
@synthesize placeholderAttributes = _placeholderAttributes;
|
||||
@synthesize window = _window;
|
||||
@synthesize editState = _editState;
|
||||
@synthesize secure = _secure;
|
||||
@synthesize editBox = _editBox;
|
||||
|
||||
- (instancetype)initWithFrame:(NSRect)frameRect editBox:(void *)editBox
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
|
||||
_editState = NO;
|
||||
_secure = NO;
|
||||
|
||||
self.textField = [[[NSTextField alloc] initWithFrame:frameRect] autorelease];
|
||||
self.secureTextField = [[[NSSecureTextField alloc] initWithFrame:frameRect] autorelease];
|
||||
|
||||
//TODO: need to delete hard code here.
|
||||
NSFont *font = [NSFont systemFontOfSize:frameRect.size.height*2/3];
|
||||
_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.window.contentView addSubview:_textField];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_textField resignFirstResponder];
|
||||
[_textField removeFromSuperview];
|
||||
[_textField release];
|
||||
|
||||
[_secureTextField resignFirstResponder];
|
||||
[_secureTextField removeFromSuperview];
|
||||
[_secureTextField release];
|
||||
|
||||
[_placeholderAttributes release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSWindow *)window
|
||||
{
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
return glview->getCocoaWindow();
|
||||
}
|
||||
|
||||
- (void)setPosition:(NSPoint)pos
|
||||
{
|
||||
NSRect frame = _textField.frame;
|
||||
frame.origin = pos;
|
||||
|
||||
_textField.frame = frame;
|
||||
_secureTextField.frame = frame;
|
||||
}
|
||||
|
||||
- (void)setupTextField:(NSTextField *)textField
|
||||
{
|
||||
textField.textColor = [NSColor whiteColor];
|
||||
textField.backgroundColor = [NSColor clearColor];
|
||||
textField.bordered = NO;
|
||||
textField.hidden = NO;
|
||||
textField.wantsLayer = YES;
|
||||
textField.delegate = self;
|
||||
}
|
||||
|
||||
- (void)doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance
|
||||
{
|
||||
[self.window.contentView doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
|
||||
}
|
||||
|
||||
- (void)setSecure:(BOOL)secure
|
||||
{
|
||||
NSAssert(secure, @"Can only set this flag to true");
|
||||
|
||||
_secure = secure;
|
||||
|
||||
[_textField.superview addSubview:_secureTextField];
|
||||
[_textField removeFromSuperview];
|
||||
}
|
||||
|
||||
- (void)openKeyboard
|
||||
{
|
||||
NSView *contentView = self.window.contentView;
|
||||
|
||||
if (!_secure) {
|
||||
[contentView addSubview:_textField];
|
||||
[_textField becomeFirstResponder];
|
||||
}
|
||||
else {
|
||||
[contentView addSubview:_secureTextField];
|
||||
[_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)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
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
#include "CCUIEditBoxMac.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -334,9 +42,7 @@ EditBoxImpl* __createSystemEditBox(EditBox* pEditBox)
|
|||
}
|
||||
|
||||
EditBoxImplMac::EditBoxImplMac(EditBox* pEditText)
|
||||
: EditBoxImpl(pEditText)
|
||||
, _anchorPoint(Vec2(0.5f, 0.5f))
|
||||
, _maxTextLength(-1)
|
||||
: EditBoxImplCommon(pEditText)
|
||||
, _sysEdit(nullptr)
|
||||
{
|
||||
//! TODO: Retina on Mac
|
||||
|
@ -349,29 +55,21 @@ EditBoxImplMac::~EditBoxImplMac()
|
|||
[_sysEdit release];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::doAnimationWhenKeyboardMove(float duration, float distance)
|
||||
void EditBoxImplMac::createNativeControl(const cocos2d::Rect &frame)
|
||||
{
|
||||
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;
|
||||
}
|
||||
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
|
||||
Size size = frame.size;
|
||||
NSRect rect = NSMakeRect(0, 0,
|
||||
size.width * glview->getScaleX(),
|
||||
size.height * glview->getScaleY());
|
||||
|
||||
float factor = cocos2d::Director::getInstance()->getContentScaleFactor();
|
||||
|
||||
rect.size.width /= factor;
|
||||
rect.size.height /= factor;
|
||||
|
||||
_sysEdit = [[UIEditBoxImplMac alloc] initWithFrame:rect editBox:this];
|
||||
|
||||
if (!_sysEdit)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
this->setNativeVisible(false);
|
||||
}
|
||||
|
||||
NSFont* EditBoxImplMac::constructFont(const char *fontName, int fontSize)
|
||||
|
@ -383,7 +81,7 @@ NSFont* EditBoxImplMac::constructFont(const char *fontName, int fontSize)
|
|||
|
||||
if (fontSize == -1)
|
||||
{
|
||||
NSRect frameRect = [_sysEdit.textField frame];
|
||||
NSRect frameRect = [_sysEdit.textInput frame];
|
||||
fontSize = frameRect.size.height*2/3;
|
||||
}
|
||||
else
|
||||
|
@ -404,16 +102,13 @@ NSFont* EditBoxImplMac::constructFont(const char *fontName, int fontSize)
|
|||
return textFont;
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setFont(const char* pFontName, int fontSize)
|
||||
void EditBoxImplMac::setNativeFont(const char *pFontName, int fontSize)
|
||||
{
|
||||
NSFont* textFont = constructFont(pFontName, fontSize);
|
||||
if (textFont != nil) {
|
||||
[_sysEdit.textField setFont:textFont];
|
||||
[_sysEdit.secureTextField setFont:textFont];
|
||||
}
|
||||
[_sysEdit setFont:textFont];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setPlaceholderFont(const char* pFontName, int fontSize)
|
||||
void EditBoxImplMac::setNativePlaceholderFont(const char *pFontName, int fontSize)
|
||||
{
|
||||
NSFont *textFont = constructFont(pFontName, fontSize);
|
||||
|
||||
|
@ -421,79 +116,50 @@ void EditBoxImplMac::setPlaceholderFont(const char* pFontName, int fontSize)
|
|||
CCLOGWARN("Font not found: %s", pFontName);
|
||||
return;
|
||||
}
|
||||
|
||||
[_sysEdit.placeholderAttributes setObject:textFont forKey:NSFontAttributeName];
|
||||
|
||||
/* reload placeholder */
|
||||
const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String;
|
||||
if (placeholder) {
|
||||
setPlaceHolder(placeholder);
|
||||
}
|
||||
[_sysEdit setPlaceholderFont:textFont];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setFontColor(const Color4B& color)
|
||||
void EditBoxImplMac::setNativeFontColor(const cocos2d::Color4B &color)
|
||||
{
|
||||
NSColor *newColor = [NSColor colorWithCalibratedRed:color.r / 255.0f green:color.g / 255.0f blue:color.b / 255.0f alpha:color.a / 255.f];
|
||||
_sysEdit.textField.textColor = newColor;
|
||||
_sysEdit.secureTextField.textColor = newColor;
|
||||
NSColor *newColor = [NSColor colorWithCalibratedRed:color.r / 255.0f
|
||||
green:color.g / 255.0f
|
||||
blue:color.b / 255.0f
|
||||
alpha:color.a / 255.f];
|
||||
|
||||
[_sysEdit setTextColor:newColor];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setPlaceholderFontColor(const Color4B& color)
|
||||
void EditBoxImplMac::setNativePlaceholderFontColor(const cocos2d::Color4B &color)
|
||||
{
|
||||
NSColor *nsColor = [NSColor colorWithCalibratedRed:color.r/255.f green:color.g / 255.f blue:color.b / 255.f alpha:color.a / 255.f];
|
||||
[_sysEdit.placeholderAttributes setObject:nsColor forKey:NSForegroundColorAttributeName];
|
||||
|
||||
/* reload placeholder */
|
||||
const char *placeholder = [_sysEdit.textField.cell placeholderAttributedString].string.UTF8String;
|
||||
if (placeholder) {
|
||||
setPlaceHolder(placeholder);
|
||||
}
|
||||
NSColor *newColor = [NSColor colorWithCalibratedRed:color.r/255.f
|
||||
green:color.g / 255.f
|
||||
blue:color.b / 255.f
|
||||
alpha:color.a / 255.f];
|
||||
[_sysEdit setPlaceholderFontColor:newColor];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setInputMode(EditBox::InputMode inputMode)
|
||||
void EditBoxImplMac::setNativeInputMode(EditBox::InputMode inputMode)
|
||||
{
|
||||
[_sysEdit setInputMode:inputMode];
|
||||
auto oldPosition = _editBox->getPosition();
|
||||
_editBox->setPosition(_editBox->getPosition() + Vec2(10,10));
|
||||
_editBox->setPosition(oldPosition);
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setMaxLength(int maxLength)
|
||||
void EditBoxImplMac::setNativeMaxLength(int maxLength)
|
||||
{
|
||||
_maxTextLength = maxLength;
|
||||
id formater = [[[CustomTextFieldFormatter alloc]init] autorelease];
|
||||
[formater setMaximumLength:maxLength];
|
||||
[_sysEdit.secureTextField setFormatter:formater];
|
||||
[_sysEdit.textField setFormatter:formater];
|
||||
[_sysEdit setMaxLength:maxLength];
|
||||
}
|
||||
|
||||
int EditBoxImplMac::getMaxLength()
|
||||
|
||||
void EditBoxImplMac::setNativeInputFlag(EditBox::InputFlag inputFlag)
|
||||
{
|
||||
return _maxTextLength;
|
||||
[_sysEdit setInputFlag:inputFlag];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setInputFlag(EditBox::InputFlag inputFlag)
|
||||
{
|
||||
switch (inputFlag)
|
||||
{
|
||||
case EditBox::InputFlag::PASSWORD:
|
||||
_sysEdit.secure = YES;
|
||||
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::INITIAL_CAPS_ALL_CHARACTERS:
|
||||
CCLOGWARN("INITIAL_CAPS_ALL_CHARACTERS not implemented");
|
||||
break;
|
||||
case EditBox::InputFlag::SENSITIVE:
|
||||
CCLOGWARN("SENSITIVE not implemented");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setReturnType(EditBox::KeyboardReturnType returnType)
|
||||
void EditBoxImplMac::setNativeReturnType(EditBox::KeyboardReturnType returnType)
|
||||
{
|
||||
[_sysEdit setReturnType:returnType];
|
||||
}
|
||||
|
||||
bool EditBoxImplMac::isEditing()
|
||||
|
@ -501,118 +167,51 @@ bool EditBoxImplMac::isEditing()
|
|||
return [_sysEdit isEditState] ? true : false;
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setText(const char* pText)
|
||||
void EditBoxImplMac::setNativeText(const char *pText)
|
||||
{
|
||||
NSString *string = [NSString stringWithUTF8String:pText];
|
||||
_sysEdit.textField.stringValue = string;
|
||||
_sysEdit.secureTextField.stringValue = string;
|
||||
NSString *text = [NSString stringWithUTF8String:pText];
|
||||
[_sysEdit setText:text];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setNativePlaceHolder(const char* pText)
|
||||
{
|
||||
[_sysEdit setPlaceHolder:pText];
|
||||
}
|
||||
|
||||
const char* EditBoxImplMac::getText(void)
|
||||
void EditBoxImplMac::setNativeVisible(bool visible)
|
||||
{
|
||||
if (_sysEdit.secureTextField.superview) {
|
||||
return [_sysEdit.secureTextField.stringValue UTF8String];
|
||||
}
|
||||
|
||||
return [_sysEdit.textField.stringValue UTF8String];
|
||||
[_sysEdit setVisible:visible];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::setPlaceHolder(const char* pText)
|
||||
void EditBoxImplMac::updateNativeFrame(const cocos2d::Rect &rect)
|
||||
{
|
||||
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;
|
||||
auto viewPortRect = eglView->getViewPortRect();
|
||||
// Coordinate System on OSX has its origin at the lower left corner.
|
||||
// https://developer.apple.com/library/ios/documentation/General/Conceptual/Devpedia-CocoaApp/CoordinateSystem.html
|
||||
auto screenPosY = viewPortRect.size.height - rect.origin.y - rect.size.height;
|
||||
[_sysEdit updateFrame:CGRectMake(rect.origin.x,
|
||||
screenPosY,
|
||||
rect.size.width, rect.size.height)];
|
||||
}
|
||||
|
||||
//TODO: I don't know why here needs to subtract `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;
|
||||
const char* EditBoxImplMac::getNativeDefaultFontName()
|
||||
{
|
||||
return [[_sysEdit getDefaultFontName] UTF8String];
|
||||
}
|
||||
|
||||
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::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditBoxImplMac::openKeyboard()
|
||||
void EditBoxImplMac::nativeOpenKeyboard()
|
||||
{
|
||||
[_sysEdit setVisible:YES];
|
||||
[_sysEdit openKeyboard];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::closeKeyboard()
|
||||
void EditBoxImplMac::nativeCloseKeyboard()
|
||||
{
|
||||
[_sysEdit closeKeyboard];
|
||||
}
|
||||
|
||||
void EditBoxImplMac::onEnter(void)
|
||||
{
|
||||
adjustTextFieldPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -53,8 +53,7 @@
|
|||
- (void)setVisible:(BOOL)visible;
|
||||
- (void)setTextColor:(UIColor*)color;
|
||||
- (void)setFont:(UIFont *)font;
|
||||
- (void)setPosition:(CGPoint)pos;
|
||||
- (void)setContentSize:(CGSize)size;
|
||||
- (void)updateFrame:(CGRect)rect;
|
||||
|
||||
- (void)openKeyboard;
|
||||
- (void)closeKeyboard;
|
||||
|
|
|
@ -274,18 +274,12 @@
|
|||
[eaglview doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
|
||||
}
|
||||
|
||||
- (void)setPosition:(CGPoint)pos
|
||||
{
|
||||
// TODO: Handle anchor point?
|
||||
CGRect frame = self.textInput.frame;
|
||||
frame.origin = pos;
|
||||
self.textInput.frame = frame;
|
||||
}
|
||||
|
||||
- (void)setContentSize:(CGSize)size
|
||||
- (void)updateFrame:(CGRect)rect
|
||||
{
|
||||
CGRect frame = self.textInput.frame;
|
||||
frame.size = size;
|
||||
frame.origin = rect.origin;
|
||||
frame.size = rect.size;
|
||||
|
||||
self.textInput.frame = frame;
|
||||
}
|
||||
|
||||
|
@ -375,12 +369,14 @@
|
|||
- (void)textViewDidChange:(UITextView *)textView
|
||||
{
|
||||
int maxLength = getEditBoxImplIOS()->getMaxLength();
|
||||
if (textView.text.length > maxLength) {
|
||||
textView.text = [textView.text substringToIndex:maxLength];
|
||||
if (textView.markedTextRange == nil) {
|
||||
if (textView.text.length > maxLength) {
|
||||
textView.text = [textView.text substringToIndex:maxLength];
|
||||
}
|
||||
|
||||
const char* inputText = [textView.text UTF8String];
|
||||
getEditBoxImplIOS()->editBoxEditingChanged(inputText);
|
||||
}
|
||||
|
||||
const char* inputText = [textView.text UTF8String];
|
||||
getEditBoxImplIOS()->editBoxEditingChanged(inputText);
|
||||
}
|
||||
|
||||
|
||||
|
@ -391,12 +387,14 @@
|
|||
- (void)textChanged:(UITextField *)textField
|
||||
{
|
||||
int maxLength = getEditBoxImplIOS()->getMaxLength();
|
||||
if (textField.text.length > maxLength) {
|
||||
textField.text = [textField.text substringToIndex:maxLength];
|
||||
if (textField.markedTextRange == nil) {
|
||||
if (textField.text.length > maxLength) {
|
||||
textField.text = [textField.text substringToIndex:maxLength];
|
||||
}
|
||||
|
||||
const char* inputText = [textField.text UTF8String];
|
||||
getEditBoxImplIOS()->editBoxEditingChanged(inputText);
|
||||
}
|
||||
|
||||
const char* inputText = [textField.text UTF8String];
|
||||
getEditBoxImplIOS()->editBoxEditingChanged(inputText);
|
||||
}
|
||||
|
||||
- (BOOL)textFieldShouldBeginEditing:(UITextField *)sender // return NO to disallow editing.
|
||||
|
|
|
@ -102,7 +102,7 @@ bool UIEditBoxTest::init()
|
|||
// bottom
|
||||
// Add an intermediate Node to test scaling and content size relative to world
|
||||
_editEmailParent = Node::create();
|
||||
_editEmailParent->setScale(0.5);
|
||||
// _editEmailParent->setScale(0.5);
|
||||
_editEmailParent->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2-50, visibleOrigin.y+visibleSize.height/4));
|
||||
addChild(_editEmailParent);
|
||||
|
||||
|
|
Loading…
Reference in New Issue