microui  14.4.1
microui
LLDW_PAINTER_impl.c
1 /*
2  * Copyright 2020-2025 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.4.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 // 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_LOG_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_LOG_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_LOG_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_LOG_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_LOG_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_LOG_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_LOG_DRAW_START(drawThickFadedCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle, thickness, fade);
79  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && ((int32_t)arcAngle != 0)) {
80  status = UI_DRAWING_drawThickFadedCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness, fade, start, end);
81  }
82  LLUI_DISPLAY_setDrawingStatus(status);
83  UI_LOG_DRAW_END(drawThickFadedCircleArc, status);
84  }
85 }
86 
87 void LLDW_PAINTER_IMPL_drawThickFadedEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
88  jint thickness, jint fade) {
89  if (LLUI_DISPLAY_requestDrawing(gc,(SNI_callback) &LLDW_PAINTER_IMPL_drawThickFadedEllipse)) {
90  DRAWING_Status status = DRAWING_DONE;
91  UI_LOG_DRAW_START(drawThickFadedEllipse, gc, x, y, width, height, thickness, fade);
92  if (((thickness > 0) || (fade > 0)) && (width > 0) && (height > 0)) {
93  status = UI_DRAWING_drawThickFadedEllipse(gc, x, y, width, height, thickness, fade);
94  }
95  LLUI_DISPLAY_setDrawingStatus(status);
96  UI_LOG_DRAW_END(drawThickFadedEllipse, status);
97  }
98 }
99 
100 void LLDW_PAINTER_IMPL_drawThickLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY,
101  jint thickness) {
102  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawThickLine)) {
103  DRAWING_Status status = DRAWING_DONE;
104  UI_LOG_DRAW_START(drawThickLine, gc, startX, startY, endX, endY, thickness);
105  if (thickness > 0) {
106  status = UI_DRAWING_drawThickLine(gc, startX, startY, endX, endY, thickness);
107  }
108  LLUI_DISPLAY_setDrawingStatus(status);
109  UI_LOG_DRAW_END(drawThickLine, status);
110  }
111 }
112 
113 void LLDW_PAINTER_IMPL_drawThickCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jint thickness) {
114  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &LLDW_PAINTER_IMPL_drawThickCircle)) {
115  DRAWING_Status status = DRAWING_DONE;
116  UI_LOG_DRAW_START(drawThickCircle, gc, x, y, diameter, thickness);
117  if ((thickness > 0) && (diameter > 0)) {
118  status = UI_DRAWING_drawThickCircle(gc, x, y, diameter, thickness);
119  }
120  LLUI_DISPLAY_setDrawingStatus(status);
121  UI_LOG_DRAW_END(drawThickCircle, status);
122  }
123 }
124 
125 void LLDW_PAINTER_IMPL_drawThickEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
126  jint thickness) {
127  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) &LLDW_PAINTER_IMPL_drawThickEllipse)){
128  DRAWING_Status status = DRAWING_DONE;
129  UI_LOG_DRAW_START(drawThickEllipse, gc, x, y, width, height, thickness);
130  if ((thickness > 0) && (width > 0) && (height > 0)) {
131  status = UI_DRAWING_drawThickEllipse(gc, x, y, width, height, thickness);
132  }
133  LLUI_DISPLAY_setDrawingStatus(status);
134  UI_LOG_DRAW_END(drawThickEllipse, status);
135  }
136 }
137 
138 void LLDW_PAINTER_IMPL_drawThickCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
139  jfloat arcAngle, jint thickness) {
140  if (LLUI_DISPLAY_requestDrawing(gc,(SNI_callback) &LLDW_PAINTER_IMPL_drawThickCircleArc)) {
141  DRAWING_Status status = DRAWING_DONE;
142  UI_LOG_DRAW_START(drawThickCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle, thickness);
143  if ((thickness > 0) && (diameter > 0) && ((int32_t)arcAngle != 0)) {
144  status = UI_DRAWING_drawThickCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness);
145  }
146  LLUI_DISPLAY_setDrawingStatus(status);
147  UI_LOG_DRAW_END(drawThickCircleArc, status);
148  }
149 }
150 
151 void LLDW_PAINTER_IMPL_drawFlippedImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
152  jint width, jint height, jint x, jint y, DRAWING_Flip transformation,
153  jint alpha) {
154  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawFlippedImage)) {
155  DRAWING_Status status = DRAWING_DONE;
156  UI_LOG_DRAW_START(drawFlippedImage, gc, UI_LOG_BUFFER(img), regionX, regionY, width, height, x, y, transformation, alpha);
157  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
158  status = UI_DRAWING_drawFlippedImage(gc, img, regionX, regionY, width, height, x, y,
159  transformation, alpha);
160  }
161  LLUI_DISPLAY_setDrawingStatus(status);
162  UI_LOG_DRAW_END(drawFlippedImage, status);
163  }
164 }
165 
166 void LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
167  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
168  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor)) {
169  DRAWING_Status status = DRAWING_DONE;
170  UI_LOG_DRAW_START(drawRotatedImage, gc, UI_LOG_BUFFER(img), x, y, rotationX, rotationY, (uint32_t)angle, alpha, UI_LOG_NearestNeighbor);
171  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
172  status = UI_DRAWING_drawRotatedImageNearestNeighbor(gc, img, x, y, rotationX, rotationY, angle,
173  alpha);
174  }
175  LLUI_DISPLAY_setDrawingStatus(status);
176  UI_LOG_DRAW_END(drawRotatedImage, status);
177  }
178 }
179 
180 void LLDW_PAINTER_IMPL_drawRotatedImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
181  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
182  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawRotatedImageBilinear)) {
183  DRAWING_Status status = DRAWING_DONE;
184  UI_LOG_DRAW_START(drawRotatedImage, gc, UI_LOG_BUFFER(img), x, y, rotationX, rotationY, (uint32_t)angle, alpha, UI_LOG_Bilinear);
185  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
186  status = UI_DRAWING_drawRotatedImageBilinear(gc, img, x, y, rotationX, rotationY, angle, alpha);
187  }
188  LLUI_DISPLAY_setDrawingStatus(status);
189  UI_LOG_DRAW_END(drawRotatedImage, status);
190  }
191 }
192 
193 void LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
194  jfloat factorX, jfloat factorY, jint alpha) {
195  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor)) {
196  DRAWING_Status status = DRAWING_DONE;
197  UI_LOG_DRAW_START(drawScaledImage, gc, UI_LOG_BUFFER(img), x, y, (uint32_t)factorX, (uint32_t)factorY, alpha, UI_LOG_NearestNeighbor);
198  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f)) {
199  status = UI_DRAWING_drawScaledImageNearestNeighbor(gc, img, x, y, factorX, factorY, alpha);
200  }
201  LLUI_DISPLAY_setDrawingStatus(status);
202  UI_LOG_DRAW_END(drawScaledImage, status);
203  }
204 }
205 
206 void LLDW_PAINTER_IMPL_drawScaledImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
207  jfloat factorX, jfloat factorY, jint alpha) {
208  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawScaledImageBilinear)) {
209  DRAWING_Status status = DRAWING_DONE;
210  UI_LOG_DRAW_START(drawScaledImage, gc, UI_LOG_BUFFER(img), x, y, (uint32_t)factorX, (uint32_t)factorY, alpha, UI_LOG_Bilinear);
211  if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f)) {
212  status = UI_DRAWING_drawScaledImageBilinear(gc, img, x, y, factorX, factorY, alpha);
213  }
214  LLUI_DISPLAY_setDrawingStatus(status);
215  UI_LOG_DRAW_END(drawScaledImage, status);
216  }
217 }
218 
219 void LLDW_PAINTER_IMPL_drawScaledStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
220  MICROUI_Font *font, jint x, jint y, jfloat xRatio, jfloat yRatio) {
221  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledStringBilinear)) {
222  DRAWING_Status status = DRAWING_DONE;
223  UI_LOG_DRAW_START(drawScaledString, gc, length, x, y, (uint32_t)xRatio, (uint32_t)yRatio, UI_LOG_Bilinear);
224  if ((length > 0) && (xRatio > 0) && (yRatio > 0)) {
225  status = UI_DRAWING_drawScaledStringBilinear(gc, chars, length, font, x, y, xRatio, yRatio);
226  }
227  LLUI_DISPLAY_setDrawingStatus(status);
228  UI_LOG_DRAW_END(drawScaledString, status);
229  }
230 }
231 
232 void LLDW_PAINTER_IMPL_drawScaledRenderableStringBilinear(MICROUI_GraphicsContext *gc, jchar *chars, jint length,
233  MICROUI_Font *font, jint width,
234  MICROUI_RenderableString *renderableString, jint x, jint y,
235  jfloat xRatio, jfloat yRatio) {
236  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawScaledRenderableStringBilinear)) {
237  DRAWING_Status status = DRAWING_DONE;
238  UI_LOG_DRAW_START(drawScaledRenderableString, gc, length, x, y, (uint32_t)xRatio, (uint32_t)yRatio, UI_LOG_Bilinear);
239  if ((length > 0) && (xRatio > 0) && (yRatio > 0)) {
240  status = UI_DRAWING_drawScaledRenderableStringBilinear(gc, chars, length, font, width, renderableString, x, y, xRatio, yRatio);
241  }
242  LLUI_DISPLAY_setDrawingStatus(status);
243  UI_LOG_DRAW_END(drawScaledRenderableString, status);
244  }
245 }
246 
247 void LLDW_PAINTER_IMPL_drawCharWithRotationBilinear(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font, jint x,
248  jint y, jint xRotation, jint yRotation, jfloat angle, jint alpha) {
249  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawCharWithRotationBilinear)) {
250  DRAWING_Status status = DRAWING_DONE;
251  UI_LOG_DRAW_START(drawRotatedCharacter, gc, c, x, y, xRotation, yRotation, (uint32_t)angle, (uint32_t)alpha, UI_LOG_Bilinear);
252  if (alpha > 0) {
253  status = UI_DRAWING_drawCharWithRotationBilinear(gc, c, font, x, y, xRotation, yRotation, angle, alpha);
254  }
255  LLUI_DISPLAY_setDrawingStatus(status);
256  UI_LOG_DRAW_END(drawRotatedCharacter, status);
257  }
258 }
259 
260 void LLDW_PAINTER_IMPL_drawCharWithRotationNearestNeighbor(MICROUI_GraphicsContext *gc, jchar c, MICROUI_Font *font,
261  jint x, jint y, jint xRotation, jint yRotation, jfloat angle,
262  jint alpha) {
263  if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLDW_PAINTER_IMPL_drawCharWithRotationNearestNeighbor)) {
264  DRAWING_Status status = DRAWING_DONE;
265  UI_LOG_DRAW_START(drawRotatedCharacter, gc, c, x, y, xRotation, yRotation, (uint32_t)angle, (uint32_t)alpha, UI_LOG_NearestNeighbor);
266  if (alpha > 0) {
267  status = UI_DRAWING_drawCharWithRotationNearestNeighbor(gc, c, font, x, y, xRotation, yRotation, angle, alpha);
268  }
269  LLUI_DISPLAY_setDrawingStatus(status);
270  UI_LOG_DRAW_END(drawRotatedCharacter, status);
271  }
272 }
273 
274 // --------------------------------------------------------------------------------
275 // EOF
276 // --------------------------------------------------------------------------------