Mercurial > MadButterfly
comparison examples/calculator/main.c @ 1025:32425882e351 refine_backend_if
Migrate examples/calculator/ to new bacend definition
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 16:05:24 +0800 |
parents | 331467b8e778 |
children | 7451af5d63ec |
comparison
equal
deleted
inserted
replaced
1024:63f2f1daf5d3 | 1025:32425882e351 |
---|---|
3 #include <mb.h> | 3 #include <mb.h> |
4 #include "calculator_scr.h" | 4 #include "calculator_scr.h" |
5 | 5 |
6 typedef struct _calc_data calc_data_t; | 6 typedef struct _calc_data calc_data_t; |
7 struct _calc_data { | 7 struct _calc_data { |
8 X_MB_runtime_t *rt; | 8 mb_rt_t *rt; |
9 calculator_scr_t *code; | 9 calculator_scr_t *code; |
10 }; | 10 }; |
11 | 11 |
12 static struct { | 12 static struct { |
13 int c; | 13 int c; |
62 static void show_text(calc_data_t *calc_data, int num, int saved, int op, | 62 static void show_text(calc_data_t *calc_data, int num, int saved, int op, |
63 const char *suffix) { | 63 const char *suffix) { |
64 char buf[20]; | 64 char buf[20]; |
65 redraw_man_t *rdman; | 65 redraw_man_t *rdman; |
66 | 66 |
67 rdman = X_MB_rdman(calc_data->rt); | 67 rdman = mb_runtime_rdman(calc_data->rt); |
68 | 68 |
69 sprintf(buf, "%d%s", num, suffix); | 69 sprintf(buf, "%d%s", num, suffix); |
70 sh_stext_set_text(calc_data->code->screen_text_u, buf); | 70 sh_stext_set_text(calc_data->code->screen_text_u, buf); |
71 calc_data->code->screen_text_u_style_blks[0].n_chars = strlen(buf); | 71 calc_data->code->screen_text_u_style_blks[0].n_chars = strlen(buf); |
72 sh_stext_set_style(calc_data->code->screen_text_u, | 72 sh_stext_set_style(calc_data->code->screen_text_u, |
140 num = 0; | 140 num = 0; |
141 op = 'N'; | 141 op = 'N'; |
142 break; | 142 break; |
143 } | 143 } |
144 } | 144 } |
145 rdman = X_MB_rdman(calc_data->rt); | 145 rdman = mb_runtime_rdman(calc_data->rt); |
146 rdman_redraw_changed(rdman); | 146 rdman_redraw_changed(rdman); |
147 } | 147 } |
148 | 148 |
149 static void buttons_handler(event_t *evt, void *arg) { | 149 static void buttons_handler(event_t *evt, void *arg) { |
150 calc_data_t *calc_data = (calc_data_t *)arg; | 150 calc_data_t *calc_data = (calc_data_t *)arg; |
172 subject_add_observer(subject, buttons_handler, calc_data); | 172 subject_add_observer(subject, buttons_handler, calc_data); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 int main(int argc, char * const argv[]) { | 176 int main(int argc, char * const argv[]) { |
177 X_MB_runtime_t *rt; | 177 mb_rt_t *rt; |
178 redraw_man_t *rdman; | 178 redraw_man_t *rdman; |
179 calculator_scr_t *calculator_scr; | 179 calculator_scr_t *calculator_scr; |
180 calc_data_t calc_data; | 180 calc_data_t calc_data; |
181 | 181 |
182 rt = X_MB_new(":0.0", 300, 400); | 182 rt = mb_runtime_new(":0.0", 300, 400); |
183 | 183 |
184 rdman = X_MB_rdman(rt); | 184 rdman = mb_runtime_rdman(rt); |
185 calculator_scr = calculator_scr_new(rdman, rdman->root_coord); | 185 calculator_scr = calculator_scr_new(rdman, rdman->root_coord); |
186 | 186 |
187 calc_data.rt = rt; | 187 calc_data.rt = rt; |
188 calc_data.code = calculator_scr; | 188 calc_data.code = calculator_scr; |
189 setup_observers(&calc_data); | 189 setup_observers(&calc_data); |
190 | 190 |
191 X_MB_handle_connection(rt); | 191 mb_runtime_event_loop(rt); |
192 | 192 |
193 calculator_scr_free(calculator_scr); | 193 calculator_scr_free(calculator_scr); |
194 X_MB_free(rt); | 194 mb_runtime_free(rt); |
195 | 195 |
196 return 0; | 196 return 0; |
197 } | 197 } |