lv_area.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @file lv_area.h
  3. *
  4. */
  5. #ifndef LV_AREA_H
  6. #define LV_AREA_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*********************
  11. * INCLUDES
  12. *********************/
  13. #include <string.h>
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. /*********************
  17. * DEFINES
  18. *********************/
  19. #define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */
  20. #define LV_COORD_MIN (-16384)
  21. /**********************
  22. * TYPEDEFS
  23. **********************/
  24. typedef int16_t lv_coord_t;
  25. typedef struct
  26. {
  27. lv_coord_t x;
  28. lv_coord_t y;
  29. }lv_point_t;
  30. typedef struct
  31. {
  32. lv_coord_t x1;
  33. lv_coord_t y1;
  34. lv_coord_t x2;
  35. lv_coord_t y2;
  36. }lv_area_t;
  37. /**********************
  38. * GLOBAL PROTOTYPES
  39. **********************/
  40. /**
  41. * Initialize an area
  42. * @param area_p pointer to an area
  43. * @param x1 left coordinate of the area
  44. * @param y1 top coordinate of the area
  45. * @param x2 right coordinate of the area
  46. * @param y2 bottom coordinate of the area
  47. */
  48. void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2);
  49. /**
  50. * Copy an area
  51. * @param dest pointer to the destination area
  52. * @param src pointer to the source area
  53. */
  54. inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
  55. {
  56. memcpy(dest, src, sizeof(lv_area_t));
  57. }
  58. /**
  59. * Get the width of an area
  60. * @param area_p pointer to an area
  61. * @return the width of the area (if x1 == x2 -> width = 1)
  62. */
  63. static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p)
  64. {
  65. return area_p->x2 - area_p->x1 + 1;
  66. }
  67. /**
  68. * Get the height of an area
  69. * @param area_p pointer to an area
  70. * @return the height of the area (if y1 == y2 -> height = 1)
  71. */
  72. static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p)
  73. {
  74. return area_p->y2 - area_p->y1 + 1;
  75. }
  76. /**
  77. * Set the width of an area
  78. * @param area_p pointer to an area
  79. * @param w the new width of the area (w == 1 makes x1 == x2)
  80. */
  81. void lv_area_set_width(lv_area_t * area_p, lv_coord_t w);
  82. /**
  83. * Set the height of an area
  84. * @param area_p pointer to an area
  85. * @param h the new height of the area (h == 1 makes y1 == y2)
  86. */
  87. void lv_area_set_height(lv_area_t * area_p, lv_coord_t h);
  88. /**
  89. * Set the position of an area (width and height will be kept)
  90. * @param area_p pointer to an area
  91. * @param x the new x coordinate of the area
  92. * @param y the new y coordinate of the area
  93. */
  94. void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y);
  95. /**
  96. * Return with area of an area (x * y)
  97. * @param area_p pointer to an area
  98. * @return size of area
  99. */
  100. uint32_t lv_area_get_size(const lv_area_t * area_p);
  101. /**
  102. * Get the common parts of two areas
  103. * @param res_p pointer to an area, the result will be stored her
  104. * @param a1_p pointer to the first area
  105. * @param a2_p pointer to the second area
  106. * @return false: the two area has NO common parts, res_p is invalid
  107. */
  108. bool lv_area_union(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
  109. /**
  110. * Join two areas into a third which involves the other two
  111. * @param res_p pointer to an area, the result will be stored here
  112. * @param a1_p pointer to the first area
  113. * @param a2_p pointer to the second area
  114. */
  115. void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
  116. /**
  117. * Check if a point is on an area
  118. * @param a_p pointer to an area
  119. * @param p_p pointer to a point
  120. * @return false:the point is out of the area
  121. */
  122. bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p);
  123. /**
  124. * Check if two area has common parts
  125. * @param a1_p pointer to an area.
  126. * @param a2_p pointer to an other area
  127. * @return false: a1_p and a2_p has no common parts
  128. */
  129. bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
  130. /**
  131. * Check if an area is fully on an other
  132. * @param ain_p pointer to an area which could be on aholder_p
  133. * @param aholder pointer to an area which could involve ain_p
  134. * @return
  135. */
  136. bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p);
  137. /**********************
  138. * MACROS
  139. **********************/
  140. #ifdef __cplusplus
  141. } /* extern "C" */
  142. #endif
  143. #endif