annotate examples/calculator/main.c @ 1435:b12c513212af

A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle. sort the scenes by layer and start attribute.
author wycc
date Mon, 11 Apr 2011 12:54:39 +0800
parents 7451af5d63ec
children
rev   line source
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
432
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
2 #include <string.h>
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 130
diff changeset
3 #include <mb.h>
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "calculator_scr.h"
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
6 typedef struct _calc_data calc_data_t;
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
7 struct _calc_data {
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
8 mb_rt_t *rt;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 calculator_scr_t *code;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 };
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 static struct {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 int c;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 int off;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 } tgt_list[] = {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 { 0, OFFSET(calculator_scr_t, but_0) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 { 1, OFFSET(calculator_scr_t, but_1) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 { 2, OFFSET(calculator_scr_t, but_2) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 { 3, OFFSET(calculator_scr_t, but_3) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 { 4, OFFSET(calculator_scr_t, but_4) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 { 5, OFFSET(calculator_scr_t, but_5) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 { 6, OFFSET(calculator_scr_t, but_6) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 { 7, OFFSET(calculator_scr_t, but_7) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 { 8, OFFSET(calculator_scr_t, but_8) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 { 9, OFFSET(calculator_scr_t, but_9) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 { '+', OFFSET(calculator_scr_t, but_add) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 { '-', OFFSET(calculator_scr_t, but_minus) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 { '*', OFFSET(calculator_scr_t, but_mul) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 { '/', OFFSET(calculator_scr_t, but_div) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 { '=', OFFSET(calculator_scr_t, but_eq) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 { 'c', OFFSET(calculator_scr_t, but_clr) }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 };
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 static int real_compute(int op, int v1, int v2) {
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
35 int r = v1;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 switch(op) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 case '+':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 r = v1 + v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 case '-':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 r = v1 - v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 case '*':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 r = v1 * v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 case '/':
93
Thinker K.F. Li <thinker@branda.to>
parents: 92
diff changeset
48 r = v1;
89
90428161fc61 Prevent divide by zero error
Thinker K.F. Li <thinker@branda.to>
parents: 88
diff changeset
49 if(v2)
93
Thinker K.F. Li <thinker@branda.to>
parents: 92
diff changeset
50 r /= v2;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 break;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
52 case 'n':
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
53 r = v2;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
54 break;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
55 case 'N':
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
56 break;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 return r;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
62 static void show_text(calc_data_t *calc_data, int num, int saved, int op,
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
63 const char *suffix) {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 char buf[20];
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
65 redraw_man_t *rdman;
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
66
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
67 rdman = mb_runtime_rdman(calc_data->rt);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
69 sprintf(buf, "%d%s", num, suffix);
432
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
70 sh_stext_set_text(calc_data->code->screen_text_u, buf);
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
71 calc_data->code->screen_text_u_style_blks[0].n_chars = strlen(buf);
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
72 sh_stext_set_style(calc_data->code->screen_text_u,
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
73 calc_data->code->screen_text_u_style_blks, 1);
278
a90fd749af82 Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents: 192
diff changeset
74 rdman_shape_changed(rdman, calc_data->code->screen_text_u);
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
75
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
76 if(op == 'n')
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
77 sprintf(buf, "None");
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
78 else
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
79 sprintf(buf, "%d%c", saved, op);
432
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
80 sh_stext_set_text(calc_data->code->saved_text, buf);
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
81 calc_data->code->saved_text_style_blks[0].n_chars = strlen(buf);
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
82 sh_stext_set_style(calc_data->code->saved_text,
331467b8e778 Make calcuator uses stext instead of text.
Thinker K.F. Li <thinker@branda.to>
parents: 280
diff changeset
83 calc_data->code->saved_text_style_blks, 1);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
84 rdman_shape_changed(rdman, calc_data->code->saved_text);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
87 static void compute(calc_data_t *calc_data, coord_t *tgt) {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 int i;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 coord_t **coord_p;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
90 redraw_man_t *rdman;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
91 static int valid_num = 0;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
92 static int factor = 1;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 static int num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
94 static int op = 'n';
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
95 static int saved = 0;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
96 char buf[2] = " ";
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 for(i = 0; i < 16; i++) {
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
99 coord_p = (coord_t **)((void *)calc_data->code + tgt_list[i].off);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 if(*coord_p == (void *)tgt)
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 if(i >= 16) return;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 if(i < 10) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 num = num * 10 + i;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
107 show_text(calc_data, num * factor, saved, op, "");
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
108 valid_num = 1;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 } else {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 switch(tgt_list[i].c) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 case 'c':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 saved = num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
113 factor = 1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
114 valid_num = 0;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
115 op = 'n';
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
116 show_text(calc_data, 0, saved, op, "");
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
119 case '-':
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
120 if(!valid_num) {
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
121 factor *= -1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
122 valid_num = 1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
123 break;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
124 }
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 case '+':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 case '*':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 case '/':
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
128 saved = real_compute(op, saved, num * factor);
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
129 buf[0] = tgt_list[i].c;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
130 show_text(calc_data, saved, saved, 'n', buf);
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
131 op = tgt_list[i].c;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
133 factor = 1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
134 valid_num = 0;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 break;
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 case '=':
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
138 saved = real_compute(op, saved, num * factor);
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
139 show_text(calc_data, saved, 0, 'n', "");
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
141 op = 'N';
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144 }
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
145 rdman = mb_runtime_rdman(calc_data->rt);
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
146 rdman_redraw_changed(rdman);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 static void buttons_handler(event_t *evt, void *arg) {
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
150 calc_data_t *calc_data = (calc_data_t *)arg;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 switch(evt->type) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 case EVT_MOUSE_BUT_PRESS:
271
c990a9a9648f Fix bug of calculator.
Thinker K.F. Li <thinker@branda.to>
parents: 192
diff changeset
154 compute(calc_data, (coord_t *)evt->cur_tgt->obj);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
159 static void setup_observers(calc_data_t *calc_data) {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 calculator_scr_t *calculator_scr;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 subject_t *subject;
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
162 coord_t *coord;
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
163 int off;
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
164 int i;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
166 calculator_scr = calc_data->code;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
168 for(i = 0; i < 16; i++) {
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
169 off = tgt_list[i].off;
93
Thinker K.F. Li <thinker@branda.to>
parents: 92
diff changeset
170 coord = OFF2TYPE(calculator_scr, off, coord_t *);
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
171 subject = coord_get_mouse_event(coord);
192
54fdc2a65242 Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents: 186
diff changeset
172 subject_add_observer(subject, buttons_handler, calc_data);
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
173 }
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 int main(int argc, char * const argv[]) {
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
177 mb_rt_t *rt;
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
178 redraw_man_t *rdman;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 calculator_scr_t *calculator_scr;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
180 calc_data_t calc_data;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181
1114
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1025
diff changeset
182 #ifdef CONSOLE_BACKEND
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1025
diff changeset
183 rt = mb_runtime_new(NULL, 300, 400);
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1025
diff changeset
184 #else
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
185 rt = mb_runtime_new(":0.0", 300, 400);
1114
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1025
diff changeset
186 #endif
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
187
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
188 rdman = mb_runtime_rdman(rt);
130
3a4d6179e6a9 change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents: 122
diff changeset
189 calculator_scr = calculator_scr_new(rdman, rdman->root_coord);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190
122
17e97e92b76e Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents: 108
diff changeset
191 calc_data.rt = rt;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
192 calc_data.code = calculator_scr;
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
193 setup_observers(&calc_data);
1114
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1025
diff changeset
194
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1025
diff changeset
195 mb_runtime_flush(rt);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
197 mb_runtime_event_loop(rt);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 calculator_scr_free(calculator_scr);
1025
32425882e351 Migrate examples/calculator/ to new bacend definition
Thinker K.F. Li <thinker@codemud.net>
parents: 432
diff changeset
200 mb_runtime_free(rt);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202 return 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 }