2016-04-25 11:17:09 +08:00
///****************************************************************************
//Copyright (c) 2014 cocos2d-x.org
//
//http://www.cocos2d-x.org
//
//* Portions Copyright (c) Microsoft Open Technologies, Inc.
//* All Rights Reserved
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
//****************************************************************************/
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
# include "platform/CCPlatformConfig.h"
# if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
# include "ui/UIEditBox/UIEditBoxImpl-winrt.h"
# include "platform/winrt/CCWinRTUtils.h"
# include "platform/winrt/CCGLViewImpl-winrt.h"
# include "2d/CCFontFreeType.h"
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
# if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
# define XAML_TOP_PADDING 10.0f
# else
# define XAML_TOP_PADDING 0.0f
# endif
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
namespace cocos2d {
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
namespace ui {
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
Platform : : String ^ EDIT_BOX_XAML_NAME = L " cocos2d_editbox " ;
Platform : : String ^ CANVAS_XAML_NAME = L " cocos2d_canvas " ;
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
EditBoxImpl * __createSystemEditBox ( EditBox * pEditBox )
{
return new UIEditBoxImplWinrt ( pEditBox ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
EditBoxWinRT : : EditBoxWinRT ( Windows : : Foundation : : EventHandler < Platform : : String ^ > ^ beginHandler ,
Windows : : Foundation : : EventHandler < Platform : : String ^ > ^ changeHandler ,
Windows : : Foundation : : EventHandler < Platform : : String ^ > ^ endHandler ) :
_beginHandler ( beginHandler ) ,
_changeHandler ( changeHandler ) ,
_endHandler ( endHandler ) ,
_color ( Windows : : UI : : Colors : : White ) ,
_initialText ( L " " ) ,
_fontFamily ( L " Segoe UI " ) ,
_fontSize ( 12 ) ,
_password ( false ) ,
_isEditing ( false ) ,
_multiline ( false ) ,
_maxLength ( 0 /* unlimited */ )
{
m_dispatcher = cocos2d : : GLViewImpl : : sharedOpenGLView ( ) - > getDispatcher ( ) ;
m_panel = cocos2d : : GLViewImpl : : sharedOpenGLView ( ) - > getPanel ( ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : closeKeyboard ( )
{
m_dispatcher . Get ( ) - > RunAsync ( Windows : : UI : : Core : : CoreDispatcherPriority : : Normal , ref new Windows : : UI : : Core : : DispatchedHandler ( [ this ] ( ) {
removeTextBox ( ) ;
_textBox = nullptr ;
auto canvas = static_cast < Canvas ^ > ( findXamlElement ( m_panel . Get ( ) , CANVAS_XAML_NAME ) ) ;
canvas - > Visibility = Visibility : : Collapsed ;
} ) ) ;
2014-10-23 22:39:38 +08:00
}
2016-04-25 11:17:09 +08:00
Windows : : UI : : Xaml : : Controls : : Control ^ EditBoxWinRT : : createPasswordBox ( )
{
auto passwordBox = ref new PasswordBox ;
passwordBox - > BorderThickness = 0 ;
passwordBox - > Name = EDIT_BOX_XAML_NAME ;
passwordBox - > Width = _size . Width ;
passwordBox - > Height = _size . Height ;
passwordBox - > Foreground = ref new Media : : SolidColorBrush ( _color ) ;
passwordBox - > Password = _initialText ;
passwordBox - > FontSize = _fontSize ;
passwordBox - > FontFamily = ref new Media : : FontFamily ( _fontFamily ) ;
passwordBox - > MaxLength = _maxLength ;
_changeToken = passwordBox - > PasswordChanged + = ref new Windows : : UI : : Xaml : : RoutedEventHandler ( this , & cocos2d : : ui : : EditBoxWinRT : : onPasswordChanged ) ;
return passwordBox ;
2014-10-23 22:39:38 +08:00
}
2016-04-25 11:17:09 +08:00
Windows : : UI : : Xaml : : Controls : : Control ^ EditBoxWinRT : : createTextBox ( )
{
auto textBox = ref new TextBox ;
textBox - > BorderThickness = 0 ;
textBox - > Name = EDIT_BOX_XAML_NAME ;
textBox - > Width = _size . Width ;
textBox - > Height = _size . Height ;
textBox - > Foreground = ref new Media : : SolidColorBrush ( _color ) ;
textBox - > Text = _initialText ;
textBox - > FontSize = _fontSize ;
textBox - > FontFamily = ref new Media : : FontFamily ( _fontFamily ) ;
textBox - > MaxLength = _maxLength ;
textBox - > AcceptsReturn = _multiline ;
textBox - > TextWrapping = _multiline ? TextWrapping : : Wrap : TextWrapping : : NoWrap ;
setInputScope ( textBox ) ;
_changeToken = textBox - > TextChanged + = ref new Windows : : UI : : Xaml : : Controls : : TextChangedEventHandler ( this , & cocos2d : : ui : : EditBoxWinRT : : onTextChanged ) ;
return textBox ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : onPasswordChanged ( Platform : : Object ^ sender , Windows : : UI : : Xaml : : RoutedEventArgs ^ args )
2014-10-24 13:01:35 +08:00
{
2016-04-25 11:17:09 +08:00
onTextChanged ( sender , nullptr ) ;
2014-10-24 13:01:35 +08:00
}
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : onTextChanged ( Platform : : Object ^ sender , Windows : : UI : : Xaml : : Controls : : TextChangedEventArgs ^ e )
{
Platform : : String ^ text = L " " ;
if ( _password ) {
text = static_cast < PasswordBox ^ > ( _textBox ) - > Password ;
}
else {
text = static_cast < TextBox ^ > ( _textBox ) - > Text ;
}
std : : shared_ptr < cocos2d : : InputEvent > inputEvent ( new UIEditBoxEvent ( this , text , _changeHandler ) ) ;
cocos2d : : GLViewImpl : : sharedOpenGLView ( ) - > QueueEvent ( inputEvent ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : onKeyDown ( Platform : : Object ^ sender , Windows : : UI : : Xaml : : Input : : KeyRoutedEventArgs ^ args )
{
if ( args - > Key = = Windows : : System : : VirtualKey : : Enter & & ! _multiline ) {
onLostFocus ( nullptr , nullptr ) ;
}
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : onGotFocus ( Platform : : Object ^ sender , Windows : : UI : : Xaml : : RoutedEventArgs ^ args )
{
Concurrency : : critical_section : : scoped_lock lock ( _critical_section ) ;
std : : shared_ptr < cocos2d : : InputEvent > inputEvent ( new UIEditBoxEvent ( this , nullptr , _beginHandler ) ) ;
cocos2d : : GLViewImpl : : sharedOpenGLView ( ) - > QueueEvent ( inputEvent ) ;
_isEditing = true ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : onLostFocus ( Platform : : Object ^ sender , Windows : : UI : : Xaml : : RoutedEventArgs ^ args )
{
_isEditing = false ;
Concurrency : : critical_section : : scoped_lock lock ( _critical_section ) ;
Platform : : String ^ text = L " " ;
if ( _password ) {
text = static_cast < PasswordBox ^ > ( _textBox ) - > Password ;
static_cast < PasswordBox ^ > ( _textBox ) - > PasswordChanged - = _changeToken ;
}
else {
text = static_cast < TextBox ^ > ( _textBox ) - > Text ;
static_cast < TextBox ^ > ( _textBox ) - > TextChanged - = _changeToken ;
}
std : : shared_ptr < cocos2d : : InputEvent > inputEvent ( new UIEditBoxEvent ( this , text , _endHandler ) ) ;
cocos2d : : GLViewImpl : : sharedOpenGLView ( ) - > QueueEvent ( inputEvent ) ;
_textBox - > LostFocus - = _unfocusToken ;
_textBox - > GotFocus - = _focusToken ;
_textBox - > KeyDown - = _keydownToken ;
closeKeyboard ( ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
bool EditBoxWinRT : : isEditing ( ) {
return _isEditing ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : openKeyboard ( )
{
m_dispatcher . Get ( ) - > RunAsync ( Windows : : UI : : Core : : CoreDispatcherPriority : : Normal , ref new Windows : : UI : : Core : : DispatchedHandler ( [ this ] ( ) {
removeTextBox ( ) ;
Canvas ^ canvas = static_cast < Canvas ^ > ( findXamlElement ( m_panel . Get ( ) , CANVAS_XAML_NAME ) ) ;
if ( _password ) {
_textBox = createPasswordBox ( ) ;
}
else {
_textBox = createTextBox ( ) ;
}
// Position the text box
canvas - > SetLeft ( _textBox , _rect . X ) ;
canvas - > SetTop ( _textBox , _rect . Y - XAML_TOP_PADDING ) ;
// Finally, insert it into the XAML scene hierarchy and make the containing canvas visible
canvas - > Children - > InsertAt ( 0 , _textBox ) ;
canvas - > Background = ref new Media : : SolidColorBrush ( ) ;
canvas - > Visibility = Visibility : : Visible ;
_keydownToken = _textBox - > KeyDown + = ref new Windows : : UI : : Xaml : : Input : : KeyEventHandler ( this , & cocos2d : : ui : : EditBoxWinRT : : onKeyDown ) ;
_focusToken = _textBox - > GotFocus + = ref new Windows : : UI : : Xaml : : RoutedEventHandler ( this , & cocos2d : : ui : : EditBoxWinRT : : onGotFocus ) ;
_unfocusToken = _textBox - > LostFocus + = ref new Windows : : UI : : Xaml : : RoutedEventHandler ( this , & cocos2d : : ui : : EditBoxWinRT : : onLostFocus ) ;
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
_textBox - > Focus ( FocusState : : Programmatic ) ;
if ( _password ) {
static_cast < PasswordBox ^ > ( _textBox ) - > SelectAll ( ) ;
}
else {
static_cast < TextBox ^ > ( _textBox ) - > Select ( _initialText - > Length ( ) , 0 ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
auto inputPane = Windows : : UI : : ViewManagement : : InputPane : : GetForCurrentView ( ) ;
} ) ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setFontColor ( Windows : : UI : : Color color )
2014-11-24 11:26:34 +08:00
{
2016-04-25 11:17:09 +08:00
_color = color ;
2014-11-24 11:26:34 +08:00
}
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setFontFamily ( Platform : : String ^ fontFamily )
2014-11-24 11:26:34 +08:00
{
2016-04-25 11:17:09 +08:00
_fontFamily = fontFamily ;
2014-11-24 11:26:34 +08:00
}
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setFontSize ( int fontSize )
{
_fontSize = fontSize ;
2014-11-24 11:26:34 +08:00
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : removeTextBox ( )
{
auto canvas = findXamlElement ( m_panel . Get ( ) , CANVAS_XAML_NAME ) ;
auto box = findXamlElement ( canvas , EDIT_BOX_XAML_NAME ) ;
removeXamlElement ( canvas , box ) ;
_isEditing = false ;
2014-11-24 11:26:34 +08:00
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setInputFlag ( int inputFlags ) {
_password = false ;
switch ( ( EditBox : : InputFlag ) inputFlags ) {
case EditBox : : InputFlag : : PASSWORD :
case EditBox : : InputFlag : : SENSITIVE :
_password = true ;
break ;
default :
CCLOG ( " Warning: cannot set INITIAL_CAPS_* input flags for WinRT edit boxes " ) ;
}
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setInputMode ( int inputMode ) {
_inputMode = inputMode ;
}
void EditBoxWinRT : : setMaxLength ( int maxLength ) {
_maxLength = maxLength ;
}
void EditBoxWinRT : : setInputScope ( TextBox ^ textBox )
2015-08-07 17:27:15 +08:00
{
2016-04-25 11:17:09 +08:00
InputScope ^ inputScope = ref new InputScope ;
InputScopeName ^ name = ref new InputScopeName ;
switch ( ( EditBox : : InputMode ) _inputMode ) {
case EditBox : : InputMode : : SINGLE_LINE :
case EditBox : : InputMode : : ANY :
name - > NameValue = InputScopeNameValue : : Default ;
break ;
case EditBox : : InputMode : : EMAIL_ADDRESS :
name - > NameValue = InputScopeNameValue : : EmailSmtpAddress ;
break ;
case EditBox : : InputMode : : DECIMAL :
case EditBox : : InputMode : : NUMERIC :
name - > NameValue = InputScopeNameValue : : Number ;
break ;
case EditBox : : InputMode : : PHONE_NUMBER :
name - > NameValue = InputScopeNameValue : : TelephoneNumber ;
break ;
case EditBox : : InputMode : : URL :
name - > NameValue = InputScopeNameValue : : Url ;
break ;
}
textBox - > InputScope = nullptr ;
inputScope - > Names - > Append ( name ) ;
textBox - > InputScope = inputScope ;
2014-11-24 11:26:34 +08:00
}
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setPosition ( Windows : : Foundation : : Rect rect )
{
_rect = rect ;
2014-11-24 11:26:34 +08:00
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setSize ( Windows : : Foundation : : Size size )
{
_size = size ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setText ( Platform : : String ^ text )
2014-11-24 11:26:34 +08:00
{
2016-04-25 11:17:09 +08:00
_initialText = text ;
// If already editing
if ( _isEditing ) {
m_dispatcher . Get ( ) - > RunAsync ( Windows : : UI : : Core : : CoreDispatcherPriority : : Normal , ref new Windows : : UI : : Core : : DispatchedHandler ( [ this ] ( ) {
auto textBox = static_cast < TextBox ^ > ( _textBox ) ;
unsigned int currentStart = textBox - > SelectionStart ;
bool cursorAtEnd = currentStart = = textBox - > Text - > Length ( ) ;
textBox - > Text = _initialText ;
if ( cursorAtEnd | | currentStart > textBox - > Text - > Length ( ) ) {
currentStart = textBox - > Text - > Length ( ) ;
}
textBox - > Select ( currentStart , 0 ) ;
} ) ) ;
}
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void EditBoxWinRT : : setVisible ( bool visible )
{
_visible = visible ;
// If already editing
m_dispatcher . Get ( ) - > RunAsync ( Windows : : UI : : Core : : CoreDispatcherPriority : : Normal , ref new Windows : : UI : : Core : : DispatchedHandler ( [ this ] ( ) {
Canvas ^ canvas = static_cast < Canvas ^ > ( findXamlElement ( m_panel . Get ( ) , CANVAS_XAML_NAME ) ) ;
canvas - > Visibility = _visible ? Visibility : : Visible : Visibility : : Collapsed ;
} ) ) ;
2014-11-24 11:26:34 +08:00
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
UIEditBoxImplWinrt : : UIEditBoxImplWinrt ( EditBox * pEditText ) : EditBoxImplCommon ( pEditText )
{
auto beginHandler = ref new Windows : : Foundation : : EventHandler < Platform : : String ^ > ( [ this ] ( Platform : : Object ^ sender , Platform : : String ^ arg ) {
this - > editBoxEditingDidBegin ( ) ;
} ) ;
auto changeHandler = ref new Windows : : Foundation : : EventHandler < Platform : : String ^ > ( [ this ] ( Platform : : Object ^ sender , Platform : : String ^ arg ) {
auto text = PlatformStringToString ( arg ) ;
this - > editBoxEditingChanged ( text ) ;
} ) ;
auto endHandler = ref new Windows : : Foundation : : EventHandler < Platform : : String ^ > ( [ this ] ( Platform : : Object ^ sender , Platform : : String ^ arg ) {
auto text = PlatformStringToString ( arg ) ;
this - > editBoxEditingDidEnd ( text ) ;
this - > onEndEditing ( text ) ;
} ) ;
_system_control = ref new EditBoxWinRT ( beginHandler , changeHandler , endHandler ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeFont ( const char * pFontName , int fontSize )
{
// fontSize
_fontSize = fontSize ;
auto transform = _editBox - > getNodeToWorldTransform ( ) ;
cocos2d : : Vec3 scale ;
transform . getScale ( & scale ) ;
_system_control - > setFontSize ( _fontSize * cocos2d : : Director : : getInstance ( ) - > getOpenGLView ( ) - > getScaleY ( ) /** scale.y*/ ) ;
// fontFamily
auto font = cocos2d : : FontFreeType : : create ( pFontName , fontSize /* TODO: Not sure if supposed to be scaled or unscaled */ , cocos2d : : GlyphCollection : : DYNAMIC , nullptr ) ;
if ( font ! = nullptr ) {
std : : string fontName = " ms-appx:///Assets/Resources/ " + std : : string ( pFontName ) + ' # ' + font - > getFontFamily ( ) ;
_system_control - > setFontFamily ( PlatformStringFromString ( pFontName ) ) ;
}
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeFontColor ( const Color4B & color )
{
Windows : : UI : : Color win_color = { 0xFF , color . r , color . g , color . b } ;
_system_control - > setFontColor ( win_color ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeInputMode ( EditBox : : InputMode inputMode )
{
_system_control - > setInputMode ( ( int ) inputMode ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeInputFlag ( EditBox : : InputFlag inputFlag )
{
_system_control - > setInputFlag ( ( int ) inputFlag ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeText ( const char * pText )
{
_system_control - > setText ( PlatformStringFromString ( pText ) ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeVisible ( bool visible )
{
_system_control - > setVisible ( visible ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : updateNativeFrame ( const Rect & rect )
{
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : nativeOpenKeyboard ( )
{
// Update the text
_system_control - > setText ( PlatformStringFromString ( getText ( ) ) ) ;
// Size
auto glView = cocos2d : : Director : : getInstance ( ) - > getOpenGLView ( ) ;
auto transform = _editBox - > getNodeToWorldTransform ( ) ;
cocos2d : : Vec3 scale ;
transform . getScale ( & scale ) ;
Windows : : Foundation : : Size xamlSize = { _editBox - > getContentSize ( ) . width * glView - > getScaleX ( ) * scale . x , _editBox - > getContentSize ( ) . height * glView - > getScaleY ( ) * scale . y } ;
_system_control - > setSize ( xamlSize ) ;
_system_control - > setFontSize ( _fontSize * cocos2d : : Director : : getInstance ( ) - > getOpenGLView ( ) - > getScaleY ( ) /** scale.y*/ ) ;
// Position
auto directorInstance = cocos2d : : Director : : getInstance ( ) ;
auto frameSize = glView - > getFrameSize ( ) ;
auto winSize = directorInstance - > getWinSize ( ) ;
auto leftBottom = _editBox - > convertToWorldSpace ( cocos2d : : Point : : ZERO ) ;
auto rightTop = _editBox - > convertToWorldSpace ( cocos2d : : Point ( _editBox - > getContentSize ( ) . width , _editBox - > getContentSize ( ) . height ) ) ;
Windows : : Foundation : : Rect rect ;
rect . X = frameSize . width / 2 + ( leftBottom . x - winSize . width / 2 ) * glView - > getScaleX ( ) ;
rect . Y = frameSize . height / 2 - ( rightTop . y - winSize . height / 2 ) * glView - > getScaleY ( ) ;
rect . Width = ( rightTop . x - leftBottom . x ) * glView - > getScaleX ( ) ;
rect . Height = ( rightTop . y - leftBottom . y ) * glView - > getScaleY ( ) ;
_system_control - > setPosition ( rect ) ;
// .. and open
_system_control - > openKeyboard ( ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : nativeCloseKeyboard ( )
{
_system_control - > closeKeyboard ( ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
void UIEditBoxImplWinrt : : setNativeMaxLength ( int maxLength )
{
_system_control - > setMaxLength ( maxLength ) ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
cocos2d : : Vec2 UIEditBoxImplWinrt : : convertDesignCoordToXamlCoord ( const cocos2d : : Vec2 & designCoord )
{
auto glView = cocos2d : : Director : : getInstance ( ) - > getOpenGLView ( ) ;
float viewH = glView - > getFrameSize ( ) . height ;
Vec2 visiblePos = Vec2 ( designCoord . x * glView - > getScaleX ( ) , designCoord . y * glView - > getScaleY ( ) ) ;
Vec2 screenGLPos = visiblePos + glView - > getViewPortRect ( ) . origin ;
Vec2 xamlPos ( screenGLPos . x , viewH - screenGLPos . y ) ;
return xamlPos ;
}
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
} // namespace ui
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
} // namespace cocos2d
2014-10-23 22:39:38 +08:00
2016-04-25 11:17:09 +08:00
# endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)