CCApplication-tizen.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /****************************************************************************
  2. Copyright (c) 2014-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #include "platform/CCPlatformConfig.h"
  21. #if CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN
  22. #include "platform/tizen/CCApplication-tizen.h"
  23. #include <unistd.h>
  24. #include <sys/time.h>
  25. #include <string>
  26. #include <app.h>
  27. #include <dlog.h>
  28. #include <Elementary.h>
  29. #include <Elementary_GL_Helpers.h>
  30. #include <efl_extension.h>
  31. #include <Evas_GL.h>
  32. #include "platform/tizen/CCGLViewImpl-tizen.h"
  33. #include "base/CCDirector.h"
  34. #include "base/CCEventKeyboard.h"
  35. #include "base/CCEventDispatcher.h"
  36. #include "platform/CCFileUtils.h"
  37. #ifdef LOG_TAG
  38. #undef LOG_TAG
  39. #endif
  40. #define LOG_TAG "cocos2d-x"
  41. ELEMENTARY_GLVIEW_GLOBAL_DEFINE();
  42. NS_CC_BEGIN
  43. void stopAccelerometerSensor();
  44. void pauseAccelerometerSensor();
  45. void resumeAccelerometerSensor();
  46. static void makeCurrent(void)
  47. {
  48. Application* app = Application::getInstance();
  49. evas_gl_make_current(app->_evasGL, app->_sfc, app->_ctx);
  50. }
  51. static Eina_Bool _key_down_cb(void *data, int type, void *ev)
  52. {
  53. makeCurrent();
  54. Ecore_Event_Key *event = (Ecore_Event_Key *)ev;
  55. if (!strcmp("XF86Stop", event->key) || !strcmp("XF86Back", event->key))
  56. {
  57. cocos2d::EventKeyboard event(cocos2d::EventKeyboard::KeyCode::KEY_ESCAPE, true);
  58. cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  59. }
  60. else if (!strcmp("XF86Menu", event->key))
  61. {
  62. cocos2d::EventKeyboard event(cocos2d::EventKeyboard::KeyCode::KEY_MENU, true);
  63. cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  64. }
  65. return ECORE_CALLBACK_PASS_ON;
  66. }
  67. static Eina_Bool _key_up_cb(void *data, int type, void *ev)
  68. {
  69. makeCurrent();
  70. Ecore_Event_Key *event = (Ecore_Event_Key *)ev;
  71. if (!strcmp("XF86Stop", event->key) || !strcmp("XF86Back", event->key))
  72. {
  73. cocos2d::EventKeyboard event(cocos2d::EventKeyboard::KeyCode::KEY_ESCAPE, false);
  74. cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  75. }
  76. else if (!strcmp("XF86Menu", event->key))
  77. {
  78. cocos2d::EventKeyboard event(cocos2d::EventKeyboard::KeyCode::KEY_MENU, false);
  79. cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
  80. }
  81. return ECORE_CALLBACK_PASS_ON;
  82. }
  83. static void draw_gl(Evas_Object *obj)
  84. {
  85. auto director = Director::getInstance();
  86. auto glview = director->getOpenGLView();
  87. director->mainLoop();
  88. glview->pollEvents();
  89. }
  90. static void del_gl(Evas_Object *obj) {
  91. }
  92. // sharedApplication pointer
  93. Application* Application::__instance = nullptr;
  94. Application::Application()
  95. : _win(nullptr)
  96. , _conform(nullptr)
  97. , _animationInterval(1.0f/60.0f*1000.0f)
  98. , _paused(false)
  99. {
  100. _orientation = APP_DEVICE_ORIENTATION_0;
  101. CC_ASSERT(! __instance);
  102. __instance = this;
  103. }
  104. Application::~Application()
  105. {
  106. CC_ASSERT(this == __instance);
  107. __instance = nullptr;
  108. }
  109. static void del_anim(void *data, Evas *evas, Evas_Object *obj, void *event_info)
  110. {
  111. Ecore_Animator *ani = (Ecore_Animator *)evas_object_data_get(obj, "ani");
  112. ecore_animator_del(ani);
  113. }
  114. static Eina_Bool anim(void *data) {
  115. elm_glview_changed_set((Evas_Object*)data);
  116. return EINA_TRUE;
  117. }
  118. static void init_gl(Evas_Object *obj) {
  119. Application *ad = Application::getInstance();
  120. //save current ctx
  121. ad->_evasGL = elm_glview_evas_gl_get(obj);
  122. ad->_ctx = evas_gl_current_context_get(ad->_evasGL);
  123. ad->_sfc = evas_gl_current_surface_get(ad->_evasGL);
  124. auto director = Director::getInstance();
  125. auto glview = director->getOpenGLView();
  126. if (glview == nullptr) {
  127. glview = GLViewImpl::create("Cocos2dxTizen");
  128. int w, h;
  129. elm_glview_size_get(obj, &w, &h);
  130. glview->setFrameSize(w, h);
  131. director->setOpenGLView(glview);
  132. }
  133. ad->initGLContextAttrs();
  134. // Initialize instance and cocos2d.
  135. if (! ad->applicationDidFinishLaunching())
  136. {
  137. return;
  138. }
  139. }
  140. static void create_indicator(Application *ad) {
  141. elm_win_conformant_set(ad->_win, EINA_TRUE);
  142. elm_win_indicator_mode_set(ad->_win, ELM_WIN_INDICATOR_SHOW);
  143. elm_win_indicator_opacity_set(ad->_win, ELM_WIN_INDICATOR_TRANSPARENT);
  144. ad->_conform = elm_conformant_add(ad->_win);
  145. evas_object_size_hint_weight_set(ad->_conform, EVAS_HINT_EXPAND,
  146. EVAS_HINT_EXPAND);
  147. elm_win_resize_object_add(ad->_win, ad->_conform);
  148. evas_object_show(ad->_conform);
  149. }
  150. static Evas_Object* add_win(const char *name) {
  151. Evas_Object *win;
  152. win = elm_win_util_standard_add(name, "tizen");
  153. if (!win)
  154. return nullptr;
  155. //fix openURL tests not goes to another program issue
  156. // elm_win_fullscreen_set(win, EINA_TRUE);
  157. evas_object_show(win);
  158. return win;
  159. }
  160. //touch call back
  161. static void touches_down_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
  162. {
  163. auto ev = (Evas_Event_Multi_Down *)event_info;
  164. int id = ev->device;
  165. float x = ev->canvas.x;
  166. float y = ev->canvas.y;
  167. makeCurrent();
  168. cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &id, &x, &y);
  169. }
  170. static void touches_move_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
  171. {
  172. auto ev = (Evas_Event_Multi_Move *)event_info;
  173. int id = ev->device;
  174. float x = ev->cur.canvas.x;
  175. float y = ev->cur.canvas.y;
  176. makeCurrent();
  177. cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(1, &id, &x, &y);
  178. }
  179. static void touches_up_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
  180. {
  181. auto ev = (Evas_Event_Multi_Up *)event_info;
  182. int id = ev->device;
  183. float x = ev->canvas.x;
  184. float y = ev->canvas.y;
  185. makeCurrent();
  186. cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &id, &x, &y);
  187. }
  188. static void touch_down_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
  189. {
  190. auto ev = (Evas_Event_Mouse_Down *)event_info;
  191. int id = ev->button;
  192. float x = ev->canvas.x;
  193. float y = ev->canvas.y;
  194. makeCurrent();
  195. cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &id, &x, &y);
  196. }
  197. static void touch_move_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
  198. {
  199. auto ev = (Evas_Event_Mouse_Move *)event_info;
  200. int id = ev->buttons;
  201. float x = ev->cur.canvas.x;
  202. float y = ev->cur.canvas.y;
  203. makeCurrent();
  204. cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(1, &id, &x, &y);
  205. }
  206. static void touch_up_cb(void *data, Evas *e , Evas_Object *obj , void *event_info)
  207. {
  208. auto ev = (Evas_Event_Mouse_Up *)event_info;
  209. int id = ev->button;
  210. float x = ev->canvas.x;
  211. float y = ev->canvas.y;
  212. makeCurrent();
  213. cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &id, &x, &y);
  214. }
  215. static Elm_GLView_Mode get_glview_mode(const GLContextAttrs &attrs)
  216. {
  217. /* for performance */
  218. Elm_GLView_Mode mode = ELM_GLVIEW_DIRECT;
  219. /* alpha */
  220. if (attrs.alphaBits > 0)
  221. {
  222. //fixme if enable this, cpp-test show white screen only.
  223. //mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_ALPHA);
  224. }
  225. /* depth */
  226. if (attrs.depthBits > 24)
  227. {
  228. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_DEPTH_32);
  229. }
  230. else if (attrs.depthBits > 16)
  231. {
  232. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_DEPTH_24);
  233. }
  234. else if (attrs.depthBits > 8)
  235. {
  236. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_DEPTH_16);
  237. }
  238. else if (attrs.depthBits > 0)
  239. {
  240. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_DEPTH_8);
  241. }
  242. /* stencil */
  243. if (attrs.stencilBits > 8)
  244. {
  245. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_STENCIL_16);
  246. }
  247. else if (attrs.stencilBits > 4)
  248. {
  249. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_STENCIL_8);
  250. }
  251. else if (attrs.stencilBits > 2)
  252. {
  253. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_STENCIL_4);
  254. }
  255. else if (attrs.stencilBits > 1)
  256. {
  257. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_STENCIL_2);
  258. }
  259. else if (attrs.stencilBits > 0)
  260. {
  261. mode = (Elm_GLView_Mode)(mode | ELM_GLVIEW_STENCIL_1);
  262. }
  263. return mode;
  264. }
  265. static bool app_create(void *data) {
  266. /* Hook to take necessary actions before main event loop starts
  267. * Initialize UI resources and application's data
  268. * If this function returns true, the main loop of application starts
  269. * If this function returns false, the application is terminated. */
  270. Evas_Object *gl;
  271. Application *ad = (Application *)data;
  272. if (!data)
  273. return false;
  274. /* Create and initialize GLView */
  275. elm_config_accel_preference_set("opengl");
  276. /* Create the window */
  277. ad->_win = add_win("cocos2d-x");
  278. if (!ad->_win)
  279. return false;
  280. int rots[2];
  281. rots[0] = ad->_orientation;
  282. rots[1] = rots[0] + 180 % 360;
  283. elm_win_wm_rotation_available_rotations_set(ad->_win, rots, 2);
  284. ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down_cb, ad);
  285. ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_up_cb, ad);
  286. gl = elm_glview_add(ad->_win);
  287. elm_win_resize_object_add(ad->_win, gl);
  288. ELEMENTARY_GLVIEW_GLOBAL_USE(gl);
  289. evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
  290. evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  291. /* Create and initialize GLView */
  292. ad->initGLContextAttrs();
  293. auto attrs = GLView::getGLContextAttrs();
  294. auto mode = get_glview_mode(attrs);
  295. elm_glview_mode_set(gl, mode);
  296. /* The resize policy tells GLView what to do with the surface when it
  297. * resizes. ELM_GLVIEW_RESIZE_POLICY_RECREATE will tell it to
  298. * destroy the current surface and recreate it to the new size.
  299. */
  300. //elm_glview_resize_policy_set(gl, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
  301. /* The render policy sets how GLView should render GL code.
  302. * ELM_GLVIEW_RENDER_POLICY_ON_DEMAND will have the GL callback
  303. * called only when the object is visible.
  304. * ELM_GLVIEW_RENDER_POLICY_ALWAYS would cause the callback to be
  305. * called even if the object were hidden.
  306. */
  307. elm_glview_render_policy_set(gl, ELM_GLVIEW_RENDER_POLICY_ON_DEMAND);
  308. /* The initialize callback function gets registered here */
  309. elm_glview_init_func_set(gl, init_gl);
  310. /* The delete callback function gets registered here */
  311. elm_glview_del_func_set(gl, del_gl);
  312. /* The resize callback function gets registered here */
  313. // Cocos2d-x doesn't support to change orientation from portrait to landscape.
  314. // So comment next line.
  315. // elm_glview_resize_func_set(gl, resize_gl);
  316. /* The render callback function gets registered here */
  317. elm_glview_render_func_set(gl, draw_gl);
  318. /* Add the GLView to the box and show it */
  319. evas_object_show(gl);
  320. elm_object_focus_set(gl, EINA_TRUE);
  321. /* This adds an animator so that the app will regularly
  322. * trigger updates of the GLView using elm_glview_changed_set().
  323. *
  324. * NOTE: If you delete GL, this animator will keep running trying to access
  325. * GL so this animator needs to be deleted with ecore_animator_del().
  326. */
  327. ecore_animator_source_set(ECORE_ANIMATOR_SOURCE_TIMER);
  328. ad->_ani = ecore_animator_add(anim, gl);
  329. evas_object_data_set(gl, "ani", ad->_ani);
  330. evas_object_event_callback_add(gl, EVAS_CALLBACK_DEL, del_anim, gl);
  331. /* Add Mouse Event Callbacks */
  332. evas_object_event_callback_add(gl, EVAS_CALLBACK_MOUSE_DOWN, touch_down_cb, ad);
  333. evas_object_event_callback_add(gl, EVAS_CALLBACK_MOUSE_MOVE, touch_move_cb, ad);
  334. evas_object_event_callback_add(gl, EVAS_CALLBACK_MOUSE_UP, touch_up_cb, ad);
  335. evas_object_event_callback_add(gl, EVAS_CALLBACK_MULTI_DOWN, touches_down_cb, ad);
  336. evas_object_event_callback_add(gl, EVAS_CALLBACK_MULTI_MOVE, touches_move_cb, ad);
  337. evas_object_event_callback_add(gl, EVAS_CALLBACK_MULTI_UP, touches_up_cb, ad);
  338. create_indicator(ad);
  339. return true;
  340. }
  341. static void app_pause(void *data)
  342. {
  343. /* Take necessary actions when application becomes invisible. */
  344. if(!data)
  345. {
  346. return;
  347. }
  348. pauseAccelerometerSensor();
  349. Application* app = ((Application *)data);
  350. app->applicationDidEnterBackground();
  351. ecore_animator_freeze(app->_ani);
  352. app->setPauseFlag(true);
  353. }
  354. static void app_resume(void *data)
  355. {
  356. /* Take necessary actions when application becomes visible. */
  357. if(!data)
  358. {
  359. return;
  360. }
  361. Application* app = ((Application *)data);
  362. app->applicationWillEnterForeground();
  363. resumeAccelerometerSensor();
  364. ecore_animator_thaw(app->_ani);
  365. app->setPauseFlag(false);
  366. }
  367. static void app_terminate(void *data)
  368. {
  369. /* Release all resources. */
  370. if(!data)
  371. {
  372. return;
  373. }
  374. stopAccelerometerSensor();
  375. Director::getInstance()->end();
  376. // Application* app = ((Application *)data);
  377. // delete app;
  378. }
  379. static void app_control(app_control_h app_control, void *data)
  380. {
  381. /* Handle the launch request. */
  382. }
  383. int Application::run()
  384. {
  385. ui_app_lifecycle_callback_s event_callback = { nullptr, };
  386. event_callback.create = app_create;
  387. event_callback.terminate = app_terminate;
  388. event_callback.pause = app_pause;
  389. event_callback.resume = app_resume;
  390. event_callback.app_control = app_control;
  391. /* ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
  392. ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
  393. ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
  394. ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
  395. ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
  396. ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
  397. */
  398. int ret = ui_app_main(_argc, _argv, &event_callback, this);
  399. if (ret != APP_ERROR_NONE) {
  400. dlog_print(DLOG_ERROR, LOG_TAG, "The application failed to start, and returned %d", ret);
  401. }
  402. return ret;
  403. }
  404. void Application::setAnimationInterval(float interval)
  405. {
  406. _animationInterval = interval*1000.0f;
  407. ecore_animator_frametime_set(interval);
  408. }
  409. void Application::setAnimationInterval(float interval, SetIntervalReason reason)
  410. {
  411. setAnimationInterval(interval);
  412. }
  413. void Application::setResourceRootPath(const std::string& rootResDir)
  414. {
  415. _resourceRootPath = rootResDir;
  416. if (_resourceRootPath[_resourceRootPath.length() - 1] != '/')
  417. {
  418. _resourceRootPath += '/';
  419. }
  420. FileUtils* pFileUtils = FileUtils::getInstance();
  421. std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
  422. searchPaths.insert(searchPaths.begin(), _resourceRootPath);
  423. pFileUtils->setSearchPaths(searchPaths);
  424. }
  425. const std::string& Application::getResourceRootPath(void)
  426. {
  427. return _resourceRootPath;
  428. }
  429. Application::Platform Application::getTargetPlatform()
  430. {
  431. return Platform::OS_TIZEN;
  432. }
  433. void Application::setDeviceOrientation(int orientation)
  434. {
  435. _orientation = orientation;
  436. }
  437. void Application::setMainArgs(int argc, char **argv)
  438. {
  439. _argc = argc;
  440. _argv = argv;
  441. }
  442. bool Application::openURL(const std::string &url)
  443. {
  444. bool flag = false;
  445. if(0==url.length())
  446. {
  447. return flag;
  448. }
  449. app_control_h app_control;
  450. app_control_create(&app_control);
  451. app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
  452. app_control_set_uri(app_control, url.c_str());
  453. int ctrlError;
  454. if ((ctrlError=app_control_send_launch_request(app_control, NULL, NULL)) == APP_CONTROL_ERROR_NONE)
  455. {
  456. flag = true;
  457. }
  458. else
  459. {
  460. dlog_print(DLOG_ERROR, LOG_TAG, "open url failed, and returned %d", ctrlError);
  461. }
  462. app_control_destroy(app_control);
  463. return flag;
  464. }
  465. //////////////////////////////////////////////////////////////////////////
  466. // static member function
  467. //////////////////////////////////////////////////////////////////////////
  468. Application* Application::getInstance()
  469. {
  470. CC_ASSERT(__instance);
  471. return __instance;
  472. }
  473. // @deprecated Use getInstance() instead
  474. Application* Application::sharedApplication()
  475. {
  476. return Application::getInstance();
  477. }
  478. const char * Application::getCurrentLanguageCode()
  479. {
  480. static char code[3]={0};
  481. char *pLanguageName = getenv("LANG");
  482. if (!pLanguageName)
  483. return "en";
  484. strtok(pLanguageName, "_");
  485. if (!pLanguageName)
  486. return "en";
  487. strncpy(code,pLanguageName,2);
  488. code[2]='\0';
  489. return code;
  490. }
  491. std::string Application::getVersion()
  492. {
  493. //TODO
  494. return "";
  495. }
  496. LanguageType Application::getCurrentLanguage()
  497. {
  498. char *pLanguageName = getenv("LANG");
  499. LanguageType ret = LanguageType::ENGLISH;
  500. if (!pLanguageName)
  501. {
  502. return LanguageType::ENGLISH;
  503. }
  504. strtok(pLanguageName, "_");
  505. if (!pLanguageName)
  506. {
  507. return LanguageType::ENGLISH;
  508. }
  509. if (0 == strcmp("zh", pLanguageName))
  510. {
  511. ret = LanguageType::CHINESE;
  512. }
  513. else if (0 == strcmp("en", pLanguageName))
  514. {
  515. ret = LanguageType::ENGLISH;
  516. }
  517. else if (0 == strcmp("fr", pLanguageName))
  518. {
  519. ret = LanguageType::FRENCH;
  520. }
  521. else if (0 == strcmp("it", pLanguageName))
  522. {
  523. ret = LanguageType::ITALIAN;
  524. }
  525. else if (0 == strcmp("de", pLanguageName))
  526. {
  527. ret = LanguageType::GERMAN;
  528. }
  529. else if (0 == strcmp("es", pLanguageName))
  530. {
  531. ret = LanguageType::SPANISH;
  532. }
  533. else if (0 == strcmp("nl", pLanguageName))
  534. {
  535. ret = LanguageType::DUTCH;
  536. }
  537. else if (0 == strcmp("ru", pLanguageName))
  538. {
  539. ret = LanguageType::RUSSIAN;
  540. }
  541. else if (0 == strcmp("ko", pLanguageName))
  542. {
  543. ret = LanguageType::KOREAN;
  544. }
  545. else if (0 == strcmp("ja", pLanguageName))
  546. {
  547. ret = LanguageType::JAPANESE;
  548. }
  549. else if (0 == strcmp("hu", pLanguageName))
  550. {
  551. ret = LanguageType::HUNGARIAN;
  552. }
  553. else if (0 == strcmp("pt", pLanguageName))
  554. {
  555. ret = LanguageType::PORTUGUESE;
  556. }
  557. else if (0 == strcmp("ar", pLanguageName))
  558. {
  559. ret = LanguageType::ARABIC;
  560. }
  561. else if (0 == strcmp("nb", pLanguageName))
  562. {
  563. ret = LanguageType::NORWEGIAN;
  564. }
  565. else if (0 == strcmp("pl", pLanguageName))
  566. {
  567. ret = LanguageType::POLISH;
  568. }
  569. return ret;
  570. }
  571. NS_CC_END
  572. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN