annotate examples/calculator/main.c @ 88:dd813dcc232c

New example, calculator.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 23 Aug 2008 15:26:47 +0800
parents
children 90428161fc61
rev   line source
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <mb_types.h>
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <X_supp.h>
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <shapes.h>
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <tools.h>
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "calculator_scr.h"
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 typedef struct _ex_rt ex_rt_t;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 struct _ex_rt {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 X_MB_runtime_t *rt;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 calculator_scr_t *code;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 };
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 static struct {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 int c;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 int off;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 } tgt_list[] = {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 { 0, OFFSET(calculator_scr_t, but_0) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 { 1, OFFSET(calculator_scr_t, but_1) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 { 2, OFFSET(calculator_scr_t, but_2) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 { 3, OFFSET(calculator_scr_t, but_3) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 { 4, OFFSET(calculator_scr_t, but_4) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 { 5, OFFSET(calculator_scr_t, but_5) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 { 6, OFFSET(calculator_scr_t, but_6) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 { 7, OFFSET(calculator_scr_t, but_7) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 { 8, OFFSET(calculator_scr_t, but_8) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 { 9, OFFSET(calculator_scr_t, but_9) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 { '+', OFFSET(calculator_scr_t, but_add) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 { '-', OFFSET(calculator_scr_t, but_minus) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 { '*', OFFSET(calculator_scr_t, but_mul) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 { '/', OFFSET(calculator_scr_t, but_div) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 { '=', OFFSET(calculator_scr_t, but_eq) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 { 'c', OFFSET(calculator_scr_t, but_clr) }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 };
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 static int real_compute(int op, int v1, int v2) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 int r = v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 switch(op) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 case '+':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 r = v1 + v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 case '-':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 r = v1 - v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 case '*':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 r = v1 * v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 case '/':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 r = v1 / v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 return r;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 static void show_text(ex_rt_t *ex_rt, int num) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 char buf[20];
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 sprintf(buf, "%d", num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 sh_text_set_text(ex_rt->code->screen_text, buf);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 rdman_shape_changed(ex_rt->rt->rdman, ex_rt->code->screen_text);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 static void compute(ex_rt_t *ex_rt, coord_t *tgt) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 int i;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 coord_t **coord_p;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 static int num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 static int saved = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 static int op = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 for(i = 0; i < 16; i++) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 coord_p = (coord_t **)((void *)ex_rt->code + tgt_list[i].off);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 if(*coord_p == (void *)tgt)
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 if(i >= 16) return;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 if(i < 10) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 num = num * 10 + i;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 show_text(ex_rt, num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 } else {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 switch(tgt_list[i].c) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 case 'c':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 saved = num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 show_text(ex_rt, 0);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 case '+':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 saved = real_compute(op, saved, num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 show_text(ex_rt, saved);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 op = '+';
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 case '-':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 saved = real_compute(op, saved, num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 show_text(ex_rt, saved);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 op = '-';
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 case '*':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 saved = real_compute(op, saved, num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 show_text(ex_rt, saved);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 op = '*';
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 case '/':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 saved = real_compute(op, saved, num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 show_text(ex_rt, saved);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 op = '/';
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 case '=':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 saved = real_compute(op, saved, num);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 show_text(ex_rt, saved);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 num = 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 rdman_redraw_changed(ex_rt->rt->rdman);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 static void buttons_handler(event_t *evt, void *arg) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 ex_rt_t *ex_rt = (ex_rt_t *)arg;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 switch(evt->type) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 case EVT_MOUSE_BUT_PRESS:
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 compute(ex_rt, (coord_t *)evt->cur_tgt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 static void setup_observers(ex_rt_t *ex_rt) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 calculator_scr_t *calculator_scr;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 ob_factory_t *factory;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 subject_t *subject;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 calculator_scr = ex_rt->code;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 factory = rdman_get_ob_factory(ex_rt->rt->rdman);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 subject = coord_get_mouse_event(calculator_scr->but_0);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 subject = coord_get_mouse_event(calculator_scr->but_1);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 subject = coord_get_mouse_event(calculator_scr->but_2);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 subject = coord_get_mouse_event(calculator_scr->but_3);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 subject = coord_get_mouse_event(calculator_scr->but_4);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 subject = coord_get_mouse_event(calculator_scr->but_5);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 subject = coord_get_mouse_event(calculator_scr->but_6);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159 subject = coord_get_mouse_event(calculator_scr->but_7);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 subject = coord_get_mouse_event(calculator_scr->but_8);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 subject = coord_get_mouse_event(calculator_scr->but_9);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165 subject = coord_get_mouse_event(calculator_scr->but_add);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 subject = coord_get_mouse_event(calculator_scr->but_minus);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 subject = coord_get_mouse_event(calculator_scr->but_mul);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 subject = coord_get_mouse_event(calculator_scr->but_div);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 subject = coord_get_mouse_event(calculator_scr->but_eq);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 subject = coord_get_mouse_event(calculator_scr->but_clr);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 subject_add_observer(factory, subject, buttons_handler, ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 int main(int argc, char * const argv[]) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 X_MB_runtime_t rt;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 calculator_scr_t *calculator_scr;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182 ex_rt_t ex_rt;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 int r;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 r = X_MB_init(":0.0", 300, 400, &rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
187 calculator_scr = calculator_scr_new(rt.rdman);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
188
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189 ex_rt.rt = &rt;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190 ex_rt.code = calculator_scr;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 setup_observers(&ex_rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193 X_MB_handle_connection(&rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 calculator_scr_free(calculator_scr);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 X_MB_destroy(&rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198 return 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 }