Control.cpp 37 KB

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