22 #include <LLUI_PAINTER_impl.h>
25 #include <LLUI_DISPLAY.h>
28 #include <LLUI_DISPLAY_impl.h>
31 #include "ui_drawing.h"
40 #if (defined(LLUI_MAJOR_VERSION) && (LLUI_MAJOR_VERSION != 14)) || (defined(LLUI_MINOR_VERSION) && \
41 (LLUI_MINOR_VERSION < 0))
42 #error "This Abstraction Layer is only compatible with UI Pack [14.0.0,15.0.0["
53 static inline void _check_bound(jint max, jint *bound, jint *size, jint *origin) {
60 if ((*bound + *size) > max) {
70 void LLUI_PAINTER_IMPL_writePixel(MICROUI_GraphicsContext *gc, jint x, jint y) {
71 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_writePixel)) {
72 DRAWING_Status status = DRAWING_DONE;
73 UI_TRACE_DRAW_START(writePixel, gc, x, y);
74 if (LLUI_DISPLAY_isPixelInClip(gc, x, y)) {
75 LLUI_DISPLAY_configureClip(gc,
false );
76 status = UI_DRAWING_writePixel(gc, x, y);
78 UI_TRACE_START(OutOfClip, UI_TRACE_IMAGE(&gc->image));
80 LLUI_DISPLAY_setDrawingStatus(status);
81 UI_TRACE_DRAW_END(writePixel, status);
86 void LLUI_PAINTER_IMPL_drawLine(MICROUI_GraphicsContext *gc, jint startX, jint startY, jint endX, jint endY) {
87 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawLine)) {
88 UI_TRACE_DRAW_START(drawLine, gc, startX, startY, endX, endY);
90 DRAWING_Status status = UI_DRAWING_drawLine(gc, startX, startY, endX, endY);
91 LLUI_DISPLAY_setDrawingStatus(status);
92 UI_TRACE_DRAW_END(drawLine, status);
97 void LLUI_PAINTER_IMPL_drawHorizontalLine(MICROUI_GraphicsContext *gc, jint x, jint y, jint length) {
98 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawHorizontalLine)) {
99 DRAWING_Status status = DRAWING_DONE;
100 UI_TRACE_DRAW_START(drawHorizontalLine, gc, x, y, length);
104 jint x2 = x + length - 1;
105 if (LLUI_DISPLAY_clipHorizontalLine(gc, &x1, &x2, y)) {
106 LLUI_DISPLAY_configureClip(gc,
false );
107 UI_TRACE_START(DrawnRegion, UI_TRACE_IMAGE(&gc->image),
true, x1, y, x2 - x1 + 1, 1);
108 status = UI_DRAWING_drawHorizontalLine(gc, x1, x2, y);
110 UI_TRACE_START(OutOfClip, UI_TRACE_IMAGE(&gc->image));
114 LLUI_DISPLAY_setDrawingStatus(status);
115 UI_TRACE_DRAW_END(drawHorizontalLine, status);
120 void LLUI_PAINTER_IMPL_drawVerticalLine(MICROUI_GraphicsContext *gc, jint x, jint y, jint length) {
121 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawVerticalLine)) {
122 DRAWING_Status status = DRAWING_DONE;
123 UI_TRACE_DRAW_START(drawVerticalLine, gc, x, y, length);
127 jint y2 = y + length - 1;
128 if (LLUI_DISPLAY_clipVerticalLine(gc, &y1, &y2, x)) {
129 LLUI_DISPLAY_configureClip(gc,
false );
130 UI_TRACE_START(DrawnRegion, UI_TRACE_IMAGE(&gc->image),
true, x, y1, 1, y2 - y1 + 1);
131 status = UI_DRAWING_drawVerticalLine(gc, x, y1, y2);
133 UI_TRACE_START(OutOfClip, UI_TRACE_IMAGE(&gc->image));
137 LLUI_DISPLAY_setDrawingStatus(status);
138 UI_TRACE_DRAW_END(drawVerticalLine, status);
143 void LLUI_PAINTER_IMPL_drawRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
144 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawRectangle)) {
145 DRAWING_Status status = DRAWING_DONE;
146 UI_TRACE_DRAW_START(drawRectangle, gc, x, y, width, height);
148 if ((width > 0) && (height > 0)) {
150 jint x2 = x + width - 1;
152 jint y2 = y + height - 1;
155 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRectangleInClip(gc, x1, y1, x2, y2));
156 status = UI_DRAWING_drawRectangle(gc, x1, y1, x2, y2);
159 LLUI_DISPLAY_setDrawingStatus(status);
160 UI_TRACE_DRAW_END(drawRectangle, status);
165 void LLUI_PAINTER_IMPL_fillRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
166 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_fillRectangle)) {
167 DRAWING_Status status = DRAWING_DONE;
168 UI_TRACE_DRAW_START(fillRectangle, gc, x, y, width, height);
170 if ((width > 0) && (height > 0)) {
172 jint x2 = x + width - 1;
174 jint y2 = y + height - 1;
176 if (LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
177 LLUI_DISPLAY_configureClip(gc,
false );
178 UI_TRACE_START(DrawnRegion, UI_TRACE_IMAGE(&gc->image),
true, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
179 status = UI_DRAWING_fillRectangle(gc, x1, y1, x2, y2);
181 UI_TRACE_START(OutOfClip, UI_TRACE_IMAGE(&gc->image));
184 LLUI_DISPLAY_setDrawingStatus(status);
185 UI_TRACE_DRAW_END(fillRectangle, status);
190 void LLUI_PAINTER_IMPL_drawRoundedRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
191 jint cornerEllipseWidth, jint cornerEllipseHeight) {
192 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawRoundedRectangle)) {
193 DRAWING_Status status = DRAWING_DONE;
194 UI_TRACE_DRAW_START(drawRoundedRectangle, gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
197 if ((width > 0) && (height > 0)) {
199 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
200 status = UI_DRAWING_drawRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
202 LLUI_DISPLAY_setDrawingStatus(status);
203 UI_TRACE_DRAW_END(drawRoundedRectangle, status);
208 void LLUI_PAINTER_IMPL_fillRoundedRectangle(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
209 jint cornerEllipseWidth, jint cornerEllipseHeight) {
210 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_fillRoundedRectangle)) {
211 DRAWING_Status status = DRAWING_DONE;
212 UI_TRACE_DRAW_START(fillRoundedRectangle, gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
215 if ((width > 0) && (height > 0)) {
217 jint x2 = x + width - 1;
219 jint y2 = y + height - 1;
221 if (LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
224 bool disable_clip = LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height);
225 LLUI_DISPLAY_configureClip(gc, !disable_clip);
226 UI_TRACE_START(DrawnRegion, UI_TRACE_IMAGE(&gc->image), disable_clip, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
227 status = UI_DRAWING_fillRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth,
228 cornerEllipseHeight);
230 UI_TRACE_START(OutOfClip, UI_TRACE_IMAGE(&gc->image));
233 LLUI_DISPLAY_setDrawingStatus(status);
234 UI_TRACE_DRAW_END(fillRoundedRectangle, status);
239 void LLUI_PAINTER_IMPL_drawCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
241 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawCircleArc)) {
242 DRAWING_Status status = DRAWING_DONE;
243 UI_TRACE_DRAW_START(drawCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle);
246 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
248 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
249 status = UI_DRAWING_drawCircleArc(gc, x, y, diameter, startAngle, arcAngle);
251 LLUI_DISPLAY_setDrawingStatus(status);
252 UI_TRACE_DRAW_END(drawCircleArc, status);
257 void LLUI_PAINTER_IMPL_drawEllipseArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
258 jfloat startAngle, jfloat arcAngle) {
259 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawEllipseArc)) {
260 DRAWING_Status status = DRAWING_DONE;
261 UI_TRACE_DRAW_START(drawEllipseArc, gc, x, y, width, height, (uint32_t)startAngle, (uint32_t)arcAngle);
264 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
266 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
267 status = UI_DRAWING_drawEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
269 LLUI_DISPLAY_setDrawingStatus(status);
270 UI_TRACE_DRAW_END(drawEllipseArc, status);
275 void LLUI_PAINTER_IMPL_fillCircleArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter, jfloat startAngle,
277 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_fillCircleArc)) {
278 DRAWING_Status status = DRAWING_DONE;
279 UI_TRACE_DRAW_START(fillCircleArc, gc, x, y, diameter, (uint32_t)startAngle, (uint32_t)arcAngle);
282 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
284 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
285 status = UI_DRAWING_fillCircleArc(gc, x, y, diameter, startAngle, arcAngle);
287 LLUI_DISPLAY_setDrawingStatus(status);
288 UI_TRACE_DRAW_END(fillCircleArc, status);
293 void LLUI_PAINTER_IMPL_fillEllipseArc(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height,
294 jfloat startAngle, jfloat arcAngle) {
295 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_fillEllipseArc)) {
296 DRAWING_Status status = DRAWING_DONE;
297 UI_TRACE_DRAW_START(fillEllipseArc, gc, x, y, width, height, (uint32_t)startAngle, (uint32_t)arcAngle);
300 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
302 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
303 status = UI_DRAWING_fillEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
305 LLUI_DISPLAY_setDrawingStatus(status);
306 UI_TRACE_DRAW_END(fillEllipseArc, status);
311 void LLUI_PAINTER_IMPL_drawEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
312 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawEllipse)) {
313 DRAWING_Status status = DRAWING_DONE;
314 UI_TRACE_DRAW_START(drawEllipse, gc, x, y, width, height);
317 if ((width > 0) && (height > 0)) {
319 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
320 status = UI_DRAWING_drawEllipse(gc, x, y, width, height);
322 LLUI_DISPLAY_setDrawingStatus(status);
323 UI_TRACE_DRAW_END(drawEllipse, status);
328 void LLUI_PAINTER_IMPL_fillEllipse(MICROUI_GraphicsContext *gc, jint x, jint y, jint width, jint height) {
329 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_fillEllipse)) {
330 DRAWING_Status status = DRAWING_DONE;
331 UI_TRACE_DRAW_START(fillEllipse, gc, x, y, width, height);
334 if ((width > 0) && (height > 0)) {
336 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
337 status = UI_DRAWING_fillEllipse(gc, x, y, width, height);
339 LLUI_DISPLAY_setDrawingStatus(status);
340 UI_TRACE_DRAW_END(fillEllipse, status);
345 void LLUI_PAINTER_IMPL_drawCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter) {
346 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawCircle)) {
347 DRAWING_Status status = DRAWING_DONE;
348 UI_TRACE_DRAW_START(drawCircle, gc, x, y, diameter);
353 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
354 status = UI_DRAWING_drawCircle(gc, x, y, diameter);
356 LLUI_DISPLAY_setDrawingStatus(status);
357 UI_TRACE_DRAW_END(drawCircle, status);
362 void LLUI_PAINTER_IMPL_fillCircle(MICROUI_GraphicsContext *gc, jint x, jint y, jint diameter) {
363 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_fillCircle)) {
364 DRAWING_Status status = DRAWING_DONE;
365 UI_TRACE_DRAW_START(fillCircle, gc, x, y, diameter);
370 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
371 status = UI_DRAWING_fillCircle(gc, x, y, diameter);
373 LLUI_DISPLAY_setDrawingStatus(status);
374 UI_TRACE_DRAW_END(fillCircle, status);
379 void LLUI_PAINTER_IMPL_drawImage(MICROUI_GraphicsContext *gc, MICROUI_Image *img, jint regionX, jint regionY,
380 jint width, jint height, jint x, jint y, jint alpha) {
381 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawImage)) {
382 DRAWING_Status status = DRAWING_DONE;
383 UI_TRACE_DRAW_START(drawImage, gc, UI_TRACE_IMAGE(img), regionX, regionY, width, height, x, y, alpha);
386 if (!LLUI_DISPLAY_isImageClosed(img) && (alpha > 0)) {
388 jint l_alpha = (alpha > 255) ? 255 : alpha;
391 _check_bound(img->width, ®ionX, &width, &x);
392 _check_bound(img->height, ®ionY, &height, &y);
395 _check_bound(gc->image.width, &x, &width, ®ionX);
396 _check_bound(gc->image.height, &y, &height, ®ionY);
398 if ((width > 0) && (height > 0)) {
399 if (LLUI_DISPLAY_clipRegion(gc, ®ionX, ®ionY, &width, &height, &x, &y)) {
400 LLUI_DISPLAY_configureClip(gc,
false );
401 UI_TRACE_START(DrawnRegion, UI_TRACE_IMAGE(&gc->image),
true, x, y, width, height);
403 if (gc->image.format == img->format) {
406 MICROUI_Image *image = LLUI_DISPLAY_getSourceImage(img);
408 if ((0xff == l_alpha) && !LLUI_DISPLAY_isTransparent(img)) {
410 status = UI_DRAWING_copyImage(gc, image, regionX, regionY, width, height, x, y);
411 }
else if (LLUI_DISPLAY_getBufferAddress(img) == LLUI_DISPLAY_getBufferAddress(&gc->image)) {
413 status = UI_DRAWING_drawRegion(gc, regionX, regionY, width, height, x, y, l_alpha);
416 status = UI_DRAWING_drawImage(gc, image, regionX, regionY, width, height, x, y, l_alpha);
420 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
423 UI_TRACE_START(OutOfClip, UI_TRACE_IMAGE(&gc->image));
431 LLUI_DISPLAY_setDrawingStatus(status);
432 UI_TRACE_DRAW_END(drawImage, status);
437 void LLUI_PAINTER_IMPL_drawString(MICROUI_GraphicsContext *gc, jchar *chars, jint offset, jint length,
438 MICROUI_Font *font, jint x, jint y) {
439 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawString)) {
440 DRAWING_Status status = DRAWING_DONE;
441 UI_TRACE_DRAW_START(drawString, gc, length, x, y);
443 status = UI_DRAWING_drawString(gc, chars + offset, length, font, x, y);
445 LLUI_DISPLAY_setDrawingStatus(status);
446 UI_TRACE_DRAW_END(drawString, status);
451 jint LLUI_PAINTER_IMPL_stringWidth(jchar *chars, jint offset, jint length, MICROUI_Font *font) {
452 UI_TRACE_START(stringWidth, length);
453 return (length <= 0) ? 0 : UI_DRAWING_stringWidth(chars + offset, length, font);
457 jint LLUI_PAINTER_IMPL_initializeRenderableStringSNIContext(jchar *chars, jint offset, jint length, MICROUI_Font *font,
458 MICROUI_RenderableString *renderableString) {
461 ret = UI_DRAWING_initializeRenderableStringSNIContext(chars + offset, length, font, renderableString);
467 void LLUI_PAINTER_IMPL_drawRenderableString(MICROUI_GraphicsContext *gc, jchar *chars, jint offset, jint length,
468 MICROUI_Font *font, jint width, MICROUI_RenderableString *renderableString,
470 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)LLUI_PAINTER_IMPL_drawRenderableString)) {
471 DRAWING_Status status = DRAWING_DONE;
472 UI_TRACE_DRAW_START(drawRenderableString, gc, length, x, y);
474 status = UI_DRAWING_drawRenderableString(gc, chars + offset, length, font, width, renderableString, x, y);
476 LLUI_DISPLAY_setDrawingStatus(status);
477 UI_TRACE_DRAW_END(drawRenderableString, status);