21 #include <LLUI_PAINTER_impl.h>
24 #include <LLUI_DISPLAY.h>
27 #include <LLUI_DISPLAY_impl.h>
30 #include "ui_drawing.h"
39 #if (defined(LLUI_MAJOR_VERSION) && (LLUI_MAJOR_VERSION != 14)) || (defined(LLUI_MINOR_VERSION) && (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, CONCAT_DEFINES(LOG_DRAW_, fn))
45 #define LOG_DRAW_END(s) LLTRACE_record_event_end_u32(LLUI_EVENT_group, LLUI_EVENT_offset + UI_LOG_DRAW, (s))
50 #define LOG_DRAW_writePixel 1
51 #define LOG_DRAW_drawLine 2
52 #define LOG_DRAW_drawHorizontalLine 3
53 #define LOG_DRAW_drawVerticalLine 4
54 #define LOG_DRAW_drawRectangle 5
55 #define LOG_DRAW_fillRectangle 6
56 #define LOG_DRAW_drawRoundedRectangle 8
57 #define LOG_DRAW_fillRoundedRectangle 9
58 #define LOG_DRAW_drawCircleArc 10
59 #define LOG_DRAW_fillCircleArc 11
60 #define LOG_DRAW_drawEllipseArc 12
61 #define LOG_DRAW_fillEllipseArc 13
62 #define LOG_DRAW_drawEllipse 14
63 #define LOG_DRAW_fillEllipse 15
64 #define LOG_DRAW_drawCircle 16
65 #define LOG_DRAW_fillCircle 17
66 #define LOG_DRAW_drawARGB 18
67 #define LOG_DRAW_drawImage 19
77 static inline void _check_bound(jint max, jint* bound, jint* size, jint* origin) {
84 if ((*bound + *size) > max) {
94 void LLUI_PAINTER_IMPL_writePixel(MICROUI_GraphicsContext* gc, jint x, jint y) {
95 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_writePixel)) {
96 DRAWING_Status status;
97 LOG_DRAW_START(writePixel);
98 if (LLUI_DISPLAY_isPixelInClip(gc, x, y)) {
99 LLUI_DISPLAY_configureClip(gc,
false);
100 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);
138 status = DRAWING_DONE;
140 LLUI_DISPLAY_setDrawingStatus(status);
141 LOG_DRAW_END(status);
146 void LLUI_PAINTER_IMPL_drawVerticalLine(MICROUI_GraphicsContext* gc, jint x, jint y, jint length) {
147 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawVerticalLine)) {
148 DRAWING_Status status;
149 LOG_DRAW_START(drawVerticalLine);
152 jint y2 = y + length - 1;
155 if ((length > 0) && LLUI_DISPLAY_clipVerticalLine(gc, &y1, &y2, x)) {
156 LLUI_DISPLAY_configureClip(gc,
false );
157 status = UI_DRAWING_drawVerticalLine(gc, x, y1, y2);
161 status = DRAWING_DONE;
163 LLUI_DISPLAY_setDrawingStatus(status);
164 LOG_DRAW_END(status);
169 void LLUI_PAINTER_IMPL_drawRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
170 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawRectangle)) {
171 DRAWING_Status status;
172 LOG_DRAW_START(drawRectangle);
175 if ((width > 0) && (height > 0)) {
177 jint x2 = x + width - 1;
179 jint y2 = y + height - 1;
182 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRectangleInClip(gc, x1, y1, x2, y2));
183 status = UI_DRAWING_drawRectangle(gc, x1, y1, x2, y2);
187 status = DRAWING_DONE;
189 LLUI_DISPLAY_setDrawingStatus(status);
190 LOG_DRAW_END(status);
195 void LLUI_PAINTER_IMPL_fillRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
196 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillRectangle)) {
197 DRAWING_Status status;
198 LOG_DRAW_START(fillRectangle);
201 jint x2 = x + width - 1;
203 jint y2 = y + height - 1;
206 if ((width > 0) && (height > 0) && LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
207 LLUI_DISPLAY_configureClip(gc,
false );
208 status = UI_DRAWING_fillRectangle(gc, x1, y1, x2, y2);
213 status = DRAWING_DONE;
215 LLUI_DISPLAY_setDrawingStatus(status);
216 LOG_DRAW_END(status);
221 void LLUI_PAINTER_IMPL_drawRoundedRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jint cornerEllipseWidth, jint cornerEllipseHeight) {
222 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawRoundedRectangle)) {
223 DRAWING_Status status;
224 LOG_DRAW_START(drawRoundedRectangle);
227 if ((width > 0) && (height > 0)) {
229 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
230 status = UI_DRAWING_drawRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
234 status = DRAWING_DONE;
236 LLUI_DISPLAY_setDrawingStatus(status);
237 LOG_DRAW_END(status);
242 void LLUI_PAINTER_IMPL_fillRoundedRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jint cornerEllipseWidth, jint cornerEllipseHeight) {
243 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillRoundedRectangle)) {
244 DRAWING_Status status;
245 LOG_DRAW_START(fillRoundedRectangle);
248 if ((width > 0) && (height > 0)) {
250 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
251 status = UI_DRAWING_fillRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
255 status = DRAWING_DONE;
257 LLUI_DISPLAY_setDrawingStatus(status);
258 LOG_DRAW_END(status);
263 void LLUI_PAINTER_IMPL_drawCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle) {
264 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawCircleArc)) {
265 DRAWING_Status status;
266 LOG_DRAW_START(drawCircleArc);
269 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
271 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
272 status = UI_DRAWING_drawCircleArc(gc, x, y, diameter, startAngle, arcAngle);
276 status = DRAWING_DONE;
278 LLUI_DISPLAY_setDrawingStatus(status);
279 LOG_DRAW_END(status);
284 void LLUI_PAINTER_IMPL_drawEllipseArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jfloat startAngle, jfloat arcAngle) {
285 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawEllipseArc)) {
286 DRAWING_Status status;
287 LOG_DRAW_START(drawEllipseArc);
290 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
292 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
293 status = UI_DRAWING_drawEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
297 status = DRAWING_DONE;
299 LLUI_DISPLAY_setDrawingStatus(status);
300 LOG_DRAW_END(status);
305 void LLUI_PAINTER_IMPL_fillCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle) {
306 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillCircleArc)) {
307 DRAWING_Status status;
308 LOG_DRAW_START(fillCircleArc);
311 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
313 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
314 status = UI_DRAWING_fillCircleArc(gc, x, y, diameter, startAngle, arcAngle);
318 status = DRAWING_DONE;
320 LLUI_DISPLAY_setDrawingStatus(status);
321 LOG_DRAW_END(status);
326 void LLUI_PAINTER_IMPL_fillEllipseArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jfloat startAngle, jfloat arcAngle) {
327 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillEllipseArc)) {
328 DRAWING_Status status;
329 LOG_DRAW_START(fillEllipseArc);
332 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
334 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
335 status = UI_DRAWING_fillEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
339 status = DRAWING_DONE;
341 LLUI_DISPLAY_setDrawingStatus(status);
342 LOG_DRAW_END(status);
347 void LLUI_PAINTER_IMPL_drawEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
348 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawEllipse)) {
349 DRAWING_Status status;
350 LOG_DRAW_START(drawEllipse);
353 if ((width > 0) && (height > 0)) {
355 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
356 status = UI_DRAWING_drawEllipse(gc, x, y, width, height);
360 status = DRAWING_DONE;
362 LLUI_DISPLAY_setDrawingStatus(status);
363 LOG_DRAW_END(status);
368 void LLUI_PAINTER_IMPL_fillEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
369 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillEllipse)) {
370 DRAWING_Status status;
371 LOG_DRAW_START(fillEllipse);
374 if ((width > 0) && (height > 0)) {
376 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
377 status = UI_DRAWING_fillEllipse(gc, x, y, width, height);
381 status = DRAWING_DONE;
383 LLUI_DISPLAY_setDrawingStatus(status);
384 LOG_DRAW_END(status);
389 void LLUI_PAINTER_IMPL_drawCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter) {
390 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawCircle)) {
391 DRAWING_Status status;
392 LOG_DRAW_START(drawCircle);
397 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
398 status = UI_DRAWING_drawCircle(gc, x, y, diameter);
402 status = DRAWING_DONE;
404 LLUI_DISPLAY_setDrawingStatus(status);
405 LOG_DRAW_END(status);
410 void LLUI_PAINTER_IMPL_fillCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter) {
411 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillCircle)) {
412 DRAWING_Status status;
413 LOG_DRAW_START(fillCircle);
418 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
419 status = UI_DRAWING_fillCircle(gc, x, y, diameter);
423 status = DRAWING_DONE;
425 LLUI_DISPLAY_setDrawingStatus(status);
426 LOG_DRAW_END(status);
431 void LLUI_PAINTER_IMPL_drawImage(MICROUI_GraphicsContext* gc, MICROUI_Image* img, jint regionX, jint regionY, jint width, jint height, jint x, jint y, jint alpha) {
432 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawImage)) {
433 DRAWING_Status status = DRAWING_DONE;
434 LOG_DRAW_START(drawImage);
437 if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0)) {
440 jint l_alpha = (alpha > 255) ? 255 : alpha;
443 _check_bound(img->width, ®ionX, &width, &x);
444 _check_bound(img->height, ®ionY, &height, &y);
447 _check_bound(gc->image.width, &x, &width, ®ionX);
448 _check_bound(gc->image.height, &y, &height, ®ionY);
450 if ((width > 0) && (height > 0) && LLUI_DISPLAY_clipRegion(gc, ®ionX, ®ionY, &width, &height, &x, &y)) {
452 LLUI_DISPLAY_configureClip(gc,
false );
454 if (gc->image.format == img->format) {
457 MICROUI_Image* image = LLUI_DISPLAY_getSourceImage(img);
459 if ((0xff == l_alpha) && !LLUI_DISPLAY_isTransparent(img)) {
461 status = UI_DRAWING_copyImage(gc, image, regionX, regionY, width, height, x, y);
463 else if (img == &gc->image){
465 status = UI_DRAWING_drawRegion(gc, regionX, regionY, width, height, x, y, l_alpha);
469 status = UI_DRAWING_drawImage(gc, image, regionX, regionY, width, height, x, y, l_alpha);
474 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
482 LLUI_DISPLAY_setDrawingStatus(status);
483 LOG_DRAW_END(status);