microui  4.0.1
microui
LLDW_PAINTER_impl.c
1 
2 /*
3  * Copyright 2020-2024 MicroEJ Corp. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be found with this software.
5  */
6 
7 /*
8  * @file
9  * @brief This file implements all "Drawing" (MicroUI extended library) drawing native functions.
10  * @see LLDW_PAINTER_impl.h file comment
11  * @author MicroEJ Developer Team
12  * @version 4.0.1
13  * @since MicroEJ UI Pack 13.0.0
14  */
15 
16 // --------------------------------------------------------------------------------
17 // Includes
18 // --------------------------------------------------------------------------------
19 
20 // implements LLDW_PAINTER_impl functions
21 #include <LLDW_PAINTER_impl.h>
22 
23 // use graphical engine functions to synchronize drawings
24 #include <LLUI_DISPLAY.h>
25 
26 // calls ui_drawing functions
27 #include "ui_drawing.h"
28 
29 // logs the drawings
30 #include "ui_log.h"
31 
32 // --------------------------------------------------------------------------------
33 // Macros and Defines
34 // --------------------------------------------------------------------------------
35 
36 // macros to log a drawing
37 #define LOG_DRAW_START(fn) LLTRACE_record_event_u32(LLUI_EVENT_group, LLUI_EVENT_offset + UI_LOG_DRAW, 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, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickFadedPoint)) {
65  LOG_DRAW_START(drawThickFadedPoint);
66  DRAWING_Status status = UI_DRAWING_drawThickFadedPoint(gc, x, y, thickness, fade);
67  LLUI_DISPLAY_setDrawingStatus(status);
68  LOG_DRAW_END(status);
69  }
70 }
71 
72 void LLDW_PAINTER_IMPL_drawThickFadedLine(MICROUI_GraphicsContext* gc, jint startX, jint startY, jint endX, jint endY, jint thickness, jint fade, DRAWING_Cap startCap, DRAWING_Cap endCap) {
73  if (((thickness > 0) || (fade > 0)) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickFadedLine)) {
74  LOG_DRAW_START(drawThickFadedLine);
75  DRAWING_Status status = UI_DRAWING_drawThickFadedLine(gc, startX, startY, endX, endY, thickness, fade, startCap, endCap);
76  LLUI_DISPLAY_setDrawingStatus(status);
77  LOG_DRAW_END(status);
78  }
79 }
80 
81 void LLDW_PAINTER_IMPL_drawThickFadedCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jint thickness, jint fade) {
82  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickFadedCircle)) {
83  LOG_DRAW_START(drawThickFadedCircle);
84  DRAWING_Status status = UI_DRAWING_drawThickFadedCircle(gc, x, y, diameter, thickness, fade);
85  LLUI_DISPLAY_setDrawingStatus(status);
86  LOG_DRAW_END(status);
87  }
88 }
89 
90 void LLDW_PAINTER_IMPL_drawThickFadedCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle, jint thickness, jint fade, DRAWING_Cap start, DRAWING_Cap end) {
91  if (((thickness > 0) || (fade > 0)) && (diameter > 0) && ((int32_t)arcAngle != 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickFadedCircleArc)) {
92  LOG_DRAW_START(drawThickFadedCircleArc);
93  DRAWING_Status status = UI_DRAWING_drawThickFadedCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness, fade, start, end);
94  LLUI_DISPLAY_setDrawingStatus(status);
95  LOG_DRAW_END(status);
96  }
97 }
98 
99 void LLDW_PAINTER_IMPL_drawThickFadedEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jint thickness, jint fade) {
100  if (((thickness > 0) || (fade > 0)) && (width > 0) && (height > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickFadedEllipse)) {
101  LOG_DRAW_START(drawThickFadedEllipse);
102  DRAWING_Status status = UI_DRAWING_drawThickFadedEllipse(gc, x, y, width, height, thickness, fade);
103  LLUI_DISPLAY_setDrawingStatus(status);
104  LOG_DRAW_END(status);
105  }
106 }
107 
108 void LLDW_PAINTER_IMPL_drawThickLine(MICROUI_GraphicsContext* gc, jint startX, jint startY, jint endX, jint endY, jint thickness) {
109  if ((thickness > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickLine)) {
110  LOG_DRAW_START(drawThickLine);
111  DRAWING_Status status = UI_DRAWING_drawThickLine(gc, startX, startY, endX, endY, thickness);
112  LLUI_DISPLAY_setDrawingStatus(status);
113  LOG_DRAW_END(status);
114  }
115 }
116 
117 void LLDW_PAINTER_IMPL_drawThickCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jint thickness) {
118  if ((thickness > 0) && (diameter > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickCircle)) {
119  LOG_DRAW_START(drawThickCircle);
120  DRAWING_Status status = UI_DRAWING_drawThickCircle(gc, x, y, diameter, thickness);
121  LLUI_DISPLAY_setDrawingStatus(status);
122  LOG_DRAW_END(status);
123  }
124 }
125 
126 void LLDW_PAINTER_IMPL_drawThickEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jint thickness) {
127  if ((thickness > 0) && (width > 0) && (height > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickEllipse)) {
128  LOG_DRAW_START(drawThickEllipse);
129  DRAWING_Status status = UI_DRAWING_drawThickEllipse(gc, x, y, width, height, thickness);
130  LLUI_DISPLAY_setDrawingStatus(status);
131  LOG_DRAW_END(status);
132  }
133 }
134 
135 void LLDW_PAINTER_IMPL_drawThickCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle, jint thickness) {
136  if ((thickness > 0) && (diameter > 0) && ((int32_t)arcAngle != 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawThickCircleArc)) {
137  LOG_DRAW_START(drawThickCircleArc);
138  DRAWING_Status status = UI_DRAWING_drawThickCircleArc(gc, x, y, diameter, startAngle, arcAngle, thickness);
139  LLUI_DISPLAY_setDrawingStatus(status);
140  LOG_DRAW_END(status);
141  }
142 }
143 
144 void LLDW_PAINTER_IMPL_drawFlippedImage(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint regionX, jint regionY, jint width, jint height, jint x, jint y, DRAWING_Flip transformation, jint alpha) {
145  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawFlippedImage)) {
146  LOG_DRAW_START(drawFlippedImage);
147  DRAWING_Status status = UI_DRAWING_drawFlippedImage(gc, img, regionX, regionY, width, height, x, y, transformation, alpha);
148  LLUI_DISPLAY_setDrawingStatus(status);
149  LOG_DRAW_END(status);
150  }
151 }
152 
153 void LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint x, jint y, jint rotationX, jint rotationY, jfloat angle, jint alpha) {
154  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawRotatedImageNearestNeighbor)) {
155  LOG_DRAW_START(drawRotatedImageNearestNeighbor);
156  DRAWING_Status status = UI_DRAWING_drawRotatedImageNearestNeighbor(gc, img, x, y, rotationX, rotationY, angle, alpha);
157  LLUI_DISPLAY_setDrawingStatus(status);
158  LOG_DRAW_END(status);
159  }
160 }
161 
162 void LLDW_PAINTER_IMPL_drawRotatedImageBilinear(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint x, jint y, jint rotationX, jint rotationY, jfloat angle, jint alpha) {
163  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawRotatedImageBilinear)) {
164  LOG_DRAW_START(drawRotatedImageBilinear);
165  DRAWING_Status status = UI_DRAWING_drawRotatedImageBilinear(gc, img, x, y, rotationX, rotationY, angle, alpha);
166  LLUI_DISPLAY_setDrawingStatus(status);
167  LOG_DRAW_END(status);
168  }
169 }
170 
171 void LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint x, jint y, jfloat factorX, jfloat factorY, jint alpha) {
172  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawScaledImageNearestNeighbor)) {
173  LOG_DRAW_START(drawScaledImageNearestNeighbor);
174  DRAWING_Status status = UI_DRAWING_drawScaledImageNearestNeighbor(gc, img, x, y, factorX, factorY, alpha);
175  LLUI_DISPLAY_setDrawingStatus(status);
176  LOG_DRAW_END(status);
177  }
178 }
179 
180 void LLDW_PAINTER_IMPL_drawScaledImageBilinear(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint x, jint y, jfloat factorX, jfloat factorY, jint alpha) {
181  if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0) && (factorX > 0.f) && (factorY > 0.f) && LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLDW_PAINTER_IMPL_drawScaledImageBilinear)) {
182  LOG_DRAW_START(drawScaledImageBilinear);
183  DRAWING_Status status = UI_DRAWING_drawScaledImageBilinear(gc, img, x, y, factorX, factorY, alpha);
184  LLUI_DISPLAY_setDrawingStatus(status);
185  LOG_DRAW_END(status);
186  }
187 }
188 
189 // --------------------------------------------------------------------------------
190 // EOF
191 // --------------------------------------------------------------------------------
192 
193 #ifdef __cplusplus
194 }
195 #endif