microui  14.5.2
microui
LLDW_PAINTER_impl.c
1 /*
2  * Copyright 2020-2025 MicroEJ Corp. All rights reserved.
3  * MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
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.5.2
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 // traces the drawings
29 #include "ui_trace.h"
30 
31 // --------------------------------------------------------------------------------
32 // LLDW_PAINTER_impl.h functions
33 // --------------------------------------------------------------------------------
34 
35 void LLDW_PAINTER_IMPL_drawThickFadedPoint(MICROUI_GraphicsContext *gc, jint x, jint y, jint thickness, jint fade) {
36  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickFadedPoint)) {
37  DRAWING_Status status = DRAWING_DONE;
38  UI_TRACE_DRAW_START(drawThickFadedPoint, gc, x, y, thickness, fade);
39  if ((thickness > 0) || (fade > 0)) {
40  status = UI_DRAWING_drawThickFadedPoint(gc, x, y, thickness, fade);
41  }
42  LLUI_DISPLAY_setDrawingStatus(status);
43  UI_TRACE_DRAW_END(drawThickFadedPoint, status);
44  }
45 }
46 
47 void LLDW_PAINTER_IMPL_drawThickFadedLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY,
48  jint thickness, jint fade, DRAWING_Cap startCap, DRAWING_Cap endCap) {
49  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickFadedLine)) {
50  DRAWING_Status status = DRAWING_DONE;
51  UI_TRACE_DRAW_START(drawThickFadedLine, gc, startX, startY, endX, endY, thickness, fade);
52  if ((thickness > 0) || (fade > 0)) {
53  status = UI_DRAWING_drawThickFadedLine(gc, startX, startY, endX, endY, thickness, fade, startCap, endCap);
54  }
55  LLUI_DISPLAY_setDrawingStatus(status);
56  UI_TRACE_DRAW_END(drawThickFadedLine, status);
57  }
58 }
59 
60 void LLDW_PAINTER_IMPL_drawThickFadedCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jint thickness,
61  jint fade) {
62  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickFadedCircle)) {
63  DRAWING_Status status = DRAWING_DONE;
64  UI_TRACE_DRAW_START(drawThickFadedCircle, gc, x, y, diameter, thickness, fade);
65  if ((thickness > 0) || (fade > 0)) {
66  status = UI_DRAWING_drawThickFadedCircle(gc, x, y, diameter, thickness, fade);
67  }
68  LLUI_DISPLAY_setDrawingStatus(status);
69  UI_TRACE_DRAW_END(drawThickFadedCircle, status);
70  }
71 }
72 
73 void LLDW_PAINTER_IMPL_drawThickFadedCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter,
74  jfloat startAngle, jfloat arcAngle, jint thickness, jint fade,
75  DRAWING_Cap start, DRAWING_Cap end) {
76  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickFadedCircleArc)) {
77  DRAWING_Status status = DRAWING_DONE;
78  UI_TRACE_DRAW_START(drawThickFadedCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle,
79  thickness, fade);
80  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && ((int32_t)arcAngle != 0)) {
81  status = UI_DRAWING_drawThickFadedCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness, fade,
82  start, end);
83  }
84  LLUI_DISPLAY_setDrawingStatus(status);
85  UI_TRACE_DRAW_END(drawThickFadedCircleArc, status);
86  }
87 }
88 
89 void LLDW_PAINTER_IMPL_drawThickFadedEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
90  jint thickness, jint fade) {
91  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickFadedEllipse)) {
92  DRAWING_Status status = DRAWING_DONE;
93  UI_TRACE_DRAW_START(drawThickFadedEllipse, gc, x, y, width, height, thickness, fade);
94  if (((thickness > 0) || (fade > 0)) && (width > 0) && (height > 0)) {
95  status = UI_DRAWING_drawThickFadedEllipse(gc, x, y, width, height, thickness, fade);
96  }
97  LLUI_DISPLAY_setDrawingStatus(status);
98  UI_TRACE_DRAW_END(drawThickFadedEllipse, status);
99  }
100 }
101 
102 void LLDW_PAINTER_IMPL_drawThickLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY,
103  jint thickness) {
104  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickLine)) {
105  DRAWING_Status status = DRAWING_DONE;
106  UI_TRACE_DRAW_START(drawThickLine, gc, startX, startY, endX, endY, thickness);
107  if (thickness > 0) {
108  status = UI_DRAWING_drawThickLine(gc, startX, startY, endX, endY, thickness);
109  }
110  LLUI_DISPLAY_setDrawingStatus(status);
111  UI_TRACE_DRAW_END(drawThickLine, status);
112  }
113 }
114 
115 void LLDW_PAINTER_IMPL_drawThickCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jint thickness) {
116  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickCircle)) {
117  DRAWING_Status status = DRAWING_DONE;
118  UI_TRACE_DRAW_START(drawThickCircle, gc, x, y, diameter, thickness);
119  if ((thickness > 0) && (diameter > 0)) {
120  status = UI_DRAWING_drawThickCircle(gc, x, y, diameter, thickness);
121  }
122  LLUI_DISPLAY_setDrawingStatus(status);
123  UI_TRACE_DRAW_END(drawThickCircle, status);
124  }
125 }
126 
127 void LLDW_PAINTER_IMPL_drawThickEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
128  jint thickness) {
129  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickEllipse)) {
130  DRAWING_Status status = DRAWING_DONE;
131  UI_TRACE_DRAW_START(drawThickEllipse, gc, x, y, width, height, thickness);
132  if ((thickness > 0) && (width > 0) && (height > 0)) {
133  status = UI_DRAWING_drawThickEllipse(gc, x, y, width, height, thickness);
134  }
135  LLUI_DISPLAY_setDrawingStatus(status);
136  UI_TRACE_DRAW_END(drawThickEllipse, status);
137  }
138 }
139 
140 void LLDW_PAINTER_IMPL_drawThickCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
141  jfloat arcAngle, jint thickness) {
142  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawThickCircleArc)) {
143  DRAWING_Status status = DRAWING_DONE;
144  UI_TRACE_DRAW_START(drawThickCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle,
145  thickness);
146  if ((thickness > 0) && (diameter > 0) && ((int32_t)arcAngle != 0)) {
147  status = UI_DRAWING_drawThickCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness);
148  }
149  LLUI_DISPLAY_setDrawingStatus(status);
150  UI_TRACE_DRAW_END(drawThickCircleArc, status);
151  }
152 }
153 
154 void LLDW_PAINTER_IMPL_drawFlippedImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
155  jint width, jint height, jint x, jint y, DRAWING_Flip transformation,
156  jint alpha) {
157  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawFlippedImage)) {
158  DRAWING_Status status = DRAWING_DONE;
159  UI_TRACE_DRAW_START(drawFlippedImage, gc, UI_TRACE_IMAGE(img), regionX, regionY, width, height, x, y,
160  transformation, alpha);
161  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
162  status = UI_DRAWING_drawFlippedImage(gc, img, regionX, regionY, width, height, x, y,
163  transformation, alpha);
164  }
165  LLUI_DISPLAY_setDrawingStatus(status);
166  UI_TRACE_DRAW_END(drawFlippedImage, status);
167  }
168 }
169 
170 void LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
171  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
172  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor)) {
173  DRAWING_Status status = DRAWING_DONE;
174  UI_TRACE_DRAW_START(drawRotatedImage, gc, UI_TRACE_IMAGE(img), x, y, rotationX, rotationY, (uint32_t)angle,
175  alpha,
176  UI_TRACE_NearestNeighbor);
177  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
178  status = UI_DRAWING_drawRotatedImageNearestNeighbor(gc, img, x, y, rotationX, rotationY, angle,
179  alpha);
180  }
181  LLUI_DISPLAY_setDrawingStatus(status);
182  UI_TRACE_DRAW_END(drawRotatedImage, status);
183  }
184 }
185 
186 void LLDW_PAINTER_IMPL_drawRotatedImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
187  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
188  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawRotatedImageBilinear)) {
189  DRAWING_Status status = DRAWING_DONE;
190  UI_TRACE_DRAW_START(drawRotatedImage, gc, UI_TRACE_IMAGE(img), x, y, rotationX, rotationY, (uint32_t)angle,
191  alpha,
192  UI_TRACE_Bilinear);
193  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
194  status = UI_DRAWING_drawRotatedImageBilinear(gc, img, x, y, rotationX, rotationY, angle, alpha);
195  }
196  LLUI_DISPLAY_setDrawingStatus(status);
197  UI_TRACE_DRAW_END(drawRotatedImage, status);
198  }
199 }
200 
201 void LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
202  jfloat factorX, jfloat factorY, jint alpha) {
203  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor)) {
204  DRAWING_Status status = DRAWING_DONE;
205  UI_TRACE_DRAW_START(drawScaledImage, gc, UI_TRACE_IMAGE(img), x, y, (uint32_t)factorX, (uint32_t)factorY, alpha,
206  UI_TRACE_NearestNeighbor);
207  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f)) {
208  status = UI_DRAWING_drawScaledImageNearestNeighbor(gc, img, x, y, factorX, factorY, alpha);
209  }
210  LLUI_DISPLAY_setDrawingStatus(status);
211  UI_TRACE_DRAW_END(drawScaledImage, status);
212  }
213 }
214 
215 void LLDW_PAINTER_IMPL_drawScaledImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
216  jfloat factorX, jfloat factorY, jint alpha) {
217  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledImageBilinear)) {
218  DRAWING_Status status = DRAWING_DONE;
219  UI_TRACE_DRAW_START(drawScaledImage, gc, UI_TRACE_IMAGE(img), x, y, (uint32_t)factorX, (uint32_t)factorY, alpha,
220  UI_TRACE_Bilinear);
221  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f)) {
222  status = UI_DRAWING_drawScaledImageBilinear(gc, img, x, y, factorX, factorY, alpha);
223  }
224  LLUI_DISPLAY_setDrawingStatus(status);
225  UI_TRACE_DRAW_END(drawScaledImage, status);
226  }
227 }
228 
229 void LLDW_PAINTER_IMPL_drawScaledStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
230  MICROUI_Font *font, jint x, jint y, jfloat xRatio, jfloat yRatio) {
231  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledStringBilinear)) {
232  DRAWING_Status status = DRAWING_DONE;
233  UI_TRACE_DRAW_START(drawScaledString, gc, length, x, y, (uint32_t)xRatio, (uint32_t)yRatio, UI_TRACE_Bilinear);
234  if ((length > 0) && (xRatio > 0) && (yRatio > 0)) {
235  status = UI_DRAWING_drawScaledStringBilinear(gc, chars, length, font, x, y, xRatio, yRatio);
236  }
237  LLUI_DISPLAY_setDrawingStatus(status);
238  UI_TRACE_DRAW_END(drawScaledString, status);
239  }
240 }
241 
242 void LLDW_PAINTER_IMPL_drawScaledRenderableStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
243  MICROUI_Font *font, jint width,
244  MICROUI_RenderableString *renderableString, jint x, jint y,
245  jfloat xRatio, jfloat yRatio) {
246  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledRenderableStringBilinear)) {
247  DRAWING_Status status = DRAWING_DONE;
248  UI_TRACE_DRAW_START(drawScaledRenderableString, gc, length, x, y, (uint32_t)xRatio, (uint32_t)yRatio,
249  UI_TRACE_Bilinear);
250  if ((length > 0) && (xRatio > 0) && (yRatio > 0)) {
251  status = UI_DRAWING_drawScaledRenderableStringBilinear(gc, chars, length, font, width, renderableString, x,
252  y, xRatio, yRatio);
253  }
254  LLUI_DISPLAY_setDrawingStatus(status);
255  UI_TRACE_DRAW_END(drawScaledRenderableString, status);
256  }
257 }
258 
259 void LLDW_PAINTER_IMPL_drawCharWithRotationBilinear(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font, jint x,
260  jint y, jint xRotation, jint yRotation, jfloat angle, jint alpha) {
261  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawCharWithRotationBilinear)) {
262  DRAWING_Status status = DRAWING_DONE;
263  UI_TRACE_DRAW_START(drawRotatedCharacter, gc, c, x, y, xRotation, yRotation, (uint32_t)angle, (uint32_t)alpha,
264  UI_TRACE_Bilinear);
265  if (alpha > 0) {
266  status = UI_DRAWING_drawCharWithRotationBilinear(gc, c, font, x, y, xRotation, yRotation, angle, alpha);
267  }
268  LLUI_DISPLAY_setDrawingStatus(status);
269  UI_TRACE_DRAW_END(drawRotatedCharacter, status);
270  }
271 }
272 
273 void LLDW_PAINTER_IMPL_drawCharWithRotationNearestNeighbor(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font,
274  jint x, jint y, jint xRotation, jint yRotation, jfloat angle,
275  jint alpha) {
276  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawCharWithRotationNearestNeighbor)) {
277  DRAWING_Status status = DRAWING_DONE;
278  UI_TRACE_DRAW_START(drawRotatedCharacter, gc, c, x, y, xRotation, yRotation, (uint32_t)angle, (uint32_t)alpha,
279  UI_TRACE_NearestNeighbor);
280  if (alpha > 0) {
281  status = UI_DRAWING_drawCharWithRotationNearestNeighbor(gc, c, font, x, y, xRotation, yRotation, angle,
282  alpha);
283  }
284  LLUI_DISPLAY_setDrawingStatus(status);
285  UI_TRACE_DRAW_END(drawRotatedCharacter, status);
286  }
287 }
288 
289 // --------------------------------------------------------------------------------
290 // EOF
291 // --------------------------------------------------------------------------------