From dac3495e2a3a7785e59b98145409a5d7614386b9 Mon Sep 17 00:00:00 2001 From: Paul Chavent Date: Sat, 27 Aug 2011 00:53:00 +0200 Subject: [PATCH 2/2] Add sozi front end. --- objects/Misc/Makefile.am | 7 +- objects/Misc/libmisc.c | 2 + objects/Misc/pixmaps/sozi-frame.xpm | 196 +++++++++ objects/Misc/sozi-frame.c | 768 +++++++++++++++++++++++++++++++++++ objects/Misc/sozi/sozi-script.h | 10 + objects/Misc/sozi/sozi-style.h | 8 + sheets/Misc.sheet.in | 3 + 7 files changed, 991 insertions(+), 3 deletions(-) create mode 100644 objects/Misc/pixmaps/sozi-frame.xpm create mode 100644 objects/Misc/sozi-frame.c create mode 100644 objects/Misc/sozi/sozi-script.h create mode 100644 objects/Misc/sozi/sozi-style.h diff --git a/objects/Misc/Makefile.am b/objects/Misc/Makefile.am index 306fae4..64e01ad 100644 --- a/objects/Misc/Makefile.am +++ b/objects/Misc/Makefile.am @@ -7,8 +7,8 @@ libmisc_objects_la_SOURCES = \ diagram_as_object.c \ grid_object.c \ measure.c \ - tree.c - + tree.c \ + sozi-frame.c libmisc_objects_la_LDFLAGS = -export-dynamic -module -avoid-version $(NO_UNDEFINED) @@ -23,7 +23,8 @@ EXTRA_DIST = \ pixmaps/grid_object.xpm \ pixmaps/measure.xpm \ pixmaps/newgroup.xpm \ - pixmaps/tree.xpm + pixmaps/tree.xpm \ + pixmaps/sozi-frame.xpm diff --git a/objects/Misc/libmisc.c b/objects/Misc/libmisc.c index e72ea9a..65b75a9 100644 --- a/objects/Misc/libmisc.c +++ b/objects/Misc/libmisc.c @@ -33,6 +33,7 @@ extern DiaObjectType grid_object_type; extern DiaObjectType tree_type; extern DiaObjectType measure_type; extern DiaObjectType diagram_as_element_type; +extern DiaObjectType sozi_frame_type; DIA_PLUGIN_CHECK_INIT @@ -48,6 +49,7 @@ dia_plugin_init(PluginInfo *info) object_register_type(&tree_type); object_register_type(&measure_type); object_register_type(&diagram_as_element_type); + object_register_type(&sozi_frame_type); return DIA_PLUGIN_INIT_OK; } diff --git a/objects/Misc/pixmaps/sozi-frame.xpm b/objects/Misc/pixmaps/sozi-frame.xpm new file mode 100644 index 0000000..e5f3ed3 --- /dev/null +++ b/objects/Misc/pixmaps/sozi-frame.xpm @@ -0,0 +1,196 @@ +/* XPM */ +static char * sozi_frame_xpm[] = { +"22 22 171 2", +" c #FFFFFF", +". c #FEFEFE", +"+ c #FDFDFD", +"@ c #F7F7F8", +"# c #D2D2D2", +"$ c #939393", +"% c #8A8A8A", +"& c #BEBEBE", +"* c #F2F2F2", +"= c #FCFCFC", +"- c #F3F3F3", +"; c #FBFBFB", +"> c #FEFEFF", +", c #FCFCFB", +"' c #FAF4F1", +") c #FAF1EB", +"! c #F8F5F2", +"~ c #BFBFBF", +"{ c #E4E4E4", +"] c #F1F1F1", +"^ c #ADADAD", +"/ c #F5F5F5", +"( c #BEBABE", +"_ c #99909A", +": c #EDEAED", +"< c #ECDCD2", +"[ c #C3682D", +"} c #C64500", +"| c #98562A", +"1 c #BBB6B2", +"2 c #F8F8F9", +"3 c #FBFCFB", +"4 c #FBFCFC", +"5 c #E8BC9E", +"6 c #F55A00", +"7 c #F05F00", +"8 c #E4BCA1", +"9 c #F3F8FC", +"0 c #F6F6F6", +"a c #DCDCDC", +"b c #CACACA", +"c c #CDCDCD", +"d c #CBCBC9", +"e c #D8D8D7", +"f c #FBFBFC", +"g c #E7B99A", +"h c #F25600", +"i c #DD7A39", +"j c #E7DDD6", +"k c #D0D0D0", +"l c #C8C8C8", +"m c #989898", +"n c #CACBCC", +"o c #A3A298", +"p c #BFB483", +"q c #EEE8D1", +"r c #FBFBFA", +"s c #FAFBFC", +"t c #E6BA9E", +"u c #EB5400", +"v c #ECA372", +"w c #F8FBFD", +"x c #ECECEC", +"y c #FBFCFE", +"z c #D3D1C7", +"A c #DDB617", +"B c #C4A423", +"C c #EFECE1", +"D c #FBFDFF", +"E c #E5C3AD", +"F c #DD5A03", +"G c #E8AD85", +"H c #F9FFFF", +"I c #E6E6E6", +"J c #E9E9EA", +"K c #CFCECD", +"L c #DEBF2D", +"M c #C99E00", +"N c #EDE9D1", +"O c #E4D5CC", +"P c #AE6636", +"Q c #E2BCA3", +"R c #FFFFFE", +"S c #E5E5E5", +"T c #C8C8C9", +"U c #D9DBE5", +"V c #DBBD39", +"W c #B79A21", +"X c #EDEADF", +"Y c #ECEAE9", +"Z c #A98C7A", +"` c #D3B8A6", +" . c #E3E3E3", +".. c #C7C7C7", +"+. c #F1F3FC", +"@. c #A5965C", +"#. c #BDB496", +"$. c #BEBBB8", +"%. c #B3ACA7", +"&. c #E9E7E7", +"*. c #B6B4B4", +"=. c #92939A", +"-. c #DFDFE3", +";. c #ADAEAF", +">. c #CCCDCE", +",. c #7D898D", +"'. c #DCDBDA", +"). c #EDEDED", +"!. c #DADADA", +"~. c #9B9B9B", +"{. c #DEDEDE", +"]. c #FFFEFE", +"^. c #B4CBD2", +"/. c #389CB5", +"(. c #6E9CA8", +"_. c #DDDDDD", +":. c #EAEAEA", +"<. c #CECECE", +"[. c #B6B6B6", +"}. c #E7E7E7", +"|. c #B2D0D8", +"1. c #1BB6DE", +"2. c #00A7D3", +"3. c #82AFBB", +"4. c #EEEEEE", +"5. c #999999", +"6. c #F0F0F0", +"7. c #E0E0E0", +"8. c #F9FCFC", +"9. c #1194B5", +"0. c #00CEFF", +"a. c #23BAE1", +"b. c #C3D0D4", +"c. c #D4D4D4", +"d. c #FAFCFC", +"e. c #2E8FA8", +"f. c #00BDEF", +"g. c #3AB4D3", +"h. c #F8F2F1", +"i. c #EBEBEB", +"j. c #C6C6C6", +"k. c #A8A8A8", +"l. c #F4F4F4", +"m. c #DBE7EB", +"n. c #6894A0", +"o. c #6C8288", +"p. c #A3A1A0", +"q. c #949494", +"r. c #8F8F8F", +"s. c #E2E2E2", +"t. c #BABABA", +"u. c #CBCACA", +"v. c #9A9898", +"w. c #F3F2F1", +"x. c #E9E9E9", +"y. c #E8E8E8", +"z. c #F9F9F9", +"A. c #F7F7F7", +"B. c #A9A9A9", +"C. c #C1C1C1", +"D. c #D7D7D7", +"E. c #F7F6F6", +"F. c #FAFAFA", +"G. c #5F5F5F", +"H. c #B2B2B2", +"I. c #F8F8F8", +"J. c #D8D8D8", +"K. c #909090", +"L. c #7D7D7D", +"M. c #858585", +"N. c #B4B4B4", +" . . . . . + + . . . . . ", +" . @ # $ % & * . = - ; . ", +" > , ' ) ! ~ { ] ^ / ( _ : ", +" < [ } | 1 2 . . * ~ 3 . . ", +" 4 5 6 7 8 9 = . 0 a b c ; d e > . ", +" f g h i j . 0 k l m n o p q r . . ", +" s t u v w . x y z A B C > . ", +" D E F G H . . = I J K L M N ", +" O P Q R . S T U V W X > ", +" . Y Z ` > . . + # 2 ", +" R $.%. . . . . &.*.c =.-. ", +" . n ;.= . . >.,.'.a ). . . ", +" . !.~.{. . . ].^./.(. . # _. ", +" . :.<.[.}. . + |.1.2.3. 4...5.= ", +" * 6.c 7.+ 8.9.0.a.b. . 6.<.+ ", +" . c.7.# - . . d.e.f.g.h. ", +" . i.j.k.l. > m.n.o.p.$ q.r.s.. ", +" . . I & t.0 ; ] u.v.w.).x.x.y.z.. . ", +" . + A.B.c C.<.D.E. . . ", +"F.G.H.i.I. 4.C./ z.; ; . . ", +". / J.~ K.L.M.N.l.. . . ", +" . . + + + . . . . . "}; diff --git a/objects/Misc/sozi-frame.c b/objects/Misc/sozi-frame.c new file mode 100644 index 0000000..5e4fded --- /dev/null +++ b/objects/Misc/sozi-frame.c @@ -0,0 +1,768 @@ +/* Dia -- an diagram creation/manipulation program + * Copyright (C) 1999 Alexander Larsson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/* standard libs*/ +#include +#include + +/* xpath for searching in the svg doc */ +#include + +/* dia stuff */ +#include "object.h" +#include "diarenderer.h" +#include "diasvgrenderer.h" +#include "properties.h" +#include "text.h" + +/* FIXME generate these headers */ +#include "pixmaps/sozi-frame.xpm" +#include "sozi/sozi-script.h" +#include "sozi/sozi-style.h" + +# define M_2_PI 6.28318530718 + +/****************************************************************************** + * TODO: + * - make a static variable that hold the sequence of the frame (local to a + * file ?) + * - implement transition options + * - render sequence number and frame timeout for example + * - + *****************************************************************************/ + +typedef struct _SoziFrame +{ + /* dia object inheritance */ + + DiaObject object; + + /* geometry of the object */ + + Point center; + real width; + real height; + real angle; + + real cos_angle; + real sin_angle; + + real m[6]; /** transformation matrix of the unit square */ + + /* corners of the object */ + + Point corners[4]; + + /* sozi specific stuff */ + + int sequence; + + Text * title; + gboolean hide; + gboolean clip; + int timeout; + +} SoziFrame; + +/****************************************************************************** + * + *****************************************************************************/ + +static DiaObject * sozi_frame_create(Point *startpoint, + void *user_data, + Handle **handle1, + Handle **handle2); +static DiaObject * sozi_frame_load(ObjectNode obj_node, int version, const char *filename); +static void sozi_frame_save(SoziFrame *sozi_frame, ObjectNode obj_node, const char *filename); + +static ObjectTypeOps sozi_frame_type_ops = +{ + (CreateFunc) sozi_frame_create, /* create */ + (LoadFunc) sozi_frame_load, /* load (== object_load_using_properties ?) */ + (SaveFunc) sozi_frame_save, /* save (== object_save_using_properties ?) */ + (GetDefaultsFunc) NULL, + (ApplyDefaultsFunc) NULL, +}; + +DiaObjectType sozi_frame_type = +{ + "Misc - Sozi Frame", /* name */ + 0, /* version */ + (char **) sozi_frame_xpm, /* pixmap */ + &sozi_frame_type_ops, /* ops */ + NULL, /* pixmap_file */ + 0 /* default_user_data */ +}; + +/****************************************************************************** + * + *****************************************************************************/ + +static void sozi_frame_destroy(SoziFrame *sozi_frame); + +static void sozi_frame_draw(SoziFrame *sozi_frame, DiaRenderer *renderer); + +static real sozi_frame_distance_from(SoziFrame *sozi_frame, Point *point); + +static void sozi_frame_select(SoziFrame *sozi_frame, Point *clicked_point, + DiaRenderer *interactive_renderer); + +static DiaObject * sozi_frame_copy(SoziFrame *sozi_frame); + +static ObjectChange* sozi_frame_move(SoziFrame *sozi_frame, Point *to); + +static ObjectChange* sozi_frame_move_handle(SoziFrame *sozi_frame, Handle *handle, + Point *to, ConnectionPoint *cp, + HandleMoveReason reason, ModifierKeys modifiers); + +static PropDescription * sozi_frame_describe_props(SoziFrame *sozi_frame); + +static void sozi_frame_get_props(SoziFrame *sozi_frame, GPtrArray *props); + +static void sozi_frame_set_props(SoziFrame *sozi_frame, GPtrArray *props); + + +static ObjectOps sozi_frame_ops = +{ + (DestroyFunc) sozi_frame_destroy, + (DrawFunc) sozi_frame_draw, + (DistanceFunc) sozi_frame_distance_from, + (SelectFunc) sozi_frame_select, + (CopyFunc) sozi_frame_copy, + (MoveFunc) sozi_frame_move, + (MoveHandleFunc) sozi_frame_move_handle, + (GetPropertiesFunc) object_create_props_dialog, + (ApplyPropertiesDialogFunc) object_apply_props_from_dialog, + (ObjectMenuFunc) 0, + (DescribePropsFunc) sozi_frame_describe_props, + (GetPropsFunc) sozi_frame_get_props, + (SetPropsFunc) sozi_frame_set_props, + (TextEditFunc) 0, + (ApplyPropertiesListFunc) object_apply_props, +}; + +/****************************************************************************** + * unit square + *****************************************************************************/ +static const Handle default_handles[4] = +{ + {HANDLE_RESIZE_NW, HANDLE_MAJOR_CONTROL, { 0, 0}, HANDLE_NONCONNECTABLE, NULL}, + {HANDLE_RESIZE_SW, HANDLE_MAJOR_CONTROL, { 0, 1}, HANDLE_NONCONNECTABLE, NULL}, + {HANDLE_RESIZE_SE, HANDLE_MAJOR_CONTROL, { 1, 1}, HANDLE_NONCONNECTABLE, NULL}, + {HANDLE_RESIZE_NE, HANDLE_MAJOR_CONTROL, { 1, 0}, HANDLE_NONCONNECTABLE, NULL}, +}; + +static const real sozi_frame_line_width = 0.01; + +/****************************************************************************** + * + *****************************************************************************/ +static void +sozi_frame_init(SoziFrame *sozi_frame, Point *center) +{ + DiaObject *dia_object; + int i; + static int sequence = 0; + char sequence_str[8]; + + dia_object = &sozi_frame->object; + + dia_object->type = &sozi_frame_type; + dia_object->ops = &sozi_frame_ops; + dia_object->position = *center; + + /* dia_object->bounding_box is set in sozi_frame_update_data */ + + dia_object->num_handles = 4; + if(dia_object->handles == NULL) { + dia_object->handles = g_new0(Handle *, 4); + } + + for (i = 0; i < 4; i++) { + if(dia_object->handles[i] == NULL) { + dia_object->handles[i] = g_new0(Handle, 1); + } + *dia_object->handles[i] = default_handles[i]; + } + + dia_object->num_connections = 1; + if(dia_object->connections == NULL) { + dia_object->connections = g_new0(ConnectionPoint *, 1); + } + + for (i = 0; i < 1; i++) { + if(dia_object->connections[i] == NULL) { + dia_object->connections[i] = g_new0(ConnectionPoint, 1); + } + dia_object->connections[0]->object = dia_object; + dia_object->connections[0]->directions = DIR_ALL; + } + + /* dia_object->enclosing_box is set in sozi_frame_update_data */ + + sozi_frame->center = *center; + sozi_frame->width = 1; + sozi_frame->height = 1; + sozi_frame->angle = 0; + + /* sozi_frame->cos_angle is set in sozi_frame_update_data */ + /* sozi_frame->sin_angle is set in sozi_frame_update_data */ + /* sozi_frame->m is set in sozi_frame_update_data */ + + /* sozi_frame->corners are set in sozi_frame_update_data */ + + sozi_frame->sequence = sequence++; /* FIXME : it is broken */ + g_snprintf(sequence_str, sizeof(sequence_str), "%d", sozi_frame->sequence); + + if(sozi_frame->title == NULL) { + sozi_frame->title = new_text_default(&sozi_frame->center, &color_black, ALIGN_LEFT); + } + text_set_string(sozi_frame->title, sequence_str); + + sozi_frame->hide = TRUE; + sozi_frame->clip = TRUE; + sozi_frame->timeout = 0; + +} + +/****************************************************************************** + * + *****************************************************************************/ +static void +sozi_frame_update_data(SoziFrame *sozi_frame) +{ + DiaObject *dia_object; + Point title_pos; + Rectangle title_bb; + int i; + + dia_object = &sozi_frame->object; + + dia_object->position = sozi_frame->center; + + dia_object->bounding_box.left = G_MAXFLOAT; + dia_object->bounding_box.top = G_MAXFLOAT; + dia_object->bounding_box.right = -G_MAXFLOAT; + dia_object->bounding_box.bottom = -G_MAXFLOAT; + + if(sozi_frame->angle < 0) { + sozi_frame->angle += M_2_PI; + } + if(M_2_PI < sozi_frame->angle) { + sozi_frame->angle -= M_2_PI; + } + sozi_frame->cos_angle = cos(sozi_frame->angle); + sozi_frame->sin_angle = sin(sozi_frame->angle); + + /* + * + * translate(center.x,center.y) . rotate(angle) . scale(width,height) . translate(-0.5,-0.5) + * + * m + * = + * | 1 0 x | . | cos(a) sin(a) 0 | . | w 0 0 | . | 1 0 -0.5 | + * | 0 1 y | | -sin(a) cos(a) 0 | | 0 h 0 | | 0 1 -0.5 | + * | 0 0 1 | | 0 0 1 | | 0 0 1 | | 0 0 1 | + * = + * | w*cos(a) h*sin(a) x-0.5*w*cos(a)-0.5*h*sin(a) | + * | -w*sin(a) h*cos(a) y+0.5*w*sin(a)-0.5*h*cos(a) | + * | 0 0 1 | + */ + sozi_frame->m[0] = sozi_frame->width * sozi_frame->cos_angle ; + sozi_frame->m[1] = sozi_frame->height * sozi_frame->sin_angle ; + sozi_frame->m[2] = sozi_frame->center.x - 0.5 * sozi_frame->width * sozi_frame->cos_angle - 0.5 * sozi_frame->height * sozi_frame->sin_angle; + sozi_frame->m[3] = -sozi_frame->width * sozi_frame->sin_angle ; + sozi_frame->m[4] = sozi_frame->height * sozi_frame->cos_angle ; + sozi_frame->m[5] = sozi_frame->center.y + 0.5 * sozi_frame->width * sozi_frame->sin_angle - 0.5 * sozi_frame->height * sozi_frame->cos_angle; + + for (i = 0; i < 4; i++) { + + sozi_frame->corners[i].x = sozi_frame->m[0] * default_handles[i].pos.x + sozi_frame->m[1] * default_handles[i].pos.y + sozi_frame->m[2]; + sozi_frame->corners[i].y = sozi_frame->m[3] * default_handles[i].pos.x + sozi_frame->m[4] * default_handles[i].pos.y + sozi_frame->m[5]; + + dia_object->handles[i]->pos = sozi_frame->corners[i]; + + if(i == 0) { + dia_object->connections[0]->last_pos = dia_object->connections[0]->pos; + dia_object->connections[0]->pos = sozi_frame->corners[i]; + } + + if(sozi_frame->corners[i].x < dia_object->bounding_box.left) { + dia_object->bounding_box.left = sozi_frame->corners[i].x - sozi_frame_line_width; + } + if(dia_object->bounding_box.right < sozi_frame->corners[i].x) { + dia_object->bounding_box.right = sozi_frame->corners[i].x + sozi_frame_line_width; + } + if(sozi_frame->corners[i].y < dia_object->bounding_box.top) { + dia_object->bounding_box.top = sozi_frame->corners[i].y - sozi_frame_line_width; + } + if(dia_object->bounding_box.bottom < sozi_frame->corners[i].y) { + dia_object->bounding_box.bottom = sozi_frame->corners[i].y + sozi_frame_line_width; + } + } + + title_pos = sozi_frame->corners[0]; + title_pos.y += text_get_ascent(sozi_frame->title); + text_set_position(sozi_frame->title, &title_pos); + text_calc_boundingbox(sozi_frame->title, &title_bb); + rectangle_union(&dia_object->bounding_box, &title_bb); + + dia_object->enclosing_box = dia_object->bounding_box; +} + +/****************************************************************************** + * + *****************************************************************************/ +static DiaObject * +sozi_frame_create(Point *startpoint, + void *user_data, + Handle **handle1, + Handle **handle2) +{ + SoziFrame *sozi_frame; + + sozi_frame = g_new0(SoziFrame, 1); + + sozi_frame_init(sozi_frame, startpoint); + + sozi_frame_update_data(sozi_frame); + + *handle1 = NULL; + *handle2 = NULL; + + return &sozi_frame->object; +} + +/****************************************************************************** + * + *****************************************************************************/ +static DiaObject * +sozi_frame_load(ObjectNode obj_node, int version, const char *filename) +{ + return object_load_using_properties(&sozi_frame_type, obj_node, version, filename); +} + +/****************************************************************************** + * + *****************************************************************************/ +static void +sozi_frame_save(SoziFrame *sozi_frame, ObjectNode obj_node, const char *filename) +{ + object_save_using_properties(&sozi_frame->object, obj_node, filename); +} + +/****************************************************************************** + * + *****************************************************************************/ +static void +sozi_frame_destroy(SoziFrame *sozi_frame) +{ + int i; + + text_destroy(sozi_frame->title); + + object_unconnect_all(&sozi_frame->object); + + for (i = 0; i < 1; i++) { + if(sozi_frame->object.connections[i] != NULL) { + g_free(sozi_frame->object.connections[i]); + } + } + + for (i = 0; i < 4; i++) { + if(sozi_frame->object.handles[i] != NULL) { + g_free(sozi_frame->object.handles[i]); + } + } + + if (sozi_frame->object.connections) { + g_free(sozi_frame->object.connections); + sozi_frame->object.connections = NULL; + } + + if (sozi_frame->object.handles) { + g_free(sozi_frame->object.handles); + sozi_frame->object.handles = NULL; + } + + if (sozi_frame->object.meta) { + g_hash_table_destroy (sozi_frame->object.meta); + sozi_frame->object.meta = NULL; + } +} + +/****************************************************************************** + * + *****************************************************************************/ + +static int +find_sozi_elem(xmlDocPtr doc, const xmlChar *sozi_elem) +{ + /* static const xmlChar *sozi_elem = (xmlChar*) "//script[ id='sozi-script']"; */ + xmlXPathContextPtr context; + xmlXPathObjectPtr result; + + context = xmlXPathNewContext(doc); + if(context == NULL) { + fprintf(stderr, "Error in xmlXPathNewContext\n"); + return 0; + } + + result = xmlXPathEvalExpression(sozi_elem, context); + xmlXPathFreeContext(context); + if(result == NULL) { + fprintf(stderr, "Error in xmlXPathEvalExpression\n"); + return 0; + } + + if(xmlXPathNodeSetIsEmpty(result->nodesetval)) { + xmlXPathFreeObject(result); + return 0; + } + + xmlXPathFreeObject(result); + return 1; +} + +static void +sozi_frame_draw_svg(SoziFrame *sozi_frame, DiaSvgRenderer *svg_renderer) +{ + static xmlNs *sozi_name_space = NULL; + static unsigned refid_cnt = 0; + xmlNodePtr root; + xmlNodePtr node; + /* buffer for storing attributes */ + gchar refid[32]; + gchar sequence[16]; + gchar x[16]; + gchar y[16]; + gchar width[16]; + gchar height[16]; + gchar transform[128]; + gchar style[128]; + + root = xmlDocGetRootElement(svg_renderer->doc); + + /* check that the sozi namespace, scripts and style are present */ + + if (!find_sozi_elem(svg_renderer->doc, (const xmlChar*) "//script[ id='sozi-script']")) { + sozi_name_space = xmlNewNs(root, (const xmlChar *)"http://sozi.baierouge.fr", (const xmlChar *)"sozi"); + + node = xmlNewChild(root, NULL, (const xmlChar *)"script", NULL); + xmlSetProp(node, (const xmlChar *)"id", (const xmlChar *)"sozi-script"); + xmlSetProp(node, (const xmlChar *)"sozi:version", (const xmlChar *)sozi_script_version); + xmlNodeSetContentLen(node, (const xmlChar *)sozi_script, sizeof(sozi_script)); + + node = xmlNewChild(root, NULL, (const xmlChar *)"style", NULL); + xmlSetProp(node, (const xmlChar *)"id", (const xmlChar *)"sozi-style"); + xmlSetProp(node, (const xmlChar *)"sozi:version", (const xmlChar *)sozi_style_version); + xmlNodeSetContentLen(node, (const xmlChar *)sozi_style, sizeof(sozi_style)); + + /* FIXME : workaround */ + xmlUnsetProp(root, (const xmlChar *)"viewBox"); + } + + assert(sozi_name_space != NULL); + + /* format attributes */ + + g_snprintf(refid , sizeof(refid) , "sozi_frame_%d", refid_cnt++); + g_snprintf(sequence , sizeof(sequence) , "%d", sozi_frame->sequence); +#if 1 /* pure transformation */ + g_snprintf(x , sizeof(x) , "0"); + g_snprintf(y , sizeof(y) , "0"); + g_snprintf(width , sizeof(width) , "1"); + g_snprintf(height , sizeof(height) , "1"); + g_snprintf(transform, sizeof(transform), "matrix(%g,%g,%g,%g,%g,%g)", + sozi_frame->m[0] * svg_renderer->scale, + sozi_frame->m[3] * svg_renderer->scale, + sozi_frame->m[1] * svg_renderer->scale, + sozi_frame->m[4] * svg_renderer->scale, + sozi_frame->m[2] * svg_renderer->scale, + sozi_frame->m[5] * svg_renderer->scale); + /* FIXME : Scaling problem on stroke width : http://dev.w3.org/SVG/modules/vectoreffects/master/SVGVectorEffects.html */ + g_snprintf(style , sizeof(style) , "fill:none;stroke:#000000;stroke-width:%g", 0.1 / svg_renderer->scale); +#elif 0 /* decompose transformation */ + g_snprintf(x , sizeof(x) , "0"); + g_snprintf(y , sizeof(y) , "0"); + g_snprintf(width , sizeof(width) , "1"); + g_snprintf(height , sizeof(height) , "1"); + g_snprintf(transform, sizeof(transform), "scale(%g,%g),translate(%g,%g),rotate(%g),scale(%g,%g),translate(-0.5,-0.5)", + svg_renderer->scale, + svg_renderer->scale, + sozi_frame->center.x, + sozi_frame->center.y, + 180 * sozi_frame->angle / M_PI, + sozi_frame->width, + sozi_frame->height); + /* FIXME : Scaling problem on stroke width : http://dev.w3.org/SVG/modules/vectoreffects/master/SVGVectorEffects.html */ + g_snprintf(style , sizeof(style) , "fill:none;stroke:#000000;stroke-width:%g", 0.1 / svg_renderer->scale); +#else /* no apply scale to transformation */ + g_snprintf(x , sizeof(x) , "%g", sozi_frame->m[2] * svg_renderer->scale); + g_snprintf(y , sizeof(y) , "%g", sozi_frame->m[5] * svg_renderer->scale); + g_snprintf(width , sizeof(width) , "%g", sozi_frame->width * svg_renderer->scale); + g_snprintf(height , sizeof(height) , "%g", sozi_frame->height * svg_renderer->scale); + g_snprintf(transform, sizeof(transform), "rotate(%g,%g,%g)", + 180 * sozi_frame->angle / M_PI, + sozi_frame->m[2] * svg_renderer->scale, + sozi_frame->m[5] * svg_renderer->scale); + g_snprintf(style , sizeof(style) , "fill:none;stroke:#000000;stroke-width:0.1"); +#endif + + /* add a "classic" frame */ + + node = xmlNewChild(svg_renderer->root, svg_renderer->svg_name_space, (const xmlChar *)"rect", NULL); + + xmlSetProp(node, (const xmlChar *)"id" , (xmlChar *)refid); + xmlSetProp(node, (const xmlChar *)"x" , (xmlChar *)x); + xmlSetProp(node, (const xmlChar *)"y" , (xmlChar *)y); + xmlSetProp(node, (const xmlChar *)"width" , (xmlChar *)width); + xmlSetProp(node, (const xmlChar *)"height" , (xmlChar *)height); + xmlSetProp(node, (const xmlChar *)"transform", (xmlChar *)transform); + xmlSetProp(node, (const xmlChar *)"style" , (xmlChar *)style); + + /* add a "custom" frame for sozi */ + + g_snprintf(sequence, sizeof(sequence), "%d", sozi_frame->sequence); + + node = xmlNewChild(root, sozi_name_space, (const xmlChar *)"frame", NULL); + xmlSetProp(node, (const xmlChar *)"sozi:refid" , (const xmlChar *)refid); + xmlSetProp(node, (const xmlChar *)"sozi:sequence" , (const xmlChar *)sequence); + xmlSetProp(node, (const xmlChar *)"sozi:title" , (const xmlChar *)text_get_line(sozi_frame->title, 0)); + xmlSetProp(node, (const xmlChar *)"sozi:hide" , (const xmlChar *)((sozi_frame->hide)?"true":"false")); + xmlSetProp(node, (const xmlChar *)"sozi:clip" , (const xmlChar *)((sozi_frame->clip)?"true":"false")); + xmlSetProp(node, (const xmlChar *)"sozi:timeout-enable" , (const xmlChar *)((sozi_frame->timeout)?"true":"false")); + xmlSetProp(node, (const xmlChar *)"sozi:timeout-ms" , (const xmlChar *)"5000"); + xmlSetProp(node, (const xmlChar *)"sozi:transition-profile" , (const xmlChar *)"linear"); + xmlSetProp(node, (const xmlChar *)"sozi:transition-zoom-percent", (const xmlChar *)"0"); + xmlSetProp(node, (const xmlChar *)"sozi:transition-duration-ms" , (const xmlChar *)"1000"); +} + +/****************************************************************************** + * + *****************************************************************************/ + +#define DIA_IS_INTERACTIVE_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_INTERACTIVE_RENDERER)) + +static void +sozi_frame_draw(SoziFrame *sozi_frame, DiaRenderer *renderer) +{ + + if (DIA_IS_SVG_RENDERER(renderer)) { + sozi_frame_draw_svg(sozi_frame, DIA_SVG_RENDERER (renderer)); + } + else if(DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer) || /* FIXME : not sure how to test if interactive renderer */ + !sozi_frame->hide) { + DiaRendererClass *renderer_ops = DIA_RENDERER_GET_CLASS (renderer); + + renderer_ops->set_linewidth(renderer, sozi_frame_line_width); + renderer_ops->set_linecaps(renderer, LINECAPS_BUTT); + renderer_ops->set_linejoin(renderer, LINEJOIN_MITER); + renderer_ops->set_linestyle(renderer, LINESTYLE_SOLID); + + renderer_ops->draw_polygon(renderer, sozi_frame->corners, 4, &color_black); + + text_draw(sozi_frame->title, renderer); + } +} + +/****************************************************************************** + * + *****************************************************************************/ + +static real +sozi_frame_distance_from(SoziFrame *sozi_frame, Point *point) +{ + return distance_polygon_point(sozi_frame->corners, 4, sozi_frame_line_width, point); +} + +/****************************************************************************** + * + *****************************************************************************/ + +static void +sozi_frame_select(SoziFrame *sozi_frame, Point *clicked_point, + DiaRenderer *interactive_renderer) +{ + text_set_cursor(sozi_frame->title, clicked_point, interactive_renderer); + text_grab_focus(sozi_frame->title, &sozi_frame->object); + sozi_frame_update_data(sozi_frame); +} + +/****************************************************************************** + * + *****************************************************************************/ + +static DiaObject * +sozi_frame_copy(SoziFrame *sozi_frame) +{ + SoziFrame *new_sozi_frame; + + new_sozi_frame = g_new0(SoziFrame, 1); + + sozi_frame_init(new_sozi_frame, &sozi_frame->center); + + new_sozi_frame->width = sozi_frame->width; + new_sozi_frame->height = sozi_frame->height; + new_sozi_frame->angle = sozi_frame->angle; + + new_sozi_frame->hide = sozi_frame->hide; + new_sozi_frame->clip = sozi_frame->clip; + new_sozi_frame->timeout = sozi_frame->timeout; + + sozi_frame_update_data(new_sozi_frame); + + return &new_sozi_frame->object; +} + +/****************************************************************************** + * + *****************************************************************************/ + +static ObjectChange* +sozi_frame_move(SoziFrame *sozi_frame, Point *to) +{ + sozi_frame->center = *to; + + sozi_frame_update_data(sozi_frame); + + return NULL; +} + +/****************************************************************************** + * + *****************************************************************************/ + +static ObjectChange* +sozi_frame_move_handle(SoziFrame *sozi_frame, Handle *handle, + Point *to, ConnectionPoint *cp, + HandleMoveReason reason, ModifierKeys modifiers) +{ + if(reason == HANDLE_MOVE_USER) { + DiaObject * dia_object = &sozi_frame->object; + Point p2; + + int i; + for(i = 0; i < 4; i++) { + if(dia_object->handles[i] == handle) { + break; + } + } + assert(i < 4); + + p2 = *to; + point_sub(&p2, &sozi_frame->center); + + if(modifiers & MODIFIER_SHIFT) { + Point p1; + p1 = handle->pos; + point_sub(&p1, &sozi_frame->center); + + sozi_frame->angle += atan2(p2.x * p1.y - p2.y * p1.x, p2.x * p1.x + p2.y * p1.y); + } + else + { + /* the y axis is downward */ + sozi_frame->width = 2 * fabs(p2.x * sozi_frame->cos_angle - p2.y * sozi_frame->sin_angle); + sozi_frame->height = 2 * fabs(p2.x * sozi_frame->sin_angle + p2.y * sozi_frame->cos_angle); + } + + sozi_frame_update_data(sozi_frame); + } + + return NULL; +} + +/****************************************************************************** + * + *****************************************************************************/ + +static PropDescription sozi_frame_props[] = +{ + PROP_STD_NOTEBOOK_BEGIN, + + PROP_NOTEBOOK_PAGE("geometry",0,N_("Geometry")), + { "x" , PROP_TYPE_REAL , PROP_FLAG_VISIBLE, N_("Position x") , NULL, NULL }, + { "y" , PROP_TYPE_REAL , PROP_FLAG_VISIBLE, N_("Position y") , NULL, NULL }, + { "width" , PROP_TYPE_REAL , PROP_FLAG_VISIBLE, N_("Width") , NULL, NULL }, + { "height", PROP_TYPE_REAL , PROP_FLAG_VISIBLE, N_("Height") , NULL, NULL }, + { "angle" , PROP_TYPE_REAL , PROP_FLAG_VISIBLE, N_("Angle (rad)") , NULL, NULL }, + + PROP_NOTEBOOK_PAGE("sozi",0,N_("Sozi")), + { "frame sequence", PROP_TYPE_INT , PROP_FLAG_VISIBLE, N_("Frame sequence") , NULL, NULL }, + { "frame title" , PROP_TYPE_TEXT , PROP_FLAG_VISIBLE, N_("Frame title") , NULL, NULL }, + { "frame hide" , PROP_TYPE_BOOL , PROP_FLAG_VISIBLE, N_("Frame hide") , NULL, NULL }, + { "frame clip" , PROP_TYPE_BOOL , PROP_FLAG_VISIBLE, N_("Frame clip") , NULL, NULL }, + { "frame timeout" , PROP_TYPE_INT , PROP_FLAG_VISIBLE, N_("Frame timeout (ms)") , NULL, NULL }, + PROP_STD_NOTEBOOK_END, + + PROP_DESC_END +}; + +static PropOffset sozi_frame_offsets[] = +{ + PROP_OFFSET_STD_NOTEBOOK_BEGIN, + + PROP_OFFSET_NOTEBOOK_PAGE("geometry"), + { "x" , PROP_TYPE_REAL , offsetof(SoziFrame, center.x) }, + { "y" , PROP_TYPE_REAL , offsetof(SoziFrame, center.y) }, + { "width" , PROP_TYPE_REAL , offsetof(SoziFrame, width) }, + { "height", PROP_TYPE_REAL , offsetof(SoziFrame, height) }, + { "angle" , PROP_TYPE_REAL , offsetof(SoziFrame, angle) }, + + PROP_OFFSET_NOTEBOOK_PAGE("sozi"), + { "frame sequence" , PROP_TYPE_INT , offsetof(SoziFrame, sequence) }, + { "frame title" , PROP_TYPE_TEXT , offsetof(SoziFrame, title) }, + { "frame hide" , PROP_TYPE_BOOL , offsetof(SoziFrame, hide) }, + { "frame clip" , PROP_TYPE_BOOL , offsetof(SoziFrame, clip) }, + { "frame timeout" , PROP_TYPE_INT , offsetof(SoziFrame, timeout) }, + + PROP_OFFSET_STD_NOTEBOOK_END, + + { NULL, 0, 0 } +}; + +static PropDescription * +sozi_frame_describe_props(SoziFrame *sozi_frame) +{ + if (sozi_frame_props[0].quark == 0) + prop_desc_list_calculate_quarks(sozi_frame_props); + return sozi_frame_props; +} + +static void +sozi_frame_get_props(SoziFrame *sozi_frame, GPtrArray *props) +{ + object_get_props_from_offsets(&sozi_frame->object, sozi_frame_offsets, props); +} + +static void +sozi_frame_set_props(SoziFrame *sozi_frame, GPtrArray *props) +{ + object_set_props_from_offsets(&sozi_frame->object, sozi_frame_offsets, props); + sozi_frame_update_data(sozi_frame); +} + + + + + diff --git a/objects/Misc/sozi/sozi-script.h b/objects/Misc/sozi/sozi-script.h new file mode 100644 index 0000000..4aa5c6b --- /dev/null +++ b/objects/Misc/sozi/sozi-script.h @@ -0,0 +1,10 @@ +#ifndef SOZI_SCRIPT_H +#define SOZI_SCRIPT_H + +static const char sozi_script_version[] = "11.07-17164227"; + +/* FIXME : too long string */ +static const char sozi_script[] = "var sozi=sozi||{};(function(){var a=sozi.events=sozi.events||{},b={};a.listen=function(d,e){var c=b[d];if(!c){c=b[d]=[]}c.push(e)};a.fire=function(g){var d=b[g],c,f,e=Array.prototype.slice.call(arguments,1);if(d){c=d.length;for(f=0;f<c;f+=1){d[f].apply(null,e)}}}}());var sozi=sozi||{};(function(){var x=sozi.framelist=sozi.framelist||{},l=this,s=l.document,r,n,c,k=0,d=5,i,v,b,z,A,w,f=300,j=30,g="decelerate",a="http://www.w3.org/2000/svg";function h(B){return function(C){sozi.player.previewFrame(B);C.stopPropagation()}}function m(B){B.stopPropagation()}function q(C){var B=C.relatedTarget;while(B!==n&&B!==r){B=B.parentNode}if(B===r){x.hide();sozi.player.restart();C.stopPropagation()}}function u(C){var B=c.getCTM().f;if(B<=-l.innerHeight/2){B+=l.innerHeight/2}else{if(B<0){B=0}}c.setAttribute("transform","translate(0,"+B+")");C.stopPropagation()}function e(C){var B=c.getCTM().f;if(B+k>=l.innerHeight*3/2){B-=l.innerHeight/2}else{if(B+k>l.innerHeight+2*d){B=l.innerHeight-k-4*d}}c.setAttribute("transform","translate(0,"+B+")");C.stopPropagation()}function t(B){var D=sozi.animation.profiles[g](B),C=1-D;A=z*D+b*C;n.setAttribute("transform","translate("+A+",0)")}function y(){}function p(){var H=s.createElementNS(a,"rect"),B=s.createElementNS(a,"path"),F=s.createElementNS(a,"path"),I=0,G,D=sozi.document.frames.length,C=sozi.location.getFrameIndex(),E,J;r=s.documentElement;n=s.createElementNS(a,"g");n.setAttribute("id","sozi-toc");r.appendChild(n);c=s.createElementNS(a,"g");n.appendChild(c);H.setAttribute("id","sozi-toc-background");H.setAttribute("x",d);H.setAttribute("y",d);H.setAttribute("rx",d);H.setAttribute("ry",d);H.addEventListener("click",m,false);H.addEventListener("mousedown",m,false);H.addEventListener("mouseout",q,false);c.appendChild(H);for(E=0;E<D;E+=1){J=s.createElementNS(a,"text");J.appendChild(s.createTextNode(sozi.document.frames[E].title));c.appendChild(J);if(E===C){J.setAttribute("class","sozi-toc-current")}G=J.getBBox().width;k+=J.getBBox().height;if(G>I){I=G}J.setAttribute("x",2*d);J.setAttribute("y",k+d);J.addEventListener("click",h(E),false);J.addEventListener("mousedown",m,false)}B.setAttribute("class","sozi-toc-arrow");B.setAttribute("d","M"+(I+3*d)+","+(5*d)+" l"+(4*d)+",0 l-"+(2*d)+",-"+(3*d)+" z");B.addEventListener("click",u,false);B.addEventListener("mousedown",m,false);n.appendChild(B);F.setAttribute("class","sozi-toc-arrow");F.setAttribute("d","M"+(I+3*d)+","+(7*d)+" l"+(4*d)+",0 l-"+(2*d)+","+(3*d)+" z");F.addEventListener("click",e,false);F.addEventListener("mousedown",m,false);n.appendChild(F);H.setAttribute("width",I+7*d);H.setAttribute("height",k+2*d);i=-I-9*d;v=0;A=z=i;n.setAttribute("transform","translate("+i+",0)");w=new sozi.animation.Animator(j,t,y)}function o(B){var E=c.getElementsByClassName("sozi-toc-current"),D=c.getElementsByTagName("text"),C;for(C=0;C<E.length;C+=1){E[C].removeAttribute("class")}D[B].setAttribute("class","sozi-toc-current")}x.show=function(){b=A;z=v;w.start(f)};x.hide=function(){b=A;z=i;w.start(f)};x.isVisible=function(){return z===v};sozi.events.listen("displayready",p);sozi.events.listen("cleanup",x.hide);sozi.events.listen("framechange",o)}());var sozi=sozi||{};(function(){var s=sozi.player=sozi.player||{},t=sozi.display=sozi.display||{},j=this,o=j.document,p=0,u=1,r=1.05,w=5,c=false,l=false,g=0,e=0;function a(A,z,B){s.stop();t.zoom(A>0?r:1/r,z,B)}function v(x){s.stop();t.rotate(x>0?w:-w)}function q(){if(sozi.framelist.isVisible()){sozi.framelist.hide();s.restart()}else{s.stop();sozi.framelist.show()}}function i(x){if(x.button===p){c=true;l=false;g=x.clientX;e=x.clientY}else{if(x.button===u){q()}}x.stopPropagation()}function m(x){if(c){s.stop();l=true;sozi.events.fire("cleanup");t.drag(x.clientX-g,x.clientY-e);g=x.clientX;e=x.clientY}x.stopPropagation()}function f(x){if(x.button===p){c=false}x.stopPropagation()}function h(x){if(!l&&x.button!==u){s.moveToNext()}x.stopPropagation()}function k(x){var y=0;if(!x){x=j.event}if(x.wheelDelta){y=x.wheelDelta;if(j.opera){y=-y}}else{if(x.detail){y=-x.detail}}if(y!==0){if(x.shiftKey){v(y)}else{a(y,x.clientX,x.clientY)}}x.stopPropagation();x.preventDefault()}function n(x){switch(x.charCode){case 43:a(1,j.innerWidth/2,j.innerHeight/2);break;case 45:a(-1,j.innerWidth/2,j.innerHeight/2);break;case 61:s.moveToCurrent();break;case 70:case 102:s.showAll();break;case 84:case 116:q();break;case 82:v(-1);break;case 114:v(1);break}x.stopPropagation()}function d(x){switch(x.keyCode){case 36:s.moveToFirst();break;case 35:s.moveToLast();break;case 38:s.jumpToPrevious();break;case 33:case 37:s.moveToPrevious();break;case 40:s.jumpToNext();break;case 34:case 39:case 13:case 32:s.moveToNext();break}x.stopPropagation()}function b(){var x=o.documentElement;x.addEventListener("click",h,false);x.addEventListener("mousedown",i,false);x.addEventListener("mouseup",f,false);x.addEventListener("mousemove",m,false);x.addEventListener("keypress",n,false);x.addEventListener("keydown",d,false);x.addEventListener("DOMMouseScroll",k,false);j.onmousewheel=k}j.addEventListener("load",b,false)}());var sozi=sozi||{};(function(){var a=sozi.animation=sozi.animation||{},b=this;a.Animator=function(d,c,e){this.timeStepMs=d||40;this.onStep=c;this.onDone=e;this.durationMs=0;this.data={};this.initialTime=0;this.started=false;this.timer=0};a.Animator.prototype.start=function(c,e){var d=this;this.durationMs=c;this.data=e;this.initialTime=Date.now();this.onStep(0,this.data);if(!this.started){this.started=true;this.timer=b.setInterval(function(){d.step()},this.timeStepMs)}};a.Animator.prototype.stop=function(){if(this.started){b.clearInterval(this.timer);this.started=false}};a.Animator.prototype.step=function(){var c=Date.now()-this.initialTime;if(c>=this.durationMs){this.stop();this.onStep(1,this.data);this.onDone()}else{this.onStep(c/this.durationMs,this.data)}};a.profiles={linear:function(c){return c},accelerate:function(c){return Math.pow(c,3)},"strong-accelerate":function(c){return Math.pow(c,5)},decelerate:function(c){return 1-Math.pow(1-c,3)},"strong-decelerate":function(c){return 1-Math.pow(1-c,5)},"accelerate-decelerate":function(c){var d=c<=0.5?c:1-c,e=Math.pow(2*d,3)/2;return c<=0.5?e:1-e},"strong-accelerate-decelerate":function(c){var d=c<=0.5?c:1-c,e=Math.pow(2*d,5)/2;return c<=0.5?e:1-e},"decelerate-accelerate":function(c){var d=c<=0.5?c:1-c,e=(1-Math.pow(1-2*d,2))/2;return c<=0.5?e:1-e},"strong-decelerate-accelerate":function(c){var d=c<=0.5?c:1-c,e=(1-Math.pow(1-2*d,3))/2;return c<=0.5?e:1-e}}}());var sozi=sozi||{};(function(){var d=sozi.player=sozi.player||{},j=sozi.display=sozi.display||{},h=this,c,k,e=500,q=-10,l="linear",g=0,n=0,o=false,p=false;function f(t,w){var v=1-t,u=w.profile(t),s=1-u,r,x;for(r in w.initialState){if(w.initialState.hasOwnProperty(r)){if(typeof w.initialState[r]==="number"&&typeof w.finalState[r]==="number"){j.geometry[r]=w.finalState[r]*u+w.initialState[r]*s}}}if(w.zoomWidth&&w.zoomWidth.k!==0){x=t-w.zoomWidth.ts;j.geometry.width=w.zoomWidth.k*x*x+w.zoomWidth.ss}if(w.zoomHeight&&w.zoomHeight.k!==0){x=t-w.zoomHeight.ts;j.geometry.height=w.zoomHeight.k*x*x+w.zoomHeight.ss}j.clip=w.finalState.clip;j.update()}function i(){var r;if(sozi.document.frames[n].timeoutEnable){p=true;r=(n+1)%sozi.document.frames.length;k=h.setTimeout(function(){d.moveToFrame(r)},sozi.document.frames[n].timeoutMs)}}function m(){g=n;if(o){i()}}d.startFromIndex=function(r){o=true;p=false;g=r;n=r;j.showFrame(sozi.document.frames[r]);i()};d.restart=function(){d.startFromIndex(n)};d.stop=function(){c.stop();if(p){h.clearTimeout(k);p=false}o=false;g=n};function b(r,B,z){var C={ss:((r<0)?Math.max(B,z):Math.min(B,z))*(100-r)/100,ts:0.5,k:0},x,w,t,s,A,y;if(r!==0){x=B-z;w=B-C.ss;t=z-C.ss;if(x!==0){s=Math.sqrt(w*t);A=(w-s)/x;y=(w+s)/x;C.ts=(A>0&&A<=1)?A:y}C.k=w/C.ts/C.ts}return C}d.jumpToFrame=function(r){d.stop();sozi.events.fire("cleanup");g=r;n=r;j.showFrame(sozi.document.frames[r]);sozi.events.fire("framechange",r)};d.previewFrame=function(s){var u=sozi.document.frames[s].geometry,r,t;if(q!==0){r=b(q,j.geometry.width,u.width);t=b(q,j.geometry.height,u.height)}n=s;c.start(e,{initialState:j.getCurrentGeometry(),finalState:u,profile:sozi.animation.profiles[l],zoomWidth:r,zoomHeight:t});sozi.events.fire("framechange",s)};d.moveToFrame=function(t){var s=e,w=q,u=sozi.animation.profiles[l],r,v;if(p){h.clearTimeout(k);p=false}if(t===(n+1)%sozi.document.frames.length){s=sozi.document.frames[t].transitionDurationMs;w=sozi.document.frames[t].transitionZoomPercent;u=sozi.document.frames[t].transitionProfile}sozi.events.fire("cleanup");if(w!==0){r=b(w,j.geometry.width,sozi.document.frames[t].geometry.width);v=b(w,j.geometry.height,sozi.document.frames[t].geometry.height)}o=true;n=t;c.start(s,{initialState:j.getCurrentGeometry(),finalState:sozi.document.frames[n].geometry,profile:u,zoomWidth:r,zoomHeight:v});sozi.events.fire("framechange",t)};d.moveToFirst=function(){d.moveToFrame(0)};d.jumpToPrevious=function(){var r=n;if(!c.started||g<=n){r-=1}if(r>=0){d.jumpToFrame(r)}};d.moveToPrevious=function(){var r=n,s;for(r-=1;r>=0;r-=1){s=sozi.document.frames[r];if(!s.timeoutEnable||s.timeoutMs!==0){d.moveToFrame(r);break}}};d.jumpToNext=function(){var r=n;if(!c.started||g>=n){r+=1}if(r<sozi.document.frames.length){d.jumpToFrame(r)}};d.moveToNext=function(){if(n<sozi.document.frames.length-1||sozi.document.frames[n].timeoutEnable){d.moveToFrame((n+1)%sozi.document.frames.length)}};d.moveToLast=function(){d.moveToFrame(sozi.document.frames.length-1)};d.moveToCurrent=function(){d.moveToFrame(n)};d.showAll=function(){d.stop();sozi.events.fire("cleanup");c.start(e,{initialState:j.getCurrentGeometry(),finalState:j.getDocumentGeometry(),profile:sozi.animation.profiles[l]})};function a(){d.startFromIndex(sozi.location.getFrameIndex())}c=new sozi.animation.Animator(40,f,m);sozi.events.listen("displayready",a)}());var sozi=sozi||{};(function(){var d=sozi.display=sozi.display||{},h=this,i=h.document,j,c,k,a,g="http://www.w3.org/2000/svg";d.geometry={cx:0,cy:0,width:1,height:1,rotate:0};d.clip=true;function f(){var o,l=i.createElementNS(g,"g"),m=i.createElementNS(g,"clipPath");j=i.documentElement;j.removeAttribute("viewBox");k=j.getBBox();a=i.createElementNS(g,"g");while(true){o=j.firstChild;if(!o){break}j.removeChild(o);a.appendChild(o)}c=i.createElementNS(g,"rect");c.setAttribute("id","sozi-clip-rect");m.setAttribute("id","sozi-clip-path");m.appendChild(c);j.appendChild(m);l.setAttribute("clip-path","url(#sozi-clip-path)");l.appendChild(a);j.appendChild(l);j.setAttribute("width",h.innerWidth);j.setAttribute("height",h.innerHeight);sozi.events.fire("displayready")}function b(){j.setAttribute("width",h.innerWidth);j.setAttribute("height",h.innerHeight);d.update()}function e(){var l={};l.scale=Math.min(h.innerWidth/d.geometry.width,h.innerHeight/d.geometry.height);l.width=d.geometry.width*l.scale;l.height=d.geometry.height*l.scale;l.x=(h.innerWidth-l.width)/2;l.y=(h.innerHeight-l.height)/2;return l}d.getElementGeometry=function(l){var s,p,t,n,q,o,r=l.getCTM(),m=Math.sqrt(r.a*r.a+r.b*r.b);if(l.nodeName==="rect"){s=l.x.baseVal.value;p=l.y.baseVal.value;t=l.width.baseVal.value;n=l.height.baseVal.value}else{q=l.getBBox();s=q.x;p=q.y;t=q.width;n=q.height}o=i.documentElement.createSVGPoint();o.x=s+t/2;o.y=p+n/2;o=o.matrixTransform(r);return{cx:o.x,cy:o.y,width:t*m,height:n*m,rotate:Math.atan2(r.b,r.a)*180/Math.PI}};d.getDocumentGeometry=function(){return{cx:k.x+k.width/2,cy:k.y+k.height/2,width:k.width,height:k.height,rotate:0,clip:false}};d.getCurrentGeometry=function(){return{cx:d.geometry.cx,cy:d.geometry.cy,width:d.geometry.width,height:d.geometry.height,rotate:d.geometry.rotate,clip:d.clip}};d.update=function(){var l=e(),n=-d.geometry.cx+d.geometry.width/2+l.x/l.scale,m=-d.geometry.cy+d.geometry.height/2+l.y/l.scale;a.setAttribute("transform","scale("+l.scale+")translate("+n+","+m+")rotate("+(-d.geometry.rotate)+","+d.geometry.cx+","+d.geometry.cy+")");c.setAttribute("x",d.clip?l.x:0);c.setAttribute("y",d.clip?l.y:0);c.setAttribute("width",d.clip?l.width:h.innerWidth);c.setAttribute("height",d.clip?l.height:h.innerHeight)};d.showFrame=function(m){var l;for(l in m.geometry){if(m.geometry.hasOwnProperty(l)){d.geometry[l]=m.geometry[l]}}d.update()};d.drag=function(m,l){var n=e(),o=d.geometry.rotate*Math.PI/180;d.geometry.cx-=(m*Math.cos(o)-l*Math.sin(o))/n.scale;d.geometry.cy-=(m*Math.sin(o)+l*Math.cos(o))/n.scale;d.clip=false;d.update()};d.zoom=function(o,m,p){var n=(1-o)*(m-h.innerWidth/2),l=(1-o)*(p-h.innerHeight/2);d.geometry.width/=o;d.geometry.height/=o;d.drag(n,l)};d.rotate=function(l){d.geometry.rotate+=l;d.geometry.rotate%=360;d.update()};sozi.events.listen("documentready",f);h.addEventListener("resize",b,false)}());var sozi=sozi||{};(function(){var c=sozi.document=sozi.document||{},g=this,a=g.document,f="http://sozi.baierouge.fr",d={title:"Untitled",sequence:"0",hide:"true",clip:"true","timeout-enable":"false","timeout-ms":"5000","transition-duration-ms":"1000","transition-zoom-percent":"0","transition-profile":"linear"};c.frames=[];function h(j,i){var k=j.getAttributeNS(f,i);return k===""?d[i]:k}function b(){var j=a.getElementsByTagNameNS(f,"frame"),k=j.length,m,l,n;for(l=0;l<k;l+=1){m=a.getElementById(j[l].getAttributeNS(f,"refid"));if(m){n={geometry:sozi.display.getElementGeometry(m),title:h(j[l],"title"),sequence:parseInt(h(j[l],"sequence"),10),hide:h(j[l],"hide")==="true",timeoutEnable:h(j[l],"timeout-enable")==="true",timeoutMs:parseInt(h(j[l],"timeout-ms"),10),transitionDurationMs:parseInt(h(j[l],"transition-duration-ms"),10),transitionZoomPercent:parseInt(h(j[l],"transition-zoom-percent"),10),transitionProfile:sozi.animation.profiles[h(j[l],"transition-profile")||"linear"]};if(n.hide){m.setAttribute("visibility","hidden")}n.geometry.clip=h(j[l],"clip")==="true";c.frames.push(n)}}c.frames.sort(function(o,i){return o.sequence-i.sequence})}function e(){b();sozi.events.fire("documentready")}g.addEventListener("load",e,false)}());var sozi=sozi||{};(function(){var a=sozi.location=sozi.location||{},e=this,c=false;a.getFrameIndex=function(){var g=e.location.hash?parseInt(e.location.hash.slice(1),10)-1:0;if(isNaN(g)||g<0){return 0}else{if(g>=sozi.document.frames.length){return sozi.document.frames.length-1}else{return g}}};function f(){var g=a.getFrameIndex();if(!c){sozi.player.moveToFrame(g)}c=false}function d(g){c=true;e.location.hash="#"+(g+1)}function b(){sozi.events.listen("framechange",d)}e.addEventListener("hashchange",f,false);e.addEventListener("load",b,false)}());"; + +#endif + diff --git a/objects/Misc/sozi/sozi-style.h b/objects/Misc/sozi/sozi-style.h new file mode 100644 index 0000000..f155d7b --- /dev/null +++ b/objects/Misc/sozi/sozi-style.h @@ -0,0 +1,8 @@ +#ifndef SOZI_STYLE_H +#define SOZI_STYLE_H + +static const char sozi_style_version[] = "11.07-17164227"; + +static const char sozi_style[] = "#sozi-toc text{fill:#eff;font-family:Verdana,sans-serif;font-size:12pt}#sozi-toc text:hover{fill:#0cf;cursor:pointer}#sozi-toc text.sozi-toc-current{fill:#fa4}#sozi-toc-background{stroke:#222;stroke-opacity:.1;stroke-width:10;fill:#222;fill-opacity:.9}.sozi-toc-arrow{fill:#eff;fill-opacity:.75;stroke:none}.sozi-toc-arrow:hover{fill:#0cf}"; + +#endif diff --git a/sheets/Misc.sheet.in b/sheets/Misc.sheet.in index 00bd80c..ca74c90 100644 --- a/sheets/Misc.sheet.in +++ b/sheets/Misc.sheet.in @@ -30,6 +30,9 @@ <_description>New-style group object, for testing + + <_description>Sozi frame, for zooming ui + -- 1.7.4.4