annotate examples/dynamic/main.c @ 201:31933f9ee70e

Chkec in demo for dynamic rectangle creation and button.
author wycc@wycc-desktop
date Sun, 07 Dec 2008 18:00:06 +0800
parents
children 8d9d717c9300
rev   line source
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
1 /*! \file
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
2 *
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
3 * svg2code_ex is an example that show programmers how to create a
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
4 * menu with MadButterfly.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
5 *
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
6 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
7 #include <stdio.h>
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
8 #include <mb.h>
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
9 #include "menu.h"
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
10 #include "button.h"
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
11
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
12
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
13 typedef struct _engine engine_t;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
14 struct _engine {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
15 X_MB_runtime_t *rt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
16 redraw_man_t *rdman;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
17 menu_t *menu;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
18 button_t *button;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
19 int state;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
20 co_aix orx,ory;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
21 int start_x,start_y;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
22 observer_t *obs1,*obs2;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
23 shape_t *rect;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
24 co_aix rx,ry;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
25 };
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
26 engine_t *engine_init()
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
27 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
28
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
29 X_MB_runtime_t *rt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
30 rt = X_MB_new(":0.0", 800, 600);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
31 engine_t *en = (engine_t *) malloc(sizeof(engine_t));
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
32
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
33 en->rt = rt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
34 en->rdman = X_MB_rdman(rt);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
35 return en;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
36 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
37
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
38 void engine_close(engine_t *en)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
39 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
40 /*
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
41 * Start handle connections, includes one to X server.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
42 * User start to interact with the application.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
43 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
44 X_MB_handle_connection(en->rt);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
45
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
46 /*
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
47 * Clean
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
48 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
49 menu_free(en->menu);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
50 X_MB_free(en->rt);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
51 free(en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
52 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
53 #define COORD_SHOW(group) coord_show(group);rdman_coord_changed(en->rdman, group)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
54 #define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(en->rdman, group)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
55
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
56 #define CMOUSE(e) (coord_get_mouse_event(e))
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
57
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
58
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
59
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
60 static void button_move(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
61 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
62 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
63
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
64
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
65 printf("Mouse move\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
66 COORD_SHOW(en->button->active);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
67 rdman_coord_changed(en->rdman,en->button->root_coord);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
68 rdman_redraw_changed(en->rdman);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
69 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
70 static void button_out(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
71 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
72 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
73
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
74 printf("mouse out\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
75 COORD_HIDE(en->button->active);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
76 rdman_coord_changed(en->rdman,en->button->root_coord);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
77 rdman_redraw_changed(en->rdman);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
78 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
79
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
80 void button_pressed(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
81 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
82 printf("Pressed\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
83 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
84
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
85 void engine_add_button(engine_t *en, coord_t *normal, coord_t *active, void (*func)())
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
86 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
87 active->matrix[2] = 200;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
88 active->matrix[5] = 200;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
89 normal->matrix[2] = 200;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
90 normal->matrix[5] = 200;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
91 COORD_HIDE(en->button->active);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
92 rdman_coord_changed(en->rdman,en->button->root_coord);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
93 rdman_redraw_changed(en->rdman);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
94 subject_add_event_observer(CMOUSE(normal), EVT_MOUSE_MOVE, button_move,en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
95 subject_add_event_observer(CMOUSE(active), EVT_MOUSE_OUT, button_out,en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
96 subject_add_event_observer(CMOUSE(active), EVT_MOUSE_BUT_RELEASE, button_pressed,en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
97 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
98
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
99
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
100 void coord_move(coord_t *c, co_aix x, co_aix y)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
101 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
102 c->matrix[2] = x;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
103 c->matrix[5] = y;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
104 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
105
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
106
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
107
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
108 static void add_rect_move(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
109 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
110 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
111 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
112
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
113 printf("resize rectangle\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
114 sh_rect_set(en->rect, en->start_x, en->start_y, mev->x - en->start_x, mev->y-en->start_y,en->rx,en->ry);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
115 rdman_shape_changed(en->rdman,en->rect);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
116 rdman_redraw_changed(en->rdman);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
117 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
118
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
119 static void add_rect_release(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
120 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
121 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
122 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
123
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
124 printf("rectangle done\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
125 subject_remove_observer(CMOUSE(en->rdman->root_coord), en->obs1);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
126 subject_remove_observer(CMOUSE(en->rdman->root_coord), en->obs2);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
127 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
128
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
129 static void add_rect_2(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
130 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
131 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
132 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
133 paint_t *color;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
134
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
135 printf("select first point\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
136 // Add an rect path
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
137
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
138 en->start_x = mev->x;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
139 en->start_y = mev->y;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
140 subject_remove_observer(CMOUSE(en->rdman->root_coord), en->obs1);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
141 subject_remove_observer(CMOUSE(en->rdman->root_coord), en->obs2);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
142 en->obs1 = subject_add_event_observer(CMOUSE(en->rdman->root_coord), EVT_MOUSE_MOVE, add_rect_move, en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
143 en->obs2 = subject_add_event_observer(CMOUSE(en->rdman->root_coord), EVT_MOUSE_BUT_RELEASE, add_rect_release, en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
144 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
145
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
146 static void add_rect_2_move(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
147 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
148 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
149 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
150
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
151 sh_rect_set(en->rect, mev->x, mev->y, 50,50,en->rx,en->ry);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
152 rdman_shape_changed(en->rdman,en->rect);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
153 rdman_redraw_changed(en->rdman);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
154 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
155
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
156 static void add_rect(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
157 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
158 engine_t *en = (engine_t *) arg;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
159 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
160 paint_t *color;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
161
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
162 printf("menut selected\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
163 en->obs1 = subject_add_event_observer(CMOUSE(en->rdman->root_coord), EVT_MOUSE_BUT_PRESS, add_rect_2, en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
164 en->obs2 = subject_add_event_observer(CMOUSE(en->rdman->root_coord), EVT_MOUSE_MOVE, add_rect_2_move, en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
165 en->rect = rdman_shape_rect_new(en->rdman, mev->x, mev->y, 50 , 50, en->rx, en->ry);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
166 // Paint it with color
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
167 color = rdman_paint_color_new(en->rdman, 0.800000, 0.800000, 0.400000, 1.000000);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
168 rdman_paint_fill(en->rdman, color, en->rect);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
169 // Add to the stage
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
170 rdman_add_shape(en->rdman, en->rect, en->menu->root_coord);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
171 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
172
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
173
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
174
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
175
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
176
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
177 int main(int argc, char * const argv[]) {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
178 subject_t *subject;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
179 engine_t *en;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
180
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
181 en = engine_init();
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
182 en->menu = menu_new(en->rdman, en->rdman->root_coord);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
183 en->button = button_new(en->rdman, en->rdman->root_coord);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
184 engine_add_button(en, en->button->normal, en->button->active, button_pressed);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
185
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
186 en->rx = 0;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
187 en->ry = 0;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
188
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
189 /*
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
190 * Register observers to subjects of events for objects.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
191 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
192 subject = coord_get_mouse_event(en->menu->rect);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
193 subject_add_event_observer(subject, EVT_MOUSE_BUT_RELEASE, add_rect, en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
194
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
195
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
196 engine_close(en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
197
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
198 return 0;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
199 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
200
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
201 /* vim: set ts=4 */