22 #include "LLUI_PAINTER_impl.h" 25 #include "ui_drawing.h" 28 #include "LLUI_DISPLAY.h" 39 #define LOG_DRAW_START(fn) LLUI_DISPLAY_logDrawingStart(CONCAT_DEFINES(LOG_DRAW_, fn)) 40 #define LOG_DRAW_END(fn) LLUI_DISPLAY_logDrawingEnd(CONCAT_DEFINES(LOG_DRAW_, fn)) 45 #define LOG_DRAW_writePixel 1 46 #define LOG_DRAW_drawLine 2 47 #define LOG_DRAW_drawHorizontalLine 3 48 #define LOG_DRAW_drawVerticalLine 4 49 #define LOG_DRAW_drawRectangle 5 50 #define LOG_DRAW_fillRectangle 6 51 #define LOG_DRAW_drawRoundedRectangle 8 52 #define LOG_DRAW_fillRoundedRectangle 9 53 #define LOG_DRAW_drawCircleArc 10 54 #define LOG_DRAW_fillCircleArc 11 55 #define LOG_DRAW_drawEllipseArc 12 56 #define LOG_DRAW_fillEllipseArc 13 57 #define LOG_DRAW_drawEllipse 14 58 #define LOG_DRAW_fillEllipse 15 59 #define LOG_DRAW_drawCircle 16 60 #define LOG_DRAW_fillCircle 17 61 #define LOG_DRAW_drawARGB 18 62 #define LOG_DRAW_drawImage 19 72 static inline void _check_bound(jint max, jint* bound, jint* size, jint* origin) {
79 if ((*bound + *size) > max) {
88 void LLUI_PAINTER_IMPL_writePixel(MICROUI_GraphicsContext* gc, jint x, jint y) {
89 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_writePixel)) {
90 DRAWING_Status status;
91 LOG_DRAW_START(writePixel);
92 if (LLUI_DISPLAY_isPixelInClip(gc, x, y)) {
93 LLUI_DISPLAY_configureClip(gc,
false);
94 status = UI_DRAWING_writePixel(gc, x, y);
98 status = DRAWING_DONE;
100 LLUI_DISPLAY_setDrawingStatus(status);
101 LOG_DRAW_END(writePixel);
106 void LLUI_PAINTER_IMPL_drawLine(MICROUI_GraphicsContext* gc, jint startX, jint startY, jint endX, jint endY) {
107 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawLine)) {
108 LOG_DRAW_START(drawLine);
110 LLUI_DISPLAY_setDrawingStatus(UI_DRAWING_drawLine(gc, startX, startY, endX, endY));
111 LOG_DRAW_END(drawLine);
116 void LLUI_PAINTER_IMPL_drawHorizontalLine(MICROUI_GraphicsContext* gc, jint x, jint y, jint length) {
117 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawHorizontalLine)) {
118 DRAWING_Status status;
119 LOG_DRAW_START(drawHorizontalLine);
122 jint x2 = x + length - 1;
125 if ((length > 0) && LLUI_DISPLAY_clipHorizontalLine(gc, &x1, &x2, y)) {
126 LLUI_DISPLAY_configureClip(gc,
false );
127 status = UI_DRAWING_drawHorizontalLine(gc, x1, x2, y);
131 status = DRAWING_DONE;
133 LLUI_DISPLAY_setDrawingStatus(status);
134 LOG_DRAW_END(drawHorizontalLine);
139 void LLUI_PAINTER_IMPL_drawVerticalLine(MICROUI_GraphicsContext* gc, jint x, jint y, jint length) {
140 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawVerticalLine)) {
141 DRAWING_Status status;
142 LOG_DRAW_START(drawVerticalLine);
145 jint y2 = y + length - 1;
148 if ((length > 0) && LLUI_DISPLAY_clipVerticalLine(gc, &y1, &y2, x)) {
149 LLUI_DISPLAY_configureClip(gc,
false );
150 status = UI_DRAWING_drawVerticalLine(gc, x, y1, y2);
154 status = DRAWING_DONE;
156 LLUI_DISPLAY_setDrawingStatus(status);
157 LOG_DRAW_END(drawVerticalLine);
162 void LLUI_PAINTER_IMPL_drawRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
163 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawRectangle)) {
164 DRAWING_Status status;
165 LOG_DRAW_START(drawRectangle);
168 if ((width > 0) && (height > 0)) {
170 jint x2 = x + width - 1;
172 jint y2 = y + height - 1;
175 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRectangleInClip(gc, x1, y1, x2, y2));
176 status = UI_DRAWING_drawRectangle(gc, x1, y1, x2, y2);
180 status = DRAWING_DONE;
182 LLUI_DISPLAY_setDrawingStatus(status);
183 LOG_DRAW_END(drawRectangle);
188 void LLUI_PAINTER_IMPL_fillRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
189 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillRectangle)) {
190 DRAWING_Status status;
191 LOG_DRAW_START(fillRectangle);
194 jint x2 = x + width - 1;
196 jint y2 = y + height - 1;
199 if ((width > 0) && (height) > 0 && LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
200 LLUI_DISPLAY_configureClip(gc,
false );
201 status = UI_DRAWING_fillRectangle(gc, x1, y1, x2, y2);
205 status = DRAWING_DONE;
207 LLUI_DISPLAY_setDrawingStatus(status);
208 LOG_DRAW_END(fillRectangle);
213 void LLUI_PAINTER_IMPL_drawRoundedRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jint cornerEllipseWidth, jint cornerEllipseHeight) {
214 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawRoundedRectangle)) {
215 DRAWING_Status status;
216 LOG_DRAW_START(drawRoundedRectangle);
219 if ((width > 0) && (height > 0)) {
221 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
222 status = UI_DRAWING_drawRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
226 status = DRAWING_DONE;
228 LLUI_DISPLAY_setDrawingStatus(status);
229 LOG_DRAW_END(drawRoundedRectangle);
234 void LLUI_PAINTER_IMPL_fillRoundedRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jint cornerEllipseWidth, jint cornerEllipseHeight) {
235 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillRoundedRectangle)) {
236 DRAWING_Status status;
237 LOG_DRAW_START(fillRoundedRectangle);
240 if ((width > 0) && (height > 0)) {
242 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
243 status = UI_DRAWING_fillRoundedRectangle(gc, x, y, width, height, cornerEllipseWidth, cornerEllipseHeight);
247 status = DRAWING_DONE;
249 LLUI_DISPLAY_setDrawingStatus(status);
250 LOG_DRAW_END(fillRoundedRectangle);
255 void LLUI_PAINTER_IMPL_drawCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle) {
256 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawCircleArc)) {
257 DRAWING_Status status;
258 LOG_DRAW_START(drawCircleArc);
261 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
263 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
264 status = UI_DRAWING_drawCircleArc(gc, x, y, diameter, startAngle, arcAngle);
268 status = DRAWING_DONE;
270 LLUI_DISPLAY_setDrawingStatus(status);
271 LOG_DRAW_END(drawCircleArc);
276 void LLUI_PAINTER_IMPL_drawEllipseArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jfloat startAngle, jfloat arcAngle) {
277 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawEllipseArc)) {
278 DRAWING_Status status;
279 LOG_DRAW_START(drawEllipseArc);
282 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
284 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
285 status = UI_DRAWING_drawEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
289 status = DRAWING_DONE;
291 LLUI_DISPLAY_setDrawingStatus(status);
292 LOG_DRAW_END(drawEllipseArc);
297 void LLUI_PAINTER_IMPL_fillCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle) {
298 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillCircleArc)) {
299 DRAWING_Status status;
300 LOG_DRAW_START(fillCircleArc);
303 if ((diameter > 0) && ((int32_t)arcAngle != 0)) {
305 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
306 status = UI_DRAWING_fillCircleArc(gc, x, y, diameter, startAngle, arcAngle);
310 status = DRAWING_DONE;
312 LLUI_DISPLAY_setDrawingStatus(status);
313 LOG_DRAW_END(fillCircleArc);
318 void LLUI_PAINTER_IMPL_fillEllipseArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, jfloat startAngle, jfloat arcAngle) {
319 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillEllipseArc)) {
320 DRAWING_Status status;
321 LOG_DRAW_START(fillEllipseArc);
324 if ((width > 0) && (height > 0) && ((int32_t)arcAngle != 0)) {
326 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
327 status = UI_DRAWING_fillEllipseArc(gc, x, y, width, height, startAngle, arcAngle);
331 status = DRAWING_DONE;
333 LLUI_DISPLAY_setDrawingStatus(status);
334 LOG_DRAW_END(fillEllipseArc);
339 void LLUI_PAINTER_IMPL_drawEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
340 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawEllipse)) {
341 DRAWING_Status status;
342 LOG_DRAW_START(drawEllipse);
345 if ((width > 0) && (height > 0)) {
347 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
348 status = UI_DRAWING_drawEllipse(gc, x, y, width, height);
352 status = DRAWING_DONE;
354 LLUI_DISPLAY_setDrawingStatus(status);
355 LOG_DRAW_END(drawEllipse);
360 void LLUI_PAINTER_IMPL_fillEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
361 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillEllipse)) {
362 DRAWING_Status status;
363 LOG_DRAW_START(fillEllipse);
366 if ((width > 0) && (height > 0)) {
368 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
369 status = UI_DRAWING_fillEllipse(gc, x, y, width, height);
373 status = DRAWING_DONE;
375 LLUI_DISPLAY_setDrawingStatus(status);
376 LOG_DRAW_END(fillEllipse);
381 void LLUI_PAINTER_IMPL_drawCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter) {
382 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawCircle)) {
383 DRAWING_Status status;
384 LOG_DRAW_START(drawCircle);
389 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
390 status = UI_DRAWING_drawCircle(gc, x, y, diameter);
394 status = DRAWING_DONE;
396 LLUI_DISPLAY_setDrawingStatus(status);
397 LOG_DRAW_END(drawCircle);
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);
415 status = DRAWING_DONE;
417 LLUI_DISPLAY_setDrawingStatus(status);
418 LOG_DRAW_END(fillCircle);
423 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) {
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)) {
432 jint l_alpha = (alpha > 255) ? 255 : alpha;
435 _check_bound(img->width, ®ionX, &width, &x);
436 _check_bound(img->height, ®ionY, &height, &y);
439 _check_bound(gc->image.width, &x, &width, ®ionX);
440 _check_bound(gc->image.height, &y, &height, ®ionY);
442 if ((width > 0) && (height > 0) && LLUI_DISPLAY_clipRegion(gc, ®ionX, ®ionY, &width, &height, &x, &y)) {
444 LLUI_DISPLAY_configureClip(gc,
false );
446 if (gc->image.format == img->format) {
449 if (0xff == l_alpha && !LLUI_DISPLAY_isTransparent(img)) {
451 status = UI_DRAWING_copyImage(gc, img, regionX, regionY, width, height, x, y);
453 else if (img == &gc->image){
455 status = UI_DRAWING_drawRegion(gc, regionX, regionY, width, height, x, y, l_alpha);
459 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
464 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
472 LLUI_DISPLAY_setDrawingStatus(status);
473 LOG_DRAW_END(drawImage);