Mercurial > MadButterfly
annotate src/mbaf/mbbutton.c @ 802:843f1b5548d7
Allow relative path
author | wycc |
---|---|
date | Wed, 01 Sep 2010 02:06:32 +0800 |
parents | 26c302b47de1 |
children | 586e50f82c1f |
rev | line source |
---|---|
294 | 1 |
2 #include <stdio.h> | |
3 #include <mb.h> | |
4 #include <string.h> | |
456
26c302b47de1
Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents:
335
diff
changeset
|
5 #include "mb_af.h" |
294 | 6 |
7 | |
8 | |
9 #define CMOUSE(e) (coord_get_mouse_event(e)) | |
10 | |
11 | |
12 static void mb_button_pressed(event_t *evt, void *arg); | |
13 static void mb_button_out(event_t *evt, void *arg); | |
14 | |
15 void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg) | |
16 { | |
17 b->press = h; | |
18 b->arg = arg; | |
19 } | |
20 | |
21 void mb_button_refresh(mb_button_t *btn) | |
22 { | |
23 rdman_coord_changed(btn->rdman,btn->root); | |
24 rdman_redraw_changed(btn->rdman); | |
25 } | |
26 | |
27 static void mb_button_move(event_t *evt, void *arg) | |
28 { | |
29 mb_button_t *btn = (mb_button_t *) arg; | |
30 | |
31 | |
32 printf("Mouse move\n"); | |
33 coord_show(btn->active); | |
34 mb_button_refresh(btn); | |
35 } | |
36 static void mb_button_out(event_t *evt, void *arg) | |
37 { | |
38 mb_button_t *btn = (mb_button_t *) arg; | |
39 | |
40 if (btn->progm) { | |
41 mb_progm_abort(btn->progm); | |
42 btn->progm = NULL; | |
43 } | |
44 printf("mouse out\n"); | |
45 coord_hide(btn->click); | |
46 coord_hide(btn->active); | |
47 coord_show(btn->normal); | |
48 mb_button_refresh(btn); | |
49 } | |
50 | |
51 static void mb_button_show_active(event_t *evt, void *arg) | |
52 { | |
53 mb_button_t *btn = (mb_button_t *) arg; | |
54 | |
55 coord_show(btn->active); | |
56 mb_button_refresh(btn); | |
57 } | |
58 | |
335
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
59 static void mb_button_end_animated_cb(event_t *evt, void *arg) |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
60 { |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
61 mb_button_t *btn = (mb_button_t *) arg; |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
62 |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
63 btn->progm = NULL; |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
64 |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
65 } |
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
66 |
294 | 67 static void mb_button_pressed(event_t *evt, void *arg) |
68 { | |
69 mb_button_t *btn = (mb_button_t *) arg; | |
70 mb_timeval_t start, playing, now; | |
71 mb_progm_t *progm; | |
72 mb_word_t *word; | |
73 | |
74 printf("Pressed\n"); | |
75 if (btn->progm) { | |
76 mb_progm_abort(btn->progm); | |
77 btn->progm = NULL; | |
78 } | |
79 coord_show(btn->click); | |
80 coord_hide(btn->active); | |
81 rdman_coord_changed(btn->rdman,btn->root); | |
82 rdman_redraw_changed(btn->rdman); | |
83 | |
84 btn->progm = progm = mb_progm_new(1, btn->rdman); | |
85 MB_TIMEVAL_SET(&start, 0, 500000); | |
86 MB_TIMEVAL_SET(&playing, 0, 0); | |
87 word = mb_progm_next_word(progm, &start, &playing); | |
88 mb_visibility_new(VIS_HIDDEN, btn->click, word); | |
89 mb_visibility_new(VIS_VISIBLE, btn->active, word); | |
90 mb_progm_free_completed(progm); | |
335
01038b8d8f05
Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents:
294
diff
changeset
|
91 subject_add_observer(mb_progm_get_complete(btn->progm), mb_button_end_animated_cb,btn); |
294 | 92 get_now(&now); |
93 printf("rt = %x\n", btn->rdman->rt); | |
94 mb_progm_start(progm, X_MB_tman(btn->rdman->rt), &now); | |
95 if (btn->press) | |
96 btn->press(btn->arg); | |
97 } | |
98 mb_button_t *mb_button_new(redraw_man_t *rdman,mb_sprite_t *sp, char *name) | |
99 { | |
100 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t)); | |
101 char *buf = (char *) malloc(strlen(name)+5); | |
102 | |
103 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name); | |
104 sprintf(buf, "%s_normal", name); | |
105 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); | |
106 if (btn->normal == NULL) { | |
107 printf("Missing normal button, this is not a correct button\n"); | |
108 } | |
109 sprintf(buf, "%s_active", name); | |
110 btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); | |
111 if (btn->active == NULL) { | |
112 printf("Missing click button, this is not a correct button\n"); | |
113 } | |
114 sprintf(buf, "%s_click", name); | |
115 btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); | |
116 if (btn->active == NULL) { | |
117 printf("Missing click button, this is not a correct button\n"); | |
118 } | |
119 btn->press = NULL; | |
120 // Show only the normal button | |
121 coord_hide(btn->active); | |
122 coord_hide(btn->click); | |
123 coord_show(btn->normal); | |
124 // Move to the same position | |
125 btn->active->matrix[2] = 200; | |
126 btn->active->matrix[5] = 200; | |
127 btn->normal->matrix[2] = 200; | |
128 btn->normal->matrix[5] = 200; | |
129 btn->click->matrix[2] = 200; | |
130 btn->click->matrix[5] = 200; | |
131 btn->rdman = rdman; | |
132 btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); | |
133 btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); | |
134 btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); | |
135 btn->progm = NULL; | |
136 rdman_redraw_changed(rdman); | |
137 return btn; | |
138 } |