UIEditBoxImpl-winrt.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. ///****************************************************************************
  2. //Copyright (c) 2014 cocos2d-x.org
  3. //Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. //
  5. //http://www.cocos2d-x.org
  6. //
  7. //* Portions Copyright (c) Microsoft Open Technologies, Inc.
  8. //* All Rights Reserved
  9. //
  10. //Permission is hereby granted, free of charge, to any person obtaining a copy
  11. //of this software and associated documentation files (the "Software"), to deal
  12. //in the Software without restriction, including without limitation the rights
  13. //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. //copies of the Software, and to permit persons to whom the Software is
  15. //furnished to do so, subject to the following conditions:
  16. //
  17. //The above copyright notice and this permission notice shall be included in
  18. //all copies or substantial portions of the Software.
  19. //
  20. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. //THE SOFTWARE.
  27. //****************************************************************************/
  28. #include "platform/CCPlatformConfig.h"
  29. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  30. #include "ui/UIEditBox/UIEditBoxImpl-winrt.h"
  31. #include "platform/winrt/CCWinRTUtils.h"
  32. #include "platform/winrt/CCGLViewImpl-winrt.h"
  33. #include "2d/CCFontFreeType.h"
  34. #if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
  35. #define XAML_TOP_PADDING 10.0f
  36. #else
  37. #define XAML_TOP_PADDING 0.0f
  38. #endif
  39. #define EDIT_BOX_PADDING 5.0f
  40. namespace cocos2d {
  41. namespace ui {
  42. Platform::String^ EDIT_BOX_XAML_NAME = L"cocos2d_editbox";
  43. Platform::String^ CANVAS_XAML_NAME = L"cocos2d_canvas";
  44. EditBoxImpl* __createSystemEditBox(EditBox* pEditBox)
  45. {
  46. return new UIEditBoxImplWinrt(pEditBox);
  47. }
  48. EditBoxWinRT::EditBoxWinRT(Windows::Foundation::EventHandler<Platform::String^>^ beginHandler,
  49. Windows::Foundation::EventHandler<Platform::String^>^ changeHandler,
  50. Windows::Foundation::EventHandler<cocos2d::EndEventArgs^>^ endHandler) :
  51. _beginHandler(beginHandler),
  52. _changeHandler(changeHandler),
  53. _endHandler(endHandler),
  54. _color(Windows::UI::Colors::White),
  55. _alignment(),
  56. _initialText(L""),
  57. _fontFamily(L"Segoe UI"),
  58. _fontSize(12),
  59. _password(false),
  60. _isEditing(false),
  61. _multiline(false),
  62. _maxLength(0 /* unlimited */)
  63. {
  64. m_dispatcher = cocos2d::GLViewImpl::sharedOpenGLView()->getDispatcher();
  65. m_panel = cocos2d::GLViewImpl::sharedOpenGLView()->getPanel();
  66. }
  67. void EditBoxWinRT::closeKeyboard()
  68. {
  69. m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
  70. removeTextBox();
  71. _textBox = nullptr;
  72. auto canvas = static_cast<Canvas^>(findXamlElement(m_panel.Get(), CANVAS_XAML_NAME));
  73. canvas->Visibility = Visibility::Collapsed;
  74. }));
  75. }
  76. Windows::UI::Xaml::Controls::Control^ EditBoxWinRT::createPasswordBox()
  77. {
  78. auto passwordBox = ref new PasswordBox;
  79. passwordBox->BorderThickness = 0;
  80. passwordBox->Name = EDIT_BOX_XAML_NAME;
  81. passwordBox->Width = _size.Width;
  82. passwordBox->Height = _size.Height;
  83. passwordBox->Foreground = ref new Media::SolidColorBrush(_color);
  84. passwordBox->FontSize = _fontSize;
  85. passwordBox->FontFamily = ref new Media::FontFamily(_fontFamily);
  86. passwordBox->MaxLength = _maxLength;
  87. passwordBox->Password = _initialText;
  88. _changeToken = passwordBox->PasswordChanged += ref new Windows::UI::Xaml::RoutedEventHandler(this, &cocos2d::ui::EditBoxWinRT::onPasswordChanged);
  89. return passwordBox;
  90. }
  91. Windows::UI::Xaml::Controls::Control^ EditBoxWinRT::createTextBox()
  92. {
  93. auto textBox = ref new TextBox;
  94. textBox->BorderThickness = 0;
  95. textBox->Name = EDIT_BOX_XAML_NAME;
  96. textBox->Width = _size.Width;
  97. textBox->Height = _size.Height;
  98. textBox->Foreground = ref new Media::SolidColorBrush(_color);
  99. textBox->FontSize = _fontSize;
  100. textBox->FontFamily = ref new Media::FontFamily(_fontFamily);
  101. textBox->MaxLength = _maxLength;
  102. textBox->AcceptsReturn = _multiline;
  103. textBox->TextWrapping = _multiline ? TextWrapping::Wrap : TextWrapping::NoWrap;
  104. textBox->Text = _initialText;
  105. setInputScope(textBox);
  106. _setTextHorizontalAlignment(textBox);
  107. _changeToken = textBox->TextChanged += ref new Windows::UI::Xaml::Controls::TextChangedEventHandler(this, &cocos2d::ui::EditBoxWinRT::onTextChanged);
  108. return textBox;
  109. }
  110. void EditBoxWinRT::onPasswordChanged(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ args)
  111. {
  112. onTextChanged(sender, nullptr);
  113. }
  114. void EditBoxWinRT::onTextChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::TextChangedEventArgs ^e)
  115. {
  116. Platform::String^ text = L"";
  117. if (_password) {
  118. text = static_cast<PasswordBox^>(_textBox)->Password;
  119. }
  120. else {
  121. text = static_cast<TextBox^>(_textBox)->Text;
  122. }
  123. std::shared_ptr<cocos2d::InputEvent> inputEvent(new UIEditBoxEvent(this, text, _changeHandler));
  124. cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(inputEvent);
  125. }
  126. void EditBoxWinRT::onKeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ args)
  127. {
  128. if (args->Key == Windows::System::VirtualKey::Enter && !_multiline) {
  129. onLostFocus(nullptr, args);
  130. }
  131. else if (args->Key == Windows::System::VirtualKey::Tab) {
  132. onLostFocus(nullptr, args);
  133. }
  134. }
  135. void EditBoxWinRT::onGotFocus(Platform::Object ^sender, Windows::UI::Xaml::RoutedEventArgs ^args)
  136. {
  137. Concurrency::critical_section::scoped_lock lock(_critical_section);
  138. std::shared_ptr<cocos2d::InputEvent> inputEvent(new UIEditBoxEvent(this, nullptr, _beginHandler));
  139. cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(inputEvent);
  140. _isEditing = true;
  141. }
  142. void EditBoxWinRT::onLostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs ^args)
  143. {
  144. EditBoxDelegate::EditBoxEndAction action = EditBoxDelegate::EditBoxEndAction::UNKNOWN;
  145. Windows::UI::Xaml::Input::KeyRoutedEventArgs^ keyArgs = dynamic_cast<Windows::UI::Xaml::Input::KeyRoutedEventArgs^>(args);
  146. if (keyArgs) {
  147. if (keyArgs->Key == Windows::System::VirtualKey::Enter && !_multiline) {
  148. action = EditBoxDelegate::EditBoxEndAction::RETURN;
  149. }
  150. else if (keyArgs->Key == Windows::System::VirtualKey::Tab) {
  151. action = EditBoxDelegate::EditBoxEndAction::TAB_TO_NEXT;
  152. }
  153. }
  154. _isEditing = false;
  155. Concurrency::critical_section::scoped_lock lock(_critical_section);
  156. Platform::String^ text = L"";
  157. if (_password) {
  158. text = static_cast<PasswordBox^>(_textBox)->Password;
  159. static_cast<PasswordBox^>(_textBox)->PasswordChanged -= _changeToken;
  160. }
  161. else {
  162. text = static_cast<TextBox^>(_textBox)->Text;
  163. static_cast<TextBox^>(_textBox)->TextChanged -= _changeToken;
  164. }
  165. std::shared_ptr<cocos2d::InputEvent> inputEvent(new UIEditBoxEndEvent(this, text, static_cast<int>(action), _endHandler));
  166. cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(inputEvent);
  167. _textBox->LostFocus -= _unfocusToken;
  168. _textBox->GotFocus -= _focusToken;
  169. _textBox->KeyDown -= _keydownToken;
  170. closeKeyboard();
  171. }
  172. bool EditBoxWinRT::isEditing() {
  173. return _isEditing;
  174. }
  175. void EditBoxWinRT::openKeyboard()
  176. {
  177. m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
  178. removeTextBox();
  179. Canvas^ canvas = static_cast<Canvas^>(findXamlElement(m_panel.Get(), CANVAS_XAML_NAME));
  180. if (_password) {
  181. _textBox = createPasswordBox();
  182. }
  183. else {
  184. _textBox = createTextBox();
  185. }
  186. // Position the text box
  187. canvas->SetLeft(_textBox, _rect.X);
  188. canvas->SetTop(_textBox, _rect.Y - XAML_TOP_PADDING);
  189. _setTexVerticalAlignment(_textBox);
  190. _setPadding(_textBox);
  191. // Finally, insert it into the XAML scene hierarchy and make the containing canvas visible
  192. canvas->Children->InsertAt(0, _textBox);
  193. canvas->Background = ref new Media::SolidColorBrush();
  194. canvas->Visibility = Visibility::Visible;
  195. _keydownToken = _textBox->KeyDown += ref new Windows::UI::Xaml::Input::KeyEventHandler(this, &cocos2d::ui::EditBoxWinRT::onKeyDown);
  196. _focusToken = _textBox->GotFocus += ref new Windows::UI::Xaml::RoutedEventHandler(this, &cocos2d::ui::EditBoxWinRT::onGotFocus);
  197. _unfocusToken = _textBox->LostFocus += ref new Windows::UI::Xaml::RoutedEventHandler(this, &cocos2d::ui::EditBoxWinRT::onLostFocus);
  198. _textBox->Focus(FocusState::Programmatic);
  199. if (_password) {
  200. static_cast<PasswordBox^>(_textBox)->SelectAll();
  201. }
  202. else {
  203. static_cast<TextBox^>(_textBox)->Select(_initialText->Length(), 0);
  204. }
  205. auto inputPane = Windows::UI::ViewManagement::InputPane::GetForCurrentView();
  206. }));
  207. }
  208. void EditBoxWinRT::setFontColor(Windows::UI::Color color)
  209. {
  210. _color = color;
  211. }
  212. void EditBoxWinRT::setFontFamily(Platform::String^ fontFamily)
  213. {
  214. _fontFamily = fontFamily;
  215. }
  216. void EditBoxWinRT::setFontSize(int fontSize)
  217. {
  218. _fontSize = fontSize;
  219. }
  220. void EditBoxWinRT::removeTextBox()
  221. {
  222. auto canvas = findXamlElement(m_panel.Get(), CANVAS_XAML_NAME);
  223. auto box = findXamlElement(canvas, EDIT_BOX_XAML_NAME);
  224. removeXamlElement(canvas, box);
  225. _isEditing = false;
  226. }
  227. void EditBoxWinRT::setInputFlag(int inputFlags) {
  228. _password = false;
  229. switch ((EditBox::InputFlag)inputFlags) {
  230. case EditBox::InputFlag::PASSWORD:
  231. _password = true;
  232. break;
  233. default:
  234. CCLOG("Warning: cannot set INITIAL_CAPS_* input flags for WinRT edit boxes");
  235. }
  236. }
  237. void EditBoxWinRT::setInputMode(int inputMode) {
  238. _multiline = (EditBox::InputMode)inputMode == EditBox::InputMode::ANY;
  239. _inputMode = inputMode;
  240. }
  241. void EditBoxWinRT::setTextHorizontalAlignment(int alignment) {
  242. _alignment = alignment;
  243. }
  244. void EditBoxWinRT::setMaxLength(int maxLength) {
  245. _maxLength = maxLength;
  246. }
  247. void EditBoxWinRT::_setTextHorizontalAlignment(TextBox^ textBox)
  248. {
  249. switch (_alignment) {
  250. default:
  251. case 0:
  252. textBox->TextAlignment = TextAlignment::Left;
  253. break;
  254. case 1:
  255. textBox->TextAlignment = TextAlignment::Center;
  256. break;
  257. case 2:
  258. textBox->TextAlignment = TextAlignment::Right;
  259. break;
  260. }
  261. }
  262. void EditBoxWinRT::_setTexVerticalAlignment(Windows::UI::Xaml::Controls::Control^ textBox) {
  263. textBox->VerticalAlignment = _multiline ? VerticalAlignment::Top : VerticalAlignment::Center;
  264. }
  265. void EditBoxWinRT::_setPadding(Windows::UI::Xaml::Controls::Control^ editBox)
  266. {
  267. float padding = EDIT_BOX_PADDING*cocos2d::Director::getInstance()->getOpenGLView()->getScaleX();
  268. if (_multiline) {
  269. editBox->Padding = Thickness(padding, padding, 0.0f, 0.0f);
  270. }
  271. else {
  272. editBox->Padding = Thickness(padding, 0.0f, 0.0f, 0.0f);
  273. }
  274. }
  275. void EditBoxWinRT::setInputScope(TextBox^ textBox)
  276. {
  277. InputScope^ inputScope = ref new InputScope;
  278. InputScopeName^ name = ref new InputScopeName;
  279. switch ((EditBox::InputMode)_inputMode) {
  280. case EditBox::InputMode::SINGLE_LINE:
  281. case EditBox::InputMode::ANY:
  282. name->NameValue = InputScopeNameValue::Default;
  283. break;
  284. case EditBox::InputMode::EMAIL_ADDRESS:
  285. name->NameValue = InputScopeNameValue::EmailSmtpAddress;
  286. break;
  287. case EditBox::InputMode::DECIMAL:
  288. case EditBox::InputMode::NUMERIC:
  289. name->NameValue = InputScopeNameValue::Number;
  290. break;
  291. case EditBox::InputMode::PHONE_NUMBER:
  292. name->NameValue = InputScopeNameValue::TelephoneNumber;
  293. break;
  294. case EditBox::InputMode::URL:
  295. name->NameValue = InputScopeNameValue::Url;
  296. break;
  297. }
  298. textBox->InputScope = nullptr;
  299. inputScope->Names->Append(name);
  300. textBox->InputScope = inputScope;
  301. }
  302. void EditBoxWinRT::setPosition(Windows::Foundation::Rect rect)
  303. {
  304. _rect = rect;
  305. }
  306. void EditBoxWinRT::setSize(Windows::Foundation::Size size)
  307. {
  308. _size = size;
  309. }
  310. void EditBoxWinRT::setText(Platform::String^ text)
  311. {
  312. _initialText = text;
  313. // If already editing
  314. if (_isEditing) {
  315. m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
  316. if (!_password) {
  317. auto textBox = static_cast<TextBox^>(_textBox);
  318. unsigned int currentStart = textBox->SelectionStart;
  319. bool cursorAtEnd = currentStart == textBox->Text->Length();
  320. textBox->Text = _initialText;
  321. if (cursorAtEnd || currentStart > textBox->Text->Length()) {
  322. currentStart = textBox->Text->Length();
  323. }
  324. textBox->Select(currentStart, 0);
  325. }
  326. }));
  327. }
  328. }
  329. void EditBoxWinRT::setVisible(bool visible)
  330. {
  331. _visible = visible;
  332. // If already editing
  333. m_dispatcher.Get()->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
  334. Canvas^ canvas = static_cast<Canvas^>(findXamlElement(m_panel.Get(), CANVAS_XAML_NAME));
  335. canvas->Visibility = _visible ? Visibility::Visible : Visibility::Collapsed;
  336. }));
  337. }
  338. UIEditBoxImplWinrt::UIEditBoxImplWinrt(EditBox* pEditText) : EditBoxImplCommon(pEditText)
  339. {
  340. auto beginHandler = ref new Windows::Foundation::EventHandler<Platform::String^>([this](Platform::Object^ sender, Platform::String^ arg) {
  341. this->editBoxEditingDidBegin();
  342. });
  343. auto changeHandler = ref new Windows::Foundation::EventHandler<Platform::String^>([this](Platform::Object^ sender, Platform::String^ arg) {
  344. auto text = PlatformStringToString(arg);
  345. this->editBoxEditingChanged(text);
  346. });
  347. auto endHandler = ref new Windows::Foundation::EventHandler<cocos2d::EndEventArgs^>([this](Platform::Object^ sender, cocos2d::EndEventArgs^ arg) {
  348. auto text = PlatformStringToString(arg->GetText());
  349. auto action = arg->GetAction();
  350. this->editBoxEditingDidEnd(text, static_cast<cocos2d::ui::EditBoxDelegate::EditBoxEndAction>(action));
  351. this->onEndEditing(text);
  352. });
  353. _system_control = ref new EditBoxWinRT(beginHandler, changeHandler, endHandler);
  354. }
  355. void UIEditBoxImplWinrt::setNativeFont(const char* pFontName, int fontSize)
  356. {
  357. // fontSize
  358. _fontSize = fontSize;
  359. auto transform = _editBox->getNodeToWorldTransform();
  360. cocos2d::Vec3 scale;
  361. transform.getScale(&scale);
  362. _system_control->setFontSize(_fontSize * cocos2d::Director::getInstance()->getOpenGLView()->getScaleY() /** scale.y*/);
  363. // fontFamily
  364. auto font = cocos2d::FontFreeType::create(pFontName, fontSize, cocos2d::GlyphCollection::DYNAMIC, nullptr);
  365. if (font != nullptr) {
  366. std::string fontName = "ms-appx:///Assets/Resources/" + std::string(pFontName) +'#' + font->getFontFamily();
  367. _system_control->setFontFamily(PlatformStringFromString(fontName));
  368. }
  369. }
  370. void UIEditBoxImplWinrt::setNativeFontColor(const Color4B& color)
  371. {
  372. Windows::UI::Color win_color = { 0xFF, color.r, color.g, color.b };
  373. _system_control->setFontColor(win_color);
  374. }
  375. void UIEditBoxImplWinrt::setNativeInputMode(EditBox::InputMode inputMode)
  376. {
  377. _system_control->setInputMode((int)inputMode);
  378. }
  379. void UIEditBoxImplWinrt::setNativeInputFlag(EditBox::InputFlag inputFlag)
  380. {
  381. _system_control->setInputFlag((int)inputFlag);
  382. }
  383. void UIEditBoxImplWinrt::setNativeTextHorizontalAlignment(cocos2d::TextHAlignment alignment)
  384. {
  385. _system_control->setTextHorizontalAlignment((int)alignment);
  386. }
  387. void UIEditBoxImplWinrt::setNativeText(const char* pText)
  388. {
  389. _system_control->setText(PlatformStringFromString(pText));
  390. }
  391. void UIEditBoxImplWinrt::setNativeVisible(bool visible)
  392. {
  393. _system_control->setVisible(visible);
  394. }
  395. void UIEditBoxImplWinrt::updateNativeFrame(const Rect& rect)
  396. {
  397. }
  398. void UIEditBoxImplWinrt::nativeOpenKeyboard()
  399. {
  400. // Update the text
  401. _system_control->setText(PlatformStringFromString(getText()));
  402. // Size
  403. auto glView = cocos2d::Director::getInstance()->getOpenGLView();
  404. auto transform = _editBox->getNodeToWorldTransform();
  405. cocos2d::Vec3 scale;
  406. transform.getScale(&scale);
  407. Windows::Foundation::Size xamlSize = { _editBox->getContentSize().width * glView->getScaleX() * scale.x, _editBox->getContentSize().height * glView->getScaleY() * scale.y };
  408. _system_control->setSize(xamlSize);
  409. _system_control->setFontSize(_fontSize * cocos2d::Director::getInstance()->getOpenGLView()->getScaleY() /** scale.y*/);
  410. // Position
  411. auto directorInstance = cocos2d::Director::getInstance();
  412. auto frameSize = glView->getFrameSize();
  413. auto winSize = directorInstance->getWinSize();
  414. auto leftBottom = _editBox->convertToWorldSpace(cocos2d::Point::ZERO);
  415. auto rightTop = _editBox->convertToWorldSpace(cocos2d::Point(_editBox->getContentSize().width, _editBox->getContentSize().height));
  416. Windows::Foundation::Rect rect;
  417. rect.X = frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX();
  418. rect.Y = frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();
  419. rect.Width = (rightTop.x - leftBottom.x) * glView->getScaleX();
  420. rect.Height = (rightTop.y - leftBottom.y) * glView->getScaleY();
  421. _system_control->setPosition(rect);
  422. // .. and open
  423. _system_control->openKeyboard();
  424. }
  425. void UIEditBoxImplWinrt::nativeCloseKeyboard()
  426. {
  427. _system_control->closeKeyboard();
  428. }
  429. void UIEditBoxImplWinrt::setNativeMaxLength(int maxLength)
  430. {
  431. _system_control->setMaxLength(maxLength);
  432. }
  433. cocos2d::Vec2 UIEditBoxImplWinrt::convertDesignCoordToXamlCoord(const cocos2d::Vec2& designCoord)
  434. {
  435. auto glView = cocos2d::Director::getInstance()->getOpenGLView();
  436. float viewH = glView->getFrameSize().height;
  437. Vec2 visiblePos = Vec2(designCoord.x * glView->getScaleX(), designCoord.y * glView->getScaleY());
  438. Vec2 screenGLPos = visiblePos + glView->getViewPortRect().origin;
  439. Vec2 xamlPos(screenGLPos.x, viewH - screenGLPos.y);
  440. return xamlPos;
  441. }
  442. } // namespace ui
  443. } // namespace cocos2d
  444. #endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)