TextBox.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef TEXTBOX_H_
  2. #define TEXTBOX_H_
  3. #include "Base.h"
  4. #include "Label.h"
  5. #include "Theme.h"
  6. #include "Keyboard.h"
  7. namespace gameplay
  8. {
  9. /**
  10. * An editable text label. Tap or click within the text box to bring up the
  11. * virtual keyboard.
  12. *
  13. * Listeners can listen for a TEXT_CHANGED event, and then query the text box
  14. * for the last keypress it received.
  15. *
  16. * The following properties are available for text boxes:
  17. *
  18. * label <Label ID>
  19. * {
  20. * style = <Style ID>
  21. * position = <x, y>
  22. * size = <width, height>
  23. * text = <string>
  24. * }
  25. */
  26. class TextBox : public Label
  27. {
  28. friend class Container;
  29. public:
  30. /**
  31. * Add a listener to be notified of specific events affecting
  32. * this control. Event types can be OR'ed together.
  33. * E.g. To listen to touch-press and touch-release events,
  34. * pass <code>Control::Listener::TOUCH | Control::Listener::RELEASE</code>
  35. * as the second parameter.
  36. *
  37. * @param listener The listener to add.
  38. * @param eventFlags The events to listen for.
  39. */
  40. virtual void addListener(Control::Listener* listener, int eventFlags);
  41. int getLastKeypress();
  42. protected:
  43. TextBox();
  44. ~TextBox();
  45. static TextBox* create(Theme::Style* style, Properties* properties);
  46. void setCursorLocation(int x, int y);
  47. bool touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  48. void keyEvent(Keyboard::KeyEvent evt, int key);
  49. void update(const Rectangle& clip);
  50. // Draw the cursor.
  51. void drawImages(SpriteBatch* spriteBatch, const Rectangle& clip);
  52. Vector2 _cursorLocation;
  53. unsigned int textIndex;
  54. int _lastKeypress;
  55. private:
  56. TextBox(const TextBox& copy);
  57. };
  58. }
  59. #endif