ImageControl.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef IMAGECONTROL_H_
  2. #define IMAGECONTROL_H_
  3. #include "Control.h"
  4. #include "Theme.h"
  5. #include "Image.h"
  6. #include "SpriteBatch.h"
  7. #include "Rectangle.h"
  8. namespace gameplay
  9. {
  10. /**
  11. * Defines an image control.
  12. *
  13. * This allows forms to display seperate images from arbitrary files not specified in the theme.
  14. *
  15. * @see http://blackberry.github.io/GamePlay/docs/file-formats.html#wiki-UI_Forms
  16. */
  17. class ImageControl : public Control
  18. {
  19. friend class Container;
  20. friend class ControlFactory;
  21. public:
  22. /**
  23. * Creates a new ImageControl.
  24. *
  25. * @param id The image control ID.
  26. * @param style The image control style (optional).
  27. *
  28. * @return The new image control.
  29. * @script{create}
  30. */
  31. static ImageControl* create(const char* id, Theme::Style* style = NULL);
  32. /**
  33. * Set the path of the image for this ImageControl to display.
  34. *
  35. * @param path The path to the image.
  36. */
  37. void setImage(const char* path);
  38. /**
  39. * Set the source region of this ImageControl. This is the region of the file,
  40. * in pixels, to use when drawing.
  41. *
  42. * @param x The x coordinate of the source region.
  43. * @param y The y coordinate of the source region.
  44. * @param width The width of the source region.
  45. * @param height The height of the source region.
  46. */
  47. void setRegionSrc(float x, float y, float width, float height);
  48. /**
  49. * Set the source region of this ImageControl. This is the region of the file,
  50. * in pixels, to use when drawing.
  51. *
  52. * @param region The new source region.
  53. */
  54. void setRegionSrc(const Rectangle& region);
  55. /**
  56. * Get the source region of this ImageControl.
  57. *
  58. * @return The source region of this ImageControl.
  59. */
  60. const Rectangle& getRegionSrc() const;
  61. /**
  62. * Sets the destination region of this ImageControl. This is the region
  63. * within the control's viewport to draw the image.
  64. *
  65. * @param x The x coordinate of the destination region.
  66. * @param y The y coordinate of the destination region.
  67. * @param width The width of the destination region.
  68. * @param height The height of the destination region.
  69. */
  70. void setRegionDst(float x, float y, float width, float height);
  71. /**
  72. * Sets the destination region of this ImageControl. This is the region
  73. * within the control's viewport to draw the image.
  74. *
  75. * @param region The new destination region.
  76. */
  77. void setRegionDst(const Rectangle& region);
  78. /**
  79. * Get the destination region of this ImageControl.
  80. *
  81. * @return The destination region of this ImageControl.
  82. */
  83. const Rectangle& getRegionDst() const;
  84. const char* getType() const;
  85. protected:
  86. ImageControl();
  87. virtual ~ImageControl();
  88. /**
  89. * Creates a new ImageControl.
  90. *
  91. * @param style The control's custom style.
  92. * @param properties A properties object containing a definition of the ImageControl (optional).
  93. *
  94. * @return The new ImageControl.
  95. * @script{create}
  96. *
  97. */
  98. static Control* create(Theme::Style* style, Properties* properties = NULL);
  99. void initialize(const char* typeName, Theme::Style* style, Properties* properties);
  100. /**
  101. * @see Control::drawImages
  102. */
  103. unsigned int drawImages(Form* form, const Rectangle& clip);
  104. /**
  105. * @see Control::updateBounds
  106. */
  107. void updateBounds();
  108. private:
  109. ImageControl(const ImageControl& copy);
  110. // Source region.
  111. Rectangle _srcRegion;
  112. // Destination region.
  113. Rectangle _dstRegion;
  114. SpriteBatch* _batch;
  115. // One over texture width and height, for use when calculating UVs from a new source region.
  116. float _tw;
  117. float _th;
  118. // Calculated UVs.
  119. Theme::UVs _uvs;
  120. };
  121. }
  122. #endif