Control.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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), _listeners(NULL),
  9. _contactIndex(INVALID_CONTACT_INDEX), _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. if (_listeners)
  667. {
  668. std::map<Listener::EventType, std::list<Listener*>*>::const_iterator itr = _listeners->find(eventType);
  669. if (itr != _listeners->end())
  670. {
  671. std::list<Listener*>* listenerList = itr->second;
  672. for (std::list<Listener*>::iterator listenerItr = listenerList->begin(); listenerItr != listenerList->end(); listenerItr++)
  673. {
  674. GP_ASSERT(*listenerItr);
  675. (*listenerItr)->controlEvent(this, eventType);
  676. }
  677. }
  678. }
  679. fireScriptEvent<void>("controlEvent", this, eventType);
  680. }
  681. void Control::update(const Control* container, const Vector2& offset)
  682. {
  683. const Rectangle& clip = container->getClip();
  684. const Rectangle& absoluteViewport = container->_viewportBounds;
  685. _clearBounds.set(_absoluteClipBounds);
  686. // Calculate the clipped bounds.
  687. float x = _bounds.x + offset.x;
  688. float y = _bounds.y + offset.y;
  689. float width = _bounds.width;
  690. float height = _bounds.height;
  691. float clipX2 = clip.x + clip.width;
  692. float x2 = clip.x + x + width;
  693. if (x2 > clipX2)
  694. width -= x2 - clipX2;
  695. float clipY2 = clip.y + clip.height;
  696. float y2 = clip.y + y + height;
  697. if (y2 > clipY2)
  698. height -= y2 - clipY2;
  699. if (x < 0)
  700. {
  701. width += x;
  702. x = -x;
  703. }
  704. else
  705. {
  706. x = 0;
  707. }
  708. if (y < 0)
  709. {
  710. height += y;
  711. y = -y;
  712. }
  713. else
  714. {
  715. y = 0;
  716. }
  717. _clipBounds.set(x, y, width, height);
  718. // Calculate the absolute bounds.
  719. x = _bounds.x + offset.x + absoluteViewport.x;
  720. y = _bounds.y + offset.y + absoluteViewport.y;
  721. _absoluteBounds.set(x, y, _bounds.width, _bounds.height);
  722. // Calculate the absolute viewport bounds.
  723. // Absolute bounds minus border and padding.
  724. const Theme::Border& border = getBorder(_state);
  725. const Theme::Padding& padding = getPadding();
  726. x += border.left + padding.left;
  727. y += border.top + padding.top;
  728. width = _bounds.width - border.left - padding.left - border.right - padding.right;
  729. height = _bounds.height - border.top - padding.top - border.bottom - padding.bottom;
  730. _viewportBounds.set(x, y, width, height);
  731. // Calculate the clip area.
  732. // Absolute bounds, minus border and padding,
  733. // clipped to the parent container's clip area.
  734. clipX2 = clip.x + clip.width;
  735. x2 = x + width;
  736. if (x2 > clipX2)
  737. width = clipX2 - x;
  738. clipY2 = clip.y + clip.height;
  739. y2 = y + height;
  740. if (y2 > clipY2)
  741. height = clipY2 - y;
  742. if (x < clip.x)
  743. {
  744. float dx = clip.x - x;
  745. width -= dx;
  746. x = clip.x;
  747. }
  748. if (y < clip.y)
  749. {
  750. float dy = clip.y - y;
  751. height -= dy;
  752. y = clip.y;
  753. }
  754. _viewportClipBounds.set(x, y, width, height);
  755. _absoluteClipBounds.set(x - border.left - padding.left, y - border.top - padding.top,
  756. width + border.left + padding.left + border.right + padding.right,
  757. height + border.top + padding.top + border.bottom + padding.bottom);
  758. if (_clearBounds.isEmpty())
  759. {
  760. _clearBounds.set(_absoluteClipBounds);
  761. }
  762. // Cache themed attributes for performance.
  763. _skin = getSkin(_state);
  764. _opacity = getOpacity(_state);
  765. }
  766. void Control::drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip)
  767. {
  768. if (!spriteBatch || !_skin || _bounds.width <= 0 || _bounds.height <= 0)
  769. return;
  770. // Get the border and background images for this control's current state.
  771. const Theme::UVs& topLeft = _skin->getUVs(Theme::Skin::TOP_LEFT);
  772. const Theme::UVs& top = _skin->getUVs(Theme::Skin::TOP);
  773. const Theme::UVs& topRight = _skin->getUVs(Theme::Skin::TOP_RIGHT);
  774. const Theme::UVs& left = _skin->getUVs(Theme::Skin::LEFT);
  775. const Theme::UVs& center = _skin->getUVs(Theme::Skin::CENTER);
  776. const Theme::UVs& right = _skin->getUVs(Theme::Skin::RIGHT);
  777. const Theme::UVs& bottomLeft = _skin->getUVs(Theme::Skin::BOTTOM_LEFT);
  778. const Theme::UVs& bottom = _skin->getUVs(Theme::Skin::BOTTOM);
  779. const Theme::UVs& bottomRight = _skin->getUVs(Theme::Skin::BOTTOM_RIGHT);
  780. // Calculate screen-space positions.
  781. const Theme::Border& border = getBorder(_state);
  782. const Theme::Padding& padding = getPadding();
  783. Vector4 skinColor = _skin->getColor();
  784. skinColor.w *= _opacity;
  785. float midWidth = _bounds.width - border.left - border.right;
  786. float midHeight = _bounds.height - border.top - border.bottom;
  787. float midX = _absoluteBounds.x + border.left;
  788. float midY = _absoluteBounds.y + border.top;
  789. float rightX = _absoluteBounds.x + _bounds.width - border.right;
  790. float bottomY = _absoluteBounds.y + _bounds.height - border.bottom;
  791. // Draw themed border sprites.
  792. if (!border.left && !border.right && !border.top && !border.bottom)
  793. {
  794. // No border, just draw the image.
  795. spriteBatch->draw(_absoluteBounds.x, _absoluteBounds.y, _bounds.width, _bounds.height, center.u1, center.v1, center.u2, center.v2, skinColor, clip);
  796. }
  797. else
  798. {
  799. if (border.left && border.top)
  800. spriteBatch->draw(_absoluteBounds.x, _absoluteBounds.y, border.left, border.top, topLeft.u1, topLeft.v1, topLeft.u2, topLeft.v2, skinColor, clip);
  801. if (border.top)
  802. spriteBatch->draw(_absoluteBounds.x + border.left, _absoluteBounds.y, midWidth, border.top, top.u1, top.v1, top.u2, top.v2, skinColor, clip);
  803. if (border.right && border.top)
  804. spriteBatch->draw(rightX, _absoluteBounds.y, border.right, border.top, topRight.u1, topRight.v1, topRight.u2, topRight.v2, skinColor, clip);
  805. if (border.left)
  806. spriteBatch->draw(_absoluteBounds.x, midY, border.left, midHeight, left.u1, left.v1, left.u2, left.v2, skinColor, clip);
  807. if (border.left && border.right && border.top && border.bottom)
  808. spriteBatch->draw(_absoluteBounds.x + border.left, _absoluteBounds.y + border.top, _bounds.width - border.left - border.right, _bounds.height - border.top - border.bottom,
  809. center.u1, center.v1, center.u2, center.v2, skinColor, clip);
  810. if (border.right)
  811. spriteBatch->draw(rightX, midY, border.right, midHeight, right.u1, right.v1, right.u2, right.v2, skinColor, clip);
  812. if (border.bottom && border.left)
  813. spriteBatch->draw(_absoluteBounds.x, bottomY, border.left, border.bottom, bottomLeft.u1, bottomLeft.v1, bottomLeft.u2, bottomLeft.v2, skinColor, clip);
  814. if (border.bottom)
  815. spriteBatch->draw(midX, bottomY, midWidth, border.bottom, bottom.u1, bottom.v1, bottom.u2, bottom.v2, skinColor, clip);
  816. if (border.bottom && border.right)
  817. spriteBatch->draw(rightX, bottomY, border.right, border.bottom, bottomRight.u1, bottomRight.v1, bottomRight.u2, bottomRight.v2, skinColor, clip);
  818. }
  819. }
  820. void Control::drawImages(SpriteBatch* spriteBatch, const Rectangle& position)
  821. {
  822. }
  823. void Control::drawText(const Rectangle& position)
  824. {
  825. }
  826. void Control::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsClear, bool cleared, float targetHeight)
  827. {
  828. if (needsClear)
  829. {
  830. GL_ASSERT( glEnable(GL_SCISSOR_TEST) );
  831. GL_ASSERT( glScissor(_clearBounds.x, targetHeight - _clearBounds.y - _clearBounds.height, _clearBounds.width, _clearBounds.height) );
  832. Game::getInstance()->clear(Game::CLEAR_COLOR, Vector4::zero(), 1.0f, 0);
  833. GL_ASSERT( glDisable(GL_SCISSOR_TEST) );
  834. }
  835. spriteBatch->start();
  836. drawBorder(spriteBatch, clip);
  837. drawImages(spriteBatch, clip);
  838. spriteBatch->finish();
  839. drawText(clip);
  840. _dirty = false;
  841. }
  842. bool Control::isDirty()
  843. {
  844. return _dirty;
  845. }
  846. bool Control::isContainer() const
  847. {
  848. return false;
  849. }
  850. Control::State Control::getState(const char* state)
  851. {
  852. if (!state)
  853. {
  854. return NORMAL;
  855. }
  856. if (strcmp(state, "NORMAL") == 0)
  857. {
  858. return NORMAL;
  859. }
  860. else if (strcmp(state, "ACTIVE") == 0)
  861. {
  862. return ACTIVE;
  863. }
  864. else if (strcmp(state, "FOCUS") == 0)
  865. {
  866. return FOCUS;
  867. }
  868. else if (strcmp(state, "DISABLED") == 0)
  869. {
  870. return DISABLED;
  871. }
  872. return NORMAL;
  873. }
  874. Theme::ThemeImage* Control::getImage(const char* id, State state)
  875. {
  876. Theme::Style::Overlay* overlay = getOverlay(state);
  877. GP_ASSERT(overlay);
  878. Theme::ImageList* imageList = overlay->getImageList();
  879. if (!imageList)
  880. return NULL;
  881. return imageList->getImage(id);
  882. }
  883. const char* Control::getType() const
  884. {
  885. return "control";
  886. }
  887. // Implementation of AnimationHandler
  888. unsigned int Control::getAnimationPropertyComponentCount(int propertyId) const
  889. {
  890. switch(propertyId)
  891. {
  892. case ANIMATE_POSITION:
  893. case ANIMATE_SIZE:
  894. return 2;
  895. case ANIMATE_POSITION_X:
  896. case ANIMATE_POSITION_Y:
  897. case ANIMATE_SIZE_WIDTH:
  898. case ANIMATE_SIZE_HEIGHT:
  899. case ANIMATE_OPACITY:
  900. return 1;
  901. default:
  902. return -1;
  903. }
  904. }
  905. void Control::getAnimationPropertyValue(int propertyId, AnimationValue* value)
  906. {
  907. GP_ASSERT(value);
  908. switch(propertyId)
  909. {
  910. case ANIMATE_POSITION:
  911. value->setFloat(0, _bounds.x);
  912. value->setFloat(1, _bounds.y);
  913. break;
  914. case ANIMATE_SIZE:
  915. value->setFloat(0, _bounds.width);
  916. value->setFloat(1, _bounds.height);
  917. break;
  918. case ANIMATE_POSITION_X:
  919. value->setFloat(0, _bounds.x);
  920. break;
  921. case ANIMATE_POSITION_Y:
  922. value->setFloat(0, _bounds.y);
  923. break;
  924. case ANIMATE_SIZE_WIDTH:
  925. value->setFloat(0, _bounds.width);
  926. break;
  927. case ANIMATE_SIZE_HEIGHT:
  928. value->setFloat(0, _bounds.height);
  929. break;
  930. case ANIMATE_OPACITY:
  931. default:
  932. break;
  933. }
  934. }
  935. void Control::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight)
  936. {
  937. GP_ASSERT(value);
  938. switch(propertyId)
  939. {
  940. case ANIMATE_POSITION:
  941. _bounds.x = Curve::lerp(blendWeight, _bounds.x, value->getFloat(0));
  942. _bounds.y = Curve::lerp(blendWeight, _bounds.y, value->getFloat(1));
  943. _dirty = true;
  944. break;
  945. case ANIMATE_POSITION_X:
  946. _bounds.x = Curve::lerp(blendWeight, _bounds.x, value->getFloat(0));
  947. _dirty = true;
  948. break;
  949. case ANIMATE_POSITION_Y:
  950. _bounds.y = Curve::lerp(blendWeight, _bounds.y, value->getFloat(0));
  951. _dirty = true;
  952. break;
  953. case ANIMATE_SIZE:
  954. _bounds.width = Curve::lerp(blendWeight, _bounds.width, value->getFloat(0));
  955. _bounds.height = Curve::lerp(blendWeight, _bounds.height, value->getFloat(1));
  956. _dirty = true;
  957. break;
  958. case ANIMATE_SIZE_WIDTH:
  959. _bounds.width = Curve::lerp(blendWeight, _bounds.width, value->getFloat(0));
  960. _dirty = true;
  961. break;
  962. case ANIMATE_SIZE_HEIGHT:
  963. _bounds.height = Curve::lerp(blendWeight, _bounds.height, value->getFloat(0));
  964. _dirty = true;
  965. break;
  966. case ANIMATE_OPACITY:
  967. _dirty = true;
  968. break;
  969. }
  970. }
  971. Theme::Style::Overlay** Control::getOverlays(unsigned char overlayTypes, Theme::Style::Overlay** overlays)
  972. {
  973. GP_ASSERT(overlays);
  974. GP_ASSERT(_style);
  975. unsigned int index = 0;
  976. if ((overlayTypes & NORMAL) == NORMAL)
  977. {
  978. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_NORMAL);
  979. }
  980. if ((overlayTypes & FOCUS) == FOCUS)
  981. {
  982. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_FOCUS);
  983. }
  984. if ((overlayTypes & ACTIVE) == ACTIVE)
  985. {
  986. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_ACTIVE);
  987. }
  988. if ((overlayTypes & DISABLED) == DISABLED)
  989. {
  990. overlays[index++] = _style->getOverlay(Theme::Style::OVERLAY_DISABLED);
  991. }
  992. return overlays;
  993. }
  994. Theme::Style::Overlay* Control::getOverlay(State state) const
  995. {
  996. GP_ASSERT(_style);
  997. switch(state)
  998. {
  999. case Control::NORMAL:
  1000. return _style->getOverlay(Theme::Style::OVERLAY_NORMAL);
  1001. case Control::FOCUS:
  1002. return _style->getOverlay(Theme::Style::OVERLAY_FOCUS);
  1003. case Control::ACTIVE:
  1004. return _style->getOverlay(Theme::Style::OVERLAY_ACTIVE);
  1005. case Control::DISABLED:
  1006. return _style->getOverlay(Theme::Style::OVERLAY_DISABLED);
  1007. default:
  1008. return NULL;
  1009. }
  1010. }
  1011. void Control::overrideStyle()
  1012. {
  1013. if (_styleOverridden)
  1014. {
  1015. return;
  1016. }
  1017. // Copy the style.
  1018. GP_ASSERT(_style);
  1019. _style = new Theme::Style(*_style);
  1020. _styleOverridden = true;
  1021. }
  1022. void Control::overrideThemedProperties(Properties* properties, unsigned char states)
  1023. {
  1024. GP_ASSERT(properties);
  1025. GP_ASSERT(_style);
  1026. GP_ASSERT(_style->_theme);
  1027. Theme::ImageList* imageList = NULL;
  1028. Theme::ThemeImage* cursor = NULL;
  1029. Theme::Skin* skin = NULL;
  1030. _style->_theme->lookUpSprites(properties, &imageList, &cursor, &skin);
  1031. if (imageList)
  1032. {
  1033. setImageList(imageList, states);
  1034. }
  1035. if (cursor)
  1036. {
  1037. setCursor(cursor, states);
  1038. }
  1039. if (skin)
  1040. {
  1041. setSkin(skin, states);
  1042. }
  1043. if (properties->exists("font"))
  1044. {
  1045. Font* font = Font::create(properties->getString("font"));
  1046. setFont(font, states);
  1047. font->release();
  1048. }
  1049. if (properties->exists("fontSize"))
  1050. {
  1051. setFontSize(properties->getInt("fontSize"), states);
  1052. }
  1053. if (properties->exists("textColor"))
  1054. {
  1055. Vector4 textColor(0, 0, 0, 1);
  1056. properties->getColor("textColor", &textColor);
  1057. setTextColor(textColor, states);
  1058. }
  1059. if (properties->exists("textAlignment"))
  1060. {
  1061. setTextAlignment(Font::getJustify(properties->getString("textAlignment")), states);
  1062. }
  1063. if (properties->exists("rightToLeft"))
  1064. {
  1065. setTextRightToLeft(properties->getBool("rightToLeft"), states);
  1066. }
  1067. if (properties->exists("opacity"))
  1068. {
  1069. setOpacity(properties->getFloat("opacity"), states);
  1070. }
  1071. }
  1072. void Control::setImageList(Theme::ImageList* imageList, unsigned char states)
  1073. {
  1074. overrideStyle();
  1075. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  1076. getOverlays(states, overlays);
  1077. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  1078. {
  1079. overlays[i]->setImageList(imageList);
  1080. }
  1081. _dirty = true;
  1082. }
  1083. void Control::setCursor(Theme::ThemeImage* cursor, unsigned char states)
  1084. {
  1085. overrideStyle();
  1086. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  1087. getOverlays(states, overlays);
  1088. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  1089. {
  1090. overlays[i]->setCursor(cursor);
  1091. }
  1092. _dirty = true;
  1093. }
  1094. void Control::setSkin(Theme::Skin* skin, unsigned char states)
  1095. {
  1096. overrideStyle();
  1097. Theme::Style::Overlay* overlays[Theme::Style::OVERLAY_MAX] = { 0 };
  1098. getOverlays(states, overlays);
  1099. for (int i = 0; i < Theme::Style::OVERLAY_MAX - 1 && overlays[i]; ++i)
  1100. {
  1101. overlays[i]->setSkin(skin);
  1102. }
  1103. _dirty = true;
  1104. }
  1105. Theme::Skin* Control::getSkin(State state)
  1106. {
  1107. Theme::Style::Overlay* overlay = getOverlay(state);
  1108. GP_ASSERT(overlay);
  1109. return overlay->getSkin();
  1110. }
  1111. Control::Alignment Control::getAlignment(const char* alignment)
  1112. {
  1113. if (!alignment)
  1114. {
  1115. return Control::ALIGN_TOP_LEFT;
  1116. }
  1117. if (strcmp(alignment, "ALIGN_LEFT") == 0)
  1118. {
  1119. return Control::ALIGN_LEFT;
  1120. }
  1121. else if (strcmp(alignment, "ALIGN_HCENTER") == 0)
  1122. {
  1123. return Control::ALIGN_HCENTER;
  1124. }
  1125. else if (strcmp(alignment, "ALIGN_RIGHT") == 0)
  1126. {
  1127. return Control::ALIGN_RIGHT;
  1128. }
  1129. else if (strcmp(alignment, "ALIGN_TOP") == 0)
  1130. {
  1131. return Control::ALIGN_TOP;
  1132. }
  1133. else if (strcmp(alignment, "ALIGN_VCENTER") == 0)
  1134. {
  1135. return Control::ALIGN_VCENTER;
  1136. }
  1137. else if (strcmp(alignment, "ALIGN_BOTTOM") == 0)
  1138. {
  1139. return Control::ALIGN_BOTTOM;
  1140. }
  1141. else if (strcmp(alignment, "ALIGN_TOP_LEFT") == 0)
  1142. {
  1143. return Control::ALIGN_TOP_LEFT;
  1144. }
  1145. else if (strcmp(alignment, "ALIGN_VCENTER_LEFT") == 0)
  1146. {
  1147. return Control::ALIGN_VCENTER_LEFT;
  1148. }
  1149. else if (strcmp(alignment, "ALIGN_BOTTOM_LEFT") == 0)
  1150. {
  1151. return Control::ALIGN_BOTTOM_LEFT;
  1152. }
  1153. else if (strcmp(alignment, "ALIGN_TOP_HCENTER") == 0)
  1154. {
  1155. return Control::ALIGN_TOP_HCENTER;
  1156. }
  1157. else if (strcmp(alignment, "ALIGN_VCENTER_HCENTER") == 0)
  1158. {
  1159. return Control::ALIGN_VCENTER_HCENTER;
  1160. }
  1161. else if (strcmp(alignment, "ALIGN_BOTTOM_HCENTER") == 0)
  1162. {
  1163. return Control::ALIGN_BOTTOM_HCENTER;
  1164. }
  1165. else if (strcmp(alignment, "ALIGN_TOP_RIGHT") == 0)
  1166. {
  1167. return Control::ALIGN_TOP_RIGHT;
  1168. }
  1169. else if (strcmp(alignment, "ALIGN_VCENTER_RIGHT") == 0)
  1170. {
  1171. return Control::ALIGN_VCENTER_RIGHT;
  1172. }
  1173. else if (strcmp(alignment, "ALIGN_BOTTOM_RIGHT") == 0)
  1174. {
  1175. return Control::ALIGN_BOTTOM_RIGHT;
  1176. }
  1177. else
  1178. {
  1179. GP_ERROR("Failed to get corresponding control alignment for unsupported value '%s'.", alignment);
  1180. }
  1181. // Default.
  1182. return Control::ALIGN_TOP_LEFT;
  1183. }
  1184. }