Mercurial > MadButterfly
annotate src/chgcolor.c @ 1307:cfbc0f3e54e3
Add supporting for programmer defined prefix for data_monitor
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 20 Jan 2011 00:34:08 +0800 |
parents | 586e50f82c1f |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
186
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
186
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <stdio.h> |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #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
|
5 #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
|
6 #include "mb_paint.h" |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 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
|
9 const mb_timeval_t *b) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 float ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 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
|
13 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
|
14 return ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 } |
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 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
|
18 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 struct _mb_chgcolor { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 mb_action_t action; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 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
|
23 paint_t *paint; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 mb_timeval_t start_time; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 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
|
27 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
|
28 }; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 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
|
31 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 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
|
33 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 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
|
35 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 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
|
37 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
|
38 * 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
|
39 * actions. */ |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 paint_color_get(chg->paint, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 &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
|
42 &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
|
43 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 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
|
46 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 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
|
49 mb_timeval_t diff; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 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
|
51 float ratio, comp; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 MB_TIMEVAL_CP(&diff, now); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 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
|
55 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
|
56 comp = 1 - ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 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
|
65 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 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
|
68 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 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
|
71 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 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
|
73 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 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
|
75 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 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
|
78 free(act); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 mb_chgcolor_t *chg; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 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
|
87 if(chg == NULL) |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 return NULL; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 chg->r = r; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 chg->g = g; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 chg->b = b; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 chg->a = a; |
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->paint = paint; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 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
|
103 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 return (mb_action_t *)chg; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
106 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
107 |