annotate src/mbaf/mbbutton.c @ 320:6e164a9dd46c

Fix the Makefile to generate files correctly. The filebrowser is not working yet.
author wycc
date Thu, 05 Mar 2009 08:19:43 +0800
parents 2ca0773cd48d
children 01038b8d8f05
rev   line source
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
1
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
2 #include <stdio.h>
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
3 #include <mb.h>
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
4 #include <string.h>
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
5 #include "mbapp.h"
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
6
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
7
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
8
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
9 #define CMOUSE(e) (coord_get_mouse_event(e))
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
10
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
11
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
12 static void mb_button_pressed(event_t *evt, void *arg);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
13 static void mb_button_out(event_t *evt, void *arg);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
14
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
15 void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
16 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
17 b->press = h;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
18 b->arg = arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
19 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
20
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
21 void mb_button_refresh(mb_button_t *btn)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
22 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
23 rdman_coord_changed(btn->rdman,btn->root);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
24 rdman_redraw_changed(btn->rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
25 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
26
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
27 static void mb_button_move(event_t *evt, void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
28 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
29 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
30
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
31
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
32 printf("Mouse move\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
33 coord_show(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
34 mb_button_refresh(btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
35 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
36 static void mb_button_out(event_t *evt, void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
37 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
38 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
39
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
40 if (btn->progm) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
41 mb_progm_abort(btn->progm);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
42 btn->progm = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
43 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
44 printf("mouse out\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
45 coord_hide(btn->click);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
46 coord_hide(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
47 coord_show(btn->normal);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
48 mb_button_refresh(btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
49 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
50
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
51 static void mb_button_show_active(event_t *evt, void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
52 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
53 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
54
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
55 coord_show(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
56 mb_button_refresh(btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
57 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
58
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
59 static void mb_button_pressed(event_t *evt, void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
60 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
61 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
62 mb_timeval_t start, playing, now;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
63 mb_progm_t *progm;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
64 mb_word_t *word;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
65
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
66 printf("Pressed\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
67 if (btn->progm) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
68 mb_progm_abort(btn->progm);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
69 btn->progm = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
70 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
71 coord_show(btn->click);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
72 coord_hide(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
73 rdman_coord_changed(btn->rdman,btn->root);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
74 rdman_redraw_changed(btn->rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
75
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
76 btn->progm = progm = mb_progm_new(1, btn->rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
77 MB_TIMEVAL_SET(&start, 0, 500000);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
78 MB_TIMEVAL_SET(&playing, 0, 0);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
79 word = mb_progm_next_word(progm, &start, &playing);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
80 mb_visibility_new(VIS_HIDDEN, btn->click, word);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
81 mb_visibility_new(VIS_VISIBLE, btn->active, word);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
82 mb_progm_free_completed(progm);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
83 get_now(&now);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
84 printf("rt = %x\n", btn->rdman->rt);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
85 mb_progm_start(progm, X_MB_tman(btn->rdman->rt), &now);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
86 if (btn->press)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
87 btn->press(btn->arg);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
88 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
89 mb_button_t *mb_button_new(redraw_man_t *rdman,mb_sprite_t *sp, char *name)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
90 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
91 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t));
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
92 char *buf = (char *) malloc(strlen(name)+5);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
93
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
94 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
95 sprintf(buf, "%s_normal", name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
96 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
97 if (btn->normal == NULL) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
98 printf("Missing normal button, this is not a correct button\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
99 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
100 sprintf(buf, "%s_active", name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
101 btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
102 if (btn->active == NULL) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
103 printf("Missing click button, this is not a correct button\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
104 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
105 sprintf(buf, "%s_click", name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
106 btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
107 if (btn->active == NULL) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
108 printf("Missing click button, this is not a correct button\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
109 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
110 btn->press = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
111 // Show only the normal button
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
112 coord_hide(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
113 coord_hide(btn->click);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
114 coord_show(btn->normal);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
115 // Move to the same position
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
116 btn->active->matrix[2] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
117 btn->active->matrix[5] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
118 btn->normal->matrix[2] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
119 btn->normal->matrix[5] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
120 btn->click->matrix[2] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
121 btn->click->matrix[5] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
122 btn->rdman = rdman;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
123 btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
124 btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
125 btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
126 btn->progm = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
127 rdman_redraw_changed(rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
128 return btn;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
129 }