changeset 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 1958bb2a87a2
children 3271ea1ef96f 5006e4abdda5
files examples/dynamic/button.svg examples/dynamic/main.c examples/dynamic/mbapp.c examples/dynamic/mbbutton.c examples/dynamic/mbbutton.h include/mb_redraw_man.h src/X_supp.c
diffstat 7 files changed, 50 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/examples/dynamic/button.svg	Sat Jan 03 08:43:29 2009 +0800
+++ b/examples/dynamic/button.svg	Sun Jan 04 09:32:49 2009 +0800
@@ -30,7 +30,7 @@
      inkscape:cx="257.06285"
      inkscape:cy="365.06674"
      inkscape:document-units="px"
-     inkscape:current-layer="btn_click"
+     inkscape:current-layer="layer1"
      showgrid="false"
      inkscape:window-width="1400"
      inkscape:window-height="978"
@@ -106,6 +106,7 @@
          x="235.71429"
          y="282.36218" /></text>
     <g
+       mbtype="button"
        id="btn"
        transform="translate(148.57143,98.571429)"
        mbname="btn">
@@ -114,7 +115,7 @@
          id="btn_normal"
          transform="translate(148.57143,98.571429)"
          mbname="btn_normal"
-         style="display:none">
+         style="">
         <rect
            ry="5.0559778"
            rx="6.0995407"
@@ -134,6 +135,15 @@
              x="10.000002"
              id="tspan2655"
              sodipodi:role="line">Click Me</tspan></text>
+        <rect
+           ry="5.0559778"
+           rx="6.0995407"
+           y="38.600159"
+           x="105.64253"
+           height="42.66333"
+           width="34.536983"
+           id="rect2385"
+           style="fill:#f136ff;fill-opacity:1;stroke:#000000;stroke-opacity:1" />
       </g>
       <g
          frame="active"
@@ -162,11 +172,11 @@
              sodipodi:role="line">Click Me</tspan></text>
       </g>
       <g
+         style="display:none"
          frame="click"
          id="btn_click"
          transform="translate(148.57143,98.571429)"
-         mbname="btn_click"
-         style="">
+         mbname="btn_click">
         <rect
            ry="5.0559778"
            rx="6.0995407"
--- a/examples/dynamic/main.c	Sat Jan 03 08:43:29 2009 +0800
+++ b/examples/dynamic/main.c	Sun Jan 04 09:32:49 2009 +0800
@@ -116,9 +116,18 @@
     MB_SPRITE_GOTO_SCENE(myApp->rootsprite,en->currentscene + 1);
 }
 
+MyApp_InitContent()
+{
+    mb_button_t *b;
+    mb_sprite_t *sprite;
+
+    sprite = sprite_load("button", myApp->rdman, myApp->rdman->root_coord);
+    b = mb_button_new(myApp->rdman, sprite, "btn");
+    mb_button_add_onClick(b, test,NULL);
+}
+
 int main(int argc, char * const argv[]) {
     subject_t *subject;
-    mb_button_t *b;
     mb_obj_t *button;
     MyAppData data;
     mb_timeval_t tmo,interval;
@@ -129,8 +138,7 @@
 	    myApp = MBApp_Init("scene");
     data.currentscene=0;
     MBApp_setData(myApp,&data);
-    //b = mb_button_new(myApp, myApp->rootsprite, "btn");
-    //mb_button_add_onClick(b, test,NULL);
+    MyApp_InitContent();
     get_now(&tmo);
     MB_TIMEVAL_SET(&interval, 1 ,0);
     mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp);
--- a/examples/dynamic/mbapp.c	Sat Jan 03 08:43:29 2009 +0800
+++ b/examples/dynamic/mbapp.c	Sun Jan 04 09:32:49 2009 +0800
@@ -10,6 +10,7 @@
     app->rt = rt;
     app->rdman =  X_MB_rdman(rt);
     app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord);
+    rdman_attach_backend(app->rdman, rt);
     return app;
 }
 
--- 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;
 }
--- a/examples/dynamic/mbbutton.h	Sat Jan 03 08:43:29 2009 +0800
+++ b/examples/dynamic/mbbutton.h	Sun Jan 04 09:32:49 2009 +0800
@@ -2,7 +2,7 @@
 #define __MBBUTTON_H
 typedef struct _mb_button {
     mb_obj_t obj;
-    MBApp *en;
+    redraw_man_t *rdman;
     int state;
     coord_t *root;
     coord_t *active;
@@ -13,7 +13,7 @@
     observer_t *obs_move,*obs_out,*obs_press;
     mb_progm_t *progm;
 } mb_button_t;
-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);
 void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg);
 #endif
 
--- a/include/mb_redraw_man.h	Sat Jan 03 08:43:29 2009 +0800
+++ b/include/mb_redraw_man.h	Sun Jan 04 09:32:49 2009 +0800
@@ -74,6 +74,10 @@
 				 *	    \see addrm_monitor_hdlr()
 				 */
     mb_obj_t *last_mouse_over;
+    void *rt;                  /*!< \brief This is a pointer to the current 
+                                *          graphic backend. 
+				*          \see rdman_attach_backend()
+				*/
 };
 
 extern int redraw_man_init(redraw_man_t *rdman, cairo_t *cr,
@@ -186,6 +190,10 @@
 #define rdman_clear_shape_gl(rdman)		\
     DARRAY_CLEAN(rdman_get_gen_geos(rdman))
 
+/*! \brief Attach backend to the redraw manager so that we can hide the backend from the users.
+ *
+ */
+#define rdman_attach_backend(rdman,backend) (((rdman)->rt)=(backend))
 /*! \brief Load sprite dymanicly from the shared object module. 
  *  
  *   The search path can be changed by sprite_set_search_path. The name can have a relative path in the front of it.
@@ -199,5 +207,4 @@
  */
 void sprite_set_search_path(char *path);
 
-
 #endif /* __REDRAW_MAN_H_ */
--- a/src/X_supp.c	Sat Jan 03 08:43:29 2009 +0800
+++ b/src/X_supp.c	Sun Jan 04 09:32:49 2009 +0800
@@ -442,6 +442,10 @@
 
     xmb_rt->rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t));
     redraw_man_init(xmb_rt->rdman, xmb_rt->cr, xmb_rt->backend_cr);
+    // FIXME: This is a wired loopback reference. This is inly required when we need 
+    //        to get the xmb_rt->tman for the animation. We should relocate the tman
+    //	      to the redraw_man_t instead.
+    xmb_rt->rdman->rt = xmb_rt;
 
     xmb_rt->tman = mb_tman_new();