# HG changeset patch # User Thinker K.F. Li # Date 1219380768 -28800 # Node ID 42698de1f653b4c1b2c90f47ed7b33ffc8a5b13f # Parent ea758bb3bbe2e7412d8556a64be671655e02d644 Support translate() function for transform attribute of 'g' tag. diff -r ea758bb3bbe2 -r 42698de1f653 examples/svg2code_ex/main.c --- a/examples/svg2code_ex/main.c Fri Aug 22 00:12:04 2008 +0800 +++ b/examples/svg2code_ex/main.c Fri Aug 22 12:52:48 2008 +0800 @@ -12,9 +12,25 @@ static void file_button_handler(event_t *evt, void *arg) { ex_rt_t *ex_rt = (ex_rt_t *)arg; - coord_show(ex_rt->code->file_menu); - rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); - rdman_redraw_changed(ex_rt->rt->rdman); + switch(evt->type) { + case EVT_MOUSE_BUT_PRESS: + coord_show(ex_rt->code->file_menu); + rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); + rdman_redraw_changed(ex_rt->rt->rdman); + break; + } +} + +static void file_menu_handler(event_t *evt, void *arg) { + ex_rt_t *ex_rt = (ex_rt_t *)arg; + + switch(evt->type) { + case EVT_MOUSE_BUT_PRESS: + coord_hide(ex_rt->code->file_menu); + rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); + rdman_redraw_changed(ex_rt->rt->rdman); + break; + } } int main(int argc, char * const argv[]) { @@ -34,6 +50,8 @@ ex_rt.rt = &rt; ex_rt.code = svg2code; subject_add_observer(factory, subject, file_button_handler, &ex_rt); + subject = coord_get_mouse_event(svg2code->file_menu); + subject_add_observer(factory, subject, file_menu_handler, &ex_rt); X_MB_handle_connection(&rt); diff -r ea758bb3bbe2 -r 42698de1f653 examples/svg2code_ex/svg2code_ex.svg --- a/examples/svg2code_ex/svg2code_ex.svg Fri Aug 22 00:12:04 2008 +0800 +++ b/examples/svg2code_ex/svg2code_ex.svg Fri Aug 22 12:52:48 2008 +0800 @@ -228,40 +228,6 @@ y="60.644024" rx="4.0216751" ry="5.0559778" /> - 檔案 + diff -r ea758bb3bbe2 -r 42698de1f653 img/madbutterfly.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/img/madbutterfly.svg Fri Aug 22 12:52:48 2008 +0800 @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff -r ea758bb3bbe2 -r 42698de1f653 src/X_supp.c --- a/src/X_supp.c Fri Aug 22 00:12:04 2008 +0800 +++ b/src/X_supp.c Fri Aug 22 12:52:48 2008 +0800 @@ -43,14 +43,13 @@ * for a shape is returned by sh_get_mouse_event_subject(). */ static void notify_shapes(redraw_man_t *rdman, + shape_t *shape, co_aix x, co_aix y, int etype, unsigned int state, unsigned int button) { mouse_event_t mouse_event; - shape_t *shape; subject_t *subject; ob_factory_t *factory; - int in_stroke; mouse_event.event.type = etype; mouse_event.x = x; @@ -58,10 +57,6 @@ mouse_event.but_state = state; mouse_event.button = button; - shape = find_shape_at_pos(rdman, x, y, - &in_stroke); - if(shape == NULL) - return; subject = sh_get_mouse_event_subject(shape); factory = rdman_get_ob_factory(rdman); @@ -82,7 +77,10 @@ int eflag = 0; int ex1=0, ey1=0, ex2=0, ey2=0; + shape_t *shape; + unsigned int state, button; + int in_stroke; int r; while(XEventsQueued(display, QueuedAfterReading) > 0) { @@ -98,8 +96,11 @@ state = get_button_state(bevt->state); button = get_button(bevt->button); - notify_shapes(rdman, x, y, EVT_MOUSE_BUT_PRESS, - state, button); + shape = find_shape_at_pos(rdman, x, y, + &in_stroke); + if(shape) + notify_shapes(rdman, shape, x, y, EVT_MOUSE_BUT_PRESS, + state, button); break; case ButtonRelease: @@ -109,8 +110,11 @@ state = get_button_state(bevt->state); button = get_button(bevt->button); - notify_shapes(rdman, x, y, EVT_MOUSE_BUT_RELEASE, - state, button); + shape = find_shape_at_pos(rdman, x, y, + &in_stroke); + if(shape) + notify_shapes(rdman, shape, x, y, EVT_MOUSE_BUT_RELEASE, + state, button); break; case MotionNotify: @@ -119,7 +123,26 @@ y = mevt->y; state = get_button_state(mevt->state); - notify_shapes(rdman, x, y, EVT_MOUSE_MOVE, state, 0); + shape = find_shape_at_pos(rdman, x, y, + &in_stroke); + if(shape != NULL) { + if(rt->last != shape) { + if(rt->last) + notify_shapes(rdman, rt->last, x, y, + EVT_MOUSE_OUT, state, 0); + notify_shapes(rdman, shape, x, y, + EVT_MOUSE_OVER, state, 0); + rt->last = shape; + } else + notify_shapes(rdman, shape, x, y, + EVT_MOUSE_MOVE, state, 0); + } else { + if(rt->last) { + notify_shapes(rdman, rt->last, x, y, + EVT_MOUSE_OUT, state, 0); + rt->last = NULL; + } + } break; case Expose: @@ -249,7 +272,8 @@ return ERR; } - XSelectInput(display, win, PointerMotionMask | ExposureMask); + XSelectInput(display, win, PointerMotionMask | ExposureMask | + ButtonPressMask | ButtonReleaseMask); XFlush(display); *displayp = display; diff -r ea758bb3bbe2 -r 42698de1f653 tools/mb_c_header.m4 --- a/tools/mb_c_header.m4 Fri Aug 22 00:12:04 2008 +0800 +++ b/tools/mb_c_header.m4 Fri Aug 22 12:52:48 2008 +0800 @@ -36,6 +36,7 @@ define([GROUP_HIDE],) define([PATH_HIDE],) define([RECT_HIDE],) +define([COORD_TRANSLATE],) define([MADBUTTERFLY],[dnl [#ifndef __$1_H_ diff -r ea758bb3bbe2 -r 42698de1f653 tools/mb_c_source.m4 --- a/tools/mb_c_source.m4 Fri Aug 22 00:12:04 2008 +0800 +++ b/tools/mb_c_source.m4 Fri Aug 22 12:52:48 2008 +0800 @@ -46,6 +46,7 @@ define([GROUP_HIDE],) define([RECT_HIDE],) define([PATH_HIDE],) +define([COORD_TRANSLATE],) divert[]]) define([S_ADD_LINEAR_PAINT],[ @@ -133,6 +134,15 @@ [ sh_hide(obj->$1); ]]) +define([S_COORD_TRANSLATE],[dnl +[ memset(obj->$1->matrix, 0, sizeof(obj->$1->matrix)); + obj->$1->matrix[0] = 1; + obj->$1->matrix[2] = $2; + obj->$1->matrix[4] = 1; + obj->$1->matrix[5] = $3; + rdman_coord_changed(rdman, obj->$1); +]]) + define([SETUP_VARS],[divert([-1]) define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) SIMPORT([ADD_LINEAR_PAINT]) @@ -152,6 +162,7 @@ SIMPORT([GROUP_HIDE]) SIMPORT([RECT_HIDE]) SIMPORT([PATH_HIDE]) +SIMPORT([COORD_TRANSLATE]) divert[]]) define([F_ADD_LINEAR_PAINT],[[ @@ -205,6 +216,7 @@ define([GROUP_HIDE],) define([RECT_HIDE],) define([PATH_HIDE],) +define([COORD_TRANSLATE],) divert[]]) define([MADBUTTERFLY],[dnl diff -r ea758bb3bbe2 -r 42698de1f653 tools/svg2code.py --- a/tools/svg2code.py Fri Aug 22 00:12:04 2008 +0800 +++ b/tools/svg2code.py Fri Aug 22 12:52:48 2008 +0800 @@ -1,6 +1,7 @@ #! /usr/bin/env python from xml.dom.minidom import parse import sys +import re svgns='http://www.w3.org/2000/svg' xlinkns='http://www.w3.org/1999/xlink' @@ -249,10 +250,28 @@ pass pass +reo_translate = re.compile('translate\\(([0-9]+),([0-9]+)\\)') +def translate_transform(coord_id, transform, codefo): + transform = transform.strip() + mo = reo_translate.match(transform) + if mo: + x = float(mo.group(1)) + y = float(mo.group(2)) + print >> codefo, 'COORD_TRANSLATE([%s], %f, %f)dnl' % ( + coord_id, x, y) + pass + pass + def translate_group(group, parent_id, codefo, doc): group_id = group.getAttribute('id') print >> codefo, 'dnl' print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) + + if group.hasAttribute('transform'): + transform = group.getAttribute('transform') + translate_transform(group_id, transform, codefo) + pass + translate_style(group, group_id, codefo, doc, 'GROUP_') for node in group.childNodes: if node.namespaceURI != svgns: