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["
51 static inline void _check_bound(jint max, jint *bound, jint *size, jint *origin) {
58 if ((*bound + *size) > max) {
68 void LLUI_PAINTER_IMPL_writePixel(MICROUI_GraphicsContext *gc, jint x, jint y) {
69 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_writePixel)) {
70 DRAWING_Status status = DRAWING_DONE;
71 UI_LOG_DRAW_START(writePixel, gc, x, y);
72 if (LLUI_DISPLAY_isPixelInClip(gc, x, y)) {
73 LLUI_DISPLAY_configureClip(gc,
false );
74 status = UI_DRAWING_writePixel(gc, x, y);
76 UI_LOG_START(OutOfClip, UI_LOG_BUFFER(&gc->image));
78 LLUI_DISPLAY_setDrawingStatus(status);
79 UI_LOG_DRAW_END(writePixel, status);
84 void LLUI_PAINTER_IMPL_drawLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY) {
85 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawLine)) {
86 UI_LOG_DRAW_START(drawLine, gc, startX, startY, endX, endY);
88 DRAWING_Status status = UI_DRAWING_drawLine(gc, startX, startY, endX, endY);
89 LLUI_DISPLAY_setDrawingStatus(status);
90 UI_LOG_DRAW_END(drawLine, status);
95 void LLUI_PAINTER_IMPL_drawHorizontalLine(MICROUI_GraphicsContext *gc, jint x, jint y, jint length) {
96 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawHorizontalLine)) {
97 DRAWING_Status status = DRAWING_DONE;
98 UI_LOG_DRAW_START(drawHorizontalLine, gc, x, y, length);
102 jint x2 = x + length - 1;
103 if (LLUI_DISPLAY_clipHorizontalLine(gc, &x1, &x2, y)) {
104 LLUI_DISPLAY_configureClip(gc,
false );
105 UI_LOG_START(DrawnRegion, UI_LOG_BUFFER(&gc->image),
true, x1, y, x2 - x1 + 1, 1);
106 status = UI_DRAWING_drawHorizontalLine(gc, x1, x2, y);
108 UI_LOG_START(OutOfClip, UI_LOG_BUFFER(&gc->image));
112 LLUI_DISPLAY_setDrawingStatus(status);
113 UI_LOG_DRAW_END(drawHorizontalLine, status);
118 void LLUI_PAINTER_IMPL_drawVerticalLine(MICROUI_GraphicsContext *gc, jint x, jint y, jint length) {
119 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawVerticalLine)) {
120 DRAWING_Status status = DRAWING_DONE;
121 UI_LOG_DRAW_START(drawVerticalLine, gc, x, y, length);
125 jint y2 = y + length - 1;
126 if (LLUI_DISPLAY_clipVerticalLine(gc, &y1, &y2, x)) {
127 LLUI_DISPLAY_configureClip(gc,
false );
128 UI_LOG_START(DrawnRegion, UI_LOG_BUFFER(&gc->image),
true, x, y1, 1, y2 - y1 + 1);
129 status = UI_DRAWING_drawVerticalLine(gc, x, y1, y2);
131 UI_LOG_START(OutOfClip, UI_LOG_BUFFER(&gc->image));
135 LLUI_DISPLAY_setDrawingStatus(status);
136 UI_LOG_DRAW_END(drawVerticalLine, status);
141 void LLUI_PAINTER_IMPL_drawRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
142 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawRectangle)) {
143 DRAWING_Status status = DRAWING_DONE;
144 UI_LOG_DRAW_START(drawRectangle, gc, x, y, width, height);
146 if ((width > 0) && (height > 0)) {
148 jint x2 = x + width - 1;
150 jint y2 = y + height - 1;
153 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRectangleInClip(gc, x1, y1, x2, y2));
154 status = UI_DRAWING_drawRectangle(gc, x1, y1, x2, y2);
157 LLUI_DISPLAY_setDrawingStatus(status);
158 UI_LOG_DRAW_END(drawRectangle, status);
163 void LLUI_PAINTER_IMPL_fillRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
164 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillRectangle)) {
165 DRAWING_Status status = DRAWING_DONE;
166 UI_LOG_DRAW_START(fillRectangle, gc, x, y, width, height);
168 if ((width > 0) && (height > 0)) {
170 jint x2 = x + width - 1;
172 jint y2 = y + height - 1;
174 if (LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
175 LLUI_DISPLAY_configureClip(gc,
false );
176 UI_LOG_START(DrawnRegion, UI_LOG_BUFFER(&gc->image),
true, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
177 status = UI_DRAWING_fillRectangle(gc, x1, y1, x2, y2);
179 UI_LOG_START(OutOfClip, UI_LOG_BUFFER(&gc->image));
182 LLUI_DISPLAY_setDrawingStatus(status);
183 UI_LOG_DRAW_END(fillRectangle, status);
188 void LLUI_PAINTER_IMPL_drawRoundedRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
189 jint cornerEllipseWidth, jint cornerEllipseHeight) {
190 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawRoundedRectangle)) {
191 DRAWING_Status status = DRAWING_DONE;
192 UI_LOG_DRAW_START(drawRoundedRectangle, gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
195 if ((width > 0) && (height > 0)) {
197 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
198 status = UI_DRAWING_drawRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
200 LLUI_DISPLAY_setDrawingStatus(status);
201 UI_LOG_DRAW_END(drawRoundedRectangle, status);
206 void LLUI_PAINTER_IMPL_fillRoundedRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
207 jint cornerEllipseWidth, jint cornerEllipseHeight) {
208 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillRoundedRectangle)) {
209 DRAWING_Status status = DRAWING_DONE;
210 UI_LOG_DRAW_START(fillRoundedRectangle, gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
213 if ((width > 0) && (height > 0)) {
215 jint x2 = x + width - 1;
217 jint y2 = y + height - 1;
219 if (LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
222 bool disable_clip = LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height);
223 LLUI_DISPLAY_configureClip(gc, !disable_clip);
224 UI_LOG_START(DrawnRegion, UI_LOG_BUFFER(&gc->image), disable_clip, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
225 status = UI_DRAWING_fillRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
228 UI_LOG_START(OutOfClip, UI_LOG_BUFFER(&gc->image));
231 LLUI_DISPLAY_setDrawingStatus(status);
232 UI_LOG_DRAW_END(fillRoundedRectangle, status);
237 void LLUI_PAINTER_IMPL_drawCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
239 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawCircleArc)) {
240 DRAWING_Status status = DRAWING_DONE;
241 UI_LOG_DRAW_START(drawCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle);
244 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
246 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
247 status = UI_DRAWING_drawCircleArc(gc, x, y, diameter, startAngle, arcAngle);
249 LLUI_DISPLAY_setDrawingStatus(status);
250 UI_LOG_DRAW_END(drawCircleArc, status);
255 void LLUI_PAINTER_IMPL_drawEllipseArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
256 jfloat startAngle, jfloat arcAngle) {
257 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawEllipseArc)) {
258 DRAWING_Status status = DRAWING_DONE;
259 UI_LOG_DRAW_START(drawEllipseArc, gc, x, y, width, height, (uint32_t)startAngle, (uint32_t)arcAngle);
262 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
264 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
265 status = UI_DRAWING_drawEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
267 LLUI_DISPLAY_setDrawingStatus(status);
268 UI_LOG_DRAW_END(drawEllipseArc, status);
273 void LLUI_PAINTER_IMPL_fillCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
275 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillCircleArc)) {
276 DRAWING_Status status = DRAWING_DONE;
277 UI_LOG_DRAW_START(fillCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle);
280 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
282 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
283 status = UI_DRAWING_fillCircleArc(gc, x, y, diameter, startAngle, arcAngle);
285 LLUI_DISPLAY_setDrawingStatus(status);
286 UI_LOG_DRAW_END(fillCircleArc, status);
291 void LLUI_PAINTER_IMPL_fillEllipseArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
292 jfloat startAngle, jfloat arcAngle) {
293 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillEllipseArc)) {
294 DRAWING_Status status = DRAWING_DONE;
295 UI_LOG_DRAW_START(fillEllipseArc, gc, x, y, width, height, (uint32_t)startAngle, (uint32_t)arcAngle);
298 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
300 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
301 status = UI_DRAWING_fillEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
303 LLUI_DISPLAY_setDrawingStatus(status);
304 UI_LOG_DRAW_END(fillEllipseArc, status);
309 void LLUI_PAINTER_IMPL_drawEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
310 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawEllipse)) {
311 DRAWING_Status status = DRAWING_DONE;
312 UI_LOG_DRAW_START(drawEllipse, gc, x, y, width, height);
315 if ((width > 0) && (height > 0)) {
317 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
318 status = UI_DRAWING_drawEllipse(gc, x, y, width, height);
320 LLUI_DISPLAY_setDrawingStatus(status);
321 UI_LOG_DRAW_END(drawEllipse, status);
326 void LLUI_PAINTER_IMPL_fillEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
327 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillEllipse)) {
328 DRAWING_Status status = DRAWING_DONE;
329 UI_LOG_DRAW_START(fillEllipse, gc, x, y, width, height);
332 if ((width > 0) && (height > 0)) {
334 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
335 status = UI_DRAWING_fillEllipse(gc, x, y, width, height);
337 LLUI_DISPLAY_setDrawingStatus(status);
338 UI_LOG_DRAW_END(fillEllipse, status);
343 void LLUI_PAINTER_IMPL_drawCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter) {
344 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawCircle)) {
345 DRAWING_Status status = DRAWING_DONE;
346 UI_LOG_DRAW_START(drawCircle, gc, x, y, diameter);
351 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
352 status = UI_DRAWING_drawCircle(gc, x, y, diameter);
354 LLUI_DISPLAY_setDrawingStatus(status);
355 UI_LOG_DRAW_END(drawCircle, status);
360 void LLUI_PAINTER_IMPL_fillCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter) {
361 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_fillCircle)) {
362 DRAWING_Status status = DRAWING_DONE;
363 UI_LOG_DRAW_START(fillCircle, gc, x, y, diameter);
368 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
369 status = UI_DRAWING_fillCircle(gc, x, y, diameter);
371 LLUI_DISPLAY_setDrawingStatus(status);
372 UI_LOG_DRAW_END(fillCircle, status);
377 void LLUI_PAINTER_IMPL_drawImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
378 jint width, jint height, jint x, jint y, jint alpha) {
379 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback) & LLUI_PAINTER_IMPL_drawImage)) {
380 DRAWING_Status status = DRAWING_DONE;
381 UI_LOG_DRAW_START(drawImage, gc, UI_LOG_BUFFER(img), regionX, regionY, width, height, x, y, alpha);
384 if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
386 jint l_alpha = (alpha > 255) ? 255 : alpha;
389 _check_bound(img->width, ®ionX, &width, &x);
390 _check_bound(img->height, ®ionY, &height, &y);
393 _check_bound(gc->image.width, &x, &width, ®ionX);
394 _check_bound(gc->image.height, &y, &height, ®ionY);
396 if ((width > 0) && (height > 0)) {
398 if (LLUI_DISPLAY_clipRegion(gc, ®ionX, ®ionY, &width, &height, &x, &y)) {
399 LLUI_DISPLAY_configureClip(gc,
false );
400 UI_LOG_START(DrawnRegion, UI_LOG_BUFFER(&gc->image),
true, x, y, width, height);
402 if (gc->image.format == img->format) {
405 MICROUI_Image *image = LLUI_DISPLAY_getSourceImage(img);
407 if ((0xff == l_alpha) && !LLUI_DISPLAY_isTransparent(img)) {
409 status = UI_DRAWING_copyImage(gc, image, regionX, regionY, width, height, x, y);
410 }
else if (LLUI_DISPLAY_getBufferAddress(img) == LLUI_DISPLAY_getBufferAddress(&gc->image)) {
412 status = UI_DRAWING_drawRegion(gc, regionX, regionY, width, height, x, y, l_alpha);
415 status = UI_DRAWING_drawImage(gc, image, regionX, regionY, width, height, x, y, l_alpha);
419 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
422 UI_LOG_START(OutOfClip, UI_LOG_BUFFER(&gc->image));
430 LLUI_DISPLAY_setDrawingStatus(status);
431 UI_LOG_DRAW_END(drawImage, status);
436 void LLUI_PAINTER_IMPL_drawString(MICROUI_GraphicsContext *gc, jchar *chars, jint offset, jint length,
437 MICROUI_Font *font, jint x, jint y) {
438 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawString)) {
439 DRAWING_Status status = DRAWING_DONE;
440 UI_LOG_DRAW_START(drawString, gc, length, x, y);
442 status = UI_DRAWING_drawString(gc, chars + offset, length, font, x, y);
444 LLUI_DISPLAY_setDrawingStatus(status);
445 UI_LOG_DRAW_END(drawString, status);
450 jint LLUI_PAINTER_IMPL_stringWidth(jchar *chars, jint offset, jint length, MICROUI_Font *font) {
451 UI_LOG_START(stringWidth, length);
452 return length <= 0 ? 0 : UI_DRAWING_stringWidth(chars + offset, length, font);
456 jint LLUI_PAINTER_IMPL_initializeRenderableStringSNIContext(jchar *chars, jint offset, jint length, MICROUI_Font *font,
457 MICROUI_RenderableString *renderableString) {
460 ret = UI_DRAWING_initializeRenderableStringSNIContext(chars + offset, length, font, renderableString);
466 void LLUI_PAINTER_IMPL_drawRenderableString(MICROUI_GraphicsContext *gc, jchar *chars, jint offset, jint length,
467 MICROUI_Font *font, jint width, MICROUI_RenderableString *renderableString,
469 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawRenderableString)) {
470 DRAWING_Status status = DRAWING_DONE;
471 UI_LOG_DRAW_START(drawRenderableString, gc, length, x, y);
473 status = UI_DRAWING_drawRenderableString(gc, chars + offset, length, font, width, renderableString, x, y);
475 LLUI_DISPLAY_setDrawingStatus(status);
476 UI_LOG_DRAW_END(drawRenderableString, status);