comparison src/paint.c @ 21:83d24300a992

opacity (alpha) channel
author Thinker K.F. Li <thinker@branda.to>
date Sat, 02 Aug 2008 16:06:53 +0800
parents cf6d65398619
children 56f592f56ff7
comparison
equal deleted inserted replaced
20:74d3d5dc9aaa 21:83d24300a992
3 #include <cairo.h> 3 #include <cairo.h>
4 #include "paint.h" 4 #include "paint.h"
5 5
6 typedef struct _paint_color { 6 typedef struct _paint_color {
7 paint_t paint; 7 paint_t paint;
8 co_comp_t r, g, b; 8 co_comp_t r, g, b, a;
9 redraw_man_t *rdman; 9 redraw_man_t *rdman;
10 } paint_color_t; 10 } paint_color_t;
11 11
12 12
13 static void paint_color_prepare(paint_t *paint, cairo_t *cr) { 13 static void paint_color_prepare(paint_t *paint, cairo_t *cr) {
14 paint_color_t *color = (paint_color_t *)paint; 14 paint_color_t *color = (paint_color_t *)paint;
15 15
16 cairo_set_source_rgb(cr, color->r, color->g, color->b); 16 cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a);
17 } 17 }
18 18
19 static void paint_color_free(paint_t *paint) { 19 static void paint_color_free(paint_t *paint) {
20 paint_color_t *color = (paint_color_t *)paint; 20 paint_color_t *color = (paint_color_t *)paint;
21 21
22 shnode_list_free(color->rdman, paint->members); 22 shnode_list_free(color->rdman, paint->members);
23 free(paint); 23 free(paint);
24 } 24 }
25 25
26 paint_t *paint_color_new(redraw_man_t *rdman, 26 paint_t *paint_color_new(redraw_man_t *rdman,
27 co_comp_t r, co_comp_t g, co_comp_t b) { 27 co_comp_t r, co_comp_t g,
28 co_comp_t b, co_comp_t a) {
28 paint_color_t *color; 29 paint_color_t *color;
29 30
30 color = (paint_color_t *)malloc(sizeof(paint_color_t)); 31 color = (paint_color_t *)malloc(sizeof(paint_color_t));
31 if(color == NULL) 32 if(color == NULL)
32 return NULL; 33 return NULL;
33 color->rdman = rdman; 34 color->rdman = rdman;
34 color->r = r; 35 color->r = r;
35 color->g = g; 36 color->g = g;
36 color->b = b; 37 color->b = b;
38 color->a = a;
37 paint_init(&color->paint, paint_color_prepare, paint_color_free); 39 paint_init(&color->paint, paint_color_prepare, paint_color_free);
38 return (paint_t *)color; 40 return (paint_t *)color;
39 } 41 }
40 42
41 void paint_color_set(paint_t *paint, 43 void paint_color_set(paint_t *paint,
42 co_comp_t r, co_comp_t g, co_comp_t b) { 44 co_comp_t r, co_comp_t g,
45 co_comp_t b, co_comp_t a) {
43 paint_color_t *color = (paint_color_t *)paint; 46 paint_color_t *color = (paint_color_t *)paint;
44 47
45 color->r = r; 48 color->r = r;
46 color->g = g; 49 color->g = g;
47 color->b = b; 50 color->b = b;
51 color->a = a;
48 } 52 }