20 #include <LLUI_PAINTER_impl.h>
23 #include <LLUI_DISPLAY.h>
26 #include <LLUI_DISPLAY_impl.h>
29 #include "ui_drawing.h"
38 #if (defined(LLUI_MAJOR_VERSION) && (LLUI_MAJOR_VERSION != 14)) || (defined(LLUI_MINOR_VERSION) && \
39 (LLUI_MINOR_VERSION < 0))
40 #error "This CCO is only compatible with UI Pack [14.0.0,15.0.0["
44 #define LOG_DRAW_START(fn) LLTRACE_record_event_u32(LLUI_EVENT_group, LLUI_EVENT_offset + UI_LOG_DRAW, \
45 CONCAT_DEFINES(LOG_DRAW_, fn))
46 #define LOG_DRAW_END(s) LLTRACE_record_event_end_u32(LLUI_EVENT_group, LLUI_EVENT_offset + UI_LOG_DRAW, (s))
51 #define LOG_DRAW_writePixel 1
52 #define LOG_DRAW_drawLine 2
53 #define LOG_DRAW_drawHorizontalLine 3
54 #define LOG_DRAW_drawVerticalLine 4
55 #define LOG_DRAW_drawRectangle 5
56 #define LOG_DRAW_fillRectangle 6
57 #define LOG_DRAW_drawRoundedRectangle 8
58 #define LOG_DRAW_fillRoundedRectangle 9
59 #define LOG_DRAW_drawCircleArc 10
60 #define LOG_DRAW_fillCircleArc 11
61 #define LOG_DRAW_drawEllipseArc 12
62 #define LOG_DRAW_fillEllipseArc 13
63 #define LOG_DRAW_drawEllipse 14
64 #define LOG_DRAW_fillEllipse 15
65 #define LOG_DRAW_drawCircle 16
66 #define LOG_DRAW_fillCircle 17
67 #define LOG_DRAW_drawARGB 18
68 #define LOG_DRAW_drawImage 19
78 static inline void _check_bound(jint max, jint *bound, jint *size, jint *origin) {
85 if ((*bound + *size) > max) {
95 void LLUI_PAINTER_IMPL_writePixel(MICROUI_GraphicsContext *gc, jint x, jint y) {
96 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_writePixel)) {
97 DRAWING_Status status;
98 LOG_DRAW_START(writePixel);
99 if (LLUI_DISPLAY_isPixelInClip(gc, x, y)) {
100 LLUI_DISPLAY_configureClip(gc,
false );
101 status = UI_DRAWING_writePixel(gc, x, y);
104 status = DRAWING_DONE;
106 LLUI_DISPLAY_setDrawingStatus(status);
107 LOG_DRAW_END(status);
112 void LLUI_PAINTER_IMPL_drawLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY) {
113 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawLine)) {
114 LOG_DRAW_START(drawLine);
116 DRAWING_Status status = UI_DRAWING_drawLine(gc, startX, startY, endX, endY);
117 LLUI_DISPLAY_setDrawingStatus(status);
118 LOG_DRAW_END(status);
123 void LLUI_PAINTER_IMPL_drawHorizontalLine(MICROUI_GraphicsContext *gc, jint x, jint y, jint length) {
124 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawHorizontalLine)) {
125 DRAWING_Status status;
126 LOG_DRAW_START(drawHorizontalLine);
129 jint x2 = x + length - 1;
132 if ((length > 0) && LLUI_DISPLAY_clipHorizontalLine(gc, &x1, &x2, y)) {
133 LLUI_DISPLAY_configureClip(gc,
false );
134 status = UI_DRAWING_drawHorizontalLine(gc, x1, x2, y);
137 status = DRAWING_DONE;
139 LLUI_DISPLAY_setDrawingStatus(status);
140 LOG_DRAW_END(status);
145 void LLUI_PAINTER_IMPL_drawVerticalLine(MICROUI_GraphicsContext *gc, jint x, jint y, jint length) {
146 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawVerticalLine)) {
147 DRAWING_Status status;
148 LOG_DRAW_START(drawVerticalLine);
151 jint y2 = y + length - 1;
154 if ((length > 0) && LLUI_DISPLAY_clipVerticalLine(gc, &y1, &y2, x)) {
155 LLUI_DISPLAY_configureClip(gc,
false );
156 status = UI_DRAWING_drawVerticalLine(gc, x, y1, y2);
159 status = DRAWING_DONE;
161 LLUI_DISPLAY_setDrawingStatus(status);
162 LOG_DRAW_END(status);
167 void LLUI_PAINTER_IMPL_drawRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
168 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawRectangle)) {
169 DRAWING_Status status;
170 LOG_DRAW_START(drawRectangle);
173 if ((width > 0) && (height > 0)) {
175 jint x2 = x + width - 1;
177 jint y2 = y + height - 1;
180 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRectangleInClip(gc, x1, y1, x2, y2));
181 status = UI_DRAWING_drawRectangle(gc, x1, y1, x2, y2);
184 status = DRAWING_DONE;
186 LLUI_DISPLAY_setDrawingStatus(status);
187 LOG_DRAW_END(status);
192 void LLUI_PAINTER_IMPL_fillRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
193 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillRectangle)) {
194 DRAWING_Status status;
195 LOG_DRAW_START(fillRectangle);
198 jint x2 = x + width - 1;
200 jint y2 = y + height - 1;
203 if ((width > 0) && (height > 0) && LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
204 LLUI_DISPLAY_configureClip(gc,
false );
205 status = UI_DRAWING_fillRectangle(gc, x1, y1, x2, y2);
208 status = DRAWING_DONE;
210 LLUI_DISPLAY_setDrawingStatus(status);
211 LOG_DRAW_END(status);
216 void LLUI_PAINTER_IMPL_drawRoundedRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
217 jint cornerEllipseWidth, jint cornerEllipseHeight) {
218 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawRoundedRectangle)) {
219 DRAWING_Status status;
220 LOG_DRAW_START(drawRoundedRectangle);
223 if ((width > 0) && (height > 0)) {
225 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
226 status = UI_DRAWING_drawRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
229 status = DRAWING_DONE;
231 LLUI_DISPLAY_setDrawingStatus(status);
232 LOG_DRAW_END(status);
237 void LLUI_PAINTER_IMPL_fillRoundedRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
238 jint cornerEllipseWidth, jint cornerEllipseHeight) {
239 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillRoundedRectangle)) {
240 DRAWING_Status status;
241 LOG_DRAW_START(fillRoundedRectangle);
244 if ((width > 0) && (height > 0)) {
246 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
247 status = UI_DRAWING_fillRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
250 status = DRAWING_DONE;
252 LLUI_DISPLAY_setDrawingStatus(status);
253 LOG_DRAW_END(status);
258 void LLUI_PAINTER_IMPL_drawCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
260 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawCircleArc)) {
261 DRAWING_Status status;
262 LOG_DRAW_START(drawCircleArc);
265 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
267 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
268 status = UI_DRAWING_drawCircleArc(gc, x, y, diameter, startAngle, arcAngle);
271 status = DRAWING_DONE;
273 LLUI_DISPLAY_setDrawingStatus(status);
274 LOG_DRAW_END(status);
279 void LLUI_PAINTER_IMPL_drawEllipseArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
280 jfloat startAngle, jfloat arcAngle) {
281 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawEllipseArc)) {
282 DRAWING_Status status;
283 LOG_DRAW_START(drawEllipseArc);
286 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
288 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
289 status = UI_DRAWING_drawEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
292 status = DRAWING_DONE;
294 LLUI_DISPLAY_setDrawingStatus(status);
295 LOG_DRAW_END(status);
300 void LLUI_PAINTER_IMPL_fillCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
302 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillCircleArc)) {
303 DRAWING_Status status;
304 LOG_DRAW_START(fillCircleArc);
307 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
309 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
310 status = UI_DRAWING_fillCircleArc(gc, x, y, diameter, startAngle, arcAngle);
313 status = DRAWING_DONE;
315 LLUI_DISPLAY_setDrawingStatus(status);
316 LOG_DRAW_END(status);
321 void LLUI_PAINTER_IMPL_fillEllipseArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
322 jfloat startAngle, jfloat arcAngle) {
323 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillEllipseArc)) {
324 DRAWING_Status status;
325 LOG_DRAW_START(fillEllipseArc);
328 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
330 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
331 status = UI_DRAWING_fillEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
334 status = DRAWING_DONE;
336 LLUI_DISPLAY_setDrawingStatus(status);
337 LOG_DRAW_END(status);
342 void LLUI_PAINTER_IMPL_drawEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
343 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawEllipse)) {
344 DRAWING_Status status;
345 LOG_DRAW_START(drawEllipse);
348 if ((width > 0) && (height > 0)) {
350 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
351 status = UI_DRAWING_drawEllipse(gc, x, y, width, height);
354 status = DRAWING_DONE;
356 LLUI_DISPLAY_setDrawingStatus(status);
357 LOG_DRAW_END(status);
362 void LLUI_PAINTER_IMPL_fillEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
363 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillEllipse)) {
364 DRAWING_Status status;
365 LOG_DRAW_START(fillEllipse);
368 if ((width > 0) && (height > 0)) {
370 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
371 status = UI_DRAWING_fillEllipse(gc, x, y, width, height);
374 status = DRAWING_DONE;
376 LLUI_DISPLAY_setDrawingStatus(status);
377 LOG_DRAW_END(status);
382 void LLUI_PAINTER_IMPL_drawCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter) {
383 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawCircle)) {
384 DRAWING_Status status;
385 LOG_DRAW_START(drawCircle);
390 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
391 status = UI_DRAWING_drawCircle(gc, x, y, diameter);
394 status = DRAWING_DONE;
396 LLUI_DISPLAY_setDrawingStatus(status);
397 LOG_DRAW_END(status);
402 void LLUI_PAINTER_IMPL_fillCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter) {
403 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillCircle)) {
404 DRAWING_Status status;
405 LOG_DRAW_START(fillCircle);
410 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
411 status = UI_DRAWING_fillCircle(gc, x, y, diameter);
414 status = DRAWING_DONE;
416 LLUI_DISPLAY_setDrawingStatus(status);
417 LOG_DRAW_END(status);
422 void LLUI_PAINTER_IMPL_drawImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
423 jint width, jint height, jint x, jint y, jint alpha) {
424 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawImage)) {
425 DRAWING_Status status = DRAWING_DONE;
426 LOG_DRAW_START(drawImage);
429 if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0)) {
431 jint l_alpha = (alpha > 255) ? 255 : alpha;
434 _check_bound(img->width, ®ionX, &width, &x);
435 _check_bound(img->height, ®ionY, &height, &y);
438 _check_bound(gc->image.width, &x, &width, ®ionX);
439 _check_bound(gc->image.height, &y, &height, ®ionY);
441 if ((width > 0) && (height > 0) && LLUI_DISPLAY_clipRegion(gc, ®ionX, ®ionY, &width, &height, &x,
443 LLUI_DISPLAY_configureClip(gc,
false );
445 if (gc->image.format == img->format) {
448 MICROUI_Image *image = LLUI_DISPLAY_getSourceImage(img);
450 if ((0xff == l_alpha) && !LLUI_DISPLAY_isTransparent(img)) {
452 status = UI_DRAWING_copyImage(gc, image, regionX, regionY, width, height, x, y);
453 }
else if (LLUI_DISPLAY_getBufferAddress(img) == LLUI_DISPLAY_getBufferAddress(&gc->image)) {
455 status = UI_DRAWING_drawRegion(gc, regionX, regionY, width, height, x, y, l_alpha);
458 status = UI_DRAWING_drawImage(gc, image, regionX, regionY, width, height, x, y, l_alpha);
462 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
470 LLUI_DISPLAY_setDrawingStatus(status);
471 LOG_DRAW_END(status);