Control.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. #ifndef CONTROL_H_
  2. #define CONTROL_H_
  3. #include "Ref.h"
  4. #include "Rectangle.h"
  5. #include "Vector2.h"
  6. #include "SpriteBatch.h"
  7. #include "Theme.h"
  8. #include "ThemeStyle.h"
  9. #include "Touch.h"
  10. #include "Keyboard.h"
  11. namespace gameplay
  12. {
  13. /**
  14. * Base class for UI controls.
  15. */
  16. class Control : public Ref, public AnimationTarget
  17. {
  18. friend class Form;
  19. friend class Container;
  20. friend class Layout;
  21. friend class AbsoluteLayout;
  22. friend class VerticalLayout;
  23. public:
  24. /**
  25. * The possible states a control can be in.
  26. */
  27. enum State
  28. {
  29. /**
  30. * State of an enabled but inactive control.
  31. */
  32. NORMAL = 0x01,
  33. /**
  34. * State of a control currently in focus.
  35. */
  36. FOCUS = 0x02,
  37. /**
  38. * State of a control that is currently being acted on,
  39. * e.g. through touch or mouse-click events.
  40. */
  41. ACTIVE = 0x04,
  42. /**
  43. * State of a control that has been disabled.
  44. */
  45. DISABLED = 0x08,
  46. };
  47. /**
  48. * Defines the set of alignments for positioning controls and justifying text.
  49. */
  50. enum Alignment
  51. {
  52. // Specify horizontal alignment, use default vertical alignment (ALIGN_TOP).
  53. ALIGN_LEFT = 0x01,
  54. ALIGN_HCENTER = 0x02,
  55. ALIGN_RIGHT = 0x04,
  56. // Specify vertical alignment, use default horizontal alignment (ALIGN_LEFT).
  57. ALIGN_TOP = 0x10,
  58. ALIGN_VCENTER = 0x20,
  59. ALIGN_BOTTOM = 0x40,
  60. // Specify both vertical and horizontal alignment.
  61. ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT,
  62. ALIGN_VCENTER_LEFT = ALIGN_VCENTER | ALIGN_LEFT,
  63. ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT,
  64. ALIGN_TOP_HCENTER = ALIGN_TOP | ALIGN_HCENTER,
  65. ALIGN_VCENTER_HCENTER = ALIGN_VCENTER | ALIGN_HCENTER,
  66. ALIGN_BOTTOM_HCENTER = ALIGN_BOTTOM | ALIGN_HCENTER,
  67. ALIGN_TOP_RIGHT = ALIGN_TOP | ALIGN_RIGHT,
  68. ALIGN_VCENTER_RIGHT = ALIGN_VCENTER | ALIGN_RIGHT,
  69. ALIGN_BOTTOM_RIGHT = ALIGN_BOTTOM | ALIGN_RIGHT
  70. };
  71. /**
  72. * A constant used for setting themed attributes on all control states simultaneously.
  73. */
  74. static const unsigned char STATE_ALL = NORMAL | FOCUS | ACTIVE | DISABLED;
  75. /**
  76. * Implement Control::Listener and call Control::addListener()
  77. * in order to listen for events on controls.
  78. */
  79. class Listener
  80. {
  81. public:
  82. enum EventType
  83. {
  84. /**
  85. * Mouse-down or touch-press event.
  86. */
  87. PRESS = 0x01,
  88. /**
  89. * Mouse-up or touch-release event.
  90. */
  91. RELEASE = 0x02,
  92. /**
  93. * Event triggered after consecutive PRESS and RELEASE events take place
  94. * within the bounds of a control.
  95. */
  96. CLICK = 0x04,
  97. /**
  98. * Event triggered when the value of a slider, check box, or radio button
  99. * changes.
  100. */
  101. VALUE_CHANGED = 0x08,
  102. /**
  103. * Event triggered when the contents of a text box are modified.
  104. */
  105. TEXT_CHANGED = 0x10
  106. };
  107. /**
  108. * Method called by controls when an event is triggered.
  109. *
  110. * @param control The control triggering the event.
  111. * @param evt The event triggered.
  112. */
  113. virtual void controlEvent(Control* control, EventType evt) = 0;
  114. };
  115. /**
  116. * Position animation property. Data = x, y
  117. */
  118. static const int ANIMATE_POSITION = 1;
  119. /**
  120. * Position x animation property. Data = x
  121. */
  122. static const int ANIMATE_POSITION_X = 2;
  123. /**
  124. * Position y animation property. Data = y
  125. */
  126. static const int ANIMATE_POSITION_Y = 3;
  127. /**
  128. * Size animation property. Data = width, height
  129. */
  130. static const int ANIMATE_SIZE = 4;
  131. /**
  132. * Size width animation property. Data = width
  133. */
  134. static const int ANIMATE_SIZE_WIDTH = 5;
  135. /**
  136. * Size height animation property. Data = height
  137. */
  138. static const int ANIMATE_SIZE_HEIGHT = 6;
  139. /**
  140. * Opacity property. Data = opacity
  141. */
  142. static const int ANIMATE_OPACITY = 7;
  143. /**
  144. * Get this control's ID string.
  145. *
  146. * @return This control's ID.
  147. */
  148. const char* getID() const;
  149. /**
  150. * Set the position of this control relative to its parent container.
  151. *
  152. * @param x The x coordinate.
  153. * @param y The y coordinate.
  154. */
  155. void setPosition(float x, float y);
  156. /**
  157. * Set the desired size of this control, including its border and padding, before clipping.
  158. *
  159. * @param width The width.
  160. * @param height The height.
  161. */
  162. void setSize(float width, float height);
  163. /**
  164. * Set the bounds of this control, relative to its parent container and including its
  165. * border and padding, before clipping.
  166. *
  167. * @param bounds The new bounds to set.
  168. */
  169. void setBounds(const Rectangle& bounds);
  170. /**
  171. * Get the bounds of this control, relative to its parent container and including its
  172. * border and padding, before clipping.
  173. *
  174. * @return The bounds of this control.
  175. */
  176. const Rectangle& getBounds() const;
  177. /**
  178. * Get the x coordinate of this control's bounds.
  179. *
  180. * @return The x coordinate of this control's bounds.
  181. */
  182. float getX() const;
  183. /**
  184. * Get the y coordinate of this control's bounds.
  185. *
  186. * @return The y coordinate of this control's bounds.
  187. */
  188. float getY() const;
  189. /**
  190. * Get the width of this control's bounds.
  191. *
  192. * @return The width of this control's bounds.
  193. */
  194. float getWidth() const;
  195. /**
  196. * Get the height of this control's bounds.
  197. *
  198. * @return The height of this control's bounds.
  199. */
  200. float getHeight() const;
  201. /**
  202. * Set the alignment of this control within its parent container.
  203. *
  204. * @param alignment This control's alignment.
  205. */
  206. void setAlignment(Alignment alignment);
  207. /**
  208. * Get the alignment of this control within its parent container.
  209. *
  210. * @return The alignment of this control within its parent container.
  211. */
  212. Alignment getAlignment() const;
  213. /**
  214. * Set this control to fit horizontally within its parent container.
  215. *
  216. * @param autoWidth Whether to size this control to fit horizontally within its parent container.
  217. */
  218. void setAutoWidth(bool autoWidth);
  219. /**
  220. * Get whether this control's width is set to automatically adjust to
  221. * fit horizontally within its parent container.
  222. *
  223. * @return Whether this control's width is set to automatically adjust.
  224. */
  225. bool getAutoWidth() const;
  226. /**
  227. * Set this control to fit vertically within its parent container.
  228. *
  229. * @param autoWidth Whether to size this control to fit vertically within its parent container.
  230. */
  231. void setAutoHeight(bool autoHeight);
  232. /**
  233. * Get whether this control's height is set to automatically adjust to
  234. * fit vertically within its parent container.
  235. *
  236. * @return Whether this control's height is set to automatically adjust.
  237. */
  238. bool getAutoHeight() const;
  239. /**
  240. * Set the size of this control's border.
  241. *
  242. * @param top The height of the border's top side.
  243. * @param bottom The height of the border's bottom side.
  244. * @param left The width of the border's left side.
  245. * @param right The width of the border's right side.
  246. * @param states The states to set this property on.
  247. * One or more members of the Control::State enum, ORed together.
  248. */
  249. void setBorder(float top, float bottom, float left, float right, unsigned char states = STATE_ALL);
  250. /**
  251. * Get the measurements of this control's border for a given state.
  252. *
  253. * @return This control's border.
  254. */
  255. const Theme::Border& getBorder(State state = NORMAL) const;
  256. /**
  257. * Set the texture region of this control's skin.
  258. *
  259. * @param region The texture region, in pixels.
  260. * @param states The states to set this property on.
  261. * One or more members of the Control::State enum, ORed together.
  262. */
  263. void setSkinRegion(const Rectangle& region, unsigned char states = STATE_ALL);
  264. /**
  265. * Get the texture region of this control's skin for a given state.
  266. *
  267. * @param state The state to get this property from.
  268. *
  269. * @return The texture region of this control's skin.
  270. */
  271. const Rectangle& getSkinRegion(State state = NORMAL) const;
  272. /**
  273. * Get the texture coordinates of an area of this control's skin for a given state.
  274. *
  275. * @param area The area of the skin to get the coordinates of.
  276. * @param state The state to get this property from.
  277. *
  278. * @return The texture coordinates of an area of this control's skin.
  279. */
  280. const Theme::UVs& getSkinUVs(Theme::Skin::SkinArea area, State state = NORMAL) const;
  281. /**
  282. * Set the blend color of this control's skin.
  283. *
  284. * @param color The new blend color.
  285. * @param states The states to set this property on.
  286. * One or more members of the Control::State enum, ORed together.
  287. */
  288. void setSkinColor(const Vector4& color, unsigned char states = STATE_ALL);
  289. /**
  290. * Get the blend color of this control's skin for a given state.
  291. *
  292. * @param state The state to get this property from.
  293. *
  294. * @return The blend color of this control's skin.
  295. */
  296. const Vector4& getSkinColor(State state = NORMAL) const;
  297. /**
  298. * Set this control's margin.
  299. *
  300. * @param top Height of top margin.
  301. * @param bottom Height of bottom margin.
  302. * @param left Width of left margin.
  303. * @param right Width of right margin.
  304. */
  305. void setMargin(float top, float bottom, float left, float right);
  306. /**
  307. * Get this control's margin.
  308. *
  309. * @return This control's margin.
  310. */
  311. const Theme::Margin& getMargin() const;
  312. /**
  313. * Set this control's padding.
  314. *
  315. * @param top Height of top padding.
  316. * @param bottom Height of bottom padding.
  317. * @param left Width of left padding.
  318. * @param right Width of right padding.
  319. */
  320. void setPadding(float top, float bottom, float left, float right);
  321. /**
  322. * Get this control's padding.
  323. *
  324. * @return This control's padding.
  325. */
  326. const Theme::Padding& getPadding() const;
  327. /**
  328. * Set the texture region of an image used by this control.
  329. *
  330. * @param id The ID of the image to modify.
  331. * @param region The new texture region of the image.
  332. * @param states The states to set this property on.
  333. * One or more members of the Control::State enum, ORed together.
  334. */
  335. void setImageRegion(const char* id, const Rectangle& region, unsigned char states = STATE_ALL);
  336. /**
  337. * Get the texture region of an image used by this control for a given state.
  338. *
  339. * @param id The ID of the image.
  340. * @param state The state to get this property from.
  341. *
  342. * @return The texture region of the specified image.
  343. */
  344. const Rectangle& getImageRegion(const char* id, State state) const;
  345. /**
  346. * Set the blend color of an image used by this control.
  347. *
  348. * @param id The ID of the image to modify.
  349. * @param color The new blend color of the image.
  350. * @param states The states to set this property on.
  351. * One or more members of the Control::State enum, ORed together.
  352. */
  353. void setImageColor(const char* id, const Vector4& color, unsigned char states = STATE_ALL);
  354. /**
  355. * Get the blend color of an image used by this control for a given state.
  356. *
  357. * @param id The ID of the image.
  358. * @param state The state to get this property from.
  359. *
  360. * @return The blend color of the specified image.
  361. */
  362. const Vector4& getImageColor(const char* id, State state) const;
  363. /**
  364. * Get the texture coordinates of an image used by this control for a given state.
  365. *
  366. * @param id The ID of the image.
  367. * @param state The state to get this property from.
  368. *
  369. * @return The texture coordinates of the specified image.
  370. */
  371. const Theme::UVs& getImageUVs(const char* id, State state) const;
  372. /**
  373. * Set the texture region of this control's cursor.
  374. *
  375. * @param region The cursor region.
  376. * @param states The states to set this property on.
  377. * One or more members of the Control::State enum, ORed together.
  378. */
  379. void setCursorRegion(const Rectangle& region, unsigned char states);
  380. /**
  381. * Get the texture region of this control's cursor for a given state.
  382. *
  383. * @param state The state to get this property from.
  384. *
  385. * @return The texture region of this control's cursor.
  386. */
  387. const Rectangle& getCursorRegion(State state) const;
  388. /**
  389. * Set the blend color of this control's cursor.
  390. *
  391. * @param color The new blend color.
  392. * @param states The states to set this property on.
  393. * One or more members of the Control::State enum, ORed together.
  394. */
  395. void setCursorColor(const Vector4& color, unsigned char states);
  396. /**
  397. * Get the blend color of this control's cursor for a given state.
  398. *
  399. * @param state The state to get this property from.
  400. *
  401. * @return The blend color of this control's cursor.
  402. */
  403. const Vector4& getCursorColor(State state);
  404. /**
  405. * Get the texture coordinates of this control's cursor for a given state.
  406. *
  407. * @param state The state to get this property from.
  408. *
  409. * @return The texture coordinates of this control's cursor.
  410. */
  411. const Theme::UVs& getCursorUVs(State state);
  412. /**
  413. * Set the font used by this control.
  414. *
  415. * @param font The new font to use.
  416. * @param states The states to set this property on.
  417. * One or more members of the Control::State enum, ORed together.
  418. */
  419. void setFont(Font* font, unsigned char states = STATE_ALL);
  420. /**
  421. * Get the font used by this control for a given state.
  422. *
  423. * @param state The state to get this property from.
  424. *
  425. * @return the font used by this control.
  426. */
  427. Font* getFont(State state = NORMAL) const;
  428. /**
  429. * Set this control's font size.
  430. *
  431. * @param size The new font size.
  432. * @param states The states to set this property on.
  433. * One or more members of the Control::State enum, ORed together.
  434. */
  435. void setFontSize(unsigned int size, unsigned char states = STATE_ALL);
  436. /**
  437. * Get this control's font size for a given state.
  438. *
  439. * @param state The state to get this property from.
  440. *
  441. * @return This control's font size.
  442. */
  443. unsigned int getFontSize(State state = NORMAL) const;
  444. /**
  445. * Set this control's text color.
  446. *
  447. * @param color The new text color.
  448. * @param states The states to set this property on.
  449. * One or more members of the Control::State enum, ORed together.
  450. */
  451. void setTextColor(const Vector4& color, unsigned char states = STATE_ALL);
  452. /**
  453. * Get this control's text color for a given state.
  454. *
  455. * @param state The state to get this property from.
  456. *
  457. * @return This control's text color.
  458. */
  459. const Vector4& getTextColor(State state = NORMAL) const;
  460. /**
  461. * Set this control's text alignment.
  462. *
  463. * @param alignment The new text alignment.
  464. * @param states The states to set this property on.
  465. * One or more members of the Control::State enum, ORed together.
  466. */
  467. void setTextAlignment(Font::Justify alignment, unsigned char states = STATE_ALL);
  468. /**
  469. * Get this control's text alignment for a given state.
  470. *
  471. * @param state The state to get this property from.
  472. *
  473. * @return This control's text alignment for the given state.
  474. */
  475. Font::Justify getTextAlignment(State state = NORMAL) const;
  476. /**
  477. * Set whether text is drawn from right to left within this control.
  478. *
  479. * @param rightToLeft Whether text is drawn from right to left within this control.
  480. * @param states The states to set this property on.
  481. * One or more members of the Control::State enum, ORed together.
  482. */
  483. void setTextRightToLeft(bool rightToLeft, unsigned char states = STATE_ALL);
  484. /**
  485. * Get whether text is drawn from right to left within this control, for a given state.
  486. *
  487. * @param state The state to get this property from.
  488. *
  489. * @return Whether text is drawn from right to left within this control, for the given state.
  490. */
  491. bool getTextRightToLeft(State state = NORMAL) const;
  492. /**
  493. * Set the opacity of this control.
  494. *
  495. * @param opacity The new opacity.
  496. * @param states The states to set this property on.
  497. * One or more members of the Control::State enum, ORed together.
  498. */
  499. void setOpacity(float opacity, unsigned char states = STATE_ALL);
  500. /**
  501. * Get the opacity of this control for a given state.
  502. *
  503. * @param state The state to get this property from.
  504. *
  505. * @return The opacity of this control for a given state.
  506. */
  507. float getOpacity(State state = NORMAL) const;
  508. /**
  509. * Get the bounds of this control, relative to its parent container, after clipping.
  510. *
  511. * @return The bounds of this control.
  512. */
  513. const Rectangle& getClipBounds() const;
  514. /**
  515. * Get the content area of this control, in screen coordinates, after clipping.
  516. *
  517. * @return The clipping area of this control.
  518. */
  519. const Rectangle& getClip() const;
  520. /**
  521. * Change this control's state.
  522. *
  523. * @param state The state to switch this control to.
  524. */
  525. void setState(State state);
  526. /**
  527. * Get this control's current state.
  528. *
  529. * @return This control's current state.
  530. */
  531. State getState() const;
  532. /**
  533. * Disable this control.
  534. */
  535. void disable();
  536. /**
  537. * Enable this control.
  538. */
  539. void enable();
  540. /**
  541. * Get whether this control is currently enabled.
  542. *
  543. * @return Whether this control is currently enabled.
  544. */
  545. bool isEnabled();
  546. /**
  547. * Set whether this control consumes touch events,
  548. * preventing them from being passed to the game.
  549. *
  550. * @param consume Whether this control consumes touch events.
  551. */
  552. void setConsumeTouchEvents(bool consume);
  553. /**
  554. * Get whether this control consumes touch events.
  555. *
  556. * @return Whether this control consumes touch events.
  557. */
  558. bool getConsumeTouchEvents();
  559. /**
  560. * Set the style this control will use when rendering.
  561. *
  562. * @param style The style this control will use when rendering.
  563. */
  564. void setStyle(Theme::Style* style);
  565. /**
  566. * Get this control's style.
  567. *
  568. * @return This control's style.
  569. */
  570. Theme::Style* getStyle() const;
  571. /**
  572. * Add a listener to be notified of specific events affecting
  573. * this control. Event types can be OR'ed together.
  574. * E.g. To listen to touch-press and touch-release events,
  575. * pass <code>Control::Listener::TOUCH | Control::Listener::RELEASE</code>
  576. * as the second parameter.
  577. *
  578. * @param listener The listener to add.
  579. * @param eventFlags The events to listen for.
  580. */
  581. virtual void addListener(Control::Listener* listener, int eventFlags);
  582. /**
  583. * @see AnimationTarget#getAnimationPropertyComponentCount
  584. */
  585. unsigned int getAnimationPropertyComponentCount(int propertyId) const;
  586. /**
  587. * @see AnimationTarget#getAnimationProperty
  588. */
  589. void getAnimationPropertyValue(int propertyId, AnimationValue* value);
  590. /**
  591. * @see AnimationTarget#setAnimationProperty
  592. */
  593. void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
  594. protected:
  595. /**
  596. * Constructor.
  597. */
  598. Control();
  599. /**
  600. * Destructor.
  601. */
  602. virtual ~Control();
  603. /**
  604. * Get the overlay type corresponding to this control's current state.
  605. *
  606. * @return The overlay type corresponding to this control's current state.
  607. */
  608. Theme::Style::OverlayType getOverlayType() const;
  609. /**
  610. * Touch callback on touch events. Controls return true if they consume the touch event.
  611. *
  612. * @param evt The touch event that occurred.
  613. * @param x The x position of the touch in pixels. Left edge is zero.
  614. * @param y The y position of the touch in pixels. Top edge is zero.
  615. * @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
  616. *
  617. * @return Whether the touch event was consumed by this control.
  618. *
  619. * @see Touch::TouchEvent
  620. */
  621. virtual bool touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  622. /**
  623. * Keyboard callback on key events.
  624. *
  625. * @param evt The key event that occured.
  626. * @param key If evt is KEY_PRESS or KEY_RELEASE then key is the key code from Keyboard::Key.
  627. * If evt is KEY_CHAR then key is the unicode value of the character.
  628. *
  629. * @see Keyboard::KeyEvent
  630. * @see Keyboard::Key
  631. */
  632. virtual void keyEvent(Keyboard::KeyEvent evt, int key);
  633. /**
  634. * Called when a control's properties change. Updates this control's internal rendering
  635. * properties, such as its text viewport.
  636. *
  637. * @param clip The clipping rectangle of this control's parent container.
  638. */
  639. virtual void update(const Rectangle& clip);
  640. /**
  641. * Draw the images associated with this control.
  642. *
  643. * @param spriteBatch The sprite batch containing this control's icons.
  644. * @param clip The clipping rectangle of this control's parent container.
  645. */
  646. virtual void drawImages(SpriteBatch* spriteBatch, const Rectangle& clip);
  647. /**
  648. * Draw this control's text.
  649. *
  650. * @param clip The clipping rectangle of this control's parent container.
  651. */
  652. virtual void drawText(const Rectangle& clip);
  653. /**
  654. * Initialize properties common to STATE_ALL Controls.
  655. */
  656. virtual void initialize(Theme::Style* style, Properties* properties);
  657. /**
  658. * Container and classes that extend it should implement this and return true.
  659. *
  660. * @return true if this object is of class Container, false otherwise.
  661. */
  662. virtual bool isContainer();
  663. /**
  664. * Returns whether this control has been modified and requires an update.
  665. *
  666. * @return Whether this control has been modified and requires an update.
  667. */
  668. virtual bool isDirty();
  669. /**
  670. * Get a Control::State enum from a matching string.
  671. *
  672. * @param state The string to match.
  673. *
  674. * @return The Control::State enum that matches the given string.
  675. */
  676. static State getState(const char* state);
  677. /**
  678. * Notify this control's listeners of a specific event.
  679. *
  680. * @param eventType The event to trigger.
  681. */
  682. void notifyListeners(Listener::EventType eventType);
  683. static Alignment getAlignment(const char* alignment);
  684. std::string _id;
  685. State _state; // Determines overlay used during draw().
  686. Rectangle _bounds; // Position, relative to parent container's clipping window, and desired size.
  687. Rectangle _clipBounds; // The position and size of this control, relative to parent container's bounds, including border and padding, after clipping.
  688. Rectangle _textBounds; // The position and size of this control's text area, before clipping. Used for text alignment.
  689. Rectangle _clip; // Clipping window of this control's content, after clipping.
  690. bool _dirty;
  691. bool _consumeTouchEvents;
  692. Alignment _alignment;
  693. bool _autoWidth;
  694. bool _autoHeight;
  695. Theme::Style* _style;
  696. std::map<Listener::EventType, std::list<Listener*>*>* _listeners;
  697. private:
  698. static const char ANIMATION_POSITION_X_BIT = 0x01;
  699. static const char ANIMATION_POSITION_Y_BIT = 0x02;
  700. static const char ANIMATION_SIZE_WIDTH_BIT = 0x04;
  701. static const char ANIMATION_SIZE_HEIGHT_BIT = 0x08;
  702. static const char ANIMATION_OPACITY_BIT = 0x10;
  703. /*
  704. * Constructor.
  705. */
  706. Control(const Control& copy);
  707. void applyAnimationValuePositionX(float x, float blendWeight);
  708. void applyAnimationValuePositionY(float y, float blendWeight);
  709. void applyAnimationValueSizeWidth(float width, float blendWeight);
  710. void applyAnimationValueSizeHeight(float height, float blendWeight);
  711. void applyAnimationValueOpacity();
  712. Theme::Style::Overlay** getOverlays(unsigned char overlayTypes, Theme::Style::Overlay** overlays);
  713. Theme::Style::Overlay* getOverlay(Control::State state) const;
  714. void overrideStyle();
  715. void addSpecificListener(Control::Listener* listener, Listener::EventType eventType);
  716. /**
  717. * Draws the themed border and background of a control.
  718. *
  719. * @param spriteBatch The sprite batch containing this control's border images.
  720. * @param clip The clipping rectangle of this control's parent container.
  721. */
  722. virtual void drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip);
  723. bool _styleOverridden;
  724. };
  725. }
  726. #endif