Skip to content

Commit

Permalink
arch(draw): allow replacing the draw engine
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the API of lv_draw_... function have been changed
  • Loading branch information
kisvegabor committed Dec 21, 2021
1 parent 0831b6b commit db53ea9
Show file tree
Hide file tree
Showing 121 changed files with 3,985 additions and 3,383 deletions.
23 changes: 12 additions & 11 deletions demos/widgets/lv_demo_widgets.c
Expand Up @@ -1280,13 +1280,13 @@ static void slider_event_cb(lv_event_t * e)
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.bg_color = lv_palette_darken(LV_PALETTE_GREY, 3);
rect_dsc.radius = LV_DPX(5);
lv_draw_rect(&bg_area, dsc->clip_area, &rect_dsc);
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &bg_area);

lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = lv_color_white();
label_dsc.font = font_normal;
lv_draw_label(&txt_area, dsc->clip_area, &label_dsc, buf, NULL);
lv_draw_label(dsc->draw_ctx, &label_dsc, &txt_area, buf, NULL);
}
}
}
Expand Down Expand Up @@ -1334,15 +1334,16 @@ static void chart_event_cb(lv_event_t * e)
draw_rect_dsc.bg_color = dsc->line_dsc->color;

lv_area_t obj_clip_area;
_lv_area_intersect(&obj_clip_area, dsc->clip_area, &obj->coords);

_lv_area_intersect(&obj_clip_area, dsc->draw_ctx->clip_area, &obj->coords);
const lv_area_t * clip_area_ori = dsc->draw_ctx->clip_area;
dsc->draw_ctx->clip_area = &obj_clip_area;
lv_area_t a;
a.x1 = dsc->p1->x;
a.x2 = dsc->p2->x - 1;
a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y);
a.y2 = obj->coords.y2;
lv_draw_rect(&a, &obj_clip_area, &draw_rect_dsc);

lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a);
dsc->draw_ctx->clip_area = clip_area_ori;
/*Remove the masks*/
lv_draw_mask_remove_id(line_mask_id);
lv_draw_mask_remove_id(fade_mask_id);
Expand Down Expand Up @@ -1396,13 +1397,13 @@ static void chart_event_cb(lv_event_t * e)
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.bg_color = ser->color;
rect_dsc.radius = LV_DPX(5);
lv_draw_rect(&bg_area, dsc->clip_area, &rect_dsc);
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &bg_area);

lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = lv_color_white();
label_dsc.font = font_normal;
lv_draw_label(&txt_area, dsc->clip_area, &label_dsc, buf, NULL);
lv_draw_label(dsc->draw_ctx, &label_dsc, &txt_area, buf, NULL);
} else {
dsc->rect_dsc->outline_width = 0;
dsc->rect_dsc->shadow_width = 0;
Expand Down Expand Up @@ -1447,18 +1448,18 @@ static void shop_chart_event_cb(lv_event_t * e)
a.y2 = a.y1 + 4 + (devices[dsc->id] * h) / 100; /*+4 to overlap the radius*/
draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_RED);
draw_rect_dsc.radius = 4;
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a);

a.y1 = a.y2 - 4; /*-4 to overlap the radius*/
a.y2 = a.y1 + (clothes[dsc->id] * h) / 100;
draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_BLUE);
draw_rect_dsc.radius = 0;
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
lv_draw_rect( dsc->draw_ctx, &draw_rect_dsc, &a);

a.y1 = a.y2;
a.y2 = a.y1 + (services[dsc->id] * h) / 100;
draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_GREEN);
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
lv_draw_rect( dsc->draw_ctx, &draw_rect_dsc, &a);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/anim/lv_example_anim_timeline_1.c
@@ -1,5 +1,5 @@
#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_FLEX && LV_BUILD_EXAMPLES

static lv_anim_timeline_t * anim_timeline = NULL;

Expand Down
5 changes: 4 additions & 1 deletion examples/libs/ffmpeg/lv_example_ffmpeg_1.c
@@ -1,5 +1,7 @@
#include "../../lv_examples.h"
#if LV_USE_FFMPEG && LV_BUILD_EXAMPLES
#if LV_BUILD_EXAMPLES
#if LV_USE_FFMPEG


/**
* Open an image from a file
Expand All @@ -24,3 +26,4 @@ void lv_example_ffmpeg_1(void)
}

#endif
#endif
4 changes: 3 additions & 1 deletion examples/libs/ffmpeg/lv_example_ffmpeg_2.c
@@ -1,5 +1,6 @@
#include "../../lv_examples.h"
#if LV_USE_FFMPEG && LV_BUILD_EXAMPLES
#if LV_BUILD_EXAMPLES
#if LV_USE_FFMPEG

/**
* Open a video from a file
Expand Down Expand Up @@ -28,3 +29,4 @@ void lv_example_ffmpeg_2(void)
}

#endif
#endif
4 changes: 3 additions & 1 deletion examples/libs/freetype/lv_example_freetype_1.c
@@ -1,5 +1,6 @@
#include "../../lv_examples.h"
#if LV_USE_FREETYPE && LV_BUILD_EXAMPLES
#if LV_BUILD_EXAMPLES
#if LV_USE_FREETYPE

/**
* Load a font with FreeType
Expand Down Expand Up @@ -42,3 +43,4 @@ void lv_example_freetype_1(void)
}

#endif
#endif
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/libs/png/lv_example_png_1.c
@@ -1,5 +1,5 @@
#include "../../lv_examples.h"
#if LV_USE_PNG && LV_BUILD_EXAMPLES
#if LV_USE_PNG && LV_USE_IMG && LV_BUILD_EXAMPLES

/**
* Open a PNG image from a file and a variable
Expand Down
4 changes: 3 additions & 1 deletion examples/libs/rlottie/lv_example_rlottie_1.c
@@ -1,5 +1,6 @@
#include "../../lv_examples.h"
#if LV_USE_RLOTTIE && LV_BUILD_EXAMPLES
#if LV_BUILD_EXAMPLES
#if LV_USE_RLOTTIE

/**
* Load an lottie animation from flash
Expand All @@ -23,3 +24,4 @@ void lv_example_rlottie_1(void)
}

#endif
#endif
4 changes: 3 additions & 1 deletion examples/libs/rlottie/lv_example_rlottie_2.c
@@ -1,5 +1,6 @@
#include "../../lv_examples.h"
#if LV_USE_RLOTTIE && LV_BUILD_EXAMPLES
#if LV_BUILD_EXAMPLES
#if LV_USE_RLOTTIE

/**
* Load an lottie animation from file
Expand All @@ -24,3 +25,4 @@ void lv_example_rlottie_2(void)
}

#endif
#endif
3 changes: 2 additions & 1 deletion examples/others/snapshot/lv_example_snapshot_1.c
Expand Up @@ -31,11 +31,12 @@ void lv_example_snapshot_1(void)
lv_obj_set_style_bg_color(snapshot_obj, lv_palette_main(LV_PALETTE_PURPLE), 0);
lv_obj_set_style_bg_opa(snapshot_obj, LV_OPA_100, 0);
lv_img_set_zoom(snapshot_obj, 128);
lv_img_set_angle(snapshot_obj, 300);

/*Create the container and its children*/
lv_obj_t * container = lv_obj_create(root);

lv_obj_align(container, LV_ALIGN_CENTER, 0, 0);
lv_obj_center(container);
lv_obj_set_size(container, 180, 180);
lv_obj_set_flex_flow(container, LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_flex_align(container, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
Expand Down
2 changes: 1 addition & 1 deletion examples/scroll/lv_example_scroll_6.c
@@ -1,5 +1,5 @@
#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_BUILD_EXAMPLES && LV_USE_FLEX

static void scroll_event_cb(lv_event_t * e)
{
Expand Down
6 changes: 3 additions & 3 deletions examples/styles/lv_example_style_5.c
Expand Up @@ -15,10 +15,10 @@ void lv_example_style_5(void)
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 1));

/*Add a shadow*/
lv_style_set_shadow_width(&style, 25);
lv_style_set_shadow_width(&style, 55);
lv_style_set_shadow_color(&style, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_shadow_ofs_x(&style, 10);
lv_style_set_shadow_ofs_y(&style, 20);
// lv_style_set_shadow_ofs_x(&style, 10);
// lv_style_set_shadow_ofs_y(&style, 20);

/*Create an object with the new style*/
lv_obj_t * obj = lv_obj_create(lv_scr_act());
Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/bar/lv_example_bar_6.c
Expand Up @@ -40,7 +40,7 @@ static void event_cb(lv_event_t * e)
txt_area.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - txt_size.y) / 2;
txt_area.y2 = txt_area.y1 + txt_size.y - 1;

lv_draw_label(&txt_area, dsc->clip_area, &label_dsc, buf, NULL);
lv_draw_label(dsc->draw_ctx, &label_dsc, &txt_area, buf, NULL);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/btnmatrix/lv_example_btnmatrix_2.c
Expand Up @@ -54,7 +54,7 @@ static void event_cb(lv_event_t * e)
img_draw_dsc.recolor = lv_color_black();
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;

lv_draw_img(&a, dsc->clip_area, &img_star, &img_draw_dsc);
lv_draw_img(dsc->draw_ctx, &img_draw_dsc, &a, &img_star);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets/canvas/lv_example_canvas_1.c
Expand Up @@ -23,7 +23,7 @@ void lv_example_canvas_1(void)

lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = lv_palette_main(LV_PALETTE_YELLOW);
label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE);

static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];

Expand All @@ -47,7 +47,7 @@ void lv_example_canvas_1(void)
img.header.h = CANVAS_HEIGHT;

lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
lv_canvas_transform(canvas, &img, 30, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
lv_canvas_transform(canvas, &img, 120, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
}

#endif
2 changes: 1 addition & 1 deletion examples/widgets/chart/lv_example_chart_2.c
Expand Up @@ -36,7 +36,7 @@ static void draw_event_cb(lv_event_t * e)
a.x2 = dsc->p2->x - 1;
a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y);
a.y2 = obj->coords.y2;
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a);

/*Remove the masks*/
lv_draw_mask_free_param(&line_mask_param);
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets/chart/lv_example_chart_4.c
Expand Up @@ -45,8 +45,8 @@ static void event_cb(lv_event_t * e)
a.y1 = chart->coords.y1 + p.y - 30;
a.y2 = chart->coords.y1 + p.y - 10;

const lv_area_t * clip_area = lv_event_get_clip_area(e);
lv_draw_rect(&a, clip_area, &draw_rect_dsc);
lv_draw_ctx_t * draw_ctx = lv_event_get_draw_ctx(e);
lv_draw_rect(draw_ctx, &draw_rect_dsc, &a);

ser = lv_chart_get_series_next(chart, ser);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets/chart/lv_example_chart_6.c
Expand Up @@ -41,7 +41,7 @@ static void event_cb(lv_event_t * e)
draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_BLUE);
draw_rect_dsc.radius = 3;

lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a);

lv_draw_label_dsc_t draw_label_dsc;
lv_draw_label_dsc_init(&draw_label_dsc);
Expand All @@ -50,7 +50,7 @@ static void event_cb(lv_event_t * e)
a.x2 -= 5;
a.y1 += 5;
a.y2 -= 5;
lv_draw_label(&a, dsc->clip_area, &draw_label_dsc, buf, NULL);
lv_draw_label(dsc->draw_ctx, &draw_label_dsc, &a, buf, NULL);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/chart/lv_example_chart_8.c
Expand Up @@ -40,7 +40,7 @@ static void draw_event_cb(lv_event_t *e)
a.x2 = dsc->p2->x;
a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y);
a.y2 = obj->coords.y2 - 13; /* -13 cuts off where the rectangle draws over the chart margin. Without this an area of 0 doesnt look like 0 */
lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc);
lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a);

/*Remove the mask*/
lv_draw_mask_free_param(&line_mask_param);
Expand Down
1 change: 0 additions & 1 deletion examples/widgets/label/lv_example_label_1.c
Expand Up @@ -15,7 +15,6 @@ void lv_example_label_1(void)
lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(label1, LV_ALIGN_CENTER, 0, -40);


lv_obj_t * label2 = lv_label_create(lv_scr_act());
lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/
lv_obj_set_width(label2, 150);
Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/label/lv_example_label_4.c
@@ -1,5 +1,5 @@
#include "../../lv_examples.h"
#if LV_USE_LABEL && LV_BUILD_EXAMPLES && LV_DRAW_COMPLEX
#if LV_USE_LABEL && LV_USE_CANVAS && LV_BUILD_EXAMPLES && LV_DRAW_COMPLEX

#define MASK_WIDTH 100
#define MASK_HEIGHT 45
Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/meter/lv_example_meter_2.c
Expand Up @@ -24,7 +24,7 @@ void lv_example_meter_2(void)
/*Add a scale first*/
lv_meter_scale_t * scale = lv_meter_add_scale(meter);
lv_meter_set_scale_ticks(meter, scale, 11, 2, 10, lv_palette_main(LV_PALETTE_GREY));
lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 10);
lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 15);
lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90);

/*Add a three arc indicator*/
Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/slider/lv_example_slider_3.c
Expand Up @@ -49,7 +49,7 @@ static void slider_event_cb(lv_event_t * e)
lv_draw_label_dsc_t label_draw_dsc;
lv_draw_label_dsc_init(&label_draw_dsc);

lv_draw_label(&label_area, dsc->clip_area, &label_draw_dsc, buf, NULL);
lv_draw_label(dsc->draw_ctx, &label_draw_dsc, &label_area, buf, NULL);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets/span/lv_example_span_1.c
Expand Up @@ -24,10 +24,10 @@ void lv_example_span_1(void)
lv_spangroup_set_mode(spans, LV_SPAN_MODE_BREAK);

lv_span_t * span = lv_spangroup_new_span(spans);
lv_span_set_text(span, "china is a beautiful country.");
lv_span_set_text(span, "China is a beautiful country.");
lv_style_set_text_color(&span->style, lv_palette_main(LV_PALETTE_RED));
lv_style_set_text_decor(&span->style, LV_TEXT_DECOR_STRIKETHROUGH | LV_TEXT_DECOR_UNDERLINE);
lv_style_set_text_opa(&span->style, LV_OPA_30);
lv_style_set_text_opa(&span->style, LV_OPA_50);

span = lv_spangroup_new_span(spans);
lv_span_set_text_static(span, "good good study, day day up.");
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets/table/lv_example_table_2.c
Expand Up @@ -21,7 +21,7 @@ static void draw_event_cb(lv_event_t * e)
sw_area.x2 = sw_area.x1 + 40;
sw_area.y1 = dsc->draw_area->y1 + lv_area_get_height(dsc->draw_area) / 2 - 10;
sw_area.y2 = sw_area.y1 + 20;
lv_draw_rect(&sw_area, dsc->clip_area, &rect_dsc);
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area);

rect_dsc.bg_color = lv_color_white();
if(chk) {
Expand All @@ -33,7 +33,7 @@ static void draw_event_cb(lv_event_t * e)
}
sw_area.y1 += 2;
sw_area.y2 -= 2;
lv_draw_rect(&sw_area, dsc->clip_area, &rect_dsc);
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area);
}
}

Expand Down
6 changes: 2 additions & 4 deletions lv_conf_template.h
Expand Up @@ -157,13 +157,11 @@
/*Use NXP's VG-Lite GPU iMX RTxxx platforms*/
#define LV_USE_GPU_NXP_VG_LITE 0

/*Use exnternal renderer*/
#define LV_USE_EXTERNAL_RENDERER 0

/*Use SDL renderer API. Requires LV_USE_EXTERNAL_RENDERER*/
/*Use SDL renderer API*/
#define LV_USE_GPU_SDL 0
#if LV_USE_GPU_SDL
#define LV_GPU_SDL_INCLUDE_PATH <SDL2/SDL.h>
#define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8)
#endif

/*-------------
Expand Down
4 changes: 2 additions & 2 deletions src/core/lv_event.c
Expand Up @@ -85,7 +85,7 @@ lv_res_t lv_obj_event_base(const lv_obj_class_t * class_p, lv_event_t * e)
if(class_p == NULL) base = e->current_target->class_p;
else base = class_p->base_class;

/*Find a base in which Call the ancestor's event handler_cb is set*/
/*Find a base in which call the ancestor's event handler_cb if set*/
while(base && base->event_cb == NULL) base = base->base_class;

if(base == NULL) return LV_RES_OK;
Expand Down Expand Up @@ -290,7 +290,7 @@ lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e)
}
}

const lv_area_t * lv_event_get_clip_area(lv_event_t * e)
lv_draw_ctx_t * lv_event_get_draw_ctx(lv_event_t * e)
{
if(e->code == LV_EVENT_DRAW_MAIN ||
e->code == LV_EVENT_DRAW_MAIN_BEGIN ||
Expand Down
6 changes: 3 additions & 3 deletions src/core/lv_event.h
Expand Up @@ -268,12 +268,12 @@ lv_indev_t * lv_event_get_indev(lv_event_t * e);
lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e);

/**
* Get the clip area passed as parameter to draw events events.
* Get the draw context which should be the first parameter of the draw functions.
* Namely: `LV_EVENT_DRAW_MAIN/POST`, `LV_EVENT_DRAW_MAIN/POST_BEGIN`, `LV_EVENT_DRAW_MAIN/POST_END`
* @param e pointer to an event
* @return the clip area to use during drawing or NULL if called on an unrelated event
* @return pointer to a draw context or NULL if called on an unrelated event
*/
const lv_area_t * lv_event_get_clip_area(lv_event_t * e);
lv_draw_ctx_t * lv_event_get_draw_ctx(lv_event_t * e);

/**
* Get the old area of the object before its size was changed. Can be used in `LV_EVENT_SIZE_CHANGED`
Expand Down

0 comments on commit db53ea9

Please sign in to comment.