changeset 214:09ad4382aa41

Modify the drag example to use the sprite API.
author wycc
date Fri, 12 Dec 2008 09:11:47 +0800
parents 5f144bab5de1
children 9643d383bbb6
files examples/drag/main.c examples/drag/menu.svg
diffstat 2 files changed, 23 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/examples/drag/main.c	Fri Dec 12 09:10:05 2008 +0800
+++ b/examples/drag/main.c	Fri Dec 12 09:11:47 2008 +0800
@@ -16,6 +16,7 @@
     int state;
     co_aix orx,ory;
     int start_x,start_y;
+    coord_t *cursor;
 };
 engine_t *engine_init()
 {
@@ -60,8 +61,8 @@
 
     en->start_x = mev->x;
     en->start_y = mev->y;
-    en->orx = en->menu->cursor->matrix[2];
-    en->ory = en->menu->cursor->matrix[5];
+    en->orx = en->cursor->matrix[2];
+    en->ory = en->cursor->matrix[5];
     printf("pressed %g %g\n",en->orx,en->ory);
     en->state = 1;
 }
@@ -78,8 +79,8 @@
 
     if (en->state) {
         printf("move to (%d %d)\n", mev->x,mev->y);
-        coord_move(en->menu->cursor,en->orx + (mev->x-en->start_x),en->ory + (mev->y-en->start_y));
-        rdman_coord_changed(en->rdman, en->menu->cursor);
+        coord_move(en->cursor,en->orx + (mev->x-en->start_x),en->ory + (mev->y-en->start_y));
+        rdman_coord_changed(en->rdman, en->cursor);
         /* Update changed part to UI. */
         rdman_redraw_changed(en->rdman);
     }
@@ -91,11 +92,15 @@
 
     en = engine_init();
     en->menu = menu_new(en->rdman, en->rdman->root_coord);
+    en->cursor = (coord_t *) MB_SPRITE_GET_OBJ(&en->menu->lsym.sprite, "star");
+    printf("en->cursor=%x star=%x\n",en->cursor,en->menu->star);
+    printf("sprite=%x\n",&en->menu->lsym.sprite);
+    printf("en->menu=%x\n",en->menu);
 
     /*
      * Register observers to subjects of events for objects.
      */
-    subject = coord_get_mouse_event(en->menu->cursor);
+    subject = coord_get_mouse_event(en->cursor);
     subject_add_event_observer(subject,  EVT_MOUSE_BUT_PRESS, cursor_press_handler, en);
     subject_add_event_observer(subject,  EVT_MOUSE_BUT_RELEASE, cursor_release_handler, en);
     subject_add_event_observer(subject,  EVT_MOUSE_MOVE, cursor_move_handler, en);
--- a/examples/drag/menu.svg	Fri Dec 12 09:10:05 2008 +0800
+++ b/examples/drag/menu.svg	Fri Dec 12 09:11:47 2008 +0800
@@ -15,16 +15,6 @@
    inkscape:version="0.46"
    sodipodi:docname="menu.svg"
    inkscape:output_extension="org.inkscape.output.svg.inkscape">
-  <defs
-     id="defs4">
-    <inkscape:perspective
-       sodipodi:type="inkscape:persp3d"
-       inkscape:vp_x="0 : 526.18109 : 1"
-       inkscape:vp_y="0 : 1000 : 0"
-       inkscape:vp_z="744.09448 : 526.18109 : 1"
-       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
-       id="perspective10" />
-  </defs>
   <sodipodi:namedview
      id="base"
      pagecolor="#ffffff"
@@ -45,6 +35,16 @@
      inkscape:window-height="725"
      inkscape:window-x="450"
      inkscape:window-y="154" />
+  <defs
+     id="defs4">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective10" />
+  </defs>
   <metadata
      id="metadata7">
     <rdf:RDF>
@@ -61,8 +61,9 @@
      inkscape:groupmode="layer"
      id="layer1">
     <g
-       id="cursor"
-       inkscape:label="#g2382">
+       id="star"
+       inkscape:label="#g2382"
+       mbname="star">
       <path
          transform="translate(-257.14286,-237.14286)"
          inkscape:label="#path2383"