mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
fix cairo global alpha
This commit is contained in:
parent
4cf013f88e
commit
67f3cc2e35
13
bin/.gitignore
vendored
13
bin/.gitignore
vendored
@ -1,13 +0,0 @@
|
||||
demoui
|
||||
genascii
|
||||
mem_test
|
||||
qt_to_xml
|
||||
runLua
|
||||
themegen
|
||||
demo1
|
||||
fontgen
|
||||
imagegen
|
||||
prefix_xml_ui
|
||||
rc_to_xml
|
||||
runTest
|
||||
xml_to_ui
|
@ -336,6 +336,39 @@ static ret_t on_paint_vg(void* ctx, event_t* e) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t on_paint_global_alpha(void* ctx, event_t* e) {
|
||||
bitmap_t img;
|
||||
paint_event_t* evt = (paint_event_t*)e;
|
||||
canvas_t* c = evt->c;
|
||||
vgcanvas_t* vg = canvas_get_vgcanvas(c);
|
||||
color_t fill = color_init(0x00, 0xff, 0x00, 0xff);
|
||||
color_t stroke = color_init(0x00, 0x00, 0xff, 0xff);
|
||||
|
||||
vgcanvas_save(vg);
|
||||
|
||||
image_manager_get_bitmap(image_manager(), "bricks", &img);
|
||||
vgcanvas_set_global_alpha(vg, 1);
|
||||
vgcanvas_draw_image(vg, &img, 0, 0, img.w, img.h, 0, 0, img.w, img.h);
|
||||
|
||||
vgcanvas_set_global_alpha(vg, 0.5);
|
||||
|
||||
vgcanvas_set_fill_color(vg, fill);
|
||||
vgcanvas_rect(vg, 0, 0, 20, 20);
|
||||
vgcanvas_fill(vg);
|
||||
|
||||
vgcanvas_set_stroke_color(vg, stroke);
|
||||
vgcanvas_set_line_width(vg, 5);
|
||||
vgcanvas_rect(vg, 20, 20, 20, 20);
|
||||
vgcanvas_stroke(vg);
|
||||
|
||||
vgcanvas_translate(vg, 15, 15);
|
||||
vgcanvas_draw_image(vg, &img, 0, 0, img.w, img.h, 0, 0, img.w, img.h);
|
||||
|
||||
vgcanvas_restore(vg);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t on_paint_vg_simple(void* ctx, event_t* e) {
|
||||
bitmap_t img;
|
||||
paint_event_t* evt = (paint_event_t*)e;
|
||||
@ -417,6 +450,7 @@ ret_t application_init() {
|
||||
|
||||
// widget_on(canvas, EVT_PAINT, on_paint_vg_simple, NULL);
|
||||
widget_on(canvas, EVT_PAINT, on_paint_vg, NULL);
|
||||
//widget_on(canvas, EVT_PAINT, on_paint_global_alpha, NULL);
|
||||
|
||||
timer_add(on_timer, win, 500);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
* 2019/06/25
|
||||
* 完善 slider。dragger 以实际 icon 为准。
|
||||
* 让 bitmap 引用 image\_manager 以区分 bitmap 是由哪个 image\_manager 加载的。
|
||||
* 修改cairo global alpha的BUG,目前draw_image/fill/stroke支持global alpha, gradient暂时不支持。
|
||||
|
||||
* 2019/06/24
|
||||
* 用 stb\_text\_edit 重新实现 edit 控件,支持取消、重做、全选、拷贝、剪切、粘贴和键盘选择等功能。
|
||||
|
@ -58,7 +58,7 @@ ret_t vgcanvas_cairo_begin_frame(vgcanvas_t* vgcanvas, rect_t* dirty_rect) {
|
||||
cairo_clip(vg);
|
||||
cairo_new_path(vg);
|
||||
cairo_save(vg);
|
||||
vgcanvas->global_alpha = 0xff;
|
||||
vgcanvas->global_alpha = 1;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -301,8 +301,10 @@ static ret_t vgcanvas_cairo_fill(vgcanvas_t* vgcanvas) {
|
||||
vgcanvas_cairo_t* canvas = (vgcanvas_cairo_t*)vgcanvas;
|
||||
|
||||
if (canvas->fill_source_type == CAIRO_SOURCE_GRADIENT) {
|
||||
/*not support global alpha yet*/
|
||||
cairo_set_source(vg, canvas->fill_gradient);
|
||||
} else {
|
||||
c.rgba.a = c.rgba.a * vgcanvas->global_alpha;
|
||||
cairo_set_source_color(vg, c);
|
||||
}
|
||||
|
||||
@ -328,8 +330,10 @@ static ret_t vgcanvas_cairo_stroke(vgcanvas_t* vgcanvas) {
|
||||
vgcanvas_cairo_t* canvas = (vgcanvas_cairo_t*)vgcanvas;
|
||||
|
||||
if (canvas->stroke_source_type == CAIRO_SOURCE_GRADIENT) {
|
||||
/*not support global alpha yet*/
|
||||
cairo_set_source(vg, canvas->stroke_gradient);
|
||||
} else {
|
||||
c.rgba.a = c.rgba.a * vgcanvas->global_alpha;
|
||||
cairo_set_source_color(vg, c);
|
||||
}
|
||||
|
||||
@ -462,7 +466,7 @@ static ret_t vgcanvas_cairo_draw_image(vgcanvas_t* vgcanvas, bitmap_t* img, floa
|
||||
float_t dh) {
|
||||
float fx = (float)dw / sw;
|
||||
float fy = (float)dh / sh;
|
||||
float_t global_alpha = 1;
|
||||
float_t global_alpha = vgcanvas->global_alpha;
|
||||
cairo_t* vg = ((vgcanvas_cairo_t*)vgcanvas)->vg;
|
||||
cairo_surface_t* surface = vgcanvas_cairo_ensure_image((vgcanvas_cairo_t*)vgcanvas, img);
|
||||
|
||||
@ -506,10 +510,6 @@ static ret_t vgcanvas_cairo_set_line_width(vgcanvas_t* vgcanvas, float_t value)
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_cairo_set_global_alpha(vgcanvas_t* vgcanvas, float_t value) {
|
||||
cairo_t* vg = ((vgcanvas_cairo_t*)vgcanvas)->vg;
|
||||
|
||||
cairo_paint_with_alpha(vg, value);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@ -841,7 +841,8 @@ vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, uint32_t stride, bitmap_form
|
||||
cairo->vg = cairo_create(surface);
|
||||
return_value_if_fail(cairo->vg, NULL);
|
||||
darray_init(&(cairo->images), 10, (tk_destroy_t)bitmap_destroy, (tk_compare_t)cairo_bitmap_cmp);
|
||||
|
||||
vgcanvas_set_global_alpha((vgcanvas_t*)cairo, 1);
|
||||
|
||||
log_debug("vgcanvas_cairo created\n");
|
||||
return &(cairo->base);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user