axmol/core/ui/UIEditBox/iOS/UIEditBoxIOS.mm

528 lines
15 KiB
Plaintext
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
Copyright (c) 2013-2015 zilongshanren
Copyright (c) 2015 Mazyad Alabduljaleel
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
https://axmol.dev/
2019-11-23 20:27:39 +08:00
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:
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2019-11-23 20:27:39 +08:00
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 "ui/UIEditBox/iOS/UIEditBoxIOS.h"
#import "ui/UIEditBox/iOS/UISingleLineTextField.h"
#import "ui/UIEditBox/iOS/UIMultilineTextField.h"
2019-11-23 20:27:39 +08:00
#import "platform/ios/EAGLView-ios.h"
#include "base/Director.h"
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
#define getEditBoxImplIOS() ((ax::ui::EditBoxImplIOS*)_editBox)
2019-11-23 20:27:39 +08:00
@implementation UIEditBoxImplIOS_objc
#pragma mark - Static methods
+ (void)initialize
{
[super initialize];
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
LoadUITextViewAXUITextInputCategory();
LoadUITextFieldAXUITextInputCategory();
2019-11-23 20:27:39 +08:00
}
#pragma mark - Init & Dealloc
- (instancetype)initWithFrame:(CGRect)frameRect editBox:(void*)editBox
2019-11-23 20:27:39 +08:00
{
self = [super init];
if (self)
{
_editState = NO;
self.frameRect = frameRect;
self.editBox = editBox;
2022-08-08 18:02:17 +08:00
self.dataInputMode = ax::ui::EditBox::InputFlag::LOWERCASE_ALL_CHARACTERS;
self.keyboardReturnType = ax::ui::EditBox::KeyboardReturnType::DEFAULT;
2019-11-23 20:27:39 +08:00
[self createMultiLineTextField];
}
2019-11-23 20:27:39 +08:00
return self;
}
- (void)dealloc
{
// custom setter cleanup
self.textInput = nil;
2019-11-23 20:27:39 +08:00
[super dealloc];
}
#pragma mark - Properties
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
- (void)setTextInput:(UIView<UITextInput, AXUITextInput>*)textInput
2019-11-23 20:27:39 +08:00
{
if (_textInput == textInput)
{
2019-11-23 20:27:39 +08:00
return;
}
2019-11-23 20:27:39 +08:00
// common init
textInput.backgroundColor = [UIColor clearColor];
textInput.hidden = true;
textInput.returnKeyType = UIReturnKeyDefault;
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
[textInput axui_setDelegate:self];
2019-11-23 20:27:39 +08:00
// Migrate properties
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
textInput.axui_textColor = _textInput.axui_textColor ?: [UIColor whiteColor];
textInput.axui_text = _textInput.axui_text ?: @"";
textInput.axui_placeholder = _textInput.axui_placeholder ?: @"";
textInput.axui_font = _textInput.axui_font ?: [UIFont systemFontOfSize:self.frameRect.size.height * 2 / 3];
textInput.axui_placeholderFont = _textInput.axui_placeholderFont ?: textInput.axui_font;
textInput.axui_placeholderTextColor = _textInput.axui_placeholderTextColor ?: [UIColor lightGrayColor];
2019-11-23 20:27:39 +08:00
[_textInput resignFirstResponder];
[_textInput removeFromSuperview];
[_textInput release];
2019-11-23 20:27:39 +08:00
_textInput = [textInput retain];
2019-11-23 20:27:39 +08:00
[self setInputFlag:self.dataInputMode];
[self setReturnType:self.keyboardReturnType];
}
#pragma mark - Public methods
- (void)createSingleLineTextField
{
CCUISingleLineTextField* textField = [[[CCUISingleLineTextField alloc] initWithFrame:self.frameRect] autorelease];
2019-11-23 20:27:39 +08:00
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.borderStyle = UITextBorderStyleNone;
2019-11-23 20:27:39 +08:00
[textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];
2019-11-23 20:27:39 +08:00
self.textInput = textField;
}
- (void)createMultiLineTextField
{
CCUIMultilineTextField* textView = [[[CCUIMultilineTextField alloc] initWithFrame:self.frameRect] autorelease];
self.textInput = textView;
2019-11-23 20:27:39 +08:00
}
#pragma mark - Public methods
- (void)setFont:(UIFont*)font
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_font = font;
2019-11-23 20:27:39 +08:00
}
- (void)setTextColor:(UIColor*)color
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_textColor = color;
2019-11-23 20:27:39 +08:00
}
- (void)setPlaceholderFont:(UIFont*)font
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_placeholderFont = font;
2019-11-23 20:27:39 +08:00
}
- (void)setPlaceholderTextColor:(UIColor*)color
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_placeholderTextColor = color;
2019-11-23 20:27:39 +08:00
}
2022-08-08 18:02:17 +08:00
- (void)setInputMode:(ax::ui::EditBox::InputMode)inputMode
2019-11-23 20:27:39 +08:00
{
// multiline input
2022-08-08 18:02:17 +08:00
if (inputMode == ax::ui::EditBox::InputMode::ANY)
{
if (![self.textInput isKindOfClass:[UITextView class]])
{
2019-11-23 20:27:39 +08:00
[self createMultiLineTextField];
}
}
else
{
if (![self.textInput isKindOfClass:[UITextField class]])
{
2019-11-23 20:27:39 +08:00
[self createSingleLineTextField];
}
}
2019-11-23 20:27:39 +08:00
switch (inputMode)
{
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputMode::EMAIL_ADDRESS:
self.keyboardType = UIKeyboardTypeEmailAddress;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputMode::NUMERIC:
self.keyboardType = UIKeyboardTypeDecimalPad;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputMode::PHONE_NUMBER:
self.keyboardType = UIKeyboardTypePhonePad;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputMode::URL:
self.keyboardType = UIKeyboardTypeURL;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputMode::DECIMAL:
self.keyboardType = UIKeyboardTypeDecimalPad;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputMode::SINGLE_LINE:
self.keyboardType = UIKeyboardTypeDefault;
break;
default:
self.keyboardType = UIKeyboardTypeDefault;
break;
2019-11-23 20:27:39 +08:00
}
}
- (void)setKeyboardType:(UIKeyboardType)type
{
self.textInput.keyboardType = type;
}
2022-08-08 18:02:17 +08:00
- (void)setInputFlag:(ax::ui::EditBox::InputFlag)flag
2019-11-23 20:27:39 +08:00
{
self.dataInputMode = flag;
switch (flag)
{
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputFlag::PASSWORD:
// textView can't be used for input password
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_secureTextEntry = YES;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputFlag::INITIAL_CAPS_WORD:
self.textInput.autocapitalizationType = UITextAutocapitalizationTypeWords;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputFlag::INITIAL_CAPS_SENTENCE:
self.textInput.autocapitalizationType = UITextAutocapitalizationTypeSentences;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputFlag::INITIAL_CAPS_ALL_CHARACTERS:
self.textInput.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputFlag::SENSITIVE:
self.textInput.autocorrectionType = UITextAutocorrectionTypeNo;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::InputFlag::LOWERCASE_ALL_CHARACTERS:
self.textInput.autocapitalizationType = UITextAutocapitalizationTypeNone;
break;
default:
break;
2019-11-23 20:27:39 +08:00
}
}
2022-08-08 18:02:17 +08:00
- (void)setReturnType:(ax::ui::EditBox::KeyboardReturnType)returnType
2019-11-23 20:27:39 +08:00
{
self.keyboardReturnType = returnType;
switch (returnType)
{
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::KeyboardReturnType::DEFAULT:
self.textInput.returnKeyType = UIReturnKeyDefault;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::KeyboardReturnType::DONE:
self.textInput.returnKeyType = UIReturnKeyDone;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::KeyboardReturnType::SEND:
self.textInput.returnKeyType = UIReturnKeySend;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::KeyboardReturnType::SEARCH:
self.textInput.returnKeyType = UIReturnKeySearch;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::KeyboardReturnType::GO:
self.textInput.returnKeyType = UIReturnKeyGo;
break;
2022-08-08 18:02:17 +08:00
case ax::ui::EditBox::KeyboardReturnType::NEXT:
self.textInput.returnKeyType = UIReturnKeyNext;
break;
default:
self.textInput.returnKeyType = UIReturnKeyDefault;
break;
2019-11-23 20:27:39 +08:00
}
}
2022-08-08 18:02:17 +08:00
- (void)setTextHorizontalAlignment:(ax::TextHAlignment)alignment
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_alignment = static_cast<NSTextAlignment>(alignment);
2019-11-23 20:27:39 +08:00
}
- (void)setText:(NSString*)text
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_text = text;
2019-11-23 20:27:39 +08:00
}
- (NSString*)text
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
return self.textInput.axui_text ?: @"";
2019-11-23 20:27:39 +08:00
}
- (void)setVisible:(BOOL)visible
{
self.textInput.hidden = !visible;
}
- (NSString*)getDefaultFontName
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
return self.textInput.axui_font.fontName ?: @"";
2019-11-23 20:27:39 +08:00
}
2022-08-08 18:02:17 +08:00
- (ax::ui::EditBoxDelegate::EditBoxEndAction)getEndAction
2019-11-23 20:27:39 +08:00
{
2022-08-08 18:02:17 +08:00
ax::ui::EditBoxDelegate::EditBoxEndAction action = ax::ui::EditBoxDelegate::EditBoxEndAction::UNKNOWN;
if (self.returnPressed)
{
2022-08-08 18:02:17 +08:00
if (self.keyboardReturnType == ax::ui::EditBox::KeyboardReturnType::NEXT)
{
2022-08-08 18:02:17 +08:00
action = ax::ui::EditBoxDelegate::EditBoxEndAction::TAB_TO_NEXT;
}
2022-08-08 18:02:17 +08:00
else if (self.keyboardReturnType == ax::ui::EditBox::KeyboardReturnType::GO ||
self.keyboardReturnType == ax::ui::EditBox::KeyboardReturnType::SEND ||
self.keyboardReturnType == ax::ui::EditBox::KeyboardReturnType::SEARCH)
{
2022-08-08 18:02:17 +08:00
action = ax::ui::EditBoxDelegate::EditBoxEndAction::RETURN;
2019-11-23 20:27:39 +08:00
}
}
return action;
}
- (void)setPlaceHolder:(NSString*)text
2019-11-23 20:27:39 +08:00
{
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
self.textInput.axui_placeholder = text;
2019-11-23 20:27:39 +08:00
}
- (void)doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance
{
auto view = ax::Director::getInstance()->getGLView();
EAGLView* eaglView = (EAGLView*)view->getEAGLView();
[eaglView doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
2019-11-23 20:27:39 +08:00
}
- (void)updateFrame:(CGRect)rect
{
CGRect frame = self.textInput.frame;
frame.origin = rect.origin;
frame.size = rect.size;
2019-11-23 20:27:39 +08:00
self.textInput.frame = frame;
}
- (void)openKeyboard
{
auto view = ax::Director::getInstance()->getGLView();
EAGLView* eaglView = (EAGLView*)view->getEAGLView();
[eaglView addSubview:self.textInput];
2019-11-23 20:27:39 +08:00
[self.textInput becomeFirstResponder];
}
- (void)closeKeyboard
{
[self.textInput resignFirstResponder];
[self.textInput removeFromSuperview];
}
- (BOOL)textFieldShouldReturn:(UITextField*)sender
2019-11-23 20:27:39 +08:00
{
if (sender == self.textInput)
{
2019-11-23 20:27:39 +08:00
self.returnPressed = YES;
[sender resignFirstResponder];
}
return NO;
}
- (void)animationSelector
{
auto view = ax::Director::getInstance()->getGLView();
EAGLView* eaglView = (EAGLView*)view->getEAGLView();
[eaglView doAnimationWhenAnotherEditBeClicked];
2019-11-23 20:27:39 +08:00
}
#pragma mark - UITextView delegate methods
- (BOOL)textViewShouldBeginEditing:(UITextView*)textView
2019-11-23 20:27:39 +08:00
{
AXLOGD("textFieldShouldBeginEditing...");
_editState = YES;
2019-11-23 20:27:39 +08:00
_returnPressed = NO;
auto view = ax::Director::getInstance()->getGLView();
EAGLView* eaglView = (EAGLView*)view->getEAGLView();
if ([eaglView isKeyboardShown])
{
2019-11-23 20:27:39 +08:00
[self performSelector:@selector(animationSelector) withObject:nil afterDelay:0.0f];
}
2019-11-23 20:27:39 +08:00
getEditBoxImplIOS()->editBoxEditingDidBegin();
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView*)textView
2019-11-23 20:27:39 +08:00
{
AXLOGD("textFieldShouldEndEditing...");
2019-11-23 20:27:39 +08:00
_editState = NO;
getEditBoxImplIOS()->refreshInactiveText();
const char* inputText = [textView.text UTF8String];
getEditBoxImplIOS()->editBoxEditingDidEnd(inputText, [self getEndAction]);
2019-11-23 20:27:39 +08:00
return YES;
}
- (BOOL)textView:(UITextView*)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
2019-11-23 20:27:39 +08:00
{
2022-08-08 18:02:17 +08:00
if (self.keyboardReturnType == ax::ui::EditBox::KeyboardReturnType::DONE && [text isEqualToString:@"\n"])
{
[self closeKeyboard];
}
2019-11-23 20:27:39 +08:00
int maxLength = getEditBoxImplIOS()->getMaxLength();
if (maxLength < 0)
{
return YES;
}
// Prevent crashing undo bug
// http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield
if (range.length + range.location > textView.text.length)
{
2019-11-23 20:27:39 +08:00
return NO;
}
NSUInteger oldLength = textView.text.length;
2019-11-23 20:27:39 +08:00
NSUInteger replacementLength = text.length;
NSUInteger rangeLength = range.length;
2019-11-23 20:27:39 +08:00
NSUInteger newLength = oldLength - rangeLength + replacementLength;
2019-11-23 20:27:39 +08:00
return newLength <= maxLength;
}
- (void)textViewDidChange:(UITextView*)textView
2019-11-23 20:27:39 +08:00
{
int maxLength = getEditBoxImplIOS()->getMaxLength();
if (textView.markedTextRange == nil)
{
if (textView.text.length > maxLength)
{
2019-11-23 20:27:39 +08:00
textView.text = [textView.text substringToIndex:maxLength];
}
2019-11-23 20:27:39 +08:00
const char* inputText = [textView.text UTF8String];
getEditBoxImplIOS()->editBoxEditingChanged(inputText);
}
}
#pragma mark - UITextField delegate methods
/**
* Called each time when the text field's text has changed.
*/
- (void)textChanged:(UITextField*)textField
2019-11-23 20:27:39 +08:00
{
int maxLength = getEditBoxImplIOS()->getMaxLength();
if (textField.markedTextRange == nil)
{
if (textField.text.length > maxLength)
{
2019-11-23 20:27:39 +08:00
textField.text = [textField.text substringToIndex:maxLength];
}
2019-11-23 20:27:39 +08:00
const char* inputText = [textField.text UTF8String];
getEditBoxImplIOS()->editBoxEditingChanged(inputText);
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField*)sender // return NO to disallow editing.
2019-11-23 20:27:39 +08:00
{
AXLOGD("textFieldShouldBeginEditing...");
_editState = YES;
2019-11-23 20:27:39 +08:00
_returnPressed = NO;
auto view = ax::Director::getInstance()->getGLView();
EAGLView* eaglView = (EAGLView*)view->getEAGLView();
if ([eaglView isKeyboardShown])
{
2019-11-23 20:27:39 +08:00
[self performSelector:@selector(animationSelector) withObject:nil afterDelay:0.0f];
}
2019-11-23 20:27:39 +08:00
getEditBoxImplIOS()->editBoxEditingDidBegin();
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField*)sender
2019-11-23 20:27:39 +08:00
{
AXLOGD("textFieldShouldEndEditing...");
_editState = NO;
2019-11-23 20:27:39 +08:00
const char* inputText = [sender.text UTF8String];
getEditBoxImplIOS()->editBoxEditingDidEnd(inputText, [self getEndAction]);
2019-11-23 20:27:39 +08:00
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
2019-11-23 20:27:39 +08:00
{
int maxLength = getEditBoxImplIOS()->getMaxLength();
if (maxLength < 0)
{
2019-11-23 20:27:39 +08:00
return YES;
}
// Prevent crashing undo bug
// http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield
if (range.length + range.location > textField.text.length)
{
2019-11-23 20:27:39 +08:00
return NO;
}
NSUInteger oldLength = textField.text.length;
2019-11-23 20:27:39 +08:00
NSUInteger replacementLength = string.length;
NSUInteger rangeLength = range.length;
2019-11-23 20:27:39 +08:00
NSUInteger newLength = oldLength - rangeLength + replacementLength;
2019-11-23 20:27:39 +08:00
return newLength <= maxLength;
}
@end