comparison examples/calculator/main.c @ 192:54fdc2a65242

Remove factory from observer APIs. - Save factory that used to new a subject as subject's attribute. - Get factory from subject himself instead of passing as an argument. - It make API of observer more simple and clean.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 18 Nov 2008 21:42:30 +0800
parents 530bb7728546
children c990a9a9648f a90fd749af82
comparison
equal deleted inserted replaced
191:18f8c3126cdb 192:54fdc2a65242
149 } 149 }
150 } 150 }
151 151
152 static void setup_observers(calc_data_t *calc_data) { 152 static void setup_observers(calc_data_t *calc_data) {
153 calculator_scr_t *calculator_scr; 153 calculator_scr_t *calculator_scr;
154 ob_factory_t *factory;
155 subject_t *subject; 154 subject_t *subject;
156 coord_t *coord; 155 coord_t *coord;
157 redraw_man_t *rdman;
158 int off; 156 int off;
159 int i; 157 int i;
160 158
161 calculator_scr = calc_data->code; 159 calculator_scr = calc_data->code;
162 rdman = X_MB_rdman(calc_data->rt);
163 factory = rdman_get_ob_factory(rdman);
164 160
165 for(i = 0; i < 16; i++) { 161 for(i = 0; i < 16; i++) {
166 off = tgt_list[i].off; 162 off = tgt_list[i].off;
167 coord = OFF2TYPE(calculator_scr, off, coord_t *); 163 coord = OFF2TYPE(calculator_scr, off, coord_t *);
168 subject = coord_get_mouse_event(coord); 164 subject = coord_get_mouse_event(coord);
169 subject_add_observer(factory, subject, buttons_handler, calc_data); 165 subject_add_observer(subject, buttons_handler, calc_data);
170 } 166 }
171 } 167 }
172 168
173 int main(int argc, char * const argv[]) { 169 int main(int argc, char * const argv[]) {
174 X_MB_runtime_t *rt; 170 X_MB_runtime_t *rt;