Mercurial > MadButterfly
comparison examples/dynamic/main.c @ 226:b24d7889cbda
* Change the color of click frame
* hide active and click and show normal at mouse out
author | wycc@wycc-desktop |
---|---|
date | Tue, 16 Dec 2008 21:24:26 +0800 |
parents | 29e1b2bffe4c |
children | a6e559fb76d7 |
comparison
equal
deleted
inserted
replaced
225:5c70883c40d5 | 226:b24d7889cbda |
---|---|
33 coord_t *normal; | 33 coord_t *normal; |
34 coord_t *click; | 34 coord_t *click; |
35 void (*press)(); | 35 void (*press)(); |
36 void *arg; | 36 void *arg; |
37 observer_t *obs_move,*obs_out,*obs_press; | 37 observer_t *obs_move,*obs_out,*obs_press; |
38 mb_progm_t *progm; | |
38 } mb_button_t; | 39 } mb_button_t; |
39 | 40 |
40 | 41 |
41 #define COORD_SHOW(group) coord_show(group);rdman_coord_changed(en->rdman, group) | 42 #define COORD_SHOW(group) coord_show(group);rdman_coord_changed(en->rdman, group) |
42 #define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(en->rdman, group) | 43 #define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(en->rdman, group) |
63 static void mb_button_out(event_t *evt, void *arg) | 64 static void mb_button_out(event_t *evt, void *arg) |
64 { | 65 { |
65 mb_button_t *btn = (mb_button_t *) arg; | 66 mb_button_t *btn = (mb_button_t *) arg; |
66 engine_t *en = btn->en; | 67 engine_t *en = btn->en; |
67 | 68 |
69 if (btn->progm) { | |
70 mb_progm_abort(btn->progm); | |
71 btn->progm = NULL; | |
72 } | |
68 printf("mouse out\n"); | 73 printf("mouse out\n"); |
74 COORD_HIDE(btn->click); | |
69 COORD_HIDE(btn->active); | 75 COORD_HIDE(btn->active); |
70 #if 0 | 76 COORD_SHOW(btn->normal); |
71 rdman_coord_changed(btn->en->rdman,btn->root); | 77 #if 1 |
78 rdman_coord_changed(btn->en->rdman,btn->normal); | |
72 #endif | 79 #endif |
73 rdman_redraw_changed(btn->en->rdman); | 80 rdman_redraw_changed(btn->en->rdman); |
74 } | 81 } |
75 | 82 |
76 void mb_button_show_active(event_t *evt, void *arg) | 83 void mb_button_show_active(event_t *evt, void *arg) |
90 mb_timeval_t start, playing, now; | 97 mb_timeval_t start, playing, now; |
91 mb_progm_t *progm; | 98 mb_progm_t *progm; |
92 mb_word_t *word; | 99 mb_word_t *word; |
93 | 100 |
94 printf("Pressed\n"); | 101 printf("Pressed\n"); |
102 if (btn->progm) { | |
103 mb_progm_abort(btn->progm); | |
104 btn->progm = NULL; | |
105 } | |
95 COORD_SHOW(btn->click); | 106 COORD_SHOW(btn->click); |
96 COORD_HIDE(btn->active); | 107 COORD_HIDE(btn->active); |
97 rdman_coord_changed(en->rdman,en->button->root_coord); | 108 rdman_coord_changed(en->rdman,en->button->root_coord); |
98 rdman_redraw_changed(en->rdman); | 109 rdman_redraw_changed(en->rdman); |
99 | 110 |
100 progm = mb_progm_new(1, en->rdman); | 111 btn->progm = progm = mb_progm_new(1, en->rdman); |
101 MB_TIMEVAL_SET(&start, 0, 500000); | 112 MB_TIMEVAL_SET(&start, 0, 500000); |
102 MB_TIMEVAL_SET(&playing, 0, 0); | 113 MB_TIMEVAL_SET(&playing, 0, 0); |
103 word = mb_progm_next_word(progm, &start, &playing); | 114 word = mb_progm_next_word(progm, &start, &playing); |
104 mb_visibility_new(VIS_HIDDEN, btn->click, word); | 115 mb_visibility_new(VIS_HIDDEN, btn->click, word); |
105 mb_visibility_new(VIS_VISIBLE, btn->active, word); | 116 mb_visibility_new(VIS_VISIBLE, btn->active, word); |
111 { | 122 { |
112 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t)); | 123 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t)); |
113 char *buf = (char *) malloc(strlen(name)+5); | 124 char *buf = (char *) malloc(strlen(name)+5); |
114 | 125 |
115 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name); | 126 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name); |
127 printf("btn->root=%x\n",btn->root); | |
116 sprintf(buf, "%s_normal", name); | 128 sprintf(buf, "%s_normal", name); |
117 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); | 129 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); |
118 if (btn->normal == NULL) { | 130 if (btn->normal == NULL) { |
119 printf("Missing normal button, this is not a correct button\n"); | 131 printf("Missing normal button, this is not a correct button\n"); |
120 } | 132 } |
139 btn->normal->matrix[2] = 200; | 151 btn->normal->matrix[2] = 200; |
140 btn->normal->matrix[5] = 200; | 152 btn->normal->matrix[5] = 200; |
141 btn->click->matrix[2] = 200; | 153 btn->click->matrix[2] = 200; |
142 btn->click->matrix[5] = 200; | 154 btn->click->matrix[5] = 200; |
143 btn->en = en; | 155 btn->en = en; |
156 printf("btn->root=%x\n",CMOUSE(btn->root)); | |
144 btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); | 157 btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); |
145 btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); | 158 btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); |
146 btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); | 159 btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); |
160 btn->progm = NULL; | |
147 rdman_redraw_changed(en->rdman); | 161 rdman_redraw_changed(en->rdman); |
148 return btn; | 162 return btn; |
149 } | 163 } |
150 | 164 |
151 | 165 |