Mercurial > MadButterfly
comparison examples/drag/main.c @ 214:09ad4382aa41
Modify the drag example to use the sprite API.
author | wycc |
---|---|
date | Fri, 12 Dec 2008 09:11:47 +0800 |
parents | 55533146efdf |
children | 1eb9ee5ae4f2 |
comparison
equal
deleted
inserted
replaced
212:5f144bab5de1 | 214:09ad4382aa41 |
---|---|
14 redraw_man_t *rdman; | 14 redraw_man_t *rdman; |
15 menu_t *menu; | 15 menu_t *menu; |
16 int state; | 16 int state; |
17 co_aix orx,ory; | 17 co_aix orx,ory; |
18 int start_x,start_y; | 18 int start_x,start_y; |
19 coord_t *cursor; | |
19 }; | 20 }; |
20 engine_t *engine_init() | 21 engine_t *engine_init() |
21 { | 22 { |
22 | 23 |
23 X_MB_runtime_t *rt; | 24 X_MB_runtime_t *rt; |
58 engine_t *en = (engine_t *) arg; | 59 engine_t *en = (engine_t *) arg; |
59 mouse_event_t *mev = (mouse_event_t *) evt; | 60 mouse_event_t *mev = (mouse_event_t *) evt; |
60 | 61 |
61 en->start_x = mev->x; | 62 en->start_x = mev->x; |
62 en->start_y = mev->y; | 63 en->start_y = mev->y; |
63 en->orx = en->menu->cursor->matrix[2]; | 64 en->orx = en->cursor->matrix[2]; |
64 en->ory = en->menu->cursor->matrix[5]; | 65 en->ory = en->cursor->matrix[5]; |
65 printf("pressed %g %g\n",en->orx,en->ory); | 66 printf("pressed %g %g\n",en->orx,en->ory); |
66 en->state = 1; | 67 en->state = 1; |
67 } | 68 } |
68 | 69 |
69 static void cursor_release_handler(event_t *evt, void *arg) { | 70 static void cursor_release_handler(event_t *evt, void *arg) { |
76 engine_t *en = (engine_t *) arg; | 77 engine_t *en = (engine_t *) arg; |
77 mouse_event_t *mev = (mouse_event_t *) evt; | 78 mouse_event_t *mev = (mouse_event_t *) evt; |
78 | 79 |
79 if (en->state) { | 80 if (en->state) { |
80 printf("move to (%d %d)\n", mev->x,mev->y); | 81 printf("move to (%d %d)\n", mev->x,mev->y); |
81 coord_move(en->menu->cursor,en->orx + (mev->x-en->start_x),en->ory + (mev->y-en->start_y)); | 82 coord_move(en->cursor,en->orx + (mev->x-en->start_x),en->ory + (mev->y-en->start_y)); |
82 rdman_coord_changed(en->rdman, en->menu->cursor); | 83 rdman_coord_changed(en->rdman, en->cursor); |
83 /* Update changed part to UI. */ | 84 /* Update changed part to UI. */ |
84 rdman_redraw_changed(en->rdman); | 85 rdman_redraw_changed(en->rdman); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
89 subject_t *subject; | 90 subject_t *subject; |
90 engine_t *en; | 91 engine_t *en; |
91 | 92 |
92 en = engine_init(); | 93 en = engine_init(); |
93 en->menu = menu_new(en->rdman, en->rdman->root_coord); | 94 en->menu = menu_new(en->rdman, en->rdman->root_coord); |
95 en->cursor = (coord_t *) MB_SPRITE_GET_OBJ(&en->menu->lsym.sprite, "star"); | |
96 printf("en->cursor=%x star=%x\n",en->cursor,en->menu->star); | |
97 printf("sprite=%x\n",&en->menu->lsym.sprite); | |
98 printf("en->menu=%x\n",en->menu); | |
94 | 99 |
95 /* | 100 /* |
96 * Register observers to subjects of events for objects. | 101 * Register observers to subjects of events for objects. |
97 */ | 102 */ |
98 subject = coord_get_mouse_event(en->menu->cursor); | 103 subject = coord_get_mouse_event(en->cursor); |
99 subject_add_event_observer(subject, EVT_MOUSE_BUT_PRESS, cursor_press_handler, en); | 104 subject_add_event_observer(subject, EVT_MOUSE_BUT_PRESS, cursor_press_handler, en); |
100 subject_add_event_observer(subject, EVT_MOUSE_BUT_RELEASE, cursor_release_handler, en); | 105 subject_add_event_observer(subject, EVT_MOUSE_BUT_RELEASE, cursor_release_handler, en); |
101 subject_add_event_observer(subject, EVT_MOUSE_MOVE, cursor_move_handler, en); | 106 subject_add_event_observer(subject, EVT_MOUSE_MOVE, cursor_move_handler, en); |
102 | 107 |
103 | 108 |