Control.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. #include "Base.h"
  2. #include "Game.h"
  3. #include "Control.h"
  4. namespace gameplay
  5. {
  6. Control::Control()
  7. : _id(""), _state(Control::NORMAL), _bounds(Rectangle::empty()), _clipBounds(Rectangle::empty()), _viewportClipBounds(Rectangle::empty()),
  8. _clearBounds(Rectangle::empty()), _dirty(true), _consumeInputEvents(true), _alignment(ALIGN_TOP_LEFT), _autoWidth(false), _autoHeight(false), _listeners(NULL),
  9. _contactIndex(INVALID_CONTACT_INDEX), _focusIndex(0), _parent(NULL), _styleOverridden(false), _skin(NULL)
  10. {
  11. addScriptEvent("controlEvent", "<Control>[Control::Listener::EventType]");
  12. }
  13. Control::~Control()
  14. {
  15. if (_listeners)
  16. {
  17. for (std::map<Listener::EventType, std::list<Listener*>*>::const_iterator itr = _listeners->begin(); itr != _listeners->end(); itr++)
  18. {
  19. std::list<Listener*>* list = itr->second;
  20. SAFE_DELETE(list);
  21. }
  22. SAFE_DELETE(_listeners);
  23. }
  24. if (_styleOverridden)
  25. {
  26. SAFE_DELETE(_style);
  27. }
  28. }
  29. void Control::initialize(Theme::Style* style, Properties* properties)
  30. {
  31. GP_ASSERT(properties);
  32. _style = style;
  33. // Properties not defined by the style.
  34. _alignment = getAlignment(properties->getString("alignment"));
  35. _autoWidth = properties->getBool("autoWidth");
  36. _autoHeight = properties->getBool("autoHeight");
  37. _consumeInputEvents = properties->getBool("consumeEvents", true);
  38. if (properties->exists("zIndex"))
  39. {
  40. _zIndex = properties->getInt("zIndex");
  41. }
  42. else
  43. {
  44. _zIndex = -1;
  45. }
  46. if (properties->exists("focusIndex"))
  47. {
  48. _focusIndex = properties->getInt("focusIndex");
  49. }
  50. else
  51. {
  52. _focusIndex = -1;
  53. }
  54. Vector2 position;
  55. Vector2 size;
  56. if (properties->exists("position"))
  57. {
  58. properties->getVector2("position", &position);
  59. }
  60. else
  61. {
  62. position.x = properties->getFloat("x");
  63. position.y = properties->getFloat("y");
  64. }
  65. if (properties->exists("size"))
  66. {
  67. properties->getVector2("size", &size);
  68. }
  69. else
  70. {
  71. size.x = properties->getFloat("width");
  72. size.y = properties->getFloat("height");
  73. }
  74. setBounds(Rectangle(position.x, position.y, size.x, size.y));
  75. const char* id = properties->getId();
  76. if (id)
  77. _id = id;
  78. // Potentially override themed properties for all states.
  79. overrideThemedProperties(properties, STATE_ALL);
  80. // Override themed properties on specific states.
  81. Properties* innerSpace = properties->getNextNamespace();
  82. while (innerSpace != NULL)
  83. {
  84. std::string spaceName(innerSpace->getNamespace());
  85. std::transform(spaceName.begin(), spaceName.end(), spaceName.begin(), (int(*)(int))toupper);
  86. if (spaceName == "STATENORMAL")
  87. {
  88. overrideThemedProperties(innerSpace, NORMAL);
  89. }
  90. else if (spaceName == "STATEFOCUS")
  91. {
  92. overrideThemedProperties(innerSpace, FOCUS);
  93. }
  94. else if (spaceName == "STATEACTIVE")
  95. {
  96. overrideThemedProperties(innerSpace, ACTIVE);
  97. }
  98. else if (spaceName == "STATEDISABLED")
  99. {
  100. overrideThemedProperties(innerSpace, DISABLED);
  101. }
  102. else if (spaceName == "MARGIN")
  103. {
  104. setMargin(innerSpace->getFloat("top"), innerSpace->getFloat("bottom"),
  105. innerSpace->getFloat("left"), innerSpace->getFloat("right"));
  106. }
  107. else if (spaceName == "PADDING")
  108. {
  109. setPadding(innerSpace->getFloat("top"), innerSpace->getFloat("bottom"),
  110. innerSpace->getFloat("left"), innerSpace->getFloat("right"));
  111. }
  112. innerSpace = properties->getNextNamespace();
  113. }
  114. }
  115. const char* Control::getId() const
  116. {
  117. return _id.c_str();
  118. }
  119. void Control::setPosition(float x, float y)
  120. {
  121. if (x != _bounds.x || y != _bounds.y)
  122. {
  123. _bounds.x = x;
  124. _bounds.y = y;
  125. _dirty = true;
  126. }
  127. }
  128. void Control::setSize(float width, float height)
  129. {
  130. if (width != _bounds.width || height != _bounds.height)
  131. {
  132. _bounds.width = width;
  133. _bounds.height = height;
  134. _dirty = true;
  135. }
  136. }
  137. void Control::setWidth(float width)
  138. {
  139. if (width != _bounds.width)
  140. {
  141. _bounds.width = width;
  142. _dirty = true;
  143. }
  144. }
  145. void Control::setHeight(float height)
  146. {
  147. if (height != _bounds.height)
  148. {
  149. _bounds.height = height;
  150. _dirty = true;
  151. }
  152. }
  153. void Control::setBounds(const Rectangle& bounds)
  154. {
  155. if (bounds != _bounds)
  156. {
  157. _bounds.set(bounds);
  158. _dirty = true;
  159. }
  160. }
  161. const Rectangle& Control::getBounds() const
  162. {
  163. return _bounds;
  164. }
  165. float Control::getX() const
  166. {
  167. return _bounds.x;
  168. }
  169. float Control::getY() const
  170. {
  171. return _bounds.y;
  172. }
  173. float Control::getWidth() const
  174. {
  175. return _bounds.width;
  176. }
  177. float Control::getHeight() const
  178. {
  179. return _bounds.height;
  180. }
  181. void Control::setAlignment(Alignment alignment)
  182. {
  183. _alignment = alignment;
  184. }
  185. Control::Alignment Control::getAlignment() const
  186. {
  187. return _alignment;
  188. }
  189. void Control::setAutoWidth(bool autoWidth)
  190. {
  191. if (_autoWidth != autoWidth)
  192. {
  193. _autoWidth = autoWidth;
  194. _dirty = true;
  195. }
  196. }
  197. bool Control::getAutoWidth() const
  198. {
  199. return _autoWidth;
  200. }
  201. void Control::setAutoHeight(bool autoHeight)
  202. {
  203. if (_autoHeight != autoHeight)
  204. {
  205. _autoHeight = autoHeight;
  206. _dirty = true;
  207. }
  208. }
  209. bool Control::getAutoHeight() const
  210. {
  211. return _autoHeight;
  212. }
  213. void Control::setOpacity(float opacity, unsigned char states)
  214. {
  215. overrideStyle();
  216. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  217. getOverlays(states, overlays);
  218. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  219. {
  220. overlays[i]->setOpacity(opacity);
  221. }
  222. _dirty = true;
  223. }
  224. float Control::getOpacity(State state) const
  225. {
  226. Theme::Style::Overlay* overlay = getOverlay(state);
  227. GP_ASSERT(overlay);
  228. return overlay->getOpacity();
  229. }
  230. void Control::setBorder(float top, float bottom, float left, float right, unsigned char states)
  231. {
  232. overrideStyle();
  233. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  234. getOverlays(states, overlays);
  235. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  236. {
  237. overlays[i]->setBorder(top, bottom, left, right);
  238. }
  239. _dirty = true;
  240. }
  241. const Theme::Border& Control::getBorder(State state) const
  242. {
  243. Theme::Style::Overlay* overlay = getOverlay(state);
  244. GP_ASSERT(overlay);
  245. return overlay->getBorder();
  246. }
  247. void Control::setSkinRegion(const Rectangle& region, unsigned char states)
  248. {
  249. overrideStyle();
  250. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  251. getOverlays(states, overlays);
  252. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  253. {
  254. overlays[i]->setSkinRegion(region, _style->_tw, _style->_th);
  255. }
  256. _dirty = true;
  257. }
  258. const Rectangle& Control::getSkinRegion(State state) const
  259. {
  260. Theme::Style::Overlay* overlay = getOverlay(state);
  261. GP_ASSERT(overlay);
  262. return overlay->getSkinRegion();
  263. }
  264. void Control::setSkinColor(const Vector4& color, unsigned char states)
  265. {
  266. overrideStyle();
  267. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  268. getOverlays(states, overlays);
  269. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  270. {
  271. overlays[i]->setSkinColor(color);
  272. }
  273. _dirty = true;
  274. }
  275. const Vector4& Control::getSkinColor(State state) const
  276. {
  277. Theme::Style::Overlay* overlay = getOverlay(state);
  278. GP_ASSERT(overlay);
  279. return overlay->getSkinColor();
  280. }
  281. void Control::setMargin(float top, float bottom, float left, float right)
  282. {
  283. GP_ASSERT(_style);
  284. overrideStyle();
  285. _style->setMargin(top, bottom, left, right);
  286. _dirty = true;
  287. }
  288. const Theme::Margin& Control::getMargin() const
  289. {
  290. GP_ASSERT(_style);
  291. return _style->getMargin();
  292. }
  293. void Control::setPadding(float top, float bottom, float left, float right)
  294. {
  295. GP_ASSERT(_style);
  296. overrideStyle();
  297. _style->setPadding(top, bottom, left, right);
  298. _dirty = true;
  299. }
  300. const Theme::Padding& Control::getPadding() const
  301. {
  302. GP_ASSERT(_style);
  303. return _style->getPadding();
  304. }
  305. void Control::setImageRegion(const char* id, const Rectangle& region, unsigned char states)
  306. {
  307. overrideStyle();
  308. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  309. getOverlays(states, overlays);
  310. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  311. {
  312. overlays[i]->setImageRegion(id, region, _style->_tw, _style->_th);
  313. }
  314. _dirty = true;
  315. }
  316. const Rectangle& Control::getImageRegion(const char* id, State state) const
  317. {
  318. Theme::Style::Overlay* overlay = getOverlay(state);
  319. GP_ASSERT(overlay);
  320. return overlay->getImageRegion(id);
  321. }
  322. void Control::setImageColor(const char* id, const Vector4& color, unsigned char states)
  323. {
  324. overrideStyle();
  325. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  326. getOverlays(states, overlays);
  327. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  328. {
  329. overlays[i]->setImageColor(id, color);
  330. }
  331. _dirty = true;
  332. }
  333. const Vector4& Control::getImageColor(const char* id, State state) const
  334. {
  335. Theme::Style::Overlay* overlay = getOverlay(state);
  336. GP_ASSERT(overlay);
  337. return overlay->getImageColor(id);
  338. }
  339. const Theme::UVs& Control::getImageUVs(const char* id, State state) const
  340. {
  341. Theme::Style::Overlay* overlay = getOverlay(state);
  342. GP_ASSERT(overlay);
  343. return overlay->getImageUVs(id);
  344. }
  345. void Control::setCursorRegion(const Rectangle& region, unsigned char states)
  346. {
  347. overrideStyle();
  348. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  349. getOverlays(states, overlays);
  350. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  351. {
  352. overlays[i]->setCursorRegion(region, _style->_tw, _style->_th);
  353. }
  354. _dirty = true;
  355. }
  356. const Rectangle& Control::getCursorRegion(State state) const
  357. {
  358. Theme::Style::Overlay* overlay = getOverlay(state);
  359. GP_ASSERT(overlay);
  360. return overlay->getCursorRegion();
  361. }
  362. void Control::setCursorColor(const Vector4& color, unsigned char states)
  363. {
  364. overrideStyle();
  365. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  366. getOverlays(states, overlays);
  367. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  368. {
  369. overlays[i]->setCursorColor(color);
  370. }
  371. _dirty = true;
  372. }
  373. const Vector4& Control::getCursorColor(State state)
  374. {
  375. Theme::Style::Overlay* overlay = getOverlay(state);
  376. GP_ASSERT(overlay);
  377. return overlay->getCursorColor();
  378. }
  379. const Theme::UVs& Control::getCursorUVs(State state)
  380. {
  381. Theme::Style::Overlay* overlay = getOverlay(state);
  382. GP_ASSERT(overlay);
  383. return overlay->getCursorUVs();
  384. }
  385. void Control::setFont(Font* font, unsigned char states)
  386. {
  387. overrideStyle();
  388. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  389. getOverlays(states, overlays);
  390. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  391. {
  392. overlays[i]->setFont(font);
  393. }
  394. _dirty = true;
  395. }
  396. Font* Control::getFont(State state) const
  397. {
  398. Theme::Style::Overlay* overlay = getOverlay(state);
  399. GP_ASSERT(overlay);
  400. return overlay->getFont();
  401. }
  402. void Control::setFontSize(unsigned int fontSize, unsigned char states)
  403. {
  404. overrideStyle();
  405. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  406. getOverlays(states, overlays);
  407. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  408. {
  409. overlays[i]->setFontSize(fontSize);
  410. }
  411. _dirty = true;
  412. }
  413. unsigned int Control::getFontSize(State state) const
  414. {
  415. Theme::Style::Overlay* overlay = getOverlay(state);
  416. GP_ASSERT(overlay);
  417. return overlay->getFontSize();
  418. }
  419. void Control::setTextColor(const Vector4& color, unsigned char states)
  420. {
  421. overrideStyle();
  422. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  423. getOverlays(states, overlays);
  424. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  425. {
  426. overlays[i]->setTextColor(color);
  427. }
  428. _dirty = true;
  429. }
  430. const Vector4& Control::getTextColor(State state) const
  431. {
  432. Theme::Style::Overlay* overlay = getOverlay(state);
  433. GP_ASSERT(overlay);
  434. return overlay->getTextColor();
  435. }
  436. void Control::setTextAlignment(Font::Justify alignment, unsigned char states)
  437. {
  438. overrideStyle();
  439. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  440. getOverlays(states, overlays);
  441. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  442. {
  443. overlays[i]->setTextAlignment(alignment);
  444. }
  445. _dirty = true;
  446. }
  447. Font::Justify Control::getTextAlignment(State state) const
  448. {
  449. Theme::Style::Overlay* overlay = getOverlay(state);
  450. GP_ASSERT(overlay);
  451. return overlay->getTextAlignment();
  452. }
  453. void Control::setTextRightToLeft(bool rightToLeft, unsigned char states)
  454. {
  455. overrideStyle();
  456. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  457. getOverlays(states, overlays);
  458. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  459. {
  460. overlays[i]->setTextRightToLeft(rightToLeft);
  461. }
  462. _dirty = true;
  463. }
  464. bool Control::getTextRightToLeft(State state) const
  465. {
  466. Theme::Style::Overlay* overlay = getOverlay(state);
  467. GP_ASSERT(overlay);
  468. return overlay->getTextRightToLeft();
  469. }
  470. const Rectangle& Control::getClipBounds() const
  471. {
  472. return _clipBounds;
  473. }
  474. const Rectangle& Control::getClip() const
  475. {
  476. return _viewportClipBounds;
  477. }
  478. void Control::setStyle(Theme::Style* style)
  479. {
  480. if (style != _style)
  481. {
  482. _dirty = true;
  483. }
  484. _style = style;
  485. }
  486. Theme::Style* Control::getStyle() const
  487. {
  488. return _style;
  489. }
  490. void Control::setState(State state)
  491. {
  492. if (getOverlay(_state) != getOverlay(state))
  493. _dirty = true;
  494. _state = state;
  495. }
  496. Control::State Control::getState() const
  497. {
  498. return _state;
  499. }
  500. void Control::disable()
  501. {
  502. _state = DISABLED;
  503. _dirty = true;
  504. }
  505. void Control::enable()
  506. {
  507. _state = NORMAL;
  508. _dirty = true;
  509. }
  510. bool Control::isEnabled()
  511. {
  512. return _state != DISABLED;
  513. }
  514. Theme::Style::OverlayType Control::getOverlayType() const
  515. {
  516. switch (_state)
  517. {
  518. case Control::NORMAL:
  519. return Theme::Style::OVERLAY_NORMAL;
  520. case Control::FOCUS:
  521. return Theme::Style::OVERLAY_FOCUS;
  522. case Control::ACTIVE:
  523. return Theme::Style::OVERLAY_ACTIVE;
  524. case Control::DISABLED:
  525. return Theme::Style::OVERLAY_DISABLED;
  526. default:
  527. return Theme::Style::OVERLAY_NORMAL;
  528. }
  529. }
  530. void Control::setConsumeInputEvents(bool consume)
  531. {
  532. _consumeInputEvents = consume;
  533. }
  534. bool Control::getConsumeInputEvents()
  535. {
  536. return _consumeInputEvents;
  537. }
  538. int Control::getZIndex() const
  539. {
  540. return _zIndex;
  541. }
  542. void Control::setZIndex(int zIndex)
  543. {
  544. if (zIndex != _zIndex)
  545. {
  546. _zIndex = zIndex;
  547. _dirty = true;
  548. }
  549. }
  550. int Control::getFocusIndex() const
  551. {
  552. return _focusIndex;
  553. }
  554. void Control::setFocusIndex(int focusIndex)
  555. {
  556. _focusIndex = focusIndex;
  557. }
  558. void Control::addListener(Control::Listener* listener, int eventFlags)
  559. {
  560. GP_ASSERT(listener);
  561. if ((eventFlags & Listener::PRESS) == Listener::PRESS)
  562. {
  563. addSpecificListener(listener, Listener::PRESS);
  564. }
  565. if ((eventFlags & Listener::RELEASE) == Listener::RELEASE)
  566. {
  567. addSpecificListener(listener, Listener::RELEASE);
  568. }
  569. if ((eventFlags & Listener::CLICK) == Listener::CLICK)
  570. {
  571. addSpecificListener(listener, Listener::CLICK);
  572. }
  573. if ((eventFlags & Listener::VALUE_CHANGED) == Listener::VALUE_CHANGED)
  574. {
  575. addSpecificListener(listener, Listener::VALUE_CHANGED);
  576. }
  577. if ((eventFlags & Listener::TEXT_CHANGED) == Listener::TEXT_CHANGED)
  578. {
  579. addSpecificListener(listener, Listener::TEXT_CHANGED);
  580. }
  581. }
  582. void Control::addSpecificListener(Control::Listener* listener, Listener::EventType eventType)
  583. {
  584. GP_ASSERT(listener);
  585. if (!_listeners)
  586. {
  587. _listeners = new std::map<Listener::EventType, std::list<Listener*>*>();
  588. }
  589. std::map<Listener::EventType, std::list<Listener*>*>::const_iterator itr = _listeners->find(eventType);
  590. if (itr == _listeners->end())
  591. {
  592. _listeners->insert(std::make_pair(eventType, new std::list<Listener*>()));
  593. itr = _listeners->find(eventType);
  594. }
  595. std::list<Listener*>* listenerList = itr->second;
  596. listenerList->push_back(listener);
  597. }
  598. bool Control::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
  599. {
  600. if (!isEnabled())
  601. return false;
  602. switch (evt)
  603. {
  604. case Touch::TOUCH_PRESS:
  605. // Controls that don't have an ACTIVE state go to the FOCUS state when pressed.
  606. // (Other controls, such as buttons and sliders, become ACTIVE when pressed and go to the FOCUS state on release.)
  607. // Labels are never any state other than NORMAL.
  608. if (_contactIndex == INVALID_CONTACT_INDEX && x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
  609. y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
  610. {
  611. _contactIndex = (int) contactIndex;
  612. notifyListeners(Listener::PRESS);
  613. return _consumeInputEvents;
  614. }
  615. else
  616. {
  617. // If this control was in focus, it's not any more.
  618. _state = NORMAL;
  619. }
  620. break;
  621. case Touch::TOUCH_RELEASE:
  622. if (_contactIndex == (int)contactIndex)
  623. {
  624. _contactIndex = INVALID_CONTACT_INDEX;
  625. // Always trigger Listener::RELEASE
  626. notifyListeners(Listener::RELEASE);
  627. // Only trigger Listener::CLICK if both PRESS and RELEASE took place within the control's bounds.
  628. if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
  629. y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
  630. {
  631. // Leave this control in the FOCUS state.
  632. notifyListeners(Listener::CLICK);
  633. }
  634. return _consumeInputEvents;
  635. }
  636. break;
  637. }
  638. return false;
  639. }
  640. bool Control::keyEvent(Keyboard::KeyEvent evt, int key)
  641. {
  642. return false;
  643. }
  644. bool Control::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
  645. {
  646. if (!isEnabled())
  647. {
  648. return false;
  649. }
  650. // By default, mouse events are either interpreted as touch events or ignored.
  651. switch (evt)
  652. {
  653. case Mouse::MOUSE_PRESS_LEFT_BUTTON:
  654. return touchEvent(Touch::TOUCH_PRESS, x, y, 0);
  655. case Mouse::MOUSE_RELEASE_LEFT_BUTTON:
  656. return touchEvent(Touch::TOUCH_RELEASE, x, y, 0);
  657. case Mouse::MOUSE_MOVE:
  658. return touchEvent(Touch::TOUCH_MOVE, x, y, 0);
  659. default:
  660. break;
  661. }
  662. return false;
  663. }
  664. void Control::notifyListeners(Listener::EventType eventType)
  665. {
  666. // This method runs untrusted code by notifying listeners of events.
  667. // If the user calls exit() or otherwise releases this control, we
  668. // need to keep it alive until the method returns.
  669. addRef();
  670. if (_listeners)
  671. {
  672. std::map<Listener::EventType, std::list<Listener*>*>::const_iterator itr = _listeners->find(eventType);
  673. if (itr != _listeners->end())
  674. {
  675. std::list<Listener*>* listenerList = itr->second;
  676. for (std::list<Listener*>::iterator listenerItr = listenerList->begin(); listenerItr != listenerList->end(); listenerItr++)
  677. {
  678. GP_ASSERT(*listenerItr);
  679. (*listenerItr)->controlEvent(this, eventType);
  680. }
  681. }
  682. }
  683. fireScriptEvent<void>("controlEvent", this, eventType);
  684. release();
  685. }
  686. void Control::update(const Control* container, const Vector2& offset)
  687. {
  688. const Rectangle& clip = container->getClip();
  689. const Rectangle& absoluteViewport = container->_viewportBounds;
  690. _clearBounds.set(_absoluteClipBounds);
  691. // Calculate the clipped bounds.
  692. float x = _bounds.x + offset.x;
  693. float y = _bounds.y + offset.y;
  694. float width = _bounds.width;
  695. float height = _bounds.height;
  696. float clipX2 = clip.x + clip.width;
  697. float x2 = clip.x + x + width;
  698. if (x2 > clipX2)
  699. width -= x2 - clipX2;
  700. float clipY2 = clip.y + clip.height;
  701. float y2 = clip.y + y + height;
  702. if (y2 > clipY2)
  703. height -= y2 - clipY2;
  704. if (x < 0)
  705. {
  706. width += x;
  707. x = -x;
  708. }
  709. else
  710. {
  711. x = 0;
  712. }
  713. if (y < 0)
  714. {
  715. height += y;
  716. y = -y;
  717. }
  718. else
  719. {
  720. y = 0;
  721. }
  722. _clipBounds.set(x, y, width, height);
  723. // Calculate the absolute bounds.
  724. x = _bounds.x + offset.x + absoluteViewport.x;
  725. y = _bounds.y + offset.y + absoluteViewport.y;
  726. _absoluteBounds.set(x, y, _bounds.width, _bounds.height);
  727. // Calculate the absolute viewport bounds.
  728. // Absolute bounds minus border and padding.
  729. const Theme::Border& border = getBorder(_state);
  730. const Theme::Padding& padding = getPadding();
  731. x += border.left + padding.left;
  732. y += border.top + padding.top;
  733. width = _bounds.width - border.left - padding.left - border.right - padding.right;
  734. height = _bounds.height - border.top - padding.top - border.bottom - padding.bottom;
  735. _viewportBounds.set(x, y, width, height);
  736. // Calculate the clip area.
  737. // Absolute bounds, minus border and padding,
  738. // clipped to the parent container's clip area.
  739. clipX2 = clip.x + clip.width;
  740. x2 = x + width;
  741. if (x2 > clipX2)
  742. width = clipX2 - x;
  743. clipY2 = clip.y + clip.height;
  744. y2 = y + height;
  745. if (y2 > clipY2)
  746. height = clipY2 - y;
  747. if (x < clip.x)
  748. {
  749. float dx = clip.x - x;
  750. width -= dx;
  751. x = clip.x;
  752. }
  753. if (y < clip.y)
  754. {
  755. float dy = clip.y - y;
  756. height -= dy;
  757. y = clip.y;
  758. }
  759. _viewportClipBounds.set(x, y, width, height);
  760. _absoluteClipBounds.set(x - border.left - padding.left, y - border.top - padding.top,
  761. width + border.left + padding.left + border.right + padding.right,
  762. height + border.top + padding.top + border.bottom + padding.bottom);
  763. if (_clearBounds.isEmpty())
  764. {
  765. _clearBounds.set(_absoluteClipBounds);
  766. }
  767. // Cache themed attributes for performance.
  768. _skin = getSkin(_state);
  769. _opacity = getOpacity(_state);
  770. }
  771. void Control::drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip)
  772. {
  773. if (!spriteBatch || !_skin || _bounds.width <= 0 || _bounds.height <= 0)
  774. return;
  775. // Get the border and background images for this control's current state.
  776. const Theme::UVs& topLeft = _skin->getUVs(Theme::Skin::TOP_LEFT);
  777. const Theme::UVs& top = _skin->getUVs(Theme::Skin::TOP);
  778. const Theme::UVs& topRight = _skin->getUVs(Theme::Skin::TOP_RIGHT);
  779. const Theme::UVs& left = _skin->getUVs(Theme::Skin::LEFT);
  780. const Theme::UVs& center = _skin->getUVs(Theme::Skin::CENTER);
  781. const Theme::UVs& right = _skin->getUVs(Theme::Skin::RIGHT);
  782. const Theme::UVs& bottomLeft = _skin->getUVs(Theme::Skin::BOTTOM_LEFT);
  783. const Theme::UVs& bottom = _skin->getUVs(Theme::Skin::BOTTOM);
  784. const Theme::UVs& bottomRight = _skin->getUVs(Theme::Skin::BOTTOM_RIGHT);
  785. // Calculate screen-space positions.
  786. const Theme::Border& border = getBorder(_state);
  787. const Theme::Padding& padding = getPadding();
  788. Vector4 skinColor = _skin->getColor();
  789. skinColor.w *= _opacity;
  790. float midWidth = _bounds.width - border.left - border.right;
  791. float midHeight = _bounds.height - border.top - border.bottom;
  792. float midX = _absoluteBounds.x + border.left;
  793. float midY = _absoluteBounds.y + border.top;
  794. float rightX = _absoluteBounds.x + _bounds.width - border.right;
  795. float bottomY = _absoluteBounds.y + _bounds.height - border.bottom;
  796. // Draw themed border sprites.
  797. if (!border.left && !border.right && !border.top && !border.bottom)
  798. {
  799. // No border, just draw the image.
  800. spriteBatch->draw(_absoluteBounds.x, _absoluteBounds.y, _bounds.width, _bounds.height, center.u1, center.v1, center.u2, center.v2, skinColor, clip);
  801. }
  802. else
  803. {
  804. if (border.left && border.top)
  805. spriteBatch->draw(_absoluteBounds.x, _absoluteBounds.y, border.left, border.top, topLeft.u1, topLeft.v1, topLeft.u2, topLeft.v2, skinColor, clip);
  806. if (border.top)
  807. spriteBatch->draw(_absoluteBounds.x + border.left, _absoluteBounds.y, midWidth, border.top, top.u1, top.v1, top.u2, top.v2, skinColor, clip);
  808. if (border.right && border.top)
  809. spriteBatch->draw(rightX, _absoluteBounds.y, border.right, border.top, topRight.u1, topRight.v1, topRight.u2, topRight.v2, skinColor, clip);
  810. if (border.left)
  811. spriteBatch->draw(_absoluteBounds.x, midY, border.left, midHeight, left.u1, left.v1, left.u2, left.v2, skinColor, clip);
  812. if (border.left && border.right && border.top && border.bottom)
  813. spriteBatch->draw(_absoluteBounds.x + border.left, _absoluteBounds.y + border.top, _bounds.width - border.left - border.right, _bounds.height - border.top - border.bottom,
  814. center.u1, center.v1, center.u2, center.v2, skinColor, clip);
  815. if (border.right)
  816. spriteBatch->draw(rightX, midY, border.right, midHeight, right.u1, right.v1, right.u2, right.v2, skinColor, clip);
  817. if (border.bottom && border.left)
  818. spriteBatch->draw(_absoluteBounds.x, bottomY, border.left, border.bottom, bottomLeft.u1, bottomLeft.v1, bottomLeft.u2, bottomLeft.v2, skinColor, clip);
  819. if (border.bottom)
  820. spriteBatch->draw(midX, bottomY, midWidth, border.bottom, bottom.u1, bottom.v1, bottom.u2, bottom.v2, skinColor, clip);
  821. if (border.bottom && border.right)
  822. spriteBatch->draw(rightX, bottomY, border.right, border.bottom, bottomRight.u1, bottomRight.v1, bottomRight.u2, bottomRight.v2, skinColor, clip);
  823. }
  824. }
  825. void Control::drawImages(SpriteBatch* spriteBatch, const Rectangle& position)
  826. {
  827. }
  828. void Control::drawText(const Rectangle& position)
  829. {
  830. }
  831. void Control::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsClear, bool cleared, float targetHeight)
  832. {
  833. if (needsClear)
  834. {
  835. GL_ASSERT( glEnable(GL_SCISSOR_TEST) );
  836. GL_ASSERT( glScissor(_clearBounds.x, targetHeight - _clearBounds.y - _clearBounds.height, _clearBounds.width, _clearBounds.height) );
  837. Game::getInstance()->clear(Game::CLEAR_COLOR, Vector4::zero(), 1.0f, 0);
  838. GL_ASSERT( glDisable(GL_SCISSOR_TEST) );
  839. }
  840. spriteBatch->start();
  841. drawBorder(spriteBatch, clip);
  842. drawImages(spriteBatch, clip);
  843. spriteBatch->finish();
  844. drawText(clip);
  845. _dirty = false;
  846. }
  847. bool Control::isDirty()
  848. {
  849. return _dirty;
  850. }
  851. bool Control::isContainer() const
  852. {
  853. return false;
  854. }
  855. Control::State Control::getState(const char* state)
  856. {
  857. if (!state)
  858. {
  859. return NORMAL;
  860. }
  861. if (strcmp(state, "NORMAL") == 0)
  862. {
  863. return NORMAL;
  864. }
  865. else if (strcmp(state, "ACTIVE") == 0)
  866. {
  867. return ACTIVE;
  868. }
  869. else if (strcmp(state, "FOCUS") == 0)
  870. {
  871. return FOCUS;
  872. }
  873. else if (strcmp(state, "DISABLED") == 0)
  874. {
  875. return DISABLED;
  876. }
  877. return NORMAL;
  878. }
  879. Theme::ThemeImage* Control::getImage(const char* id, State state)
  880. {
  881. Theme::Style::Overlay* overlay = getOverlay(state);
  882. GP_ASSERT(overlay);
  883. Theme::ImageList* imageList = overlay->getImageList();
  884. if (!imageList)
  885. return NULL;
  886. return imageList->getImage(id);
  887. }
  888. const char* Control::getType() const
  889. {
  890. return "control";
  891. }
  892. // Implementation of AnimationHandler
  893. unsigned int Control::getAnimationPropertyComponentCount(int propertyId) const
  894. {
  895. switch(propertyId)
  896. {
  897. case ANIMATE_POSITION:
  898. case ANIMATE_SIZE:
  899. return 2;
  900. case ANIMATE_POSITION_X:
  901. case ANIMATE_POSITION_Y:
  902. case ANIMATE_SIZE_WIDTH:
  903. case ANIMATE_SIZE_HEIGHT:
  904. case ANIMATE_OPACITY:
  905. return 1;
  906. default:
  907. return -1;
  908. }
  909. }
  910. void Control::getAnimationPropertyValue(int propertyId, AnimationValue* value)
  911. {
  912. GP_ASSERT(value);
  913. switch(propertyId)
  914. {
  915. case ANIMATE_POSITION:
  916. value->setFloat(0, _bounds.x);
  917. value->setFloat(1, _bounds.y);
  918. break;
  919. case ANIMATE_SIZE:
  920. value->setFloat(0, _bounds.width);
  921. value->setFloat(1, _bounds.height);
  922. break;
  923. case ANIMATE_POSITION_X:
  924. value->setFloat(0, _bounds.x);
  925. break;
  926. case ANIMATE_POSITION_Y:
  927. value->setFloat(0, _bounds.y);
  928. break;
  929. case ANIMATE_SIZE_WIDTH:
  930. value->setFloat(0, _bounds.width);
  931. break;
  932. case ANIMATE_SIZE_HEIGHT:
  933. value->setFloat(0, _bounds.height);
  934. break;
  935. case ANIMATE_OPACITY:
  936. default:
  937. break;
  938. }
  939. }
  940. void Control::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight)
  941. {
  942. GP_ASSERT(value);
  943. switch(propertyId)
  944. {
  945. case ANIMATE_POSITION:
  946. _bounds.x = Curve::lerp(blendWeight, _bounds.x, value->getFloat(0));
  947. _bounds.y = Curve::lerp(blendWeight, _bounds.y, value->getFloat(1));
  948. _dirty = true;
  949. break;
  950. case ANIMATE_POSITION_X:
  951. _bounds.x = Curve::lerp(blendWeight, _bounds.x, value->getFloat(0));
  952. _dirty = true;
  953. break;
  954. case ANIMATE_POSITION_Y:
  955. _bounds.y = Curve::lerp(blendWeight, _bounds.y, value->getFloat(0));
  956. _dirty = true;
  957. break;
  958. case ANIMATE_SIZE:
  959. _bounds.width = Curve::lerp(blendWeight, _bounds.width, value->getFloat(0));
  960. _bounds.height = Curve::lerp(blendWeight, _bounds.height, value->getFloat(1));
  961. _dirty = true;
  962. break;
  963. case ANIMATE_SIZE_WIDTH:
  964. _bounds.width = Curve::lerp(blendWeight, _bounds.width, value->getFloat(0));
  965. _dirty = true;
  966. break;
  967. case ANIMATE_SIZE_HEIGHT:
  968. _bounds.height = Curve::lerp(blendWeight, _bounds.height, value->getFloat(0));
  969. _dirty = true;
  970. break;
  971. case ANIMATE_OPACITY:
  972. _dirty = true;
  973. break;
  974. }
  975. }
  976. Theme::Style::Overlay** Control::getOverlays(unsigned char overlayTypes, Theme::Style::Overlay** overlays)
  977. {
  978. GP_ASSERT(overlays);
  979. GP_ASSERT(_style);
  980. unsigned int index = 0;
  981. if ((overlayTypes & NORMAL) == NORMAL)
  982. {
  983. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_NORMAL);
  984. }
  985. if ((overlayTypes & FOCUS) == FOCUS)
  986. {
  987. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_FOCUS);
  988. }
  989. if ((overlayTypes & ACTIVE) == ACTIVE)
  990. {
  991. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_ACTIVE);
  992. }
  993. if ((overlayTypes & DISABLED) == DISABLED)
  994. {
  995. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_DISABLED);
  996. }
  997. return overlays;
  998. }
  999. Theme::Style::Overlay* Control::getOverlay(State state) const
  1000. {
  1001. GP_ASSERT(_style);
  1002. switch(state)
  1003. {
  1004. case Control::NORMAL:
  1005. return _style->getOverlay(Theme::Style::OVERLAY_NORMAL);
  1006. case Control::FOCUS:
  1007. return _style->getOverlay(Theme::Style::OVERLAY_FOCUS);
  1008. case Control::ACTIVE:
  1009. return _style->getOverlay(Theme::Style::OVERLAY_ACTIVE);
  1010. case Control::DISABLED:
  1011. return _style->getOverlay(Theme::Style::OVERLAY_DISABLED);
  1012. default:
  1013. return NULL;
  1014. }
  1015. }
  1016. void Control::overrideStyle()
  1017. {
  1018. if (_styleOverridden)
  1019. {
  1020. return;
  1021. }
  1022. // Copy the style.
  1023. GP_ASSERT(_style);
  1024. _style = new Theme::Style(*_style);
  1025. _styleOverridden = true;
  1026. }
  1027. void Control::overrideThemedProperties(Properties* properties, unsigned char states)
  1028. {
  1029. GP_ASSERT(properties);
  1030. GP_ASSERT(_style);
  1031. GP_ASSERT(_style->_theme);
  1032. Theme::ImageList* imageList = NULL;
  1033. Theme::ThemeImage* cursor = NULL;
  1034. Theme::Skin* skin = NULL;
  1035. _style->_theme->lookUpSprites(properties, &imageList, &cursor, &skin);
  1036. if (imageList)
  1037. {
  1038. setImageList(imageList, states);
  1039. }
  1040. if (cursor)
  1041. {
  1042. setCursor(cursor, states);
  1043. }
  1044. if (skin)
  1045. {
  1046. setSkin(skin, states);
  1047. }
  1048. if (properties->exists("font"))
  1049. {
  1050. Font* font = Font::create(properties->getString("font"));
  1051. setFont(font, states);
  1052. font->release();
  1053. }
  1054. if (properties->exists("fontSize"))
  1055. {
  1056. setFontSize(properties->getInt("fontSize"), states);
  1057. }
  1058. if (properties->exists("textColor"))
  1059. {
  1060. Vector4 textColor(0, 0, 0, 1);
  1061. properties->getColor("textColor", &textColor);
  1062. setTextColor(textColor, states);
  1063. }
  1064. if (properties->exists("textAlignment"))
  1065. {
  1066. setTextAlignment(Font::getJustify(properties->getString("textAlignment")), states);
  1067. }
  1068. if (properties->exists("rightToLeft"))
  1069. {
  1070. setTextRightToLeft(properties->getBool("rightToLeft"), states);
  1071. }
  1072. if (properties->exists("opacity"))
  1073. {
  1074. setOpacity(properties->getFloat("opacity"), states);
  1075. }
  1076. }
  1077. void Control::setImageList(Theme::ImageList* imageList, unsigned char states)
  1078. {
  1079. overrideStyle();
  1080. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  1081. getOverlays(states, overlays);
  1082. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  1083. {
  1084. overlays[i]->setImageList(imageList);
  1085. }
  1086. _dirty = true;
  1087. }
  1088. void Control::setCursor(Theme::ThemeImage* cursor, unsigned char states)
  1089. {
  1090. overrideStyle();
  1091. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  1092. getOverlays(states, overlays);
  1093. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  1094. {
  1095. overlays[i]->setCursor(cursor);
  1096. }
  1097. _dirty = true;
  1098. }
  1099. void Control::setSkin(Theme::Skin* skin, unsigned char states)
  1100. {
  1101. overrideStyle();
  1102. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  1103. getOverlays(states, overlays);
  1104. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  1105. {
  1106. overlays[i]->setSkin(skin);
  1107. }
  1108. _dirty = true;
  1109. }
  1110. Theme::Skin* Control::getSkin(State state)
  1111. {
  1112. Theme::Style::Overlay* overlay = getOverlay(state);
  1113. GP_ASSERT(overlay);
  1114. return overlay->getSkin();
  1115. }
  1116. Control::Alignment Control::getAlignment(const char* alignment)
  1117. {
  1118. if (!alignment)
  1119. {
  1120. return Control::ALIGN_TOP_LEFT;
  1121. }
  1122. if (strcmp(alignment, "ALIGN_LEFT") == 0)
  1123. {
  1124. return Control::ALIGN_LEFT;
  1125. }
  1126. else if (strcmp(alignment, "ALIGN_HCENTER") == 0)
  1127. {
  1128. return Control::ALIGN_HCENTER;
  1129. }
  1130. else if (strcmp(alignment, "ALIGN_RIGHT") == 0)
  1131. {
  1132. return Control::ALIGN_RIGHT;
  1133. }
  1134. else if (strcmp(alignment, "ALIGN_TOP") == 0)
  1135. {
  1136. return Control::ALIGN_TOP;
  1137. }
  1138. else if (strcmp(alignment, "ALIGN_VCENTER") == 0)
  1139. {
  1140. return Control::ALIGN_VCENTER;
  1141. }
  1142. else if (strcmp(alignment, "ALIGN_BOTTOM") == 0)
  1143. {
  1144. return Control::ALIGN_BOTTOM;
  1145. }
  1146. else if (strcmp(alignment, "ALIGN_TOP_LEFT") == 0)
  1147. {
  1148. return Control::ALIGN_TOP_LEFT;
  1149. }
  1150. else if (strcmp(alignment, "ALIGN_VCENTER_LEFT") == 0)
  1151. {
  1152. return Control::ALIGN_VCENTER_LEFT;
  1153. }
  1154. else if (strcmp(alignment, "ALIGN_BOTTOM_LEFT") == 0)
  1155. {
  1156. return Control::ALIGN_BOTTOM_LEFT;
  1157. }
  1158. else if (strcmp(alignment, "ALIGN_TOP_HCENTER") == 0)
  1159. {
  1160. return Control::ALIGN_TOP_HCENTER;
  1161. }
  1162. else if (strcmp(alignment, "ALIGN_VCENTER_HCENTER") == 0)
  1163. {
  1164. return Control::ALIGN_VCENTER_HCENTER;
  1165. }
  1166. else if (strcmp(alignment, "ALIGN_BOTTOM_HCENTER") == 0)
  1167. {
  1168. return Control::ALIGN_BOTTOM_HCENTER;
  1169. }
  1170. else if (strcmp(alignment, "ALIGN_TOP_RIGHT") == 0)
  1171. {
  1172. return Control::ALIGN_TOP_RIGHT;
  1173. }
  1174. else if (strcmp(alignment, "ALIGN_VCENTER_RIGHT") == 0)
  1175. {
  1176. return Control::ALIGN_VCENTER_RIGHT;
  1177. }
  1178. else if (strcmp(alignment, "ALIGN_BOTTOM_RIGHT") == 0)
  1179. {
  1180. return Control::ALIGN_BOTTOM_RIGHT;
  1181. }
  1182. else
  1183. {
  1184. GP_ERROR("Failed to get corresponding control alignment for unsupported value '%s'.", alignment);
  1185. }
  1186. // Default.
  1187. return Control::ALIGN_TOP_LEFT;
  1188. }
  1189. }