microui  4.1.0
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 4.1.0
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 
59 // --------------------------------------------------------------------------------
60 // LLDW_PAINTER_impl.h functions
61 // --------------------------------------------------------------------------------
62 
63 void LLDW_PAINTER_IMPL_drawThickFadedPoint(MICROUI_GraphicsContext *gc, jint x, jint y, jint thickness, jint fade) {
64  if (((thickness > 0) || (fade > 0)) && LLUI_DISPLAY_requestDrawing(gc,
65  (SNI_callback) &
66  LLDW_PAINTER_IMPL_drawThickFadedPoint)) {
67  LOG_DRAW_START(drawThickFadedPoint);
68  DRAWING_Status status = UI_DRAWING_drawThickFadedPoint(gc, x, y, thickness, fade);
69  LLUI_DISPLAY_setDrawingStatus(status);
70  LOG_DRAW_END(status);
71  }
72 }
73 
74 void LLDW_PAINTER_IMPL_drawThickFadedLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY,
75  jint thickness, jint fade, DRAWING_Cap startCap, DRAWING_Cap endCap) {
76  if (((thickness > 0) || (fade > 0)) && LLUI_DISPLAY_requestDrawing(gc,
77  (SNI_callback) &
78  LLDW_PAINTER_IMPL_drawThickFadedLine)) {
79  LOG_DRAW_START(drawThickFadedLine);
80  DRAWING_Status status = UI_DRAWING_drawThickFadedLine(gc, startX, startY, endX, endY, thickness, fade, startCap,
81  endCap);
82  LLUI_DISPLAY_setDrawingStatus(status);
83  LOG_DRAW_END(status);
84  }
85 }
86 
87 void LLDW_PAINTER_IMPL_drawThickFadedCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jint thickness,
88  jint fade) {
89  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && LLUI_DISPLAY_requestDrawing(gc,
90  (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,
142  (SNI_callback) &
143  LLDW_PAINTER_IMPL_drawThickCircle)) {
144  LOG_DRAW_START(drawThickCircle);
145  DRAWING_Status status = UI_DRAWING_drawThickCircle(gc, x, y, diameter, thickness);
146  LLUI_DISPLAY_setDrawingStatus(status);
147  LOG_DRAW_END(status);
148  }
149 }
150 
151 void LLDW_PAINTER_IMPL_drawThickEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
152  jint thickness) {
153  if ((thickness > 0) && (width > 0) && (height > 0) && LLUI_DISPLAY_requestDrawing(gc,
154  (SNI_callback) &
155  LLDW_PAINTER_IMPL_drawThickEllipse))
156  {
157  LOG_DRAW_START(drawThickEllipse);
158  DRAWING_Status status = UI_DRAWING_drawThickEllipse(gc, x, y, width, height, thickness);
159  LLUI_DISPLAY_setDrawingStatus(status);
160  LOG_DRAW_END(status);
161  }
162 }
163 
164 void LLDW_PAINTER_IMPL_drawThickCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
165  jfloat arcAngle, jint thickness) {
166  if ((thickness > 0) && (diameter > 0) && ((int32_t)arcAngle != 0) && LLUI_DISPLAY_requestDrawing(gc,
167  (SNI_callback) &
168  LLDW_PAINTER_IMPL_drawThickCircleArc))
169  {
170  LOG_DRAW_START(drawThickCircleArc);
171  DRAWING_Status status = UI_DRAWING_drawThickCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness);
172  LLUI_DISPLAY_setDrawingStatus(status);
173  LOG_DRAW_END(status);
174  }
175 }
176 
177 void LLDW_PAINTER_IMPL_drawFlippedImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
178  jint width, jint height, jint x, jint y, DRAWING_Flip transformation,
179  jint alpha) {
180  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && LLUI_DISPLAY_requestDrawing(gc,
181  (SNI_callback) &
182  LLDW_PAINTER_IMPL_drawFlippedImage)) {
183  LOG_DRAW_START(drawFlippedImage);
184  DRAWING_Status status = UI_DRAWING_drawFlippedImage(gc, img, regionX, regionY, width, height, x, y,
185  transformation, alpha);
186  LLUI_DISPLAY_setDrawingStatus(status);
187  LOG_DRAW_END(status);
188  }
189 }
190 
191 void LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
192  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
193  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && LLUI_DISPLAY_requestDrawing(gc,
194  (SNI_callback) &
195  LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor))
196  {
197  LOG_DRAW_START(drawRotatedImageNearestNeighbor);
198  DRAWING_Status status = UI_DRAWING_drawRotatedImageNearestNeighbor(gc, img, x, y, rotationX, rotationY, angle,
199  alpha);
200  LLUI_DISPLAY_setDrawingStatus(status);
201  LOG_DRAW_END(status);
202  }
203 }
204 
205 void LLDW_PAINTER_IMPL_drawRotatedImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
206  jint rotationX, jint rotationY, jfloat angle, jint alpha) {
207  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && LLUI_DISPLAY_requestDrawing(gc,
208  (SNI_callback) &
209  LLDW_PAINTER_IMPL_drawRotatedImageBilinear))
210  {
211  LOG_DRAW_START(drawRotatedImageBilinear);
212  DRAWING_Status status = UI_DRAWING_drawRotatedImageBilinear(gc, img, x, y, rotationX, rotationY, angle, alpha);
213  LLUI_DISPLAY_setDrawingStatus(status);
214  LOG_DRAW_END(status);
215  }
216 }
217 
218 void LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
219  jfloat factorX, jfloat factorY, jint alpha) {
220  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f) &&
221  LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor)) {
222  LOG_DRAW_START(drawScaledImageNearestNeighbor);
223  DRAWING_Status status = UI_DRAWING_drawScaledImageNearestNeighbor(gc, img, x, y, factorX, factorY, alpha);
224  LLUI_DISPLAY_setDrawingStatus(status);
225  LOG_DRAW_END(status);
226  }
227 }
228 
229 void LLDW_PAINTER_IMPL_drawScaledImageBilinear(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint x, jint y,
230  jfloat factorX, jfloat factorY, jint alpha) {
231  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f) &&
232  LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLDW_PAINTER_IMPL_drawScaledImageBilinear)) {
233  LOG_DRAW_START(drawScaledImageBilinear);
234  DRAWING_Status status = UI_DRAWING_drawScaledImageBilinear(gc, img, x, y, factorX, factorY, alpha);
235  LLUI_DISPLAY_setDrawingStatus(status);
236  LOG_DRAW_END(status);
237  }
238 }
239 
240 // --------------------------------------------------------------------------------
241 // EOF
242 // --------------------------------------------------------------------------------
243 
244 #ifdef __cplusplus
245 }
246 #endif