Mercurial > MadButterfly
changeset 21:83d24300a992
opacity (alpha) channel
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 02 Aug 2008 16:06:53 +0800 |
parents | 74d3d5dc9aaa |
children | 8fcf2d878ecd |
files | src/X_main.c src/paint.c src/paint.h |
diffstat | 3 files changed, 18 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/X_main.c Sat Aug 02 15:46:26 2008 +0800 +++ b/src/X_main.c Sat Aug 02 16:06:53 2008 +0800 @@ -23,8 +23,8 @@ coord1 = rdman_coord_new(&rdman, rdman.root_coord); coord2 = rdman_coord_new(&rdman, rdman.root_coord); - fill1 = paint_color_new(&rdman, 1, 1, 0); - fill2 = paint_color_new(&rdman, 0, 1, 1); + fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); + fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); rdman_paint_fill(&rdman, fill1, path1); coord1->matrix[0] = 0.8; @@ -54,8 +54,8 @@ coord1->matrix[5] += 1; coord2->matrix[2] -= 1; coord2->matrix[5] += 1; - paint_color_set(fill1, 1, 1, (i/25) & 0x1); - paint_color_set(fill2, (i/25) & 0x1, 1, 1); + paint_color_set(fill1, 1, 1, (i/25) & 0x1, 0.5); + paint_color_set(fill2, (i/25) & 0x1, 1, 1, 0.5); rdman_paint_changed(&rdman, fill1); rdman_paint_changed(&rdman, fill2); rdman_coord_changed(&rdman, coord1); @@ -66,8 +66,8 @@ for(i = 0; i < 5; i++) { usleep(500000); - paint_color_set(fill1, 1, i % 2, 0); - paint_color_set(fill2, 0, i % 2, 1); + paint_color_set(fill1, 1, i % 2, 0, 0.5); + paint_color_set(fill2, 0, i % 2, 1, 0.5); rdman_paint_changed(&rdman, fill1); rdman_paint_changed(&rdman, fill2); rdman_redraw_changed(&rdman);
--- a/src/paint.c Sat Aug 02 15:46:26 2008 +0800 +++ b/src/paint.c Sat Aug 02 16:06:53 2008 +0800 @@ -5,7 +5,7 @@ typedef struct _paint_color { paint_t paint; - co_comp_t r, g, b; + co_comp_t r, g, b, a; redraw_man_t *rdman; } paint_color_t; @@ -13,7 +13,7 @@ static void paint_color_prepare(paint_t *paint, cairo_t *cr) { paint_color_t *color = (paint_color_t *)paint; - cairo_set_source_rgb(cr, color->r, color->g, color->b); + cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a); } static void paint_color_free(paint_t *paint) { @@ -24,7 +24,8 @@ } paint_t *paint_color_new(redraw_man_t *rdman, - co_comp_t r, co_comp_t g, co_comp_t b) { + co_comp_t r, co_comp_t g, + co_comp_t b, co_comp_t a) { paint_color_t *color; color = (paint_color_t *)malloc(sizeof(paint_color_t)); @@ -34,15 +35,18 @@ color->r = r; color->g = g; color->b = b; + color->a = a; paint_init(&color->paint, paint_color_prepare, paint_color_free); return (paint_t *)color; } void paint_color_set(paint_t *paint, - co_comp_t r, co_comp_t g, co_comp_t b) { + co_comp_t r, co_comp_t g, + co_comp_t b, co_comp_t a) { paint_color_t *color = (paint_color_t *)paint; color->r = r; color->g = g; color->b = b; + color->a = a; }
--- a/src/paint.h Sat Aug 02 15:46:26 2008 +0800 +++ b/src/paint.h Sat Aug 02 16:06:53 2008 +0800 @@ -9,9 +9,11 @@ typedef float co_comp_t; extern paint_t *paint_color_new(redraw_man_t *rdman, - co_comp_t r, co_comp_t g, co_comp_t b); + co_comp_t r, co_comp_t g, + co_comp_t b, co_comp_t a); extern void paint_color_set(paint_t *paint, - co_comp_t r, co_comp_t g, co_comp_t b); + co_comp_t r, co_comp_t g, + co_comp_t b, co_comp_t a); #define paint_init(_paint, _prepare, _free) \ do { \ (_paint)->prepare = _prepare; \