Mercurial > MadButterfly
annotate src/paint.c @ 194:45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
- Free members of a coord in rdman_coord_subtree_free().
- Fix core dump issue of subject_notify() that can not free subjects well.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 19 Nov 2008 20:53:40 +0800 |
parents | 530bb7728546 |
children | 29acbd8a0dd0 |
rev | line source |
---|---|
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <stdio.h> |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include <stdlib.h> |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <cairo.h> |
186
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
4 #include "mb_paint.h" |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
55 | 6 #define ASSERT(x) |
7 | |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
8 /*! \brief Solid color paint. |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
9 */ |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 typedef struct _paint_color { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 paint_t paint; |
21 | 12 co_comp_t r, g, b, a; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 } paint_color_t; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 |
147
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
15 int _paint_color_size = sizeof(paint_color_t); |
146
e96a584487af
Use elmpool to manage paint_color_t objects.
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
16 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 static void paint_color_prepare(paint_t *paint, cairo_t *cr) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 paint_color_t *color = (paint_color_t *)paint; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 |
21 | 21 cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a); |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
24 static void paint_color_free(redraw_man_t *rdman, paint_t *paint) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
25 shnode_list_free(rdman, paint->members); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
26 elmpool_elm_free(rdman->paint_color_pool, paint); |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
29 paint_t *rdman_paint_color_new(redraw_man_t *rdman, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
30 co_comp_t r, co_comp_t g, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
31 co_comp_t b, co_comp_t a) { |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 paint_color_t *color; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 |
146
e96a584487af
Use elmpool to manage paint_color_t objects.
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
34 color = (paint_color_t *)elmpool_elm_alloc(rdman->paint_color_pool); |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 if(color == NULL) |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 return NULL; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 color->r = r; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 color->g = g; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 color->b = b; |
21 | 40 color->a = a; |
19 | 41 paint_init(&color->paint, paint_color_prepare, paint_color_free); |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 return (paint_t *)color; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 void paint_color_set(paint_t *paint, |
21 | 46 co_comp_t r, co_comp_t g, |
47 co_comp_t b, co_comp_t a) { | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 paint_color_t *color = (paint_color_t *)paint; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 color->r = r; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 color->g = g; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 color->b = b; |
21 | 53 color->a = a; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 } |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
55 |
52
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
56 void paint_color_get(paint_t *paint, |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
57 co_comp_t *r, co_comp_t *g, |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
58 co_comp_t *b, co_comp_t *a) { |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
59 paint_color_t *color = (paint_color_t *)paint; |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
60 |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
61 *r = color->r; |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
62 *g = color->g; |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
63 *b = color->b; |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
64 *a = color->a; |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
65 } |
59a295651480
Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
66 |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
67 /*! \brief Linear gradient. |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
68 */ |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
69 typedef struct _paint_linear { |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
70 paint_t paint; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
71 co_aix x1, y1; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
72 co_aix x2, y2; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
73 int n_stops; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
74 grad_stop_t *stops; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
75 int flags; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
76 cairo_pattern_t *ptn; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
77 } paint_linear_t; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
78 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
79 #define LIF_DIRTY 0x1 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
80 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
81 static void paint_linear_prepare(paint_t *paint, cairo_t *cr) { |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
82 paint_linear_t *linear = (paint_linear_t *)paint; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
83 cairo_pattern_t *ptn; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
84 grad_stop_t *stop; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
85 int i; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
86 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
87 ptn = linear->ptn; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
88 if(linear->flags & LIF_DIRTY) { |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
89 if(ptn) |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
90 cairo_pattern_destroy(ptn); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
91 linear->flags &= ~LIF_DIRTY; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
92 ptn = cairo_pattern_create_linear(linear->x1, linear->y1, |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
93 linear->x2, linear->y2); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
94 for(i = 0; i < linear->n_stops; i++) { |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
95 stop = &linear->stops[i]; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
96 cairo_pattern_add_color_stop_rgba(ptn, stop->offset, |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
97 stop->r, stop->g, stop->b, |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
98 stop->a); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
99 } |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
100 linear->ptn = ptn; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
101 } |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
102 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
103 cairo_set_source(cr, ptn); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
104 } |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
105 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
106 static void paint_linear_free(redraw_man_t *rdman, paint_t *paint) { |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
107 paint_linear_t *linear = (paint_linear_t *)paint; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
108 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
109 if(linear->ptn) |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
110 cairo_pattern_destroy(linear->ptn); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
111 free(paint); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
112 } |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
113 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
114 paint_t *rdman_paint_linear_new(redraw_man_t *rdman, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
115 co_aix x1, co_aix y1, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
116 co_aix x2, co_aix y2) { |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
117 paint_linear_t *linear; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
118 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
119 linear = (paint_linear_t *)malloc(sizeof(paint_linear_t)); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
120 if(linear == NULL) |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
121 return NULL; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
122 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
123 paint_init(&linear->paint, paint_linear_prepare, paint_linear_free); |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
124 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
125 linear->x1 = x1; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
126 linear->y1 = y1; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
127 linear->x2 = x2; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
128 linear->y2 = y2; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
129 linear->n_stops = 0; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
130 linear->stops = NULL; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
131 linear->flags = LIF_DIRTY; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
132 linear->ptn = NULL; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
133 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
134 return (paint_t *)linear; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
135 } |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
136 |
58 | 137 /*! \brief Setup color stop for a linear radient paint. |
138 * | |
139 * stops should be managed by users of the function. It should be | |
140 * available before the paint being freed or changed to another | |
141 * array of stops. | |
142 */ | |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
143 grad_stop_t *paint_linear_stops(paint_t *paint, |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
144 int n_stops, |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
145 grad_stop_t *stops) { |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
146 paint_linear_t *linear = (paint_linear_t *)paint; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
147 grad_stop_t *old_stops; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
148 |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
149 old_stops = linear->stops; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
150 linear->n_stops = n_stops; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
151 linear->stops = stops; |
55 | 152 linear->flags |= LIF_DIRTY; |
153 | |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
154 return old_stops; |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
155 } |
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
21
diff
changeset
|
156 |
55 | 157 /*! \brief Radial gradient. |
158 * | |
159 * NOTE: The only supported gradient unit is userSpaceOnUse. | |
160 */ | |
161 typedef struct _paint_radial { | |
162 paint_t paint; | |
163 co_aix cx, cy; | |
164 co_aix r; | |
165 int n_stops; | |
166 grad_stop_t *stops; | |
167 int flags; | |
168 cairo_pattern_t *ptn; | |
169 } paint_radial_t; | |
170 | |
171 #define RDF_DIRTY 0x1 | |
172 | |
173 static void paint_radial_prepare(paint_t *paint, cairo_t *cr) { | |
174 paint_radial_t *radial = (paint_radial_t *)paint; | |
175 cairo_pattern_t *ptn; | |
176 grad_stop_t *stop; | |
177 int i; | |
178 | |
179 if(radial->flags & RDF_DIRTY) { | |
180 ptn = cairo_pattern_create_radial(radial->cx, radial->cy, 0, | |
181 radial->cx, radial->cy, | |
182 radial->r); | |
183 ASSERT(ptn != NULL); | |
184 stop = radial->stops; | |
185 for(i = 0; i < radial->n_stops; i++, stop++) { | |
186 cairo_pattern_add_color_stop_rgba(ptn, stop->offset, | |
187 stop->r, stop->g, | |
188 stop->b, stop->a); | |
189 } | |
190 cairo_pattern_destroy(radial->ptn); | |
191 radial->ptn = ptn; | |
192 } | |
193 cairo_set_source(cr, radial->ptn); | |
194 } | |
195 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
196 static void paint_radial_free(redraw_man_t *rdman, paint_t *paint) { |
55 | 197 paint_radial_t *radial = (paint_radial_t *)paint; |
198 | |
199 if(radial->ptn) | |
200 cairo_pattern_destroy(radial->ptn); | |
201 free(paint); | |
202 } | |
203 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
204 paint_t *rdman_paint_radial_new(redraw_man_t *rdman, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
205 co_aix cx, co_aix cy, co_aix r) { |
55 | 206 paint_radial_t *radial; |
207 | |
208 radial = O_ALLOC(paint_radial_t); | |
209 if(radial == NULL) | |
210 return NULL; | |
211 | |
212 paint_init(&radial->paint, paint_radial_prepare, paint_radial_free); | |
213 radial->cx = cx; | |
214 radial->cy = cy; | |
215 radial->r = r; | |
56
e444a8c01735
Change interface of paint_radial_new()
Thinker K.F. Li <thinker@branda.to>
parents:
55
diff
changeset
|
216 radial->n_stops = 0; |
e444a8c01735
Change interface of paint_radial_new()
Thinker K.F. Li <thinker@branda.to>
parents:
55
diff
changeset
|
217 radial->stops = NULL; |
55 | 218 radial->flags = RDF_DIRTY; |
219 radial->ptn = NULL; | |
220 | |
221 return (paint_t *)radial; | |
222 } | |
223 | |
58 | 224 /*! \brief Setup color stop for a radial radient paint. |
225 * | |
226 * stops should be managed by users of the function. It should be | |
227 * available before the paint being freed or changed to another | |
228 * array of stops. | |
229 */ | |
55 | 230 grad_stop_t *paint_radial_stops(paint_t *paint, |
231 int n_stops, | |
232 grad_stop_t *stops) { | |
233 paint_radial_t *radial = (paint_radial_t *)paint; | |
234 grad_stop_t *old_stops; | |
235 | |
236 old_stops = radial->stops; | |
237 radial->n_stops = n_stops; | |
238 radial->stops = stops; | |
239 radial->flags |= RDF_DIRTY; | |
240 | |
241 return old_stops; | |
242 } | |
243 |