UIEditBoxImpl-winrt.cpp 19 KB

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