# HG changeset patch # User Thinker K.F. Li # Date 1229160231 -28800 # Node ID 064ff6318dfc58a293d5705b8efd27818c2e85f1 # Parent a0a3196b1a05513c8724fe6641fee1f5c0dba773# Parent 8d9d717c93005f156e790f84df48a685b54b72fb merge changsets 8d9d717c9300 and a0a3196b1a05 diff -r a0a3196b1a05 -r 064ff6318dfc examples/drag/main.c --- a/examples/drag/main.c Fri Dec 12 09:35:27 2008 +0800 +++ b/examples/drag/main.c Sat Dec 13 17:23:51 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 a0a3196b1a05 -r 064ff6318dfc examples/drag/menu.svg --- a/examples/drag/menu.svg Fri Dec 12 09:35:27 2008 +0800 +++ b/examples/drag/menu.svg Sat Dec 13 17:23:51 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"> - - - - - - @@ -125,92 +105,90 @@ x="235.71429" y="282.36218" /> - - - - Line - - - - - - Line + transform="translate(20.000001,42.857139)" + id="btn" + frame="click" + mbname="btn"> + + + + Rect + + + + Rect + + + + Rect + + #include +#include #include "menu.h" #include "button.h" @@ -23,6 +24,120 @@ shape_t *rect; co_aix rx,ry; }; + + +typedef struct _mb_button { + engine_t *en; + coord_t *root; + coord_t *active; + coord_t *normal; + coord_t *click; + void (*press)(); + void *arg; +} mb_button_t; + + +#define COORD_SHOW(group) coord_show(group);rdman_coord_changed(en->rdman, group) +#define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(en->rdman, group) + +#define CMOUSE(e) (coord_get_mouse_event(e)) + + + +static void mb_button_move(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + engine_t *en = btn->en; + + + printf("Mouse move\n"); + COORD_SHOW(btn->active); + rdman_coord_changed(btn->en->rdman,btn->root); + rdman_redraw_changed(btn->en->rdman); +} +static void mb_button_out(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + engine_t *en = btn->en; + + printf("mouse out\n"); + COORD_HIDE(btn->active); + rdman_coord_changed(btn->en->rdman,btn->root); + rdman_redraw_changed(btn->en->rdman); +} + +void mb_button_show_active(const mb_timeval_t *tmo, const mb_timeval_t *now, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + engine_t *en = btn->en; + + COORD_HIDE(btn->click); + rdman_coord_changed(btn->en->rdman,btn->root); + rdman_redraw_changed(btn->en->rdman); +} + +void mb_button_pressed(event_t *evt, void *arg) +{ + mb_button_t *btn = (mb_button_t *) arg; + engine_t *en = btn->en; + mb_timeval_t now,to; + + printf("Pressed\n"); + COORD_SHOW(btn->click); + rdman_coord_changed(en->rdman,en->button->root_coord); + rdman_redraw_changed(en->rdman); + get_now(&now); + MB_TIMEVAL_SET(&to, 0, 500); + MB_TIMEVAL_ADD(&to,&now); + + mb_tman_timeout(X_MB_tman(btn->en->rt), &to, mb_button_show_active, arg); +} +mb_button_t *mb_button_new(engine_t *en,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); + + btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name); + sprintf(buf, "%s_normal", name); + btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); + if (btn->normal == NULL) { + printf("Missing normal button, this is not a correct button\n"); + } + sprintf(buf, "%s_active", name); + btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); + if (btn->active == NULL) { + printf("Missing active button, this is not a correct button\n"); + } + sprintf(buf, "%s_click", name); + btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf); + if (btn->click == NULL) { + printf("Missing click button, this is not a correct button\n"); + } + btn->press = NULL; + // Show only the normal button + COORD_HIDE(btn->active); + COORD_HIDE(btn->click); + // Move to the same position + btn->active->matrix[2] = 200; + btn->active->matrix[5] = 200; + btn->normal->matrix[2] = 200; + btn->normal->matrix[5] = 200; + btn->click->matrix[2] = 200; + btn->click->matrix[5] = 200; + btn->en = en; + subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); + subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); + subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_RELEASE, mb_button_pressed,btn); + return btn; +} + + +void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg) +{ + b->press = h; + b->arg = arg; +} + engine_t *engine_init() { @@ -50,51 +165,7 @@ X_MB_free(en->rt); free(en); } -#define COORD_SHOW(group) coord_show(group);rdman_coord_changed(en->rdman, group) -#define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(en->rdman, group) -#define CMOUSE(e) (coord_get_mouse_event(e)) - - - -static void button_move(event_t *evt, void *arg) -{ - engine_t *en = (engine_t *) arg; - - - printf("Mouse move\n"); - COORD_SHOW(en->button->active); - rdman_coord_changed(en->rdman,en->button->root_coord); - rdman_redraw_changed(en->rdman); -} -static void button_out(event_t *evt, void *arg) -{ - engine_t *en = (engine_t *) arg; - - printf("mouse out\n"); - COORD_HIDE(en->button->active); - rdman_coord_changed(en->rdman,en->button->root_coord); - rdman_redraw_changed(en->rdman); -} - -void button_pressed(event_t *evt, void *arg) -{ - printf("Pressed\n"); -} - -void engine_add_button(engine_t *en, coord_t *normal, coord_t *active, void (*func)()) -{ - active->matrix[2] = 200; - active->matrix[5] = 200; - normal->matrix[2] = 200; - normal->matrix[5] = 200; - COORD_HIDE(en->button->active); - rdman_coord_changed(en->rdman,en->button->root_coord); - rdman_redraw_changed(en->rdman); - subject_add_event_observer(CMOUSE(normal), EVT_MOUSE_MOVE, button_move,en); - subject_add_event_observer(CMOUSE(active), EVT_MOUSE_OUT, button_out,en); - subject_add_event_observer(CMOUSE(active), EVT_MOUSE_BUT_RELEASE, button_pressed,en); -} void coord_move(coord_t *c, co_aix x, co_aix y) @@ -171,17 +242,22 @@ } - +void test(void *a) +{ + printf("Button is pressed.....\n"); +} int main(int argc, char * const argv[]) { subject_t *subject; engine_t *en; + mb_button_t *b; en = engine_init(); en->menu = menu_new(en->rdman, en->rdman->root_coord); en->button = button_new(en->rdman, en->rdman->root_coord); - engine_add_button(en, en->button->normal, en->button->active, button_pressed); + b = mb_button_new(en, (mb_sprite_t *) en->button, "btn"); + mb_button_add_onClick(b, test,NULL); en->rx = 0; en->ry = 0; diff -r a0a3196b1a05 -r 064ff6318dfc inkscape/AssignSymbol.py --- a/inkscape/AssignSymbol.py Fri Dec 12 09:35:27 2008 +0800 +++ b/inkscape/AssignSymbol.py Sat Dec 13 17:23:51 2008 +0800 @@ -18,6 +18,7 @@ text = self.text.get_text() if text != self.defaultname: self.node.set("mbname",text) + self.node.set("id",text) gtk.main_quit() def confirm(self,msg): diff -r a0a3196b1a05 -r 064ff6318dfc inkscape/README.mbext --- a/inkscape/README.mbext Fri Dec 12 09:35:27 2008 +0800 +++ b/inkscape/README.mbext Sat Dec 13 17:23:51 2008 +0800 @@ -34,10 +34,13 @@ + + +