Control.h 26 KB

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