diff examples/dynamic/mbbutton.c @ 249:ab8284c8dcee

* Add loopback reference from rdman to the backend. This is only required when we need to acquire the tman for the animation. This is not a reasonable arrangement since the animation should be backend transparent. We should not touch the backend directly from the animation. We should relocate the tman to the rdman. * Remove reference to the MBApp from the mb_button_t so that it will be easier for us to generate button inside the sprite.
author wycc
date Sun, 04 Jan 2009 09:32:49 +0800
parents d9a78c859660
children 26c302b47de1
line wrap: on
line diff
--- a/examples/dynamic/mbbutton.c	Sat Jan 03 08:43:29 2009 +0800
+++ b/examples/dynamic/mbbutton.c	Sun Jan 04 09:32:49 2009 +0800
@@ -7,8 +7,6 @@
 
 
 #define CMOUSE(e) (coord_get_mouse_event(e))
-#define MBAPP_DATA(app,type) ((type *) ((app)->private))
-#define MBAPP_RDMAN(app) (((MBApp *) app)->rdman)
 
 
 static void mb_button_pressed(event_t *evt, void *arg);
@@ -22,26 +20,22 @@
 
 void mb_button_refresh(mb_button_t *btn)
 {
-    rdman_coord_changed(btn->en->rdman,btn->root);
-    rdman_redraw_changed(btn->en->rdman);
+    rdman_coord_changed(btn->rdman,btn->root);
+    rdman_redraw_changed(btn->rdman);
 }
 
 static void mb_button_move(event_t *evt, void *arg) 
 {
     mb_button_t *btn = (mb_button_t *) arg;
-    MBApp *en = btn->en;
 
     
     printf("Mouse move\n");
-    arg = (void *)en;
     coord_show(btn->active);
     mb_button_refresh(btn);
 }
 static void mb_button_out(event_t *evt, void *arg) 
 {
     mb_button_t *btn = (mb_button_t *) arg;
-    MBApp *en = btn->en;
-    arg = (void *) en;
 
     if (btn->progm) {
 	    mb_progm_abort(btn->progm);
@@ -57,7 +51,6 @@
 static void mb_button_show_active(event_t *evt, void *arg)
 {
     mb_button_t *btn = (mb_button_t *) arg;
-    MBApp *en = btn->en;
 
     coord_show(btn->active);
     mb_button_refresh(btn);
@@ -66,11 +59,9 @@
 static void mb_button_pressed(event_t *evt, void *arg)
 {
     mb_button_t *btn = (mb_button_t *) arg;
-    MBApp *en = btn->en;
     mb_timeval_t start, playing, now;
     mb_progm_t *progm;
     mb_word_t *word;
-    arg = (void *) en;
 
     printf("Pressed\n");
     if (btn->progm) {
@@ -79,10 +70,10 @@
     }
     coord_show(btn->click);
     coord_hide(btn->active);
-    rdman_coord_changed(MBAPP_RDMAN(arg),btn->root);
-    rdman_redraw_changed(MBAPP_RDMAN(arg));
+    rdman_coord_changed(btn->rdman,btn->root);
+    rdman_redraw_changed(btn->rdman);
 
-    btn->progm = progm = mb_progm_new(1, MBAPP_RDMAN(arg));
+    btn->progm = progm = mb_progm_new(1, btn->rdman);
     MB_TIMEVAL_SET(&start, 0, 500000);
     MB_TIMEVAL_SET(&playing, 0, 0);
     word = mb_progm_next_word(progm, &start, &playing);
@@ -90,15 +81,15 @@
     mb_visibility_new(VIS_VISIBLE, btn->active, word);
     mb_progm_free_completed(progm);
     get_now(&now);
-    mb_progm_start(progm, X_MB_tman(en->rt), &now);
+    printf("rt = %x\n", btn->rdman->rt);
+    mb_progm_start(progm, X_MB_tman(btn->rdman->rt), &now);
     if (btn->press)
     	btn->press(btn->arg);
 }
-mb_button_t *mb_button_new(MBApp *app,mb_sprite_t *sp, char *name)
+mb_button_t *mb_button_new(redraw_man_t *rdman,mb_sprite_t *sp, char *name)
 {
     mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t));
     char *buf = (char *) malloc(strlen(name)+5);
-    MBApp *arg = app;
 
     btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name);
     sprintf(buf, "%s_normal", name);
@@ -128,11 +119,11 @@
     btn->normal->matrix[5] = 200;
     btn->click->matrix[2] = 200;
     btn->click->matrix[5] = 200;
-    btn->en = app;
+    btn->rdman = rdman;
     btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn);
     btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn);
     btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn);
     btn->progm = NULL;
-    rdman_redraw_changed(MBAPP_RDMAN(arg));
+    rdman_redraw_changed(rdman);
     return btn;
 }