21 #include <LLUI_PAINTER_impl.h> 24 #include <LLUI_DISPLAY.h> 27 #include <LLUI_DISPLAY_impl.h> 30 #include "ui_drawing.h" 36 #if (defined(LLUI_MAJOR_VERSION) && (LLUI_MAJOR_VERSION != 13)) || (defined(LLUI_MINOR_VERSION) && (LLUI_MINOR_VERSION < 5)) 37 #error "This CCO is only compatible with UI Pack [13.5.0,14.0.0[" 41 #define LOG_DRAW_START(fn) LLUI_DISPLAY_logDrawingStart(CONCAT_DEFINES(LOG_DRAW_, fn)) 42 #define LOG_DRAW_END(fn) LLUI_DISPLAY_logDrawingEnd(CONCAT_DEFINES(LOG_DRAW_, fn)) 47 #define LOG_DRAW_writePixel 1 48 #define LOG_DRAW_drawLine 2 49 #define LOG_DRAW_drawHorizontalLine 3 50 #define LOG_DRAW_drawVerticalLine 4 51 #define LOG_DRAW_drawRectangle 5 52 #define LOG_DRAW_fillRectangle 6 53 #define LOG_DRAW_drawRoundedRectangle 8 54 #define LOG_DRAW_fillRoundedRectangle 9 55 #define LOG_DRAW_drawCircleArc 10 56 #define LOG_DRAW_fillCircleArc 11 57 #define LOG_DRAW_drawEllipseArc 12 58 #define LOG_DRAW_fillEllipseArc 13 59 #define LOG_DRAW_drawEllipse 14 60 #define LOG_DRAW_fillEllipse 15 61 #define LOG_DRAW_drawCircle 16 62 #define LOG_DRAW_fillCircle 17 63 #define LOG_DRAW_drawARGB 18 64 #define LOG_DRAW_drawImage 19 74 static inline void _check_bound(jint max, jint* bound, jint* size, jint* origin) {
81 if ((*bound + *size) > max) {
91 void LLUI_PAINTER_IMPL_writePixel(MICROUI_GraphicsContext* gc, jint x, jint y) {
92 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_writePixel)) {
93 DRAWING_Status status;
94 LOG_DRAW_START(writePixel);
95 if (LLUI_DISPLAY_isPixelInClip(gc, x, y)) {
96 LLUI_DISPLAY_configureClip(gc,
false);
97 status = UI_DRAWING_writePixel(gc, x, y);
101 status = DRAWING_DONE;
103 LLUI_DISPLAY_setDrawingStatus(status);
104 LOG_DRAW_END(writePixel);
109 void LLUI_PAINTER_IMPL_drawLine(MICROUI_GraphicsContext* gc, jint startX, jint startY, jint endX, jint endY) {
110 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawLine)) {
111 LOG_DRAW_START(drawLine);
113 LLUI_DISPLAY_setDrawingStatus(UI_DRAWING_drawLine(gc, startX, startY, endX, endY));
114 LOG_DRAW_END(drawLine);
119 void LLUI_PAINTER_IMPL_drawHorizontalLine(MICROUI_GraphicsContext* gc, jint x, jint y, jint length) {
120 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawHorizontalLine)) {
121 DRAWING_Status status;
122 LOG_DRAW_START(drawHorizontalLine);
125 jint x2 = x + length - 1;
128 if ((length > 0) && LLUI_DISPLAY_clipHorizontalLine(gc, &x1, &x2, y)) {
129 LLUI_DISPLAY_configureClip(gc,
false );
130 status = UI_DRAWING_drawHorizontalLine(gc, x1, x2, y);
134 status = DRAWING_DONE;
136 LLUI_DISPLAY_setDrawingStatus(status);
137 LOG_DRAW_END(drawHorizontalLine);
142 void LLUI_PAINTER_IMPL_drawVerticalLine(MICROUI_GraphicsContext* gc, jint x, jint y, jint length) {
143 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawVerticalLine)) {
144 DRAWING_Status status;
145 LOG_DRAW_START(drawVerticalLine);
148 jint y2 = y + length - 1;
151 if ((length > 0) && LLUI_DISPLAY_clipVerticalLine(gc, &y1, &y2, x)) {
152 LLUI_DISPLAY_configureClip(gc,
false );
153 status = UI_DRAWING_drawVerticalLine(gc, x, y1, y2);
157 status = DRAWING_DONE;
159 LLUI_DISPLAY_setDrawingStatus(status);
160 LOG_DRAW_END(drawVerticalLine);
165 void LLUI_PAINTER_IMPL_drawRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
166 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawRectangle)) {
167 DRAWING_Status status;
168 LOG_DRAW_START(drawRectangle);
171 if ((width > 0) && (height > 0)) {
173 jint x2 = x + width - 1;
175 jint y2 = y + height - 1;
178 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRectangleInClip(gc, x1, y1, x2, y2));
179 status = UI_DRAWING_drawRectangle(gc, x1, y1, x2, y2);
183 status = DRAWING_DONE;
185 LLUI_DISPLAY_setDrawingStatus(status);
186 LOG_DRAW_END(drawRectangle);
191 void LLUI_PAINTER_IMPL_fillRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
192 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillRectangle)) {
193 DRAWING_Status status;
194 LOG_DRAW_START(fillRectangle);
197 jint x2 = x + width - 1;
199 jint y2 = y + height - 1;
202 if ((width > 0) && (height) > 0 && LLUI_DISPLAY_clipRectangle(gc, &x1, &y1, &x2, &y2)) {
203 LLUI_DISPLAY_configureClip(gc,
false );
204 status = UI_DRAWING_fillRectangle(gc, x1, y1, x2, y2);
209 status = DRAWING_DONE;
211 LLUI_DISPLAY_setDrawingStatus(status);
212 LOG_DRAW_END(fillRectangle);
217 void LLUI_PAINTER_IMPL_drawRoundedRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, 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);
230 status = DRAWING_DONE;
232 LLUI_DISPLAY_setDrawingStatus(status);
233 LOG_DRAW_END(drawRoundedRectangle);
238 void LLUI_PAINTER_IMPL_fillRoundedRectangle(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, 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);
251 status = DRAWING_DONE;
253 LLUI_DISPLAY_setDrawingStatus(status);
254 LOG_DRAW_END(fillRoundedRectangle);
259 void LLUI_PAINTER_IMPL_drawCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle) {
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);
272 status = DRAWING_DONE;
274 LLUI_DISPLAY_setDrawingStatus(status);
275 LOG_DRAW_END(drawCircleArc);
280 void LLUI_PAINTER_IMPL_drawEllipseArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, 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);
293 status = DRAWING_DONE;
295 LLUI_DISPLAY_setDrawingStatus(status);
296 LOG_DRAW_END(drawEllipseArc);
301 void LLUI_PAINTER_IMPL_fillCircleArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter, jfloat startAngle, jfloat arcAngle) {
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);
314 status = DRAWING_DONE;
316 LLUI_DISPLAY_setDrawingStatus(status);
317 LOG_DRAW_END(fillCircleArc);
322 void LLUI_PAINTER_IMPL_fillEllipseArc(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height, 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);
335 status = DRAWING_DONE;
337 LLUI_DISPLAY_setDrawingStatus(status);
338 LOG_DRAW_END(fillEllipseArc);
343 void LLUI_PAINTER_IMPL_drawEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
344 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawEllipse)) {
345 DRAWING_Status status;
346 LOG_DRAW_START(drawEllipse);
349 if ((width > 0) && (height > 0)) {
351 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
352 status = UI_DRAWING_drawEllipse(gc, x, y, width, height);
356 status = DRAWING_DONE;
358 LLUI_DISPLAY_setDrawingStatus(status);
359 LOG_DRAW_END(drawEllipse);
364 void LLUI_PAINTER_IMPL_fillEllipse(MICROUI_GraphicsContext* gc, jint x, jint y, jint width, jint height) {
365 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillEllipse)) {
366 DRAWING_Status status;
367 LOG_DRAW_START(fillEllipse);
370 if ((width > 0) && (height > 0)) {
372 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, width, height));
373 status = UI_DRAWING_fillEllipse(gc, x, y, width, height);
377 status = DRAWING_DONE;
379 LLUI_DISPLAY_setDrawingStatus(status);
380 LOG_DRAW_END(fillEllipse);
385 void LLUI_PAINTER_IMPL_drawCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter) {
386 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawCircle)) {
387 DRAWING_Status status;
388 LOG_DRAW_START(drawCircle);
393 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
394 status = UI_DRAWING_drawCircle(gc, x, y, diameter);
398 status = DRAWING_DONE;
400 LLUI_DISPLAY_setDrawingStatus(status);
401 LOG_DRAW_END(drawCircle);
406 void LLUI_PAINTER_IMPL_fillCircle(MICROUI_GraphicsContext* gc, jint x, jint y, jint diameter) {
407 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_fillCircle)) {
408 DRAWING_Status status;
409 LOG_DRAW_START(fillCircle);
414 LLUI_DISPLAY_configureClip(gc, !LLUI_DISPLAY_isRegionInClip(gc, x, y, diameter, diameter));
415 status = UI_DRAWING_fillCircle(gc, x, y, diameter);
419 status = DRAWING_DONE;
421 LLUI_DISPLAY_setDrawingStatus(status);
422 LOG_DRAW_END(fillCircle);
427 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) {
428 if (LLUI_DISPLAY_requestDrawing(gc, (SNI_callback)&LLUI_PAINTER_IMPL_drawImage)) {
429 DRAWING_Status status = DRAWING_DONE;
430 LOG_DRAW_START(drawImage);
433 if (!LLUI_DISPLAY_isClosed(img) && (alpha > 0)) {
436 jint l_alpha = (alpha > 255) ? 255 : alpha;
439 _check_bound(img->width, ®ionX, &width, &x);
440 _check_bound(img->height, ®ionY, &height, &y);
443 _check_bound(gc->image.width, &x, &width, ®ionX);
444 _check_bound(gc->image.height, &y, &height, ®ionY);
446 if ((width > 0) && (height > 0) && LLUI_DISPLAY_clipRegion(gc, ®ionX, ®ionY, &width, &height, &x, &y)) {
448 LLUI_DISPLAY_configureClip(gc,
false );
450 if (gc->image.format == img->format) {
453 if ((0xff == l_alpha) && !LLUI_DISPLAY_isTransparent(img)) {
455 status = UI_DRAWING_copyImage(gc, img, regionX, regionY, width, height, x, y);
457 else if (img == &gc->image){
459 status = UI_DRAWING_drawRegion(gc, regionX, regionY, width, height, x, y, l_alpha);
463 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
468 status = UI_DRAWING_drawImage(gc, img, regionX, regionY, width, height, x, y, l_alpha);
476 LLUI_DISPLAY_setDrawingStatus(status);
477 LOG_DRAW_END(drawImage);