Mercurial > MadButterfly
annotate src/chgcolor.c @ 446:2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Original
- sh_stext_t does not apply shifting of text himself to scaled font face, but
- apply aggreagated matrix to font face.
- shifting in parent parent coord_t would applied to scaled font.
- amount of shifting is also multiplied by aggreagated matrix.
- It means shiftings of parent coord_ts are applied two times.
Now,
- remove x, y shifting from aggreagated matrices before applying
to scaled fonts.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 02 Aug 2009 10:59:59 +0800 |
parents | 530bb7728546 |
children | 586e50f82c1f |
rev | line source |
---|---|
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <stdio.h> |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include <stdlib.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
|
3 #include "mb_animate.h" |
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" |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 static float comp_mb_timeval_ratio(const mb_timeval_t *a, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 const mb_timeval_t *b) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 float ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 return ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 typedef struct _mb_chgcolor mb_chgcolor_t; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 struct _mb_chgcolor { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 mb_action_t action; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 co_comp_t r, g, b, a; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 paint_t *paint; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 mb_timeval_t start_time; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 const mb_timeval_t *playing_time; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 co_comp_t s_r, s_g, s_b, s_a; /*!< saved RGBA values. */ |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 }; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 static void mb_chgcolor_start(mb_action_t *act, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 const mb_timeval_t *playing_time, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 mb_chgcolor_t *chg = (mb_chgcolor_t *)act; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 MB_TIMEVAL_CP(&chg->start_time, now); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 chg->playing_time = playing_time; /* playing_time is in word, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 * it live time is as long as |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 * actions. */ |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 paint_color_get(chg->paint, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 &chg->s_r, &chg->s_g, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 &chg->s_b, &chg->s_a); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 static void mb_chgcolor_step(mb_action_t *act, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 mb_chgcolor_t *chg = (mb_chgcolor_t *)act; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 mb_timeval_t diff; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 co_comp_t r, g, b, a; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 float ratio, comp; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 MB_TIMEVAL_CP(&diff, now); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 MB_TIMEVAL_DIFF(&diff, &chg->start_time); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 ratio = comp_mb_timeval_ratio(&diff, chg->playing_time); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 comp = 1 - ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 r = chg->s_r * comp + ratio * chg->r; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 g = chg->s_g * comp + ratio * chg->g; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 b = chg->s_b * comp + ratio * chg->b; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 a = chg->s_a * comp + ratio * chg->a; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 paint_color_set(chg->paint, r, g, b, a); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 rdman_paint_changed(rdman, chg->paint); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 static void mb_chgcolor_stop(mb_action_t *act, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 mb_chgcolor_t *chg = (mb_chgcolor_t *)act; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 paint_color_set(chg->paint, chg->r, chg->g, chg->b, chg->a); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 rdman_paint_changed(rdman, chg->paint); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 static void mb_chgcolor_free(mb_action_t *act) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 free(act); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 mb_action_t *mb_chgcolor_new(co_comp_t r, co_comp_t g, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 co_comp_t b, co_comp_t a, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 paint_t *paint, mb_word_t *word) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 mb_chgcolor_t *chg; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
83 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 chg = (mb_chgcolor_t *)malloc(sizeof(mb_chgcolor_t)); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 if(chg == NULL) |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 return NULL; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 chg->r = r; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 chg->g = g; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 chg->b = b; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 chg->a = a; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 chg->paint = paint; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
94 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 chg->action.start = mb_chgcolor_start; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 chg->action.step = mb_chgcolor_step; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 chg->action.stop = mb_chgcolor_stop; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
98 chg->action.free = mb_chgcolor_free; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
99 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
100 mb_word_add_action(word, (mb_action_t *)chg); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
101 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 return (mb_action_t *)chg; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 |