wgl_shared_utils.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H
  6. #define WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdbool.h>
  11. #include "../3rdparty/lv_conf.h"
  12. typedef lv_coord_t wgl_coord_t; /* lv_coord_t is defined in lv_conf.h */
  13. /**
  14. * Represents a point on the screen.
  15. */
  16. typedef struct
  17. {
  18. lv_coord_t x;
  19. lv_coord_t y;
  20. } wgl_point_t;
  21. /** Represents an area of the screen. */
  22. typedef struct
  23. {
  24. lv_coord_t x1;
  25. lv_coord_t y1;
  26. lv_coord_t x2;
  27. lv_coord_t y2;
  28. } wgl_area_t;
  29. /** Describes the properties of a glyph. */
  30. typedef struct
  31. {
  32. uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
  33. uint8_t box_w; /**< Width of the glyph's bounding box*/
  34. uint8_t box_h; /**< Height of the glyph's bounding box*/
  35. int8_t ofs_x; /**< x offset of the bounding box*/
  36. int8_t ofs_y; /**< y offset of the bounding box*/
  37. uint8_t bpp; /**< Bit-per-pixel: 1, 2, 4, 8*/
  38. }wgl_font_glyph_dsc_t;
  39. /*Describe the properties of a font*/
  40. typedef struct _wgl_font_struct
  41. {
  42. /** Get a glyph's descriptor from a font*/
  43. bool (*get_glyph_dsc)(const struct _wgl_font_struct *, wgl_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next);
  44. /** Get a glyph's bitmap from a font*/
  45. const uint8_t * (*get_glyph_bitmap)(const struct _wgl_font_struct *, uint32_t);
  46. /*Pointer to the font in a font pack (must have the same line height)*/
  47. uint8_t line_height; /**< The real line height where any text fits*/
  48. uint8_t base_line; /**< Base line measured from the top of the line_height*/
  49. void * dsc; /**< Store implementation specific data here*/
  50. #if LV_USE_USER_DATA
  51. wgl_font_user_data_t user_data; /**< Custom user data for font. */
  52. #endif
  53. } wgl_font_t;
  54. #if LV_COLOR_DEPTH == 1
  55. #define LV_COLOR_SIZE 8
  56. #elif LV_COLOR_DEPTH == 8
  57. #define LV_COLOR_SIZE 8
  58. #elif LV_COLOR_DEPTH == 16
  59. #define LV_COLOR_SIZE 16
  60. #elif LV_COLOR_DEPTH == 32
  61. #define LV_COLOR_SIZE 32
  62. #else
  63. #error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
  64. #endif
  65. /**********************
  66. * TYPEDEFS
  67. **********************/
  68. typedef union
  69. {
  70. uint8_t blue : 1;
  71. uint8_t green : 1;
  72. uint8_t red : 1;
  73. uint8_t full : 1;
  74. } wgl_color1_t;
  75. typedef union
  76. {
  77. struct
  78. {
  79. uint8_t blue : 2;
  80. uint8_t green : 3;
  81. uint8_t red : 3;
  82. } ch;
  83. uint8_t full;
  84. } wgl_color8_t;
  85. typedef union
  86. {
  87. struct
  88. {
  89. #if LV_COLOR_16_SWAP == 0
  90. uint16_t blue : 5;
  91. uint16_t green : 6;
  92. uint16_t red : 5;
  93. #else
  94. uint16_t green_h : 3;
  95. uint16_t red : 5;
  96. uint16_t blue : 5;
  97. uint16_t green_l : 3;
  98. #endif
  99. } ch;
  100. uint16_t full;
  101. } wgl_color16_t;
  102. typedef union
  103. {
  104. struct
  105. {
  106. uint8_t blue;
  107. uint8_t green;
  108. uint8_t red;
  109. uint8_t alpha;
  110. } ch;
  111. uint32_t full;
  112. } wgl_color32_t;
  113. #if LV_COLOR_DEPTH == 1
  114. typedef uint8_t wgl_color_int_t;
  115. typedef wgl_color1_t wgl_color_t;
  116. #elif LV_COLOR_DEPTH == 8
  117. typedef uint8_t wgl_color_int_t;
  118. typedef wgl_color8_t wgl_color_t;
  119. #elif LV_COLOR_DEPTH == 16
  120. typedef uint16_t wgl_color_int_t;
  121. typedef wgl_color16_t wgl_color_t;
  122. #elif LV_COLOR_DEPTH == 32
  123. typedef uint32_t wgl_color_int_t;
  124. typedef wgl_color32_t wgl_color_t;
  125. #else
  126. #error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
  127. #endif
  128. typedef uint8_t wgl_opa_t;
  129. /*Border types (Use 'OR'ed values)*/
  130. enum {
  131. WGL_BORDER_NONE = 0x00,
  132. WGL_BORDER_BOTTOM = 0x01,
  133. WGL_BORDER_TOP = 0x02,
  134. WGL_BORDER_LEFT = 0x04,
  135. WGL_BORDER_RIGHT = 0x08,
  136. WGL_BORDER_FULL = 0x0F,
  137. WGL_BORDER_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/
  138. };
  139. typedef uint8_t wgl_border_part_t;
  140. /*Shadow types*/
  141. enum {
  142. WGL_SHADOW_BOTTOM = 0, /**< Only draw bottom shadow */
  143. WGL_SHADOW_FULL, /**< Draw shadow on all sides */
  144. };
  145. typedef uint8_t wgl_shadow_type_t;
  146. /**
  147. * Objects in LittlevGL can be assigned a style - which holds information about
  148. * how the object should be drawn.
  149. *
  150. * This allows for easy customization without having to modify the object's design
  151. * function.
  152. */
  153. typedef struct
  154. {
  155. uint8_t glass : 1; /**< 1: Do not inherit this style*/
  156. /** Object background. */
  157. struct
  158. {
  159. wgl_color_t main_color; /**< Object's main background color. */
  160. wgl_color_t grad_color; /**< Second color. If not equal to `main_color` a gradient will be drawn for the background. */
  161. wgl_coord_t radius; /**< Object's corner radius. You can use #WGL_RADIUS_CIRCLE if you want to draw a circle. */
  162. wgl_opa_t opa; /**< Object's opacity (0-255). */
  163. struct
  164. {
  165. wgl_color_t color; /**< Border color */
  166. wgl_coord_t width; /**< Border width */
  167. wgl_border_part_t part; /**< Which borders to draw */
  168. wgl_opa_t opa; /**< Border opacity. */
  169. } border;
  170. struct
  171. {
  172. wgl_color_t color;
  173. wgl_coord_t width;
  174. wgl_shadow_type_t type; /**< Which parts of the shadow to draw */
  175. } shadow;
  176. struct
  177. {
  178. wgl_coord_t top;
  179. wgl_coord_t bottom;
  180. wgl_coord_t left;
  181. wgl_coord_t right;
  182. wgl_coord_t inner;
  183. } padding;
  184. } body;
  185. /** Style for text drawn by this object. */
  186. struct
  187. {
  188. wgl_color_t color; /**< Text color */
  189. wgl_color_t sel_color; /**< Text selection background color. */
  190. const wgl_font_t * font;
  191. wgl_coord_t letter_space; /**< Space between letters */
  192. wgl_coord_t line_space; /**< Space between lines (vertical) */
  193. wgl_opa_t opa; /**< Text opacity */
  194. } text;
  195. /**< Style of images. */
  196. struct
  197. {
  198. wgl_color_t color; /**< Color to recolor the image with */
  199. wgl_opa_t intense; /**< Opacity of recoloring (0 means no recoloring) */
  200. wgl_opa_t opa; /**< Opacity of whole image */
  201. } image;
  202. /**< Style of lines (not borders). */
  203. struct
  204. {
  205. wgl_color_t color;
  206. wgl_coord_t width;
  207. wgl_opa_t opa;
  208. uint8_t rounded : 1; /**< 1: rounded line endings*/
  209. } line;
  210. } wgl_style_t;
  211. /* Object native function IDs */
  212. enum {
  213. OBJ_FUNC_ID_DEL,
  214. OBJ_FUNC_ID_DEL_ASYNC,
  215. OBJ_FUNC_ID_CLEAN,
  216. OBJ_FUNC_ID_SET_EVT_CB,
  217. OBJ_FUNC_ID_ALIGN,
  218. /* Number of functions */
  219. _OBJ_FUNC_ID_NUM,
  220. };
  221. /* Button native function IDs */
  222. enum {
  223. BTN_FUNC_ID_CREATE,
  224. BTN_FUNC_ID_SET_TOGGLE,
  225. BTN_FUNC_ID_SET_STATE,
  226. BTN_FUNC_ID_TOGGLE,
  227. BTN_FUNC_ID_SET_INK_IN_TIME,
  228. BTN_FUNC_ID_SET_INK_WAIT_TIME,
  229. BTN_FUNC_ID_SET_INK_OUT_TIME,
  230. BTN_FUNC_ID_GET_STATE,
  231. BTN_FUNC_ID_GET_TOGGLE,
  232. BTN_FUNC_ID_GET_INK_IN_TIME,
  233. BTN_FUNC_ID_GET_INK_WAIT_TIME,
  234. BTN_FUNC_ID_GET_INK_OUT_TIME,
  235. /* Number of functions */
  236. _BTN_FUNC_ID_NUM,
  237. };
  238. /* Check box native function IDs */
  239. enum {
  240. CB_FUNC_ID_CREATE,
  241. CB_FUNC_ID_SET_TEXT,
  242. CB_FUNC_ID_SET_STATIC_TEXT,
  243. CB_FUNC_ID_GET_TEXT,
  244. CB_FUNC_ID_GET_TEXT_LENGTH,
  245. /* Number of functions */
  246. _CB_FUNC_ID_NUM,
  247. };
  248. /* List native function IDs */
  249. enum {
  250. LIST_FUNC_ID_CREATE,
  251. LIST_FUNC_ID_ADD_BTN,
  252. /* Number of functions */
  253. _LIST_FUNC_ID_NUM,
  254. };
  255. /* Label native function IDs */
  256. enum {
  257. LABEL_FUNC_ID_CREATE,
  258. LABEL_FUNC_ID_SET_TEXT,
  259. LABEL_FUNC_ID_SET_ARRAY_TEXT,
  260. LABEL_FUNC_ID_SET_STATIC_TEXT,
  261. LABEL_FUNC_ID_SET_LONG_MODE,
  262. LABEL_FUNC_ID_SET_ALIGN,
  263. LABEL_FUNC_ID_SET_RECOLOR,
  264. LABEL_FUNC_ID_SET_BODY_DRAW,
  265. LABEL_FUNC_ID_SET_ANIM_SPEED,
  266. LABEL_FUNC_ID_SET_TEXT_SEL_START,
  267. LABEL_FUNC_ID_SET_TEXT_SEL_END,
  268. LABEL_FUNC_ID_GET_TEXT,
  269. LABEL_FUNC_ID_GET_TEXT_LENGTH,
  270. LABEL_FUNC_ID_GET_LONG_MODE,
  271. LABEL_FUNC_ID_GET_ALIGN,
  272. LABEL_FUNC_ID_GET_RECOLOR,
  273. LABEL_FUNC_ID_GET_BODY_DRAW,
  274. LABEL_FUNC_ID_GET_ANIM_SPEED,
  275. LABEL_FUNC_ID_GET_LETTER_POS,
  276. LABEL_FUNC_ID_GET_TEXT_SEL_START,
  277. LABEL_FUNC_ID_GET_TEXT_SEL_END,
  278. LABEL_FUNC_ID_INS_TEXT,
  279. LABEL_FUNC_ID_CUT_TEXT,
  280. /* Number of functions */
  281. _LABEL_FUNC_ID_NUM,
  282. };
  283. #ifdef __cplusplus
  284. }
  285. #endif
  286. #endif /* WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H */