Mercurial > MadButterfly
annotate examples/dynamic/main.c @ 224:29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
- backend does not interpret mouse events (over/out/move), now.
- redraw manager, now, interpret mouse events to make it backend independent.
- The task (interpret mouse events) should be moved to somewhere in futhure.
- backend only sent MotionNotify as EVT_MOUSE_MOVE_RAW.
- EVT_MOUSE_MOVE_RAW is interpreted by backend independent code.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 15 Dec 2008 10:13:03 +0800 |
parents | ad4f8a956505 |
children | b24d7889cbda |
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> |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
9 #include <string.h> |
201
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
10 #include "menu.h" |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
11 #include "button.h" |
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 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
14 typedef struct _engine engine_t; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
15 struct _engine { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
16 X_MB_runtime_t *rt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
17 redraw_man_t *rdman; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
18 menu_t *menu; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
19 button_t *button; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
20 int state; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
21 co_aix orx,ory; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
22 int start_x,start_y; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
23 observer_t *obs1,*obs2; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
24 shape_t *rect; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
25 co_aix rx,ry; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
26 }; |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
27 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
28 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
29 typedef struct _mb_button { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
30 engine_t *en; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
31 coord_t *root; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
32 coord_t *active; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
33 coord_t *normal; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
34 coord_t *click; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
35 void (*press)(); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
36 void *arg; |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
37 observer_t *obs_move,*obs_out,*obs_press; |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
38 } mb_button_t; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
39 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
40 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
41 #define COORD_SHOW(group) coord_show(group);rdman_coord_changed(en->rdman, group) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
42 #define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(en->rdman, group) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
43 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
44 #define CMOUSE(e) (coord_get_mouse_event(e)) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
45 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
46 |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
47 static void mb_button_pressed(event_t *evt, void *arg); |
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
48 static void mb_button_out(event_t *evt, void *arg); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
49 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
50 static void mb_button_move(event_t *evt, void *arg) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
51 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
52 mb_button_t *btn = (mb_button_t *) arg; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
53 engine_t *en = btn->en; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
54 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
55 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
56 printf("Mouse move\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
57 COORD_SHOW(btn->active); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
58 #if 0 |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
59 rdman_coord_changed(btn->en->rdman,btn->root); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
60 #endif |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
61 rdman_redraw_changed(btn->en->rdman); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
62 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
63 static void mb_button_out(event_t *evt, void *arg) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
64 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
65 mb_button_t *btn = (mb_button_t *) arg; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
66 engine_t *en = btn->en; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
67 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
68 printf("mouse out\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
69 COORD_HIDE(btn->active); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
70 #if 0 |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
71 rdman_coord_changed(btn->en->rdman,btn->root); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
72 #endif |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
73 rdman_redraw_changed(btn->en->rdman); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
74 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
75 |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
76 void mb_button_show_active(event_t *evt, void *arg) |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
77 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
78 mb_button_t *btn = (mb_button_t *) arg; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
79 engine_t *en = btn->en; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
80 |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
81 COORD_SHOW(btn->active); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
82 rdman_coord_changed(btn->en->rdman,btn->root); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
83 rdman_redraw_changed(btn->en->rdman); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
84 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
85 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
86 void mb_button_pressed(event_t *evt, void *arg) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
87 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
88 mb_button_t *btn = (mb_button_t *) arg; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
89 engine_t *en = btn->en; |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
90 mb_timeval_t start, playing, now; |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
91 mb_progm_t *progm; |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
92 mb_word_t *word; |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
93 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
94 printf("Pressed\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
95 COORD_SHOW(btn->click); |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
96 COORD_HIDE(btn->active); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
97 rdman_coord_changed(en->rdman,en->button->root_coord); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
98 rdman_redraw_changed(en->rdman); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
99 |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
100 progm = mb_progm_new(1, en->rdman); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
101 MB_TIMEVAL_SET(&start, 0, 500000); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
102 MB_TIMEVAL_SET(&playing, 0, 0); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
103 word = mb_progm_next_word(progm, &start, &playing); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
104 mb_visibility_new(VIS_HIDDEN, btn->click, word); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
105 mb_visibility_new(VIS_VISIBLE, btn->active, word); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
106 mb_progm_free_completed(progm); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
107 get_now(&now); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
108 mb_progm_start(progm, X_MB_tman(en->rt), &now); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
109 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
110 mb_button_t *mb_button_new(engine_t *en,mb_sprite_t *sp, char *name) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
111 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
112 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t)); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
113 char *buf = (char *) malloc(strlen(name)+5); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
114 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
115 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
116 sprintf(buf, "%s_normal", name); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
117 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
118 if (btn->normal == NULL) { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
119 printf("Missing normal button, this is not a correct button\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
120 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
121 sprintf(buf, "%s_active", name); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
122 btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
123 if (btn->active == NULL) { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
124 printf("Missing active button, this is not a correct button\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
125 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
126 sprintf(buf, "%s_click", name); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
127 btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
128 if (btn->click == NULL) { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
129 printf("Missing click button, this is not a correct button\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
130 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
131 btn->press = NULL; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
132 // Show only the normal button |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
133 COORD_HIDE(btn->active); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
134 COORD_HIDE(btn->click); |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
135 COORD_SHOW(btn->normal); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
136 // Move to the same position |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
137 btn->active->matrix[2] = 200; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
138 btn->active->matrix[5] = 200; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
139 btn->normal->matrix[2] = 200; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
140 btn->normal->matrix[5] = 200; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
141 btn->click->matrix[2] = 200; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
142 btn->click->matrix[5] = 200; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
143 btn->en = en; |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
144 btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
145 btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
221
diff
changeset
|
146 btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
147 rdman_redraw_changed(en->rdman); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
148 return btn; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
149 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
150 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
151 |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
152 void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
153 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
154 b->press = h; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
155 b->arg = arg; |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
156 } |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
157 |
201
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
158 engine_t *engine_init() |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
159 { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
160 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
161 X_MB_runtime_t *rt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
162 rt = X_MB_new(":0.0", 800, 600); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
163 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
|
164 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
165 en->rt = rt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
166 en->rdman = X_MB_rdman(rt); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
167 return en; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
168 } |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
169 |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
170 void engine_mainloop(engine_t *en) |
201
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 * Start handle connections, includes one to X server. |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
174 * User start to interact with the application. |
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 X_MB_handle_connection(en->rt); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
177 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
178 /* |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
179 * Clean |
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 menu_free(en->menu); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
182 X_MB_free(en->rt); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
183 free(en); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
184 } |
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 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
187 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
|
188 { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
189 engine_t *en = (engine_t *) arg; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
190 mouse_event_t *mev = (mouse_event_t *) evt; |
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 printf("resize rectangle\n"); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
193 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
|
194 rdman_shape_changed(en->rdman,en->rect); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
195 rdman_redraw_changed(en->rdman); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
196 } |
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 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
|
199 { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
200 engine_t *en = (engine_t *) arg; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
201 mouse_event_t *mev = (mouse_event_t *) evt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
202 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
203 printf("rectangle done\n"); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
204 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
|
205 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
|
206 } |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
207 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
208 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
|
209 { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
210 engine_t *en = (engine_t *) arg; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
211 mouse_event_t *mev = (mouse_event_t *) evt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
212 paint_t *color; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
213 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
214 printf("select first point\n"); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
215 // Add an rect path |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
216 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
217 en->start_x = mev->x; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
218 en->start_y = mev->y; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 } |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
224 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
225 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
|
226 { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
227 engine_t *en = (engine_t *) arg; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
228 mouse_event_t *mev = (mouse_event_t *) evt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
229 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
230 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
|
231 rdman_shape_changed(en->rdman,en->rect); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
232 rdman_redraw_changed(en->rdman); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
233 } |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
234 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
235 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
|
236 { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
237 engine_t *en = (engine_t *) arg; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
238 mouse_event_t *mev = (mouse_event_t *) evt; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
239 paint_t *color; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
240 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
241 printf("menut selected\n"); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 // Paint it with color |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
246 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
|
247 rdman_paint_fill(en->rdman, color, en->rect); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
248 // Add to the stage |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
249 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
|
250 } |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
251 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
252 |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
253 void test(void *a) |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
254 { |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
255 printf("Button is pressed.....\n"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
256 } |
201
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
257 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
258 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
259 int main(int argc, char * const argv[]) { |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
260 subject_t *subject; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
261 engine_t *en; |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
262 mb_button_t *b; |
201
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
263 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
264 en = engine_init(); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
265 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
|
266 en->button = button_new(en->rdman, en->rdman->root_coord); |
217
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
267 b = mb_button_new(en, (mb_sprite_t *) en->button, "btn"); |
8d9d717c9300
Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents:
201
diff
changeset
|
268 mb_button_add_onClick(b, test,NULL); |
201
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
269 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
270 en->rx = 0; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
271 en->ry = 0; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
272 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
273 /* |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
274 * Register observers to subjects of events for objects. |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
275 */ |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
276 subject = coord_get_mouse_event(en->menu->rect); |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
277 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
|
278 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
279 |
221
ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents:
217
diff
changeset
|
280 engine_mainloop(en); |
201
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
281 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
282 return 0; |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
283 } |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
284 |
31933f9ee70e
Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff
changeset
|
285 /* vim: set ts=4 */ |