microui  14.1.1
microui
LLDW_PAINTER_impl.c
1 /*
2  * Copyright 2020-2024 MicroEJ Corp. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be found with this software.
4  */
5 
6 /*
7  * @file
8  * @brief This file implements all "Drawing" (MicroUI extended library) drawing native functions.
9  * @see LLDW_PAINTER_impl.h file comment
10  * @author MicroEJ Developer Team
11  * @version 14.1.1
12  * @since MicroEJ UI Pack 13.0.0
13  */
14 
15 // --------------------------------------------------------------------------------
16 // Includes
17 // --------------------------------------------------------------------------------
18 
19 // implements LLDW_PAINTER_impl functions
20 #include <LLDW_PAINTER_impl.h>
21 
22 // use graphical engine functions to synchronize drawings
23 #include <LLUI_DISPLAY.h>
24 
25 // calls ui_drawing functions
26 #include "ui_drawing.h"
27 
28 // logs the drawings
29 #include "ui_log.h"
30 
31 // --------------------------------------------------------------------------------
32 // Macros and Defines
33 // --------------------------------------------------------------------------------
34 
35 // macros to log a drawing
36 #define LOG_DRAW_START(fn) LLTRACE_record_event_u32(LLUI_EVENT_group, LLUI_EVENT_offset + UI_LOG_DRAW, \
37  CONCAT_DEFINES(LOG_DRAW_, fn))
38 #define LOG_DRAW_END(s) LLTRACE_record_event_end_u32(LLUI_EVENT_group, LLUI_EVENT_offset + UI_LOG_DRAW, (s))
39 
40 /*
41  * LOG_DRAW_EVENT logs identifiers
42  */
43 #define LOG_DRAW_drawThickFadedPoint 100
44 #define LOG_DRAW_drawThickFadedLine 101
45 #define LOG_DRAW_drawThickFadedCircle 102
46 #define LOG_DRAW_drawThickFadedCircleArc 103
47 #define LOG_DRAW_drawThickFadedEllipse 104
48 #define LOG_DRAW_drawThickLine 105
49 #define LOG_DRAW_drawThickCircle 106
50 #define LOG_DRAW_drawThickEllipse 107
51 #define LOG_DRAW_drawThickCircleArc 108
52 
53 #define LOG_DRAW_drawFlippedImage 200
54 #define LOG_DRAW_drawRotatedImageNearestNeighbor 201
55 #define LOG_DRAW_drawRotatedImageBilinear 202
56 #define LOG_DRAW_drawScaledImageNearestNeighbor 203
57 #define LOG_DRAW_drawScaledImageBilinear 204
58 #define LOG_DRAW_drawScaledStringBilinear 205
59 #define LOG_DRAW_drawCharWithRotationBilinear 206
60 #define LOG_DRAW_drawCharWithRotationNearestNeighbor 207
61 
62 // --------------------------------------------------------------------------------
63 // LLDW_PAINTER_impl.h functions
64 // --------------------------------------------------------------------------------
65 
66 void LLDW_PAINTER_IMPL_drawThickFadedPoint(MICROUI_GraphicsContext *gc, jint x, jint y, jint thickness, jint fade) {
67  if (((thickness > 0) || (fade > 0)) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &
68  LLDW_PAINTER_IMPL_drawThickFadedPoint)) {
69  LOG_DRAW_START(drawThickFadedPoint);
70  DRAWING_Status status = UI_DRAWING_drawThickFadedPoint(gc, x, y, thickness, fade);
71  LLUI_DISPLAY_setDrawingStatus(status);
72  LOG_DRAW_END(status);
73  }
74 }
75 
76 void LLDW_PAINTER_IMPL_drawThickFadedLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY,
77  jint thickness, jint fade, DRAWING_Cap startCap, DRAWING_Cap endCap) {
78  if (((thickness > 0) || (fade > 0)) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &
79  LLDW_PAINTER_IMPL_drawThickFadedLine)) {
80  LOG_DRAW_START(drawThickFadedLine);
81  DRAWING_Status status = UI_DRAWING_drawThickFadedLine(gc, startX, startY, endX, endY, thickness, fade, startCap,
82  endCap);
83  LLUI_DISPLAY_setDrawingStatus(status);
84  LOG_DRAW_END(status);
85  }
86 }
87 
88 void LLDW_PAINTER_IMPL_drawThickFadedCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jint thickness,
89  jint fade) {
90  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &
91  LLDW_PAINTER_IMPL_drawThickFadedCircle))
92  {
93  LOG_DRAW_START(drawThickFadedCircle);
94  DRAWING_Status status = UI_DRAWING_drawThickFadedCircle(gc, x, y, diameter, thickness, fade);
95  LLUI_DISPLAY_setDrawingStatus(status);
96  LOG_DRAW_END(status);
97  }
98 }
99 
100 void LLDW_PAINTER_IMPL_drawThickFadedCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter,
101  jfloat startAngle, jfloat arcAngle, jint thickness, jint fade,
102  DRAWING_Cap start, DRAWING_Cap end) {
103  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && ((int32_t)arcAngle != 0) && LLUI_DISPLAY_requestDrawing(gc,
104  (
105  SNI_callback)
106  &
107  LLDW_PAINTER_IMPL_drawThickFadedCircleArc))
108  {
109  LOG_DRAW_START(drawThickFadedCircleArc);
110  DRAWING_Status status = UI_DRAWING_drawThickFadedCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness,
111  fade, start, end);
112  LLUI_DISPLAY_setDrawingStatus(status);
113  LOG_DRAW_END(status);
114  }
115 }
116 
117 void LLDW_PAINTER_IMPL_drawThickFadedEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
118  jint thickness, jint fade) {
119  if (((thickness > 0) || (fade > 0)) && (width > 0) && (height > 0) && LLUI_DISPLAY_requestDrawing(gc,
120  (SNI_callback) &
121  LLDW_PAINTER_IMPL_drawThickFadedEllipse))
122  {
123  LOG_DRAW_START(drawThickFadedEllipse);
124  DRAWING_Status status = UI_DRAWING_drawThickFadedEllipse(gc, x, y, width, height, thickness, fade);
125  LLUI_DISPLAY_setDrawingStatus(status);
126  LOG_DRAW_END(status);
127  }
128 }
129 
130 void LLDW_PAINTER_IMPL_drawThickLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY,
131  jint thickness) {
132  if ((thickness > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawThickLine)) {
133  LOG_DRAW_START(drawThickLine);
134  DRAWING_Status status = UI_DRAWING_drawThickLine(gc, startX, startY, endX, endY, thickness);
135  LLUI_DISPLAY_setDrawingStatus(status);
136  LOG_DRAW_END(status);
137  }
138 }
139 
140 void LLDW_PAINTER_IMPL_drawThickCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jint thickness) {
141  if ((thickness > 0) && (diameter > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &
142  LLDW_PAINTER_IMPL_drawThickCircle)) {
143  LOG_DRAW_START(drawThickCircle);
144  DRAWING_Status status = UI_DRAWING_drawThickCircle(gc, x, y, diameter, thickness);
145  LLUI_DISPLAY_setDrawingStatus(status);
146  LOG_DRAW_END(status);
147  }
148 }
149 
150 void LLDW_PAINTER_IMPL_drawThickEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
151  jint thickness) {
152  if ((thickness > 0) && (width > 0) && (height > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &
153  LLDW_PAINTER_IMPL_drawThickEllipse))
154  {
155  LOG_DRAW_START(drawThickEllipse);
156  DRAWING_Status status = UI_DRAWING_drawThickEllipse(gc, x, y, width, height, thickness);
157  LLUI_DISPLAY_setDrawingStatus(status);
158  LOG_DRAW_END(status);
159  }
160 }
161 
162 void LLDW_PAINTER_IMPL_drawThickCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
163  jfloat arcAngle, jint thickness) {
164  if ((thickness > 0) && (diameter > 0) && ((int32_t)arcAngle != 0) && LLUI_DISPLAY_requestDrawing(gc,
165  (SNI_callback) &
166  LLDW_PAINTER_IMPL_drawThickCircleArc))
167  {
168  LOG_DRAW_START(drawThickCircleArc);
169  DRAWING_Status status = UI_DRAWING_drawThickCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness);
170  LLUI_DISPLAY_setDrawingStatus(status);
171  LOG_DRAW_END(status);
172  }
173 }
174 
175 void LLDW_PAINTER_IMPL_drawFlippedImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
176  jint width, jint height, jint x, jint y, DRAWING_Flip transformation,
177  jint alpha) {
178  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)
179  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawFlippedImage)) {
180  LOG_DRAW_START(drawFlippedImage);
181  DRAWING_Status status = UI_DRAWING_drawFlippedImage(gc, img, regionX, regionY, width, height, x, y,
182  transformation, alpha);
183  LLUI_DISPLAY_setDrawingStatus(status);
184  LOG_DRAW_END(status);
185  }
186 }
187 
188 void LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
189  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
190  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)
191  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor)) {
192  LOG_DRAW_START(drawRotatedImageNearestNeighbor);
193  DRAWING_Status status = UI_DRAWING_drawRotatedImageNearestNeighbor(gc, img, x, y, rotationX, rotationY, angle,
194  alpha);
195  LLUI_DISPLAY_setDrawingStatus(status);
196  LOG_DRAW_END(status);
197  }
198 }
199 
200 void LLDW_PAINTER_IMPL_drawRotatedImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
201  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
202  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)
203  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawRotatedImageBilinear)) {
204  LOG_DRAW_START(drawRotatedImageBilinear);
205  DRAWING_Status status = UI_DRAWING_drawRotatedImageBilinear(gc, img, x, y, rotationX, rotationY, angle, alpha);
206  LLUI_DISPLAY_setDrawingStatus(status);
207  LOG_DRAW_END(status);
208  }
209 }
210 
211 void LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
212  jfloat factorX, jfloat factorY, jint alpha) {
213  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f)
214  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor)) {
215  LOG_DRAW_START(drawScaledImageNearestNeighbor);
216  DRAWING_Status status = UI_DRAWING_drawScaledImageNearestNeighbor(gc, img, x, y, factorX, factorY, alpha);
217  LLUI_DISPLAY_setDrawingStatus(status);
218  LOG_DRAW_END(status);
219  }
220 }
221 
222 void LLDW_PAINTER_IMPL_drawScaledImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
223  jfloat factorX, jfloat factorY, jint alpha) {
224  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f)
225  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawScaledImageBilinear)) {
226  LOG_DRAW_START(drawScaledImageBilinear);
227  DRAWING_Status status = UI_DRAWING_drawScaledImageBilinear(gc, img, x, y, factorX, factorY, alpha);
228  LLUI_DISPLAY_setDrawingStatus(status);
229  LOG_DRAW_END(status);
230  }
231 }
232 
233 void LLDW_PAINTER_IMPL_drawScaledStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
234  MICROUI_Font *font, jint x, jint y, jfloat xRatio, jfloat yRatio) {
235  if ((length > 0) && (xRatio > 0) && (yRatio > 0)
236  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledStringBilinear)) {
237  LOG_DRAW_START(drawScaledStringBilinear);
238  DRAWING_Status status = UI_DRAWING_drawScaledStringBilinear(gc, chars, length, font, x, y, xRatio, yRatio);
239  LLUI_DISPLAY_setDrawingStatus(status);
240  LOG_DRAW_END(status);
241  }
242 }
243 
244 void LLDW_PAINTER_IMPL_drawScaledRenderableStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
245  MICROUI_Font *font, jint width,
246  MICROUI_RenderableString *renderableString, jint x, jint y,
247  jfloat xRatio, jfloat yRatio) {
248  if ((length > 0) && (xRatio > 0) && (yRatio > 0)
249  && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledRenderableStringBilinear)) {
250  LOG_DRAW_START(drawScaledStringBilinear);
251  DRAWING_Status status = UI_DRAWING_drawScaledRenderableStringBilinear(gc, chars, length, font, width,
252  renderableString, x, y, xRatio, yRatio);
253  LLUI_DISPLAY_setDrawingStatus(status);
254  LOG_DRAW_END(status);
255  }
256 }
257 
258 void LLDW_PAINTER_IMPL_drawCharWithRotationBilinear(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font, jint x,
259  jint y, jint xRotation, jint yRotation, jfloat angle, jint alpha) {
260  if ((alpha > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawCharWithRotationBilinear)) {
261  LOG_DRAW_START(drawCharWithRotationBilinear);
262  DRAWING_Status status = UI_DRAWING_drawCharWithRotationBilinear(gc, c, font, x, y, xRotation, yRotation, angle,
263  alpha);
264  LLUI_DISPLAY_setDrawingStatus(status);
265  LOG_DRAW_END(status);
266  }
267 }
268 
269 void LLDW_PAINTER_IMPL_drawCharWithRotationNearestNeighbor(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font,
270  jint x, jint y, jint xRotation, jint yRotation, jfloat angle,
271  jint alpha) {
272  if ((alpha > 0) &&
273  LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawCharWithRotationNearestNeighbor)) {
274  LOG_DRAW_START(drawCharWithRotationNearestNeighbor);
275  DRAWING_Status status = UI_DRAWING_drawCharWithRotationNearestNeighbor(gc, c, font, x, y, xRotation, yRotation,
276  angle, alpha);
277  LLUI_DISPLAY_setDrawingStatus(status);
278  LOG_DRAW_END(status);
279  }
280 }
281 
282 // --------------------------------------------------------------------------------
283 // EOF
284 // --------------------------------------------------------------------------------