luat_lv_draw.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #include "luat_base.h"
  2. #include "lvgl.h"
  3. #include "luat_lvgl.h"
  4. // int16_t lv_draw_mask_add(void* param, void* custom_id)
  5. int luat_lv_draw_mask_add(lua_State *L) {
  6. LV_DEBUG("CALL lv_draw_mask_add");
  7. void* param = (void*)lua_touserdata(L, 1);
  8. void* custom_id = (void*)lua_touserdata(L, 2);
  9. int16_t ret;
  10. ret = lv_draw_mask_add(param ,custom_id);
  11. lua_pushinteger(L, ret);
  12. return 1;
  13. }
  14. // lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t* mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len)
  15. int luat_lv_draw_mask_apply(lua_State *L) {
  16. LV_DEBUG("CALL lv_draw_mask_apply");
  17. lv_opa_t* mask_buf = (lv_opa_t*)lua_touserdata(L, 1);
  18. lv_coord_t abs_x = (lv_coord_t)luaL_checkinteger(L, 2);
  19. lv_coord_t abs_y = (lv_coord_t)luaL_checkinteger(L, 3);
  20. lv_coord_t len = (lv_coord_t)luaL_checkinteger(L, 4);
  21. lv_draw_mask_res_t ret;
  22. ret = lv_draw_mask_apply(mask_buf ,abs_x ,abs_y ,len);
  23. lua_pushboolean(L, ret == 0 ? 1 : 0);
  24. lua_pushinteger(L, ret);
  25. return 2;
  26. }
  27. // void* lv_draw_mask_remove_id(int16_t id)
  28. int luat_lv_draw_mask_remove_id(lua_State *L) {
  29. LV_DEBUG("CALL lv_draw_mask_remove_id");
  30. int16_t id = (int16_t)luaL_checkinteger(L, 1);
  31. void* ret = NULL;
  32. ret = lv_draw_mask_remove_id(id);
  33. lua_pushlightuserdata(L, ret);
  34. return 1;
  35. }
  36. // void* lv_draw_mask_remove_custom(void* custom_id)
  37. int luat_lv_draw_mask_remove_custom(lua_State *L) {
  38. LV_DEBUG("CALL lv_draw_mask_remove_custom");
  39. void* custom_id = (void*)lua_touserdata(L, 1);
  40. void* ret = NULL;
  41. ret = lv_draw_mask_remove_custom(custom_id);
  42. lua_pushlightuserdata(L, ret);
  43. return 1;
  44. }
  45. // uint8_t lv_draw_mask_get_cnt()
  46. int luat_lv_draw_mask_get_cnt(lua_State *L) {
  47. LV_DEBUG("CALL lv_draw_mask_get_cnt");
  48. uint8_t ret;
  49. ret = lv_draw_mask_get_cnt();
  50. lua_pushinteger(L, ret);
  51. return 1;
  52. }
  53. // void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t* param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, lv_coord_t p2y, lv_draw_mask_line_side_t side)
  54. int luat_lv_draw_mask_line_points_init(lua_State *L) {
  55. LV_DEBUG("CALL lv_draw_mask_line_points_init");
  56. lv_draw_mask_line_param_t* param = (lv_draw_mask_line_param_t*)lua_touserdata(L, 1);
  57. lv_coord_t p1x = (lv_coord_t)luaL_checkinteger(L, 2);
  58. lv_coord_t p1y = (lv_coord_t)luaL_checkinteger(L, 3);
  59. lv_coord_t p2x = (lv_coord_t)luaL_checkinteger(L, 4);
  60. lv_coord_t p2y = (lv_coord_t)luaL_checkinteger(L, 5);
  61. lv_draw_mask_line_side_t side = (lv_draw_mask_line_side_t)luaL_checkinteger(L, 6);
  62. lv_draw_mask_line_points_init(param ,p1x ,p1y ,p2x ,p2y ,side);
  63. return 0;
  64. }
  65. // void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t* param, lv_coord_t p1x, lv_coord_t py, int16_t angle, lv_draw_mask_line_side_t side)
  66. int luat_lv_draw_mask_line_angle_init(lua_State *L) {
  67. LV_DEBUG("CALL lv_draw_mask_line_angle_init");
  68. lv_draw_mask_line_param_t* param = (lv_draw_mask_line_param_t*)lua_touserdata(L, 1);
  69. lv_coord_t p1x = (lv_coord_t)luaL_checkinteger(L, 2);
  70. lv_coord_t py = (lv_coord_t)luaL_checkinteger(L, 3);
  71. int16_t angle = (int16_t)luaL_checkinteger(L, 4);
  72. lv_draw_mask_line_side_t side = (lv_draw_mask_line_side_t)luaL_checkinteger(L, 5);
  73. lv_draw_mask_line_angle_init(param ,p1x ,py ,angle ,side);
  74. return 0;
  75. }
  76. // void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t* param, lv_coord_t vertex_x, lv_coord_t vertex_y, lv_coord_t start_angle, lv_coord_t end_angle)
  77. int luat_lv_draw_mask_angle_init(lua_State *L) {
  78. LV_DEBUG("CALL lv_draw_mask_angle_init");
  79. lv_draw_mask_angle_param_t* param = (lv_draw_mask_angle_param_t*)lua_touserdata(L, 1);
  80. lv_coord_t vertex_x = (lv_coord_t)luaL_checkinteger(L, 2);
  81. lv_coord_t vertex_y = (lv_coord_t)luaL_checkinteger(L, 3);
  82. lv_coord_t start_angle = (lv_coord_t)luaL_checkinteger(L, 4);
  83. lv_coord_t end_angle = (lv_coord_t)luaL_checkinteger(L, 5);
  84. lv_draw_mask_angle_init(param ,vertex_x ,vertex_y ,start_angle ,end_angle);
  85. return 0;
  86. }
  87. // void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t* param, lv_area_t* rect, lv_coord_t radius, bool inv)
  88. int luat_lv_draw_mask_radius_init(lua_State *L) {
  89. LV_DEBUG("CALL lv_draw_mask_radius_init");
  90. lv_draw_mask_radius_param_t* param = (lv_draw_mask_radius_param_t*)lua_touserdata(L, 1);
  91. lua_pushvalue(L, 2);
  92. lv_area_t rect = {0};
  93. lua_geti(L, -1, 1); rect.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  94. lua_geti(L, -1, 2); rect.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  95. lua_geti(L, -1, 3); rect.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  96. lua_geti(L, -1, 4); rect.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  97. lua_pop(L, 1);
  98. lv_coord_t radius = (lv_coord_t)luaL_checkinteger(L, 3);
  99. bool inv = (bool)lua_toboolean(L, 4);
  100. lv_draw_mask_radius_init(param ,&rect ,radius ,inv);
  101. return 0;
  102. }
  103. // void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t* param, lv_area_t* coords, lv_opa_t opa_top, lv_coord_t y_top, lv_opa_t opa_bottom, lv_coord_t y_bottom)
  104. int luat_lv_draw_mask_fade_init(lua_State *L) {
  105. LV_DEBUG("CALL lv_draw_mask_fade_init");
  106. lv_draw_mask_fade_param_t* param = (lv_draw_mask_fade_param_t*)lua_touserdata(L, 1);
  107. lua_pushvalue(L, 2);
  108. lv_area_t coords = {0};
  109. lua_geti(L, -1, 1); coords.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  110. lua_geti(L, -1, 2); coords.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  111. lua_geti(L, -1, 3); coords.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  112. lua_geti(L, -1, 4); coords.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  113. lua_pop(L, 1);
  114. lv_opa_t opa_top = (lv_opa_t)luaL_checkinteger(L, 3);
  115. lv_coord_t y_top = (lv_coord_t)luaL_checkinteger(L, 4);
  116. lv_opa_t opa_bottom = (lv_opa_t)luaL_checkinteger(L, 5);
  117. lv_coord_t y_bottom = (lv_coord_t)luaL_checkinteger(L, 6);
  118. lv_draw_mask_fade_init(param ,&coords ,opa_top ,y_top ,opa_bottom ,y_bottom);
  119. return 0;
  120. }
  121. // void lv_draw_mask_map_init(lv_draw_mask_map_param_t* param, lv_area_t* coords, lv_opa_t* map)
  122. int luat_lv_draw_mask_map_init(lua_State *L) {
  123. LV_DEBUG("CALL lv_draw_mask_map_init");
  124. lv_draw_mask_map_param_t* param = (lv_draw_mask_map_param_t*)lua_touserdata(L, 1);
  125. lua_pushvalue(L, 2);
  126. lv_area_t coords = {0};
  127. lua_geti(L, -1, 1); coords.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  128. lua_geti(L, -1, 2); coords.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  129. lua_geti(L, -1, 3); coords.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  130. lua_geti(L, -1, 4); coords.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  131. lua_pop(L, 1);
  132. lv_opa_t* map = (lv_opa_t*)lua_touserdata(L, 3);
  133. lv_draw_mask_map_init(param ,&coords ,map);
  134. return 0;
  135. }
  136. // void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t* dsc)
  137. int luat_lv_draw_rect_dsc_init(lua_State *L) {
  138. LV_DEBUG("CALL lv_draw_rect_dsc_init");
  139. lv_draw_rect_dsc_t* dsc = (lv_draw_rect_dsc_t*)lua_touserdata(L, 1);
  140. lv_draw_rect_dsc_init(dsc);
  141. return 0;
  142. }
  143. // void lv_draw_rect(lv_area_t* coords, lv_area_t* mask, lv_draw_rect_dsc_t* dsc)
  144. int luat_lv_draw_rect(lua_State *L) {
  145. LV_DEBUG("CALL lv_draw_rect");
  146. lua_pushvalue(L, 1);
  147. lv_area_t coords = {0};
  148. lua_geti(L, -1, 1); coords.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  149. lua_geti(L, -1, 2); coords.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  150. lua_geti(L, -1, 3); coords.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  151. lua_geti(L, -1, 4); coords.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  152. lua_pop(L, 1);
  153. lua_pushvalue(L, 2);
  154. lv_area_t mask = {0};
  155. lua_geti(L, -1, 1); mask.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  156. lua_geti(L, -1, 2); mask.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  157. lua_geti(L, -1, 3); mask.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  158. lua_geti(L, -1, 4); mask.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  159. lua_pop(L, 1);
  160. lv_draw_rect_dsc_t* dsc = (lv_draw_rect_dsc_t*)lua_touserdata(L, 3);
  161. lv_draw_rect(&coords ,&mask ,dsc);
  162. return 0;
  163. }
  164. // void lv_draw_px(lv_point_t* point, lv_area_t* clip_area, lv_style_t* style)
  165. int luat_lv_draw_px(lua_State *L) {
  166. LV_DEBUG("CALL lv_draw_px");
  167. lua_pushvalue(L, 1);
  168. lv_point_t point = {0};
  169. lua_geti(L, -1, 1); point.x = luaL_checkinteger(L, -1); lua_pop(L, 1);
  170. lua_geti(L, -1, 2); point.y = luaL_checkinteger(L, -1); lua_pop(L, 1);
  171. lua_pop(L, 1);
  172. lua_pushvalue(L, 2);
  173. lv_area_t clip_area = {0};
  174. lua_geti(L, -1, 1); clip_area.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  175. lua_geti(L, -1, 2); clip_area.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  176. lua_geti(L, -1, 3); clip_area.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  177. lua_geti(L, -1, 4); clip_area.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  178. lua_pop(L, 1);
  179. lv_style_t* style = (lv_style_t*)lua_touserdata(L, 3);
  180. lv_draw_px(&point ,&clip_area ,style);
  181. return 0;
  182. }
  183. // void lv_draw_label_dsc_init(lv_draw_label_dsc_t* dsc)
  184. int luat_lv_draw_label_dsc_init(lua_State *L) {
  185. LV_DEBUG("CALL lv_draw_label_dsc_init");
  186. lv_draw_label_dsc_t* dsc = (lv_draw_label_dsc_t*)lua_touserdata(L, 1);
  187. lv_draw_label_dsc_init(dsc);
  188. return 0;
  189. }
  190. // void lv_draw_label(lv_area_t* coords, lv_area_t* mask, lv_draw_label_dsc_t* dsc, char* txt, lv_draw_label_hint_t* hint)
  191. int luat_lv_draw_label(lua_State *L) {
  192. LV_DEBUG("CALL lv_draw_label");
  193. lua_pushvalue(L, 1);
  194. lv_area_t coords = {0};
  195. lua_geti(L, -1, 1); coords.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  196. lua_geti(L, -1, 2); coords.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  197. lua_geti(L, -1, 3); coords.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  198. lua_geti(L, -1, 4); coords.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  199. lua_pop(L, 1);
  200. lua_pushvalue(L, 2);
  201. lv_area_t mask = {0};
  202. lua_geti(L, -1, 1); mask.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  203. lua_geti(L, -1, 2); mask.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  204. lua_geti(L, -1, 3); mask.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  205. lua_geti(L, -1, 4); mask.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  206. lua_pop(L, 1);
  207. lv_draw_label_dsc_t* dsc = (lv_draw_label_dsc_t*)lua_touserdata(L, 3);
  208. char* txt = (char*)luaL_checkstring(L, 4);
  209. lv_draw_label_hint_t* hint = (lv_draw_label_hint_t*)lua_touserdata(L, 5);
  210. lv_draw_label(&coords ,&mask ,dsc ,txt ,hint);
  211. return 0;
  212. }
  213. // void lv_draw_img_dsc_init(lv_draw_img_dsc_t* dsc)
  214. int luat_lv_draw_img_dsc_init(lua_State *L) {
  215. LV_DEBUG("CALL lv_draw_img_dsc_init");
  216. lv_draw_img_dsc_t* dsc = (lv_draw_img_dsc_t*)lua_touserdata(L, 1);
  217. lv_draw_img_dsc_init(dsc);
  218. return 0;
  219. }
  220. // void lv_draw_img(lv_area_t* coords, lv_area_t* mask, void* src, lv_draw_img_dsc_t* dsc)
  221. int luat_lv_draw_img(lua_State *L) {
  222. LV_DEBUG("CALL lv_draw_img");
  223. lua_pushvalue(L, 1);
  224. lv_area_t coords = {0};
  225. lua_geti(L, -1, 1); coords.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  226. lua_geti(L, -1, 2); coords.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  227. lua_geti(L, -1, 3); coords.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  228. lua_geti(L, -1, 4); coords.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  229. lua_pop(L, 1);
  230. lua_pushvalue(L, 2);
  231. lv_area_t mask = {0};
  232. lua_geti(L, -1, 1); mask.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  233. lua_geti(L, -1, 2); mask.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  234. lua_geti(L, -1, 3); mask.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  235. lua_geti(L, -1, 4); mask.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  236. lua_pop(L, 1);
  237. void* src = (void*)lua_touserdata(L, 3);
  238. lv_draw_img_dsc_t* dsc = (lv_draw_img_dsc_t*)lua_touserdata(L, 4);
  239. lv_draw_img(&coords ,&mask ,src ,dsc);
  240. return 0;
  241. }
  242. // void lv_draw_line(lv_point_t* point1, lv_point_t* point2, lv_area_t* clip, lv_draw_line_dsc_t* dsc)
  243. int luat_lv_draw_line(lua_State *L) {
  244. LV_DEBUG("CALL lv_draw_line");
  245. lua_pushvalue(L, 1);
  246. lv_point_t point1 = {0};
  247. lua_geti(L, -1, 1); point1.x = luaL_checkinteger(L, -1); lua_pop(L, 1);
  248. lua_geti(L, -1, 2); point1.y = luaL_checkinteger(L, -1); lua_pop(L, 1);
  249. lua_pop(L, 1);
  250. lua_pushvalue(L, 2);
  251. lv_point_t point2 = {0};
  252. lua_geti(L, -1, 1); point2.x = luaL_checkinteger(L, -1); lua_pop(L, 1);
  253. lua_geti(L, -1, 2); point2.y = luaL_checkinteger(L, -1); lua_pop(L, 1);
  254. lua_pop(L, 1);
  255. lua_pushvalue(L, 3);
  256. lv_area_t clip = {0};
  257. lua_geti(L, -1, 1); clip.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  258. lua_geti(L, -1, 2); clip.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  259. lua_geti(L, -1, 3); clip.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  260. lua_geti(L, -1, 4); clip.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  261. lua_pop(L, 1);
  262. lv_draw_line_dsc_t* dsc = (lv_draw_line_dsc_t*)lua_touserdata(L, 4);
  263. lv_draw_line(&point1 ,&point2 ,&clip ,dsc);
  264. return 0;
  265. }
  266. // void lv_draw_line_dsc_init(lv_draw_line_dsc_t* dsc)
  267. int luat_lv_draw_line_dsc_init(lua_State *L) {
  268. LV_DEBUG("CALL lv_draw_line_dsc_init");
  269. lv_draw_line_dsc_t* dsc = (lv_draw_line_dsc_t*)lua_touserdata(L, 1);
  270. lv_draw_line_dsc_init(dsc);
  271. return 0;
  272. }
  273. // void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, lv_area_t* clip_area, lv_draw_line_dsc_t* dsc)
  274. int luat_lv_draw_arc(lua_State *L) {
  275. LV_DEBUG("CALL lv_draw_arc");
  276. lv_coord_t center_x = (lv_coord_t)luaL_checkinteger(L, 1);
  277. lv_coord_t center_y = (lv_coord_t)luaL_checkinteger(L, 2);
  278. uint16_t radius = (uint16_t)luaL_checkinteger(L, 3);
  279. uint16_t start_angle = (uint16_t)luaL_checkinteger(L, 4);
  280. uint16_t end_angle = (uint16_t)luaL_checkinteger(L, 5);
  281. lua_pushvalue(L, 6);
  282. lv_area_t clip_area = {0};
  283. lua_geti(L, -1, 1); clip_area.x1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  284. lua_geti(L, -1, 2); clip_area.y1 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  285. lua_geti(L, -1, 3); clip_area.x2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  286. lua_geti(L, -1, 4); clip_area.y2 = luaL_checkinteger(L, -1); lua_pop(L, 1);
  287. lua_pop(L, 1);
  288. lv_draw_line_dsc_t* dsc = (lv_draw_line_dsc_t*)lua_touserdata(L, 7);
  289. lv_draw_arc(center_x ,center_y ,radius ,start_angle ,end_angle ,&clip_area ,dsc);
  290. return 0;
  291. }