# HG changeset patch # User wycc # Date 1229044307 -28800 # Node ID 09ad4382aa414d151c221ab27edeb1ce88a7c261 # Parent 5f144bab5de120e086246ff6274e892116ef1bba Modify the drag example to use the sprite API. diff -r 5f144bab5de1 -r 09ad4382aa41 examples/drag/main.c --- 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); diff -r 5f144bab5de1 -r 09ad4382aa41 examples/drag/menu.svg --- 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"> - - - + + + @@ -61,8 +61,9 @@ inkscape:groupmode="layer" id="layer1"> + id="star" + inkscape:label="#g2382" + mbname="star">