wgl_shared_utils.h 8.7 KB

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