annotate src/mbaf/mbbutton.c @ 1431:60f2c9a24cdb

Keep the same active layer and frame when switching back a timeline. - Add functions to remember frame and layer for timeline at domview. - Recall active frame and layer when calling switch_component() and switch_timeline().
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 11 Apr 2011 00:05:25 +0800
parents dffecd62817c
children
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 456
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 456
diff changeset
2 // vim: sw=4:ts=8:sts=4
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
3
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
4 #include <stdio.h>
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
5 #include <mb.h>
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
6 #include <string.h>
456
26c302b47de1 Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents: 335
diff changeset
7 #include "mb_af.h"
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
8
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
9
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
10
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
11 #define CMOUSE(e) (coord_get_mouse_event(e))
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
12
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
13
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
14 static void mb_button_pressed(event_t *evt, void *arg);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
15 static void mb_button_out(event_t *evt, void *arg);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
16
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
17 void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
18 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
19 b->press = h;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
20 b->arg = arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
21 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
22
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
23 void mb_button_refresh(mb_button_t *btn)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
24 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
25 rdman_coord_changed(btn->rdman,btn->root);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
26 rdman_redraw_changed(btn->rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
27 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
28
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 456
diff changeset
29 static void mb_button_move(event_t *evt, void *arg)
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
30 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
31 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
32
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 456
diff changeset
33
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
34 printf("Mouse move\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
35 coord_show(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
36 mb_button_refresh(btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
37 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 456
diff changeset
38 static void mb_button_out(event_t *evt, void *arg)
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
39 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
40 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
41
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
42 if (btn->progm) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
43 mb_progm_abort(btn->progm);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
44 btn->progm = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
45 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
46 printf("mouse out\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
47 coord_hide(btn->click);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
48 coord_hide(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
49 coord_show(btn->normal);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
50 mb_button_refresh(btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
51 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
52
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
53 static void mb_button_show_active(event_t *evt, void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
54 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
55 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
56
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
57 coord_show(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
58 mb_button_refresh(btn);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
59 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
60
335
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
61 static void mb_button_end_animated_cb(event_t *evt, void *arg)
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
62 {
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
63 mb_button_t *btn = (mb_button_t *) arg;
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
64
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
65 btn->progm = NULL;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 456
diff changeset
66
335
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
67 }
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
68
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
69 static void mb_button_pressed(event_t *evt, void *arg)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
70 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
71 mb_button_t *btn = (mb_button_t *) arg;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
72 mb_timeval_t start, playing, now;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
73 mb_progm_t *progm;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
74 mb_word_t *word;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
75
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
76 printf("Pressed\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
77 if (btn->progm) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
78 mb_progm_abort(btn->progm);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
79 btn->progm = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
80 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
81 coord_show(btn->click);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
82 coord_hide(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
83 rdman_coord_changed(btn->rdman,btn->root);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
84 rdman_redraw_changed(btn->rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
85
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
86 btn->progm = progm = mb_progm_new(1, btn->rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
87 MB_TIMEVAL_SET(&start, 0, 500000);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
88 MB_TIMEVAL_SET(&playing, 0, 0);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
89 word = mb_progm_next_word(progm, &start, &playing);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
90 mb_visibility_new(VIS_HIDDEN, btn->click, word);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
91 mb_visibility_new(VIS_VISIBLE, btn->active, word);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
92 mb_progm_free_completed(progm);
335
01038b8d8f05 Set the progm to be NULL so that we won't call mb_progm_abort when we call it at the next time. This will fix the crash issue of the dynamic. However, the dynamic is still crash sometimes if we click the button quickly. It looks like it crashes in the refresh. We need to future figure out the issue.
wycc
parents: 294
diff changeset
93 subject_add_observer(mb_progm_get_complete(btn->progm), mb_button_end_animated_cb,btn);
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
94 get_now(&now);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
95 printf("rt = %x\n", btn->rdman->rt);
1023
dffecd62817c Use mb_timer_man_t instead of mb_tman_t in mbaf
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
96 mb_progm_start(progm, mb_runtime_timer_man(btn->rdman->rt), &now);
294
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
97 if (btn->press)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
98 btn->press(btn->arg);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
99 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
100 mb_button_t *mb_button_new(redraw_man_t *rdman,mb_sprite_t *sp, char *name)
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
101 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
102 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t));
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
103 char *buf = (char *) malloc(strlen(name)+5);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
104
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
105 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
106 sprintf(buf, "%s_normal", name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
107 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
108 if (btn->normal == NULL) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
109 printf("Missing normal button, this is not a correct button\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
110 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
111 sprintf(buf, "%s_active", name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
112 btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
113 if (btn->active == NULL) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
114 printf("Missing click button, this is not a correct button\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
115 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
116 sprintf(buf, "%s_click", name);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
117 btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
118 if (btn->active == NULL) {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
119 printf("Missing click button, this is not a correct button\n");
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
120 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
121 btn->press = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
122 // Show only the normal button
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
123 coord_hide(btn->active);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
124 coord_hide(btn->click);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
125 coord_show(btn->normal);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
126 // Move to the same position
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
127 btn->active->matrix[2] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
128 btn->active->matrix[5] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
129 btn->normal->matrix[2] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
130 btn->normal->matrix[5] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
131 btn->click->matrix[2] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
132 btn->click->matrix[5] = 200;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
133 btn->rdman = rdman;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
134 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
135 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
136 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
137 btn->progm = NULL;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
138 rdman_redraw_changed(rdman);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
139 return btn;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
140 }