Subversion Repositories wimsdev

Rev

Rev 8244 | Rev 8262 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7614 schaersvoo 1
/*
2
27/7/2013 version 0.01
3
"Inspired" by FLY program: http://martin.gleeson.com/fly
4
*********************************************************************************
5
* J.M. Evers 7/2013                                                             *
6
* This is all just amateur scriblings... So no copyrights.                      *
7
* This source code file, and compiled objects derived from it,                  *
8
* can be used and distributed without restriction, including for commercial use *
9
* No warrenty whatsoever                                                        *
10
*********************************************************************************
11
*/
7848 bpr 12
#include "canvasdraw.h"
7614 schaersvoo 13
 
14
/******************************************************************************
15
**  Internal Functions
16
******************************************************************************/
17
void    add_to_buffer(char *tmp); /* add tmp_buffer to the buffer */
18
void    sync_input(FILE *infile);/* proceed with inputfile */
19
void    add_javascript_functions(int js_functions[], int canvas_root_id);
20
void    reset();/* reset some global variables like "use_filled" , "use_dashed" */
21
int     get_token(FILE *infile); /* read next char until EOL*/
8225 bpr 22
/*
7614 schaersvoo 23
int     x2px(double x);
24
int     y2px(double y);
8225 bpr 25
*/
7614 schaersvoo 26
double  px2x(int x);
27
double  px2y(int y);
7906 schaersvoo 28
double  get_real(FILE *infile,int last); /* read a value; calculation and symbols allowed */
7614 schaersvoo 29
char    *str_replace ( const char *word, const char *sub_word, const char *rep_word );
30
char    *get_color(FILE *infile,int last); /* read hex-color or colorname -> hex */
7906 schaersvoo 31
char    *get_string(FILE *infile,int last); /* get the string at the end of a command */
7614 schaersvoo 32
char    *get_string_argument(FILE *infile,int last); /* the same, but with "comma" as  separator */
33
char    *convert_hex2rgb(char *hexcolor);
8257 schaersvoo 34
void    add_read_canvas(int canvas_root_id,int reply_format,int reply_precision);
7614 schaersvoo 35
void    make_js_include(int canvas_root_id);
36
void    check_string_length(int length);/* checks if the length of string argument of command is correct */
8224 bpr 37
FILE    *js_include_file;
7614 schaersvoo 38
FILE    *get_file(int *line_number, char **filename);
39
FILE    *infile;    /* will be stdin */
40
/******************************************************************************
41
** global
42
******************************************************************************/
43
int finished = FALSE;/* main variable for signalling the end of the fly-script ; if finished = 1 ; write to stdout or canvasz */
44
int line_number = 1;/* used in canvas_error() ; keep track of line number in canvasdraw/fly - script */
45
/* set some variables to avoid trouble (NaN) in case of syntax and other usage errors */
46
int xsize = 320;
47
int ysize = 320;
48
double xmin = 0.0;
49
double xmax = 320.0;
50
double ymin = 0.0;
51
double ymax = 320.0;
52
double tmax = 2;
53
double tmin = -2;
54
/* flag to indicate parsing of line status */
8224 bpr 55
int done = FALSE;
7614 schaersvoo 56
int type; /* eg command number */
57
int onclick = 0;/* 0 = noninteractive ; 1 = onclick ; 2 = draggable*/
8097 schaersvoo 58
int slider = 0;/* slider=1 : x-values ; slider=2 : y-values;slider=3 angle values */
7785 schaersvoo 59
int use_affine = FALSE;
7614 schaersvoo 60
int use_rotate = FALSE;
61
int use_filled = FALSE;
62
int use_dashed = FALSE; /* dashing not natively supported in firefox  , for now... */
8097 schaersvoo 63
 
7614 schaersvoo 64
char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
65
 
66
/******************************************************************************
67
** Main Program
68
******************************************************************************/
69
int main(int argc, char *argv[]){
70
    /* need unique id for every call to canvasdraw : rand(); is too slow...will result in many identical id's */
71
    struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
72
    infile = stdin;/* read flyscript via stdin */
73
    int i,c;
74
    double double_data[MAX_INT+1];
75
    int int_data[MAX_INT+1];
76
    for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
77
    int use_parametric = FALSE;/* will be reset after parametric plotting */
78
    int use_axis = FALSE;
79
    int use_axis_numbering = FALSE;
7797 schaersvoo 80
    int use_pan_and_zoom = FALSE;
7956 schaersvoo 81
    int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
7858 schaersvoo 82
    int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
83
    int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
7614 schaersvoo 84
    int line_width = 1;
85
    int decimals = 2;
86
    int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate */
87
    int use_userdraw = FALSE; /* flag to indicate user interaction: incompatible with "drag & drop" code !! */
88
    int drag_type = -1;/* 0,1,2 : xy,x,y */
89
    int use_tooltip = FALSE;
90
    char *tooltip_text = "Click here";
91
    char *temp = ""; /* */
92
    char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
93
    char *stroke_color = "255,0,0";
94
    char *fill_color = "0,255,0";
95
    char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
96
    char *font_color = "#00000";
97
    char *draw_type = "points";
98
    char *fly_font = "normal";
99
    char *input_style = "";
100
    char *flytext = "";
7785 schaersvoo 101
    char *affine_matrix = "[1,0,0,1,0,0]";
7614 schaersvoo 102
    int pixelsize = 1;
103
    int reply_format = 0;
104
    int input_cnt = 0;
105
    int ext_img_cnt = 0;
8071 schaersvoo 106
    int slider_cnt = 0;
7614 schaersvoo 107
    int font_size = 12;
8071 schaersvoo 108
    int dashtype[2] = { 4 , 4 };
7614 schaersvoo 109
    int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
110
    for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
111
    int arrow_head = 8; /* size in px*/
7833 schaersvoo 112
    int crosshair_size = 5; /* size in px*/
8224 bpr 113
    int plot_steps = 250;
7983 schaersvoo 114
    int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange*/
7614 schaersvoo 115
    int click_cnt = 1;
116
    int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
117
    int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
7989 schaersvoo 118
    int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
7956 schaersvoo 119
    int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
8074 schaersvoo 120
    int reply_precision = 100; /* used for precision of student answers / drawings */
7614 schaersvoo 121
    double angle = 0.0;
122
    int clickfillmarge = 20;
123
    int animation_type = 9; /* == object type curve in drag library */
7823 schaersvoo 124
    int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
8112 schaersvoo 125
    int use_slider_display = 0; /* in case of a slider, should we display it's value ?*/
7614 schaersvoo 126
    size_t string_length = 0;
127
    double stroke_opacity = 0.8;
128
    double fill_opacity = 0.8;
129
    char *URL = "http://localhost/images";
130
    memset(buffer,'\0',MAX_BUFFER);
131
    void *tmp_buffer = "";
8224 bpr 132
 
7614 schaersvoo 133
    /* default writing a unzipped js-include file into wims getfile directory */
134
    char *w_wims_session = getenv("w_wims_session");
8224 bpr 135
    if(  w_wims_session == NULL || *w_wims_session == 0 ){
7614 schaersvoo 136
        canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
137
    }
138
    int L0=strlen(w_wims_session) + 21;
139
    char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
140
    snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
141
    mode_t process_mask = umask(0); /* check if file exists */
142
    int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
143
    if( result == 0 || errno == EEXIST ){
144
     umask(process_mask); /* be sure to set correct permission */
8224 bpr 145
     char *w_session = getenv("w_session");
7614 schaersvoo 146
     int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
147
    char *getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
8224 bpr 148
     snprintf(getfile_cmd,L1,"wims.cgi?session=%s&cmd=getfile&special_parm=%d.js",w_session,canvas_root_id);/* extension ".gz" is MANDATORY for webserver */
7614 schaersvoo 149
    /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
150
    /* now write file into getfile dir*/
151
    char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
152
    int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
153
    char *location = my_newmem(L2); /* create memory to fit string precisely */
154
    snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
155
    js_include_file = fopen(location,"w");/* open the file location for writing */
156
    /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
157
    if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
158
 
159
/* ----------------------------------------------------- */
160
/* while more lines to process */
161
 
162
    while(!finished){
7983 schaersvoo 163
        if(line_number>1 && found_size_command == 0){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
7614 schaersvoo 164
        type = get_token(infile);
165
        done = FALSE;
166
        /*
167
        @canvasdraw
8224 bpr 168
        @will try use the same syntax as flydraw or svgdraw to paint a html5 bitmap image<br />by generating a tailor-made javascript include file: providing only the js-functionality needed to perform the job.<br />thus ensuring a minimal strain on the client browser <br />(unlike some popular 'canvas-do-it-all' libraries, who have proven to be not suitable for low-end computers found in schools...)
8257 schaersvoo 169
        @General syntax <ul><li>The transparency of all objects can be controlled by command 'opacity [0-255],[0,255]'</il><li>a line based object can be controlled by command 'linewidth int'</li><li>a line based object may be dashed by using keyword 'dashed' before the object command.<br />the dashing type can be controled by command 'dashtype int,int'</li><li>a fillable object can be set fillable by starting the object command with an 'f'<br />(like frect,fcircle,ftriangle...)<br />or by using the keyword 'filled' before the object command.<br />The fill colour will be the stroke colour...(19/10/2013)</li><li> all draggable objects may have a slider for translation / rotation; several objects may be translated / rotated by a single slider</li> <li> a draggable object can be set draggable by a preceding command 'drag x/y/xy'<br />The translation can be read by javascript:read_dragdrop();The replyformat is : object_number : x-orig : y-orig : x-drag : y-drag<br />The x-orig/y-orig will be returned in maximum precision (javascript float)...<br />the x-drag/y-drag will be returned in defined 'precision' number of decimals<br />Multiple objects may be set draggable / clickable (no limit)<br /> not all flydraw objects may be dragged / clicked<br />Only draggable / clickable objects will be scaled on zoom and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword 'onclick'<br />not all flydraw objects can be set clickable</li><li><b>remarks using a ';' as command separator</b><br />commands with only numeric or colour arguments may be using a ';' as command separator (in stead of a new line)<br />commands with a string argument may not use a ';' as command separator !<br />these exceptions are not really straight forward... so keep this in mind.</li></ul>Note: for now just <b>one interactive</b> instance of canvasdraw is allowed <br />[e.g. using command 'userdraw' and function javascript:read_canvas()]<br />Aim is to allow multiple interactive instances of canvasdraw to exist in a single page (this will however call for a much more 'object oriented approach' and decent javascript programming...)
7614 schaersvoo 170
        */
171
        switch(type){
172
        case END:
173
        finished = 1;
174
        done = TRUE;
175
        break;
176
        case 0:
177
            sync_input(infile);
178
            break;
179
        case COMMENT:
180
            sync_input(infile);
181
            break;
182
        case EMPTY:
183
            sync_input(infile);
184
            break;
185
        case SIZE:
186
            /*
187
            @size width,height
188
            @set canvas size in pixels
189
            @mandatory first command
7906 schaersvoo 190
            @if xrange and/or yrange is not given the range will be set to pixels :<br />xrange 0,xsize yrange 0,ysize<br />note: lower left  corner is Origin (0:0) !!! this in contrast to flydraw
7614 schaersvoo 191
            */
7983 schaersvoo 192
            found_size_command = 1;
7614 schaersvoo 193
            xsize = (int)(abs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
194
            ysize = (int)(abs(round(get_real(infile,1))));
195
            /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
196
            xmin = 0;xmax = xsize;
7647 schaersvoo 197
            ymin = 0;ymax = ysize;
7614 schaersvoo 198
 
8224 bpr 199
/*
7614 schaersvoo 200
 The sequence in which stuff is finally printed is important !!
201
 for example, when writing a 'include.js" the may not be a "script tag <script>" etc etc
202
*/
8257 schaersvoo 203
fprintf(stdout,"\n<script type=\"text/javascript\">\
204
if( typeof wims_status === 'undefined' ){ var wims_status = \"$status\";};\
205
if( typeof use_dragdrop_reply === 'undefined' ){ var use_dragdrop_reply = false;};\
206
if( typeof canvas_scripts === 'undefined' ){ var canvas_scripts = new Array();};\
207
canvas_scripts.push(\"%d\");</script>\n\
208
<!-- canvasdraw div and tooltip placeholder, if needed -->\n<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div><div id=\"tooltip_placeholder_div%d\" style=\"display:block;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\n",canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id);
209
fprintf(stdout,"<!-- include actual object code via include file -->\n<script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,getfile_cmd);
8146 schaersvoo 210
fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
8108 schaersvoo 211
\"use strict\";\n\
8146 schaersvoo 212
<!-- these variables and functions must be global -->\n\
8257 schaersvoo 213
var read_dragdrop%d;\
214
var read_canvas%d;\
8130 schaersvoo 215
var set_clock;\
8146 schaersvoo 216
var clear_draw_area;\
8257 schaersvoo 217
var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
8146 schaersvoo 218
var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
7729 schaersvoo 219
var xsize = %d;\
220
var ysize = %d;\
7797 schaersvoo 221
var precision = 100;\
7729 schaersvoo 222
var canvas_div = document.getElementById(\"canvas_div%d\");\
8105 schaersvoo 223
var create_canvas%d = function(canvas_type,size_x,size_y){var cnv;if(document.getElementById(\"wims_canvas%d\"+canvas_type)){ cnv = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{try{ cnv = document.createElement(\"canvas\"); }catch(e){alert(\"Your browser does not support HTML5 CANVAS:GET FIREFOX !\");return;};canvas_div.appendChild(cnv);};cnv.width = size_x;cnv.height = size_y;cnv.style.top = 0;cnv.style.left = 0;cnv.style.position = \"absolute\";cnv.id = \"wims_canvas%d\"+canvas_type;return cnv;};\
7729 schaersvoo 224
function findPosX(i){ var obj = i;var curleft = 0;if(obj.offsetParent){while(1){curleft += obj.offsetLeft;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.x){curleft += obj.x;};};return curleft;};function findPosY(i){var obj = i;var curtop = 0;if(obj.offsetParent){while(1){curtop += obj.offsetTop;if(!obj.offsetParent){break;};obj = obj.offsetParent;};}else{if(obj.y){curtop += obj.y;};};return curtop;};\
7990 schaersvoo 225
function x2px(x){if(use_xlogscale == 0 ){return parseFloat(x*xsize/(xmax - xmin) - xsize*xmin/(xmax - xmin));}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_in = Math.log(x)/Math.log(xlogbase);return x_in*xsize/(x_max - x_min) - xsize*x_min/(x_max - x_min);};};\
226
function px2x(px){if(use_xlogscale == 0 ){return parseFloat(px*(xmax - xmin)/xsize + xmin);}else{var x_max = Math.log(xmax)/Math.log(xlogbase);var x_min = Math.log(xmin)/Math.log(xlogbase);var x_out = x_min +px*(x_max - x_min)/(xsize);return Math.pow(xlogbase,x_out);};};\
227
function px2y(py){if(use_ylogscale == 0 ){return parseFloat(ymax - py*(ymax - ymin)/ysize);}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_out = y_max +py*(y_min - y_max)/(ysize);return Math.pow(ylogbase,y_out);};};\
228
function y2px(y){if(use_ylogscale == 0){return parseFloat(-1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin));}else{var y_max = Math.log(ymax)/Math.log(ylogbase);var y_min = Math.log(ymin)/Math.log(ylogbase);var y_in = Math.log(y)/Math.log(ylogbase);return (y_max - y_in)*ysize/(y_max - y_min);};};\
8071 schaersvoo 229
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
230
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
7729 schaersvoo 231
function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\
232
function distance_to_line (r,q,x,y){var c = (y) - (-1/r)*(x);var xs = r*(c - q)/(r*r+1);var ys = (r)*(xs)+(q);return parseInt(Math.sqrt( (xs-x)*(xs-x) + (ys-y)*(ys-y) ));};\
8105 schaersvoo 233
function move(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = obj.x[p] + dx;obj.y[p] = obj.y[p] + dy;};return obj;};\
234
function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = x2px(obj.xorg[p] + dx);obj.y[p] = y2px(obj.yorg[p] + dy);};return obj;};\
7881 schaersvoo 235
var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
236
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
237
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
7735 schaersvoo 238
var xlogbase = 10;\
239
var ylogbase = 10;\
7729 schaersvoo 240
var use_xlogscale = 0;\
241
var use_ylogscale = 0;\
242
var x_strings = null;\
243
var y_strings = null;\
244
var use_pan_and_zoom = 0;\
7858 schaersvoo 245
var use_jsmath = 0;\
7729 schaersvoo 246
var xstart = 0;\
7996 schaersvoo 247
var ystart = 0;\
248
var unit_x=\" \";\
8257 schaersvoo 249
var unit_y=\" \";",canvas_root_id,canvas_root_id,canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 250
/* default add the drag code : nearly always used ...*/
8257 schaersvoo 251
  add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
252
 
7614 schaersvoo 253
            break;
254
        case XRANGE:
255
        /*
256
        @ xrange xmin,xmax
8224 bpr 257
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 258
        */
259
            for(i = 0 ; i<2; i++){
260
                switch(i){
261
                    case 0: xmin = get_real(infile,0);break;
262
                    case 1: xmax = get_real(infile,1);break;
263
                    default: break;
264
                }
265
            }
266
            if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
267
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
7983 schaersvoo 268
            found_size_command++;
7614 schaersvoo 269
            break;
270
        case YRANGE:
271
        /*
272
        @ yrange ymin,ymax
273
        @ if not given 0,ysize (eg in pixels)
274
        */
275
            for(i = 0 ; i<2; i++){
276
                switch(i){
277
                    case 0: ymin = get_real(infile,0);break;
278
                    case 1: ymax = get_real(infile,1);break;
279
                    default: break;
280
                }
281
            }
282
            if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
283
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
7983 schaersvoo 284
            found_size_command++;
7614 schaersvoo 285
            break;
286
        case TRANGE:
287
        /*
288
        @ trange tmin,tmax
289
        @ default -2,2
290
        */
291
            use_parametric = TRUE;
292
            for(i = 0 ; i<2; i++){
293
                switch(i){
294
                    case 0: tmin = get_real(infile,0);break;
295
                    case 1: tmax = get_real(infile,1);break;
296
                    default: break;
297
                }
298
            }
299
            if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
300
            break;
301
        case LINEWIDTH:
302
        /*
303
        @ linewidth int
304
        @ default 1
305
        */
306
            line_width = (int) (get_real(infile,1));
307
            break;
308
        case ARROWHEAD:
309
        /*
310
        @ arrowhead int
311
        @ default 8 (pixels)
312
        */
313
            arrow_head = (int) (get_real(infile,1));
314
            break;
315
        case CROSSHAIRSIZE:
316
        /*
317
        @ crosshairsize int
318
        @ default 10 (px)
319
        */
320
            crosshair_size = (int) (get_real(infile,1));
321
            break;
322
        case CROSSHAIR:
323
        /*
324
        @ crosshair x,y,color
325
        @ draw a single crosshair point at (x;y) in color 'color'
7956 schaersvoo 326
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
7614 schaersvoo 327
        @ may be set draggable / onclick
328
        */
329
            for(i=0;i<3;i++){
330
                switch(i){
331
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
332
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
333
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
334
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 335
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 336
                        click_cnt++;reset();
337
                        break;
338
                    default:break;
339
                }
340
            }
341
            break;
342
        case CROSSHAIRS:
343
        /*
344
        @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
345
        @ draw multiple crosshair points at given coordinates in color 'color'
7956 schaersvoo 346
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
7614 schaersvoo 347
        @ may be set draggable / onclick individually (!)
348
        */
349
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
350
            fill_color = stroke_color;
351
            i=0;
352
            while( ! done ){     /* get next item until EOL*/
353
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
354
                if(i%2 == 0 ){
355
                    double_data[i] = get_real(infile,0); /* x */
356
                }
357
                else
358
                {
359
                    double_data[i] = get_real(infile,1); /* y */
360
                }
361
                i++;
362
            }
363
            decimals = find_number_of_digits(precision);
364
            for(c=0 ; c < i-1 ; c = c+2){
8097 schaersvoo 365
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,7,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],crosshair_size,crosshair_size,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 366
                click_cnt++;
367
            }
368
            reset();
369
            break;
370
        case POINT:
371
        /*
372
        @ point x,y,color
373
        @ draw a single point at (x;y) in color 'color'
7956 schaersvoo 374
        @ use command 'linewidth int'  to adust size
7614 schaersvoo 375
        @ may be set draggable / onclick
8224 bpr 376
        @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
7614 schaersvoo 377
        */
378
            for(i=0;i<3;i++){
379
                switch(i){
380
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
381
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
382
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
383
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 384
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 385
                    click_cnt++;break;
386
                    default: break;
387
                }
388
            }
389
            reset();
390
            break;
391
        case POINTS:
392
        /*
7634 schaersvoo 393
        @ points color,x1,y1,x2,y2,...,x_n,y_n
7614 schaersvoo 394
        @ draw multiple points at given coordinates in color 'color'
7956 schaersvoo 395
        @ use command 'linewidth int'  to adust size
7614 schaersvoo 396
        @ may be set draggable / onclick individually (!)
397
        */
398
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
399
            fill_color = stroke_color;
400
            i=0;
401
            while( ! done ){     /* get next item until EOL*/
402
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
403
                if(i%2 == 0 ){
404
                    double_data[i] = get_real(infile,0); /* x */
405
                }
406
                else
407
                {
408
                    double_data[i] = get_real(infile,1); /* y */
409
                }
410
                i++;
411
            }
8224 bpr 412
            decimals = find_number_of_digits(precision);
7614 schaersvoo 413
            for(c = 0 ; c < i-1 ; c = c+2){
8097 schaersvoo 414
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,1,0,0,0,use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 415
                click_cnt++;
416
            }
417
            reset();
418
            break;
419
        case SEGMENT:
420
        /*
421
        @ segment x1,y1,x2,y2,color
422
        @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
423
        @ may be set draggable / onclick
424
        */
425
            for(i=0;i<5;i++) {
426
                switch(i){
427
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
428
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
429
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
430
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
431
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
432
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 433
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 434
                        click_cnt++;reset();
435
                        break;
436
                    default: break;
437
                }
438
            }
439
            break;
440
        case LINE:
441
        /*
442
        @ line x1,y1,x2,y2,color
443
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
444
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
445
        @ may be set draggable / onclick
446
        */
447
            for(i=0;i<5;i++){
448
                switch(i){
449
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
450
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
451
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
452
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
453
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
454
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
455
                        double_data[1] = xmin;
456
                        double_data[3] = ymax;
457
                        double_data[0] = double_data[10];
458
                        double_data[2] = double_data[10];
459
                    }
460
                    else
461
                    {
462
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
463
                            double_data[1] = double_data[11];
464
                            double_data[3] = double_data[11];
465
                            double_data[0] = ymin;
466
                            double_data[2] = xmax;
467
                        }
468
                        else
469
                        {
470
                        /* m */
471
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
472
                        /* q */
473
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
8224 bpr 474
 
7614 schaersvoo 475
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
8224 bpr 476
 
7614 schaersvoo 477
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
478
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
479
                            double_data[0] = xmin;
480
                            double_data[2] = xmax;
481
                        }
482
                    }
483
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 484
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 485
                    click_cnt++;reset();
486
                    break;
487
                }
488
            }
489
            break;
8244 schaersvoo 490
        case HALFLINE:
491
        /*
492
        @ demiline x1,y1,x2,y2,color
493
        @ alternative : halfline
494
        @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
495
        @ may be set draggable / onclick
496
        */
497
            for(i=0;i<5;i++){
498
                switch(i){
499
                    case 0: double_data[0]= get_real(infile,0);break; /* x-values */
500
                    case 1: double_data[1]= get_real(infile,0);break; /* y-values */
501
                    case 2: double_data[10]= get_real(infile,0);break; /* x-values */
502
                    case 3: double_data[11]= get_real(infile,0);break; /* y-values */
503
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
504
                    if(double_data[0] == double_data[10]){ /* vertical halfline */
505
                        if(double_data[1] < double_data[11]){
506
                         double_data[3] = ymax + 1000;
507
                        }
508
                        else
509
                        {
510
                         double_data[3] = ymin - 1000;
511
                        }
512
                        double_data[2] = double_data[0];
513
                    }
514
                    else
515
                    { /* horizontal halfline*/
516
                     if( double_data[1] == double_data[11] ){
517
                      if( double_data[0] < double_data[10] ){
518
                        double_data[2] = xmax + 1000; /* halfline to the right */
519
                      }
520
                      else
521
                      {
522
                        double_data[2] = xmin - 1000; /* halfline to the left */
523
                      }
524
                      double_data[3] = double_data[1];
525
                     }
526
                     else
527
                     {
528
                      /* any other halfline */
529
                      /* slope */
530
                      double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
531
                      /* const */
532
                      double_data[13] = double_data[1] - double_data[12]*double_data[0];
533
                      if( double_data[0] < double_data[10] ){
534
                       double_data[2] = double_data[2] + 1000;
535
                      }
536
                      else
537
                      {
538
                       double_data[2] = double_data[2] - 1000;
539
                      }
540
                      double_data[3] = double_data[12]*double_data[2] + double_data[13];
541
                     }
542
                    }    
543
                    decimals = find_number_of_digits(precision);
544
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,18,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
545
                    click_cnt++;reset();
546
                    break;
547
                }
548
            }
549
 
550
            break;
8224 bpr 551
        case HLINE:
7614 schaersvoo 552
        /*
553
        @ hline x,y,color
554
        @ draw a horizontal line through point (x:y) in color 'color'
555
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
556
        @ may be set draggable / onclick
557
        */
558
            for(i=0;i<3;i++) {
559
                switch(i){
560
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
561
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
562
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
563
                    double_data[3] = double_data[1];
564
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 565
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[1],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 566
                    click_cnt++;reset();
567
                    break;
568
                }
569
            }
570
            break;
571
        case VLINE:
572
        /*
573
        @ vline x,y,color
574
        @ draw a vertical line through point (x:y) in color 'color'
575
        @ may be set draggable / onclick
576
        */
577
            for(i=0;i<3;i++) {
578
                switch(i){
579
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
580
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
581
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
582
                        double_data[2] = double_data[0];
583
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 584
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,ymin,decimals,ymax,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 585
                        click_cnt++;reset();
586
                    break;
587
                }
588
            }
589
            break;
590
        case SQUARE:
591
        /*
8071 schaersvoo 592
        @ square x,y,side (px) ,color
7614 schaersvoo 593
        @ draw a square with left top corner (x:y) with side 'side' in color 'color'
594
        @ use command 'fsquare x,y,side,color' for a filled square
595
        @ use command/keyword  'filled' before command 'square x,y,side,color'
596
        @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
597
        @ may be set draggable / onclick
598
        */
599
            for(i=0;i<5;i++){
600
                switch(i){
8071 schaersvoo 601
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
602
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
603
                    case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
604
                    case 3:
605
                        stroke_color = get_color(infile,1);/* name or hex color */
7614 schaersvoo 606
                        decimals = find_number_of_digits(precision);
8071 schaersvoo 607
                        double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
608
                        double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
8097 schaersvoo 609
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[3],decimals,double_data[3],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[4],decimals,double_data[4],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 610
                        click_cnt++;reset();
611
                        break;
612
                }
613
            }
614
            break;
615
        case ROUNDRECT:
616
        /*
617
        @ roundrect x1,y1,x2,y2,radius,color
618
        @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
619
        @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
620
        @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
621
        @ may be set draggable / onclick
622
        */
623
            for(i=0;i<6;i++){
624
                switch(i){
625
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
626
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
627
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
628
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
629
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
630
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
8071 schaersvoo 631
                        /* ensure no inverted roundrect is produced... */
632
                        if( double_data[0] > double_data[2] ){double_data[4] = double_data[0];double_data[0] = double_data[2];double_data[2] = double_data[4];}
8224 bpr 633
                        if( double_data[3] > double_data[1] ){double_data[4] = double_data[1];double_data[1] = double_data[3];double_data[3] = double_data[4];}
7614 schaersvoo 634
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 635
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,6,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 636
                        click_cnt++;reset();
637
                    break;
638
                }
639
            }
640
            break;
641
        case RECT:
642
        /*
643
        @ rect x1,y1,x2,y2,color
644
        @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
645
        @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
646
        @ use command 'fillcolor color' before 'frect' to set the fill colour.
647
        @ may be set draggable / onclick
648
        */
649
            for(i=0;i<5;i++){
650
                switch(i){
651
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
652
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
653
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
654
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
655
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
656
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 657
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,1,[%.*f,%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f,%.*f],[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[2],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[3],decimals,double_data[3],line_width,line_width,line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 658
                        click_cnt++;reset();
659
                        break;
660
                }
661
            }
662
            break;
663
        case POLYLINE:
664
        /*
665
        @ polyline color,x1,y1,x2,y2...x_n,y_n
666
        @ may be set draggable / onclick
667
        */
668
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
669
            i=0;
670
            c=0;
671
            while( ! done ){     /* get next item until EOL*/
672
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
673
                for( c = 0 ; c < 2; c++){
674
                    if(c == 0 ){
675
                        double_data[i] = get_real(infile,0);
676
                        i++;
677
                    }
678
                    else
679
                    {
680
                        double_data[i] = get_real(infile,1);
681
                        i++;
682
                    }
683
                }
684
            }
685
            /* draw path : not closed & not filled */
686
            decimals = find_number_of_digits(precision);
8097 schaersvoo 687
            fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 688
            click_cnt++;reset();
689
            break;
690
        case POLY:
691
        /*
692
        @ poly color,x1,y1,x2,y2...x_n,y_n
693
        @ draw closed polygon
694
        @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
695
        @ may be set draggable / onclick
696
        */
697
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
698
            i=0;
699
            c=0;
700
            while( ! done ){     /* get next item until EOL*/
701
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
702
                for( c = 0 ; c < 2; c++){
703
                    if(c == 0 ){
704
                        double_data[i] = get_real(infile,0);
705
                        i++;
706
                    }
707
                    else
708
                    {
709
                        double_data[i] = get_real(infile,1);
710
                        i++;
711
                    }
712
                }
713
            }
714
            /* draw path :  closed & optional filled */
715
                decimals = find_number_of_digits(precision);
8097 schaersvoo 716
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,i,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 717
                click_cnt++;reset();
718
            break;
8224 bpr 719
        case ARC:
7614 schaersvoo 720
        /*
721
         @ arc xc,yc,width,height,start_angle,end_angle,color
722
         @ can not be set "onclick" or "drag xy"
8105 schaersvoo 723
         @ attention: width == height == radius in pixels
724
         @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work
725
         @ use command 'angle' for scalable angle
7614 schaersvoo 726
        */
727
            for(i=0;i<7;i++){
728
                switch(i){
729
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
730
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
731
                    case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
732
                    case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
733
                    case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
734
                    case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
735
                    case 6:stroke_color = get_color(infile,1);/* name or hex color */
736
                    /* in Shape library:
737
                        x[0] = x[1] = xc
738
                        y[0] = y[1] = yc
8224 bpr 739
                        w[0] = w[1] = radius = width = height
740
                        h[0] = start_angle ; h[1] = end_engle
7614 schaersvoo 741
                    */
742
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 743
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],int_data[0],int_data[0],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 744
                        reset();
745
                    break;
746
                }
747
            }
748
            break;
8224 bpr 749
        case ANGLE:
8105 schaersvoo 750
        /*
751
         @ angle xc,yc,width,start_angle,end_angle,color
752
         @ width is in x-range
753
         @ will zoom in/out
754
         @ if size is controlled by command 'slider' use radians to set limits of slider.
755
        */
756
            for(i=0;i<7;i++){
757
                switch(i){
758
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
759
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
760
                    case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
761
                    case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
762
                    case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
763
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
764
                        decimals = find_number_of_digits(precision);
765
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,17,[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],[%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[1],decimals,double_data[2],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
766
                        reset();
767
                    break;
768
                }
769
            }
770
            break;
771
 
7614 schaersvoo 772
        case ELLIPSE:
773
        /*
774
        @ ellipse xc,yc,radius_x,radius_y,color
8224 bpr 775
        @ a ellipse with center xc/yc in x/y-range
7614 schaersvoo 776
        @ radius_x and radius_y are in pixels
777
        @ may be set draggable / onclick
8224 bpr 778
        @ will shrink / expand on zoom out / zoom in
7614 schaersvoo 779
        */
780
            for(i=0;i<5;i++){
781
                switch(i){
782
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
783
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
784
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
8224 bpr 785
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
7614 schaersvoo 786
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
787
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 788
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,3,[%.*f],[%.*f],[%.*f],[%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 789
                        click_cnt++;reset();
790
                    break;
791
                }
792
            }
793
            break;
794
        case DASHTYPE:
795
        /*
796
        @ dashtype int ,int
7956 schaersvoo 797
        @ When dashed is set, the objects will be drawn with this dashtyp
7614 schaersvoo 798
        @ default value "dashtype 2,2"
799
        */
800
            for(i=0;i<2;i++){
801
                switch(i){
802
                    case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
803
                    case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
804
                }
805
            }
806
        break;
807
        case CIRCLE:
808
        /*
809
        @ circle xc,yc,width (2*r in pixels),color
810
        @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
811
        @ use command 'fillcolor color' to set the fillcolor
812
        @ may be set draggable / onclick
8224 bpr 813
        @ will shrink / expand on zoom out / zoom in
7614 schaersvoo 814
        */
815
            for(i=0;i<4;i++){
816
                switch(i){
817
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
818
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
8116 schaersvoo 819
                    case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
7614 schaersvoo 820
                    case 3: stroke_color = get_color(infile,1);/* name or hex color */
821
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 822
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,13,[%.*f],[%.*f],[%.3f],[%.3f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],double_data[2],double_data[2],line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 823
                        click_cnt++;reset();
824
                    break;
825
                }
826
            }
827
            break;
828
        case RAYS:
829
        /*
830
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
831
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 832
         @ may be set draggable or onclick (every individual ray)
7614 schaersvoo 833
        */
834
            stroke_color=get_color(infile,0);
7786 schaersvoo 835
            fill_color = stroke_color;
836
            double_data[0] = get_real(infile,0);/* xc */
837
            double_data[1] = get_real(infile,0);/* yc */
838
            i=2;
839
            while( ! done ){     /* get next item until EOL*/
840
                if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
841
                if(i%2 == 0 ){
842
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 843
                }
7786 schaersvoo 844
                else
845
                {
846
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 847
                }
7786 schaersvoo 848
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
849
                i++;
7614 schaersvoo 850
            }
8224 bpr 851
 
852
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
853
            decimals = find_number_of_digits(precision);
7786 schaersvoo 854
            for(c=2; c<i;c = c+2){
7614 schaersvoo 855
                click_cnt++;
8097 schaersvoo 856
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,4,[%.*f,%.*f],[%.*f,%.*f],[30,30],[30,30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[c],decimals,double_data[1],decimals,double_data[c+1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 857
            }
858
            reset();
859
            break;
860
        case ARROW:
861
        /*
862
        @ arrow x1,y1,x2,y2,h,color
863
        @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
864
        @ use command 'linewidth int' to adjust thickness of the arrow
865
        @ may be set draggable / onclick
866
        */
867
            for(i=0;i<6;i++){
868
                switch(i){
869
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
870
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
871
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
872
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
873
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
874
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
875
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 876
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,8,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 877
                        click_cnt++;
878
                        reset();
879
                        break;
880
                }
881
            }
882
            break;
883
        case ARROW2:
884
        /*
885
        @ arrow2 x1,y1,x2,y2,h,color
886
        @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
887
        @ use command 'arrowhead int' to adjust the arrow head size
888
        @ use command 'linewidth int' to adjust thickness of the arrow
889
        @ may be set draggable / onclick
890
        */
891
            for(i=0;i<6;i++){
892
                switch(i){
893
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
894
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
895
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
896
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
897
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
898
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
899
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 900
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,10,[%.*f,%.*f],[%.*f,%.*f],[%d,%d],[%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[1],decimals,double_data[3],arrow_head,arrow_head,arrow_head,arrow_head,line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 901
                        click_cnt++;reset();
902
                        break;
903
                }
904
            }
905
            break;
8224 bpr 906
        case PARALLEL:
7614 schaersvoo 907
        /*
908
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
8224 bpr 909
         @ can not be set "onclick" or "drag xy"
7614 schaersvoo 910
        */
911
            for( i = 0;i < 8; i++ ){
912
                switch(i){
913
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
914
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
915
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
916
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
917
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
918
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
919
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
920
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
921
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 922
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,11,[%.*f,%.*f,%.*f],[%.*f,%.*f,%.*f],[%d,%d,%d],[%d,%d,%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],int_data[0],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 923
                    click_cnt++;reset();
924
                    break;
925
                    default: break;
926
                }
927
            }
928
            break;
929
        case TRIANGLE:
930
        /*
931
         @triangle x1,y1,x2,y2,x3,y3,color
7956 schaersvoo 932
         @may be set draggable / onclic
7614 schaersvoo 933
        */
934
            for(i=0;i<7;i++){
935
                switch(i){
936
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
937
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
938
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
939
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
940
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
941
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
942
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
943
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 944
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,5,%s,[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,double_xy2js_array(double_data,6,decimals),line_width,stroke_color,stroke_opacity,stroke_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 945
                        click_cnt++;reset();
946
                        break;
947
                    default: break;
948
                }
949
            }
950
            break;
951
        case LATTICE:
952
        /*
953
         @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
8224 bpr 954
         @can not be set "onclick" or "drag xy"
7614 schaersvoo 955
        */
956
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
957
            for( i = 0; i<9; i++){
958
                switch(i){
959
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
960
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
961
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
8071 schaersvoo 962
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
7614 schaersvoo 963
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
8071 schaersvoo 964
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
7614 schaersvoo 965
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
966
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
967
                    case 8: stroke_color=get_color(infile,1);
968
                        decimals = find_number_of_digits(precision);
8071 schaersvoo 969
                        string_length = snprintf(NULL,0,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 970
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 971
                        snprintf(tmp_buffer,string_length,"draw_lattice(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 972
                        add_to_buffer(tmp_buffer);
973
                    break;
974
                    default:break;
975
                }
976
            }
977
            reset();
978
            break;
979
        case SNAPTOGRID:
980
        /*
981
         @ snaptogrid
982
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
983
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
7784 schaersvoo 984
         @ if xminor / yminor is defined, the drawing will snap to xminor and yminor<br />use only even dividers in x/y-minor...for example<br />snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
7614 schaersvoo 985
        */
7881 schaersvoo 986
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
7614 schaersvoo 987
        break;
7784 schaersvoo 988
        case XSNAPTOGRID:
989
        /*
990
         @ xsnaptogrid
991
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
992
         @ in case of userdraw the drawn points will snap to xmajor grid
7856 schaersvoo 993
         @ if xminor is defined, the drawing will snap to xminor <br />use only even dividers in x-minor...for example<br />xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
7784 schaersvoo 994
        */
7881 schaersvoo 995
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
7784 schaersvoo 996
        break;
997
        case YSNAPTOGRID:
998
        /*
999
         @ ysnaptogrid
1000
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
1001
         @ in case of userdraw the drawn points will snap to ymajor grid
7856 schaersvoo 1002
         @ if yminor is defined, the drawing will snap to yminor <br />use only even dividers in y-minor...for example<br />ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red<br /> will snap on x=0, x=0.5, x=1, x=1.5 ....<br /> will snap on y=0, y=0.25 y=0.5 y=0.75 ...<br />
7784 schaersvoo 1003
        */
7881 schaersvoo 1004
        fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
7784 schaersvoo 1005
        break;
8222 schaersvoo 1006
        case USERINPUT:
1007
        /*
1008
         @ userinput function | textarea | inputfield
1009
         @ alternative command + argment to keywords "userinput_function","userinput_textarea" and "userinput_xy"
1010
         @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
1011
         @ function may be used any time (e.g. without userdraw)
1012
        */
1013
            temp = get_string_argument(infile,1);
1014
            if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
8224 bpr 1015
             if( js_function[DRAW_JSFUNCTION] != 1 ){
8222 schaersvoo 1016
              js_function[DRAW_JSFUNCTION] = 1;
1017
              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
1018
              add_input_jsfunction(js_include_file,canvas_root_id,1,input_style,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1]);
1019
              input_cnt++;
1020
             }
1021
             if( use_js_math == FALSE){/* add this stuff only once...*/
1022
              add_to_js_math(js_include_file);
1023
              use_js_math = TRUE;
1024
             }
1025
             if( use_js_plot == FALSE){
1026
              use_js_plot = TRUE;
1027
              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1028
             }
1029
            }
1030
            else
1031
            {
1032
             if(strstr(temp,"inputfield") != 0 ){
1033
              if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
1034
              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
1035
              use_input_xy = 1;
1036
             }
1037
             else
1038
             {
1039
              if(strstr(temp,"textarea") != 0 ){
1040
               if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
1041
               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
1042
               use_input_xy = 2;
1043
              }
1044
              else
1045
              {
1046
                canvas_error("userinput argument may be \"function,inputfield,textarea\"");
1047
              }
1048
             }
1049
            }
1050
            break;
7663 schaersvoo 1051
        case USERTEXTAREA_XY:
1052
        /*
1053
        @ usertextarea_xy
8224 bpr 1054
        @ keyword
7663 schaersvoo 1055
        @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
8224 bpr 1056
        @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
7663 schaersvoo 1057
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
8224 bpr 1058
        @ user drawings will not zoom on zooming (or pan on panning)
7663 schaersvoo 1059
        */
7856 schaersvoo 1060
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
7956 schaersvoo 1061
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7749 schaersvoo 1062
            use_input_xy = 2;
1063
            break;
7652 schaersvoo 1064
        case USERINPUT_XY:
1065
        /*
1066
        @ userinput_xy
8224 bpr 1067
        @ keyword
7652 schaersvoo 1068
        @ to be used in combination with command "userdraw object_type,color"
8224 bpr 1069
        @ if set two (or three) input fields are added to the document<br />(one for x-values , one for y-values and in case of drawing circle one for radius-values)
7652 schaersvoo 1070
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
7749 schaersvoo 1071
        @ math input is allowed (e.g something like: 1+3,2*6,1/3,sqrt(3), sin(pi/4),10^-2,log(2)...)<br />eval function is 'protected' against code injection.
7652 schaersvoo 1072
        @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
8224 bpr 1073
        @ user drawings will not zoom on zooming (or pan on panning)
7652 schaersvoo 1074
        */
7749 schaersvoo 1075
            /* add simple eval check to avoid code injection with unprotected eval(string) */
7856 schaersvoo 1076
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
7956 schaersvoo 1077
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7749 schaersvoo 1078
            use_input_xy = 1;
1079
            break;
8193 schaersvoo 1080
        case USERINPUT_FUNCTION:
1081
        /*
1082
        @ userinput_function
1083
        @ keyword
1084
        @ if set , a inputfield will be added to the page
1085
        @ the userinput value will be plotted in the canvas
1086
        @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, it's id is canvas_input0
1087
        @ use before this command 'userinput_function',<br />commands like 'inputstyle some_css' , 'xlabel some_description' , 'opacity int,int' , 'linewidth int' , 'dashed' and 'dashtype int,int' to modify
1088
        @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
1089
        */
8224 bpr 1090
            if( js_function[DRAW_JSFUNCTION] != 1 ){
8193 schaersvoo 1091
             js_function[DRAW_JSFUNCTION] = 1;
1092
             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
1093
             add_input_jsfunction(js_include_file,canvas_root_id,1,input_style,input_cnt,stroke_color,stroke_opacity,line_width,use_dashed,dashtype[0],dashtype[1]);
1094
             input_cnt++;
1095
            }
1096
            if( use_js_math == FALSE){/* add this stuff only once...*/
1097
             add_to_js_math(js_include_file);
1098
             use_js_math = TRUE;
1099
            }
1100
            if( use_js_plot == FALSE){
1101
             use_js_plot = TRUE;
1102
             add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1103
            }
1104
            break;
7614 schaersvoo 1105
        case USERDRAW:
1106
        /*
1107
        @ userdraw object_type,color
8244 schaersvoo 1108
        @ implemented object_type: <ul><li>point</li><li>points</li><li>crosshair</li><li>crosshairs</li><li>line</li><li>lines</li><li>vline</li><li>vlines</li><li>hline</li><li>hlines</li><li>demiline</li><li>demilines</li><li>segment</li><li>segments</li><li>polyline</li><li>circle</li><li>circles</li><li>arrow</li><li>arrow2 (double arrow)</li><li>arrows</li><li>arrows2 (double arrows)</li><li>triangle</li><li>polygon</li><li>poly[3-9]</li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline</li><li>freehandlines</li><li>path</li><li>paths</li><li>text</li><li>arc</li><li>arcs</li><li>input<br/>place a single inputfield on 'canvas'<br />use commands 'inputstyle' for css styling: use command 'linewidth' for adjusting the input field size (default 1)</li><li>inputs<br/>place multiple inputfield : placing inputfields on top of each other is not possible</li></ul>
7614 schaersvoo 1109
        @ note: mouselisteners are only active if "$status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required)
7956 schaersvoo 1110
        @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />while typing the background of every typed char will be lightblue..."backspace / delete / esc" will remove typed text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt()" : lightblue background will disappear<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" , a confirm will popup asking to delete the selected text.This text will be removed from the "userdraw_txt()" answer array.<br />Use commands 'fontsize' and 'fontfamily' to control the text appearance
8224 bpr 1111
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
7614 schaersvoo 1112
        @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse butten (e.g. event.which != 1 : all buttons but left)
1113
        @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
8224 bpr 1114
        @ use command "dashed" and/or "dashtype int,int" to trigger dashing
7614 schaersvoo 1115
        @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
1116
        @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
8224 bpr 1117
        @ may be combined with keyword 'userinput_xy' or
7653 schaersvoo 1118
        @ note: when zooming / panning after a drawing, the drawing will NOT be zoomed / panned...this is a "design" flaw and not a feature <br />To avoid trouble do not use zooming / panning together width userdraw.!
7614 schaersvoo 1119
        */
1120
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
1121
                canvas_error("Only one userdraw primitive may be used: read documentation !!");
1122
            }
8074 schaersvoo 1123
            reply_precision = precision;
7614 schaersvoo 1124
            use_userdraw = TRUE;
8130 schaersvoo 1125
            fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};if(wims_status != \"done\"){canvas_div.addEventListener(\"mousedown\",user_draw,false);canvas_div.addEventListener(\"mousemove\",user_drag,false);canvas_div.addEventListener(\"touchstart\",user_draw,false);canvas_div.addEventListener(\"touchmove\",user_drag,false);}\n<!-- end userdraw mouse events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
7614 schaersvoo 1126
            draw_type = get_string_argument(infile,0);
1127
            stroke_color = get_color(infile,1);
1128
            if( strcmp(draw_type,"point") == 0 ){
1129
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1130
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 1131
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 1132
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1133
                if(use_input_xy == 1){
7652 schaersvoo 1134
                    add_input_circle(js_include_file,1,1);
1135
                    add_input_xy(js_include_file,canvas_root_id);
1136
                }
7614 schaersvoo 1137
                add_js_points(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);
1138
            }
1139
            else
1140
            if( strcmp(draw_type,"points") == 0 ){
1141
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1142
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 1143
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 1144
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1145
                if(use_input_xy == 1){
7652 schaersvoo 1146
                    add_input_circle(js_include_file,1,2);
1147
                    add_input_xy(js_include_file,canvas_root_id);
1148
                }
7614 schaersvoo 1149
                add_js_points(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,1,stroke_color,stroke_opacity,0,1,1);
1150
            }
1151
            else
1152
            if( strcmp(draw_type,"segment") == 0 ){
1153
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1154
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 1155
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 1156
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1157
                if(use_input_xy == 1){
7652 schaersvoo 1158
                    add_input_segment(js_include_file,1);
1159
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1160
                }
7614 schaersvoo 1161
                add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1162
            }
1163
            else
7663 schaersvoo 1164
            if( strcmp(draw_type,"polyline") == 0 ){
1165
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 1166
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 1167
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 1168
                if( use_input_xy == 1 ){
1169
                    add_input_polyline(js_include_file);
1170
                    add_input_xy(js_include_file,canvas_root_id);
7663 schaersvoo 1171
                }
1172
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1173
            }
1174
            else
7614 schaersvoo 1175
            if( strcmp(draw_type,"segments") == 0 ){
1176
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1177
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 1178
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 1179
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1180
                if(use_input_xy == 1){
7652 schaersvoo 1181
                    add_input_segment(js_include_file,2);
1182
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1183
                }
7614 schaersvoo 1184
                add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1185
            }
1186
            else
1187
            if( strcmp(draw_type,"circle") == 0 ){
1188
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1189
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 1190
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
8071 schaersvoo 1191
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1192
                if(use_input_xy == 1){
7652 schaersvoo 1193
                    add_input_circle(js_include_file,2,1);
1194
                    add_input_xyr(js_include_file,canvas_root_id);
1195
                }
7614 schaersvoo 1196
                add_js_circles(js_include_file,1,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
1197
            }
1198
            else
1199
            if( strcmp(draw_type,"circles") == 0 ){
1200
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1201
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 1202
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
1203
                add_js_circles(js_include_file,2,draw_type,line_width,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1204
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1205
                if(use_input_xy == 1){
7652 schaersvoo 1206
                    add_input_circle(js_include_file,2,2);
1207
                    add_input_xyr(js_include_file,canvas_root_id);
1208
                }
7614 schaersvoo 1209
            }
1210
            else
1211
            if(strcmp(draw_type,"crosshair") == 0 ){
1212
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 1213
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 1214
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
1215
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 1216
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1217
                if(use_input_xy == 1){
7654 schaersvoo 1218
                    add_input_crosshair(js_include_file,1);
1219
                    add_input_xy(js_include_file,canvas_root_id);
1220
                }
7614 schaersvoo 1221
            }
1222
            else
1223
            if(strcmp(draw_type,"crosshairs") == 0 ){
1224
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 1225
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 1226
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
1227
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 1228
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1229
                if(use_input_xy == 1){
7654 schaersvoo 1230
                    add_input_crosshair(js_include_file,2);
1231
                    add_input_xy(js_include_file,canvas_root_id);
1232
                }
7614 schaersvoo 1233
            }
1234
            else
1235
            if(strcmp(draw_type,"freehandline") == 0 ){
1236
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1237
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1238
                add_js_paths(js_include_file,1,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1239
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1240
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1241
            }
1242
            else
1243
            if(strcmp(draw_type,"freehandlines") == 0 ){
1244
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1245
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1246
                add_js_paths(js_include_file,2,draw_type,line_width,0,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1247
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1248
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1249
            }
1250
            else
1251
            if(strcmp(draw_type,"path") == 0 ){
1252
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1253
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1254
                add_js_paths(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1255
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1256
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1257
            }
1258
            else
1259
            if(strcmp(draw_type,"paths") == 0 ){
1260
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1261
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1262
                add_js_paths(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1263
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1264
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1265
            }
1266
            else
1267
            if(strcmp(draw_type,"arrows") == 0 ){
1268
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1269
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1270
                add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
8224 bpr 1271
                if(use_input_xy == 1){
7654 schaersvoo 1272
                    add_input_arrow(js_include_file,2);
1273
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1274
                }
8071 schaersvoo 1275
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1276
            }
1277
            else
7874 schaersvoo 1278
            if(strcmp(draw_type,"arrows2") == 0 ){
1279
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1280
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1281
                add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
8224 bpr 1282
                if(use_input_xy == 1){
7874 schaersvoo 1283
                    add_input_arrow(js_include_file,1);
1284
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1285
                }
8071 schaersvoo 1286
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 1287
            }
1288
            else
1289
            if(strcmp(draw_type,"arrow2") == 0 ){
1290
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1291
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1292
                add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
8224 bpr 1293
                if(use_input_xy == 1){
7874 schaersvoo 1294
                    add_input_arrow(js_include_file,1);
1295
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1296
                }
8071 schaersvoo 1297
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 1298
            }
1299
            else
7614 schaersvoo 1300
            if(strcmp(draw_type,"arrow") == 0 ){
1301
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1302
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1303
                add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head);
8224 bpr 1304
                if(use_input_xy == 1){
7654 schaersvoo 1305
                    add_input_arrow(js_include_file,1);
1306
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1307
                }
8071 schaersvoo 1308
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1309
            }
1310
            else
1311
            if(strcmp(draw_type,"polygon") == 0){
1312
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1313
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1314
                add_js_poly(js_include_file,-1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1315
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1316
                if(use_input_xy == 2){
7780 schaersvoo 1317
                  add_textarea_polygon(js_include_file);
1318
                  add_textarea_xy(js_include_file,canvas_root_id);
7746 schaersvoo 1319
                }
7614 schaersvoo 1320
            }
8224 bpr 1321
            else
7614 schaersvoo 1322
            if(strncmp(draw_type,"poly",4) == 0){
1323
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
1324
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1325
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1326
                add_js_poly(js_include_file,(int) (draw_type[4]-'0'),draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1327
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1328
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1329
            }
8224 bpr 1330
            else
7614 schaersvoo 1331
            if(strcmp(draw_type,"triangle") == 0){
1332
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1333
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1334
                add_js_poly(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1335
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1336
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1337
            }
8224 bpr 1338
            else
7989 schaersvoo 1339
            if( strcmp(draw_type,"hline") == 0 ){
1340
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1341
                if(reply_format == 0){reply_format = 11;}
1342
                add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1343
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1344
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1345
            }
1346
            else
1347
            if( strcmp(draw_type,"hlines") == 0 ){
1348
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1349
                if(reply_format == 0){reply_format = 11;}
1350
                add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1351
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1352
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1353
            }
1354
            else
1355
            if( strcmp(draw_type,"vline") == 0 ){
1356
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1357
                if(reply_format == 0){reply_format = 11;}
1358
                add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1359
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1360
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1361
            }
1362
            else
1363
            if( strcmp(draw_type,"vlines") == 0 ){
1364
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1365
                if(reply_format == 0){reply_format = 11;}
1366
                add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1367
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1368
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1369
            }
1370
            else
7614 schaersvoo 1371
            if( strcmp(draw_type,"line") == 0 ){
1372
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1373
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 1374
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 1375
                add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 1376
                if( use_input_xy == 1 ){
7780 schaersvoo 1377
                    add_input_line(js_include_file,1);
7747 schaersvoo 1378
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1379
                }
8071 schaersvoo 1380
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1381
            }
1382
            else
1383
            if( strcmp(draw_type,"lines") == 0 ){
1384
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1385
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 1386
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 1387
                add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 1388
                if( use_input_xy == 1 ){
7780 schaersvoo 1389
                    add_input_line(js_include_file,2);
7747 schaersvoo 1390
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
7746 schaersvoo 1391
                }
8071 schaersvoo 1392
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1393
            }
1394
            else
8244 schaersvoo 1395
            if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"demilines") == 0 ){
1396
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1397
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
1398
                if(reply_format == 0){reply_format = 11;}
1399
                add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1400
                if( use_input_xy == 1 ){
1401
                    add_input_demiline(js_include_file,2);
1402
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1403
                }
1404
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1405
            }
1406
            else
1407
            if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"demilines") == 0 ){
1408
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1409
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
1410
                if(reply_format == 0){reply_format = 11;}
1411
                add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1412
                if( use_input_xy == 1 ){
1413
                    add_input_demiline(js_include_file,1);
1414
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1415
                }
1416
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1417
            }
1418
            else
7614 schaersvoo 1419
            if( strcmp(draw_type,"rects") == 0){
1420
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 1421
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1422
                add_js_rect(js_include_file,2,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1423
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1424
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1425
            }
8224 bpr 1426
            else
7614 schaersvoo 1427
            if( strcmp(draw_type,"roundrects") == 0){
1428
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 1429
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1430
                add_js_rect(js_include_file,2,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1431
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1432
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1433
            }
8224 bpr 1434
            else
7614 schaersvoo 1435
            if( strcmp(draw_type,"rect") == 0){
1436
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 1437
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1438
                add_js_rect(js_include_file,1,0,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1439
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1440
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1441
            }
8224 bpr 1442
            else
7614 schaersvoo 1443
            if( strcmp(draw_type,"roundrect") == 0){
1444
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 1445
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1446
                add_js_rect(js_include_file,1,1,draw_type,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
7652 schaersvoo 1447
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1448
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1449
            }
1450
            else
8083 schaersvoo 1451
            if( strcmp(draw_type,"arcs") == 0){
1452
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
1453
                if(reply_format == 0){reply_format = 25;}
1454
                add_js_arc(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
1455
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1456
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1457
            }
1458
            else
8071 schaersvoo 1459
            if( strcmp(draw_type,"arc") == 0){
1460
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
8083 schaersvoo 1461
                if(reply_format == 0){reply_format = 25;}
1462
                add_js_arc(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1463
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1464
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1465
            }
1466
            else
7614 schaersvoo 1467
            if( strcmp(draw_type,"text") == 0){
8224 bpr 1468
                if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
7876 schaersvoo 1469
                if(reply_format == 0){reply_format = 17;}
8071 schaersvoo 1470
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity);
7652 schaersvoo 1471
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1472
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1473
            }
8116 schaersvoo 1474
            else
1475
            if( strcmp(draw_type,"inputs") == 0){
8224 bpr 1476
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 1477
                if(reply_format == 0){reply_format = 27;}
8116 schaersvoo 1478
                add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width);
1479
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1480
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1481
            }
1482
            else
1483
            if( strcmp(draw_type,"input") == 0){
8224 bpr 1484
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 1485
                if(reply_format == 0){reply_format = 27;}
8116 schaersvoo 1486
                add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width);
1487
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1488
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1489
            }
8193 schaersvoo 1490
            else
7614 schaersvoo 1491
            {
1492
                canvas_error("unknown drawtype or typo? ");
1493
            }
1494
            reset();
1495
        break;
1496
        case PLOTSTEPS:
1497
            /*
1498
             @ plotsteps a_number
1499
             @ default 150
1500
             @ use with care !
1501
            */
1502
            plot_steps = (int) (get_real(infile,1));
1503
            break;
1504
        case FONTSIZE:
1505
        /*
1506
         @fontsize font_size
1507
         @default value 12
1508
        */
1509
            font_size = (int) (get_real(infile,1));
1510
            break;
1511
        case FONTCOLOR:
1512
        /*
1513
         @fontcolor color
1514
         @color: hexcolor or colorname
1515
         @default: black
1516
         @example usage: x/y-axis text
1517
        */
1518
            font_color = get_color(infile,1);
1519
            break;
1520
        case ANIMATE:
1521
        /*
1522
         @animate type
8109 schaersvoo 1523
         @REMOVED : this should be done with a slider
7614 schaersvoo 1524
         @type may be "point" (nothing else , yet...)
1525
         @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
1526
         @will animate a point on the next plot/curve command
1527
         @the curve will not be draw
1528
         @moves repeatedly from xmin to xmax
1529
        */
1530
            if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
1531
            break;
7788 schaersvoo 1532
        case LEVELCURVE:
1533
        /*
1534
        @levelcurve color,expression in x/y,l1,l2,...
7792 schaersvoo 1535
        @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
1536
        @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
1537
        @every individual level curve may be set 'onclick / drag xy' <br />e.g. every single level curve (l1,l2,l3...l_n) has a unique identifier
1538
        @note : the arrays for holding the javascript data are limited in size
1539
        @note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
7788 schaersvoo 1540
        */
7792 schaersvoo 1541
            fill_color = get_color(infile,0);
7788 schaersvoo 1542
            char *fun1 = get_string_argument(infile,0);
1543
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
1544
            i = 0;
1545
            done = FALSE;
1546
            while( !done ){
1547
             double_data[i] = get_real(infile,1);
1548
             i++;
1549
            }
1550
            for(c = 0 ; c < i; c++){
8097 schaersvoo 1551
             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,16,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,eval_levelcurve(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision,double_data[c]),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7788 schaersvoo 1552
             click_cnt++;
1553
            }
1554
            reset();
1555
            break;
7858 schaersvoo 1556
        case TRACE_JSCURVE:
7823 schaersvoo 1557
        /*
7858 schaersvoo 1558
         @trace_jscurve some_math_function
7823 schaersvoo 1559
         @will use a crosshair to trace the jsmath curve
7856 schaersvoo 1560
         @two inputfields will display the current x/y-values (numerical evaluation by javascript)
8224 bpr 1561
         @default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields
7823 schaersvoo 1562
         @use linewidth,strokecolor,crosshairsize to adjust the corsshair.
7858 schaersvoo 1563
         @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors...
7823 schaersvoo 1564
        */
1565
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7833 schaersvoo 1566
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7858 schaersvoo 1567
            if( use_js_math == FALSE){
1568
                add_to_js_math(js_include_file);
1569
                use_js_math = TRUE;
1570
            }
7823 schaersvoo 1571
            add_trace_js_mouse(js_include_file,TRACE_CANVAS,canvas_root_id,stroke_color,get_string(infile,1),font_size,stroke_opacity,line_width,crosshair_size);
1572
            break;
1573
        case JSMATH:
1574
        /*
7858 schaersvoo 1575
            @jsmath some_math_function
7856 schaersvoo 1576
            @will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
8224 bpr 1577
            @default labels 'x' and 'y'<br />the commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' will set the label for the input fields
7858 schaersvoo 1578
            @example: jsmath sin(x^2)
1579
            @the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x in stead of 2x etc etc<br />no check is done on the validity of your function and/or syntax<br />use error console to debug any errors...
7823 schaersvoo 1580
        */
1581
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7858 schaersvoo 1582
            if( use_js_math == FALSE){
1583
                add_to_js_math(js_include_file);
1584
                use_js_math = TRUE;
1585
            }
7823 schaersvoo 1586
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1));
1587
            break;
7858 schaersvoo 1588
        case JSCURVE:
1589
        /*
1590
         @jscurve color,formula(x)
1591
         @your function will be plotted by the javascript engine of the client browser.
7983 schaersvoo 1592
         @use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
7858 schaersvoo 1593
         @use parenthesis and rawmath : use 2*x in stead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
7981 schaersvoo 1594
         @Attention : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
7858 schaersvoo 1595
         @no validity check is done by wims.
1596
         @zooming & panning are implemented :<br />use command 'zoom color' for mouse driven zooming<br />or use keyword 'setlimits' for inputfields setting xmin/xmax, ymin/ymax
1597
         @use command 'trace_jscurve formula(x)` for tracing
1598
         @use commmand 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
1599
         @can not be set draggable / onclick (yet)
8224 bpr 1600
         @commands plotjump / plotstep are not active for 'jscurve'
7858 schaersvoo 1601
        */
1602
            stroke_color = get_color(infile,0);
1603
            if( use_js_math == FALSE){/* add this stuff only once...*/
1604
                add_to_js_math(js_include_file);
1605
                use_js_math = TRUE;
1606
            }
1607
            if( use_js_plot == FALSE){
1608
                use_js_plot = TRUE;
1609
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1610
            }
1611
            temp = get_string_argument(infile,1);
1612
            string_length = snprintf(NULL,0,  "jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1613
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1614
            snprintf(tmp_buffer,string_length,"jsplot(%d,\"%s\",%d,\"%s\",%.2f,%d,%d,%d); ",JSPLOT_CANVAS+use_js_plot,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1615
            add_to_buffer(tmp_buffer);
1616
            use_js_plot++; /* we need to create multiple canvasses, so we may zoom and pan ?? */
1617
 
1618
        break;
7614 schaersvoo 1619
        case CURVE:
1620
        /*
1621
         @curve color,formula(x)
1622
         @plot color,formula(x)
1623
         @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
1624
         @use command "precision" to increase the number of digits of the plotted points
1625
         @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
1626
         @may be set draggable / onclick
1627
        */
1628
            if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
1629
                use_parametric = FALSE;
1630
                stroke_color = get_color(infile,0);
1631
                char *fun1 = get_string_argument(infile,0);
1632
                char *fun2 = get_string_argument(infile,1);
1633
                if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
8097 schaersvoo 1634
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,animation_type,eval_parametric(xsize,ysize,fun1,fun2,xmin,xmax,ymin,ymax,tmin,tmax,plot_steps,precision),2*line_width,2*line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1635
                click_cnt++;
1636
            }
1637
            else
1638
            {
1639
                stroke_color = get_color(infile,0);
1640
                char *fun1 = get_string_argument(infile,1);
8224 bpr 1641
                if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
8097 schaersvoo 1642
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,animation_type,eval(xsize,ysize,fun1,xmin,xmax,ymin,ymax,plot_steps,precision),line_width,line_width,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,flytext,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1643
                click_cnt++;
1644
            }
7788 schaersvoo 1645
            animation_type = 9;/* reset to curve plotting without animation */
7614 schaersvoo 1646
            reset();
1647
            break;
1648
        case FLY_TEXT:
1649
        /*
1650
        @ text fontcolor,x,y,font,text_string
1651
        @ font may be described by keywords : giant,huge,normal,small,tiny
8224 bpr 1652
        @ use command 'fontsize' to increase base fontsize for these keywords
7614 schaersvoo 1653
        @ may be set "onclick" or "drag xy"
1654
        @ backwards compatible with flydraw
1655
        @ unicode supported: text red,0,0,huge,\\u2232
7874 schaersvoo 1656
        @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
1657
        @ Avoid  mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
7614 schaersvoo 1658
        */
1659
            for(i = 0; i < 5 ;i++){
1660
                switch(i){
1661
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
1662
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
1663
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
1664
                    case 3: fly_font = get_string_argument(infile,0);
1665
                            if(strcmp(fly_font,"giant") == 0){
1666
                                font_size = (int)(font_size + 24);
1667
                            }
1668
                            else
1669
                            {
1670
                                if(strcmp(fly_font,"huge") == 0){
1671
                                    font_size = (int)(font_size + 14);
1672
                                }
1673
                                else
1674
                                {
1675
                                    if(strcmp(fly_font,"large") == 0){
1676
                                        font_size = (int)(font_size + 6);
1677
                                        }
1678
                                        else
1679
                                        {
1680
                                            if(strcmp(fly_font,"small") == 0){
1681
                                                font_size = (int)(font_size - 4);
1682
                                                if(font_size<0){font_size = 8;}
1683
                                        }
1684
                                    }
1685
                                }
1686
                            }
1687
                            break; /* font_size ! */
8224 bpr 1688
                    case 4:
7614 schaersvoo 1689
                        temp = get_string_argument(infile,1);
1690
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 1691
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1692
                        click_cnt++;reset();break;
1693
                    default:break;
1694
                }
1695
            }
1696
            break;
1697
        case FLY_TEXTUP:
1698
        /*
1699
         @ textup fontcolor,x,y,font,text_string
1700
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
1701
         @ font may be described by keywords : giant,huge,normal,small,tiny
8224 bpr 1702
         @ use command 'fontsize' to increase base fontsize for the keywords
7614 schaersvoo 1703
         @ backwards compatible with flydraw
1704
         @ unicode supported: textup red,0,0,huge,\\u2232
1705
         @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
7874 schaersvoo 1706
         @ Avoid  mixing old flydraw commands 'text' 'textup' with new canvasdraw commands 'string' stringup'<br />If the fontfamily was set completely like "fontfamily italic 24px Ariel".<br />In that case reset 'fontfamily' to something lke 'fontfamily Ariel' before the old flydraw commands.
7614 schaersvoo 1707
        */
8224 bpr 1708
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
7614 schaersvoo 1709
            for(i = 0; i<5 ;i++){
1710
                switch(i){
1711
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
1712
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
1713
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
1714
                    case 3: fly_font = get_string_argument(infile,0);
1715
                            if(strcmp(fly_font,"giant") == 0){
1716
                                font_size = (int)(font_size + 24);
1717
                            }
1718
                            else
1719
                            {
1720
                                if(strcmp(fly_font,"huge") == 0){
1721
                                    font_size = (int)(font_size + 14);
1722
                                }
1723
                                else
1724
                                {
1725
                                    if(strcmp(fly_font,"large") == 0){
1726
                                        font_size = (int)(font_size + 6);
1727
                                        }
1728
                                        else
1729
                                        {
1730
                                            if(strcmp(fly_font,"small") == 0){
1731
                                                font_size = (int)(font_size - 4);
1732
                                                if(font_size<0){font_size = 8;}
1733
                                        }
1734
                                    }
1735
                                }
1736
                            }
1737
                            break; /* font_size ! */
8224 bpr 1738
                    case 4:
7614 schaersvoo 1739
                    decimals = find_number_of_digits(precision);
1740
                    temp = get_string_argument(infile,1);
8071 schaersvoo 1741
                    string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1742
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1743
                    snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1744
                    add_to_buffer(tmp_buffer);
1745
                    break;
1746
                    default:break;
1747
                }
1748
            }
1749
            reset();
1750
            break;
1751
        case FONTFAMILY:
1752
        /*
1753
         @ fontfamily font_description
1754
         @ set the font family; for browsers that support it
1755
         @ font_description: Ariel ,Courier, Helvetica etc
1756
         @ in case commands<br /> 'string color,x,y,the string'<br /> 'stringup color,x,y,rotation,the string'<br />fontfamily can be something like:<br />italic 34px Ariel
1757
         @ use correct syntax : 'font style' 'font size'px 'fontfamily'
1758
        */
1759
            font_family = get_string(infile,1);
1760
            break;
1761
        case STRINGUP:
8224 bpr 1762
        /*
1763
         @ stringup color,x,y,rotation_degrees,the text string
7614 schaersvoo 1764
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
1765
         @ unicode supported: stringup red,0,0,45,\\u2232
1766
         @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
1767
 
1768
        */
1769
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
1770
            for(i=0;i<6;i++){
1771
                switch(i){
1772
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
1773
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
1774
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
1775
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
1776
                    case 4: decimals = find_number_of_digits(precision);
1777
                            temp = get_string_argument(infile,1);
8071 schaersvoo 1778
                            string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1779
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1780
                            snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s);\n",STATIC_CANVAS,int_data[0],int_data[1],font_size,font_family,font_color,stroke_opacity,double_data[0],temp,use_rotate,angle,use_affine,affine_matrix);
7614 schaersvoo 1781
                            add_to_buffer(tmp_buffer);
1782
                            break;
1783
                    default:break;
1784
                }
1785
            }
1786
            reset();
1787
            break;
1788
        case STRING:
8224 bpr 1789
        /*
7614 schaersvoo 1790
         @ string color,x,y,the text string
1791
         @ may be set "onclick" or "drag xy"
1792
         @ unicode supported: string red,0,0,\\u2232
8224 bpr 1793
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
7614 schaersvoo 1794
        */
1795
            for(i=0;i<5;i++){
1796
                switch(i){
1797
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
1798
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
1799
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
1800
                    case 3: decimals = find_number_of_digits(precision);
1801
                        temp = get_string_argument(infile,1);
1802
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 1803
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,14,[%.*f],[%.*f],[30],[30],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%f,\"%s\",%d,\"%s\",%d,%s,%d,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],line_width,stroke_color,stroke_opacity,stroke_color,stroke_opacity,0,0,0,0,use_rotate,angle,temp,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt);
7614 schaersvoo 1804
                        click_cnt++;reset();break;
1805
                    default:break;
1806
                }
1807
            }
1808
            break;
7983 schaersvoo 1809
        case CENTERSTRING:
8224 bpr 1810
        /*
7983 schaersvoo 1811
         @ centerstring color,y-value,the text string
7984 schaersvoo 1812
         @ title color,y-value,the text string
7983 schaersvoo 1813
         @ draw a string centered on the canvas at y = y-value
1814
         @ can not set "onclick" or "drag xy" (...)
1815
         @ unicode supported: centerstring red,5,\\u2232
8224 bpr 1816
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
7983 schaersvoo 1817
        */
1818
            if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
1819
            for(i=0;i<3;i++){
1820
                switch(i){
1821
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
1822
                    case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
1823
                    case 2: temp = get_string_argument(infile,1);
1824
                            /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
1825
                            decimals = find_number_of_digits(precision);
1826
                            string_length = snprintf(NULL,0,
1827
                            "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
1828
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1829
                            snprintf(tmp_buffer,string_length,"draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
1830
                            add_to_buffer(tmp_buffer);
1831
                            break;
1832
                    default:break;
1833
                }
1834
            }
1835
            break;
7614 schaersvoo 1836
        case MATHML:
1837
        /*
1838
        @ mathml x1,y1,x2,y2,mathml_string
8224 bpr 1839
        @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
7614 schaersvoo 1840
        @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
8224 bpr 1841
        @ if inputfields are incorporated in mathml (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_mathml();<br />attention: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
7614 schaersvoo 1842
        @ If other inputfields (command input / command textarea) or userdraw is performed, the function read_canvas() will not read mathml. Use some generic function to read it....
8224 bpr 1843
 
7614 schaersvoo 1844
        */
1845
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
1846
            for(i=0;i<5;i++){
1847
                switch(i){
1848
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1849
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1850
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1851
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1852
                    case 4: decimals = find_number_of_digits(precision);
8224 bpr 1853
                            if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
7614 schaersvoo 1854
                            temp = get_string(infile,1);
1855
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
1856
                            string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
1857
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1858
                            snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,%d,%d,\"%s\",%d);\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp,onclick);
1859
                            add_to_buffer(tmp_buffer);
8224 bpr 1860
                            /*
1861
                             in case inputs are present , trigger adding the read_mathml()
7614 schaersvoo 1862
                             if no other reply_format is defined
1863
                             note: all other reply types will include a reading of elements with id='mathml'+p)
1864
                             */
1865
                            if(strstr(temp,"mathml0") != NULL){
7876 schaersvoo 1866
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
7614 schaersvoo 1867
                            }
1868
                            break;
1869
                    default:break;
1870
                }
1871
            }
1872
            reset();
1873
            break;
1874
        case HTTP:
1875
        /*
1876
         @http x1,y1,x2,y2,http://some_adress.com
8224 bpr 1877
         @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
7614 schaersvoo 1878
         @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
1879
         @can not be 'set onclick' or 'drag xy'
1880
        */
8224 bpr 1881
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
7614 schaersvoo 1882
            for(i=0;i<5;i++){
1883
                switch(i){
1884
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1885
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1886
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1887
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1888
                    case 4: decimals = find_number_of_digits(precision);
1889
                            temp = get_string(infile,1);
1890
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
1891
                            string_length = snprintf(NULL,0,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
1892
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1893
                            snprintf(tmp_buffer,string_length,"draw_http(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
1894
                            add_to_buffer(tmp_buffer);
1895
                    break;
1896
                }
1897
            }
1898
            reset();
1899
            break;
1900
        case HTML:
1901
        /*
1902
         @ html x1,y1,x2,y2,html_string
1903
         @ all tags are allowed
1904
         @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
1905
         @ if inputfields are incorporated  (with id's : id='mathml0',id='mathml1',...id='mathml_n')<br />the user_input values will be read by javascript:read_canvas(); <br />If other inputfields (command input / command textarea) or userdraw is performed, these values will NOT be read as well.
8224 bpr 1906
 
7614 schaersvoo 1907
         note: uses the same code as 'mathml'
1908
        */
1909
            break;
1910
        case X_AXIS_STRINGS:
1911
        /*
1912
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1913
         @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1914
         @ use these x-axis values in stead of default xmin...xmax
1915
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1916
         @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
1917
         @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 1,100,grey,1,4,6,grey
1918
         @ example:<br />size 400,400<br />xrange -5*pi,5*pi<br />yrange -100,500<br />axis<br />xaxis -4*pi:-4\\u03c0:-3*pi:-3\\u03c0:-2*pi:-2\\u03c0:-1*pi:-\\u03c0:0:0:pi:\\u03c0:2*pi:2\\u03c01:3*pi:3\\u03c0:4*pi:4\\u03c0<br />#'xmajor' steps should be synchronised with numbers eg. "1" in this example<br />grid pi,1,grey,1,3,6,grey
1919
        */
1920
            temp = get_string(infile,1);
1921
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
1922
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
1923
            fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
1924
            use_axis_numbering = 1;
1925
            break;
1926
        case Y_AXIS_STRINGS:
1927
        /*
1928
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1929
         @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1930
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1931
         @ use these y-axis values in stead of default ymin...ymax
1932
         @ example:<br />size 400,400<br />yrange 0,13<br />xrange -100,500<br />axis<br />yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december<br />#'ymajor' steps should be synchronised with numbers eg. "1" in this example<br />grid 100,1,grey,4,1,6,grey
1933
        */
1934
            temp = get_string(infile,1);
1935
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
1936
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
1937
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
1938
            use_axis_numbering = 1;
1939
            break;
8224 bpr 1940
 
7614 schaersvoo 1941
        case AXIS_NUMBERING:
1942
        /*
8224 bpr 1943
            @ axisnumbering
8101 schaersvoo 1944
            @ keyword, no arguments required
7614 schaersvoo 1945
        */
1946
            use_axis_numbering = 1;
1947
            break;
1948
        case AXIS:
1949
        /*
1950
            @ axis
8101 schaersvoo 1951
            @ keyword, no arguments required
7614 schaersvoo 1952
 
1953
        */
1954
            use_axis = TRUE;
1955
            break;
8101 schaersvoo 1956
        case KILLSLIDER:
1957
        /*
1958
         @ killslider
1959
         @ keyword, no arguments required
1960
         @ ends grouping of object under a preciously defined slider
1961
        */
1962
            slider = 0;
1963
            break;
8071 schaersvoo 1964
        case SLIDER:
1965
        /*
8097 schaersvoo 1966
        @ slider start_value,end_value,width px,height px,type,label
1967
        @ type: xy,x,y,angle
8112 schaersvoo 1968
        @ if a value display is desired, use<br />type:xy display,x display,y display,angle radian,angle degree
1969
        @ is a unit for x / y value display is needed, use commands 'xunit' and / or 'yunit'
8101 schaersvoo 1970
        @ use commmand 'slider' before draggable/clickable objects.
1971
        @ a slider will affect all draggable objects after the 'slider' command...<br />and can be used to group translate / rotate several objects...<br />until a next 'slider' or keyword 'killslider'
8097 schaersvoo 1972
        @ amount of sliders is not limited.
8101 schaersvoo 1973
        @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
8097 schaersvoo 1974
        @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
1975
        @ every draggable object may have it's own slider (no limit in amount of sliders)
8071 schaersvoo 1976
        @ label: some slider text
1977
        @ use fillcolor for slider ball
1978
        @ use strokecolor for slider bar
8097 schaersvoo 1979
        @ use fontfamily / fontcolor to set used fonts
8071 schaersvoo 1980
        @ use opacity (only fill opacity will be used) to set transparency
8111 schaersvoo 1981
        @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
8071 schaersvoo 1982
        */
1983
            for(i=0; i<6 ; i++){
1984
                switch(i){
1985
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
1986
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
1987
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
1988
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
8111 schaersvoo 1989
                    case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
8112 schaersvoo 1990
                    /* xy display*/
1991
                    if(strstr(temp,"xy")!= 0){
8097 schaersvoo 1992
                     slider = 4;
1993
                    }
1994
                    else
1995
                    {
8112 schaersvoo 1996
                     if(strstr(temp,"x") != 0){
8097 schaersvoo 1997
                      slider = 1;
1998
                     }
1999
                     else
2000
                     {
8112 schaersvoo 2001
                      if(strstr(temp,"y") != 0){
8097 schaersvoo 2002
                       slider = 2;
2003
                      }
2004
                      else
2005
                      {
8112 schaersvoo 2006
                       if(strstr(temp,"angle") != 0){ /* angle diplay radian */
8097 schaersvoo 2007
                        slider = 3;
2008
                       }
2009
                       else
8112 schaersvoo 2010
                       {
8097 schaersvoo 2011
                        canvas_error("slider types may be : x , y , xy , angle");
8112 schaersvoo 2012
                       }
8097 schaersvoo 2013
                      }
2014
                     }
2015
                    }
8112 schaersvoo 2016
                    if(strstr(temp,"display")!=0){
2017
                     use_slider_display = 1; /* show x xy values in canvas window */
2018
                    }
2019
                    else
2020
                    {
2021
                     if(strstr(temp,"degree")!= 0){
2022
                      use_slider_display = 2; /* show angle values in canvas window */
2023
                     }
2024
                     else
2025
                     {
2026
                      if(strstr(temp,"radian")!=0){
2027
                       use_slider_display = 3; /* show radian values in canvas window */
2028
                      }
2029
                     }
2030
                    }
2031
                    if(use_slider_display != 0 && slider_cnt == 0){ /*add just once the display js-code */
2032
                     add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
2033
                    }
8097 schaersvoo 2034
                    break;
2035
                    case 5: /* some string used for slider description  */
8071 schaersvoo 2036
                    slider_cnt++;
8097 schaersvoo 2037
                    if(slider == 4){
8112 schaersvoo 2038
                     add_xyslider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display );
8097 schaersvoo 2039
                    }else{
8112 schaersvoo 2040
                     add_slider(js_include_file,canvas_root_id,double_data[0],double_data[1],int_data[0],int_data[1],slider,get_string_argument(infile,1),slider_cnt,stroke_color,fill_color,line_width,fill_opacity,font_family,font_color,use_slider_display);
8097 schaersvoo 2041
                    }
8071 schaersvoo 2042
                    break;
2043
                }
8097 schaersvoo 2044
             }
8071 schaersvoo 2045
            break;
7654 schaersvoo 2046
        case SGRAPH:
2047
        /*
2048
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
2049
         @ primitive implementation of a 'broken scale' graph...
7976 schaersvoo 2050
         @ not very versatile: only usable in combination with userdraw <br />eg no other objects will obey this "coordinate system"<br />if you want to place an object into this coordinate system, be aware that 10% or 20% of xsize and/or ysize is 'lost'.<br />Use these "formulas" to recalculate the virtual coordinates:<br />factor=0.8 in case xstart != xmin (or ystart != ymin)<br />factor=0.9 in case xstart = xmin (or ystart = ymin)<br />px_x_point = ((factor*xsize)/(xmax - xstart))*(x_point - xmax)+xsize<br />x_recalculated = px*(xmax - xmin)/xsize + $xmin<br />px_y_point = -1*factor*y_point*ysize/(ymax - ystart) + ymax*factor*ysize/(ymax - ystart)<br />y_recalculated = ymax - py*(ymax - ymin)/ysize<br />
8224 bpr 2051
         @ example:<br />size 400,400<br />xrange 0,10000<br />yrange 0,100<br />sgraph 9000,50,100,10,4,4,grey,blue<br />userinput_xy<br />linewidth 2<br />userdraw segments,red
7654 schaersvoo 2052
        */
8224 bpr 2053
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
7654 schaersvoo 2054
            for(i = 0 ; i < 8 ;i++){
2055
                switch(i){
2056
                    case 0:double_data[0] = get_real(infile,0);break;
2057
                    case 1:double_data[1] = get_real(infile,0);break;
2058
                    case 2:double_data[2] = get_real(infile,0);break;
2059
                    case 3:double_data[3] = get_real(infile,0);break;
2060
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
2061
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
2062
                    case 6:stroke_color = get_color(infile,0);break;
2063
                    case 7:font_color = get_color(infile,1);
7658 schaersvoo 2064
                    string_length = snprintf(NULL,0,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size);
7654 schaersvoo 2065
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7658 schaersvoo 2066
                    snprintf(tmp_buffer,string_length,"xstart = %f;\nystart = %f;\ndraw_sgraph(%d,%d,%f,%f,%d,%d,\"%s\",\"%s\",\"%s\",%f,%d);\n",double_data[0],double_data[1],GRID_CANVAS,precision,double_data[2],double_data[3],int_data[0],int_data[1],stroke_color,font_color,font_family,stroke_opacity,font_size);
7654 schaersvoo 2067
                    add_to_buffer(tmp_buffer);
2068
                    break;
2069
                    default:break;
2070
                }
2071
            }
2072
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
2073
            break;
7614 schaersvoo 2074
        case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
2075
        /*
2076
         @ grid step_x,step_y,gridcolor
2077
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
2078
         @ if keywords "axis" or "axisnumbering" are set, use :<br />grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color<br />minor x step = step_x / minor_x
7654 schaersvoo 2079
         @ if xmin > 0 and/or ymin > 0 and zooming / panning is not activ: <br /> be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual <br /> as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV)
7614 schaersvoo 2080
         @ can not be set "onclick" or "drag xy"
2081
         @ use commands 'xlabel some_string' and/or 'ylabel some_string' to label axis;<br />use command "fontsize" to adjust size (the font family is non-configurable 'italic your_fontsize px Ariel')
2082
         @ see commands "xaxis" or "xaxistext", "yaxis" or "yaxistext" to set tailormade values on axis (the used font is set by command fontfamily; default '12px Ariel')
2083
         @ see command "legend" to set a legend for the graph ;<br />use command "fontsize" to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
2084
        */
7729 schaersvoo 2085
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
7614 schaersvoo 2086
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
2087
            for(i=0;i<4;i++){
2088
                switch(i){
2089
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
2090
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
2091
                    case 2:
2092
                    if( use_axis == TRUE ){
2093
                        stroke_color = get_color(infile,0);
2094
                        done = FALSE;
2095
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
2096
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
2097
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
2098
                        fill_color = get_color(infile,1); /* used as axis_color*/
2099
                    }
2100
                    else
2101
                    {
2102
                        int_data[0] = 1;
2103
                        int_data[1] = 1;
2104
                        stroke_color = get_color(infile,1);
2105
                        fill_color = stroke_color;
2106
                    }
2107
                    if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor tickt must be positive !");}
7634 schaersvoo 2108
                    /* set snap_x snap_y values in pixels */
7988 schaersvoo 2109
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
8071 schaersvoo 2110
                    string_length = snprintf(NULL,0,  "draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
7614 schaersvoo 2111
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 2112
                    snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,%.2f,%.*f,%.*f,%d,%d,%d,%d,\"%s\",\"%s\",%d,\"%s\",%d,%d,%d,%.2f,%d,%s,%d,%d,%d,\"%s\",%.2f);\n",canvas_root_id,GRID_CANVAS,precision,stroke_opacity,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],int_data[2],line_width,stroke_color,fill_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype[0],dashtype[1],font_color,fill_opacity);
7614 schaersvoo 2113
                    add_to_buffer(tmp_buffer);
2114
                    break;
2115
                }
2116
            }
2117
            reset();
2118
            break;
2119
        case OPACITY:
2120
        /*
2121
        @ opacity 0-255,0-255
2122
        @
2123
        */
2124
            for(i = 0 ; i<2;i++){
2125
                switch(i){
2126
                    case 0: double_data[0]=(int)(get_real(infile,0));break;
2127
                    case 1: double_data[1]=(int)(get_real(infile,1));break;
2128
                    default: break;
2129
                }
2130
            }
2131
            if( double_data[0] < 0 || double_data[0] > 255 || double_data[1] < 0 || double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255]");}/* typo or non-RGB ? */
2132
            stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
2133
            fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
2134
            break;
2135
        case ROTATE:
2136
        /*
2137
         @rotate rotation_angle
8097 schaersvoo 2138
         @angle in degrees
7614 schaersvoo 2139
        */
2140
            use_rotate = TRUE;
8097 schaersvoo 2141
            angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
7614 schaersvoo 2142
            break;
7785 schaersvoo 2143
        case KILLAFFINE:
2144
        /*
2145
        @ killaffine
2146
        @ keyword : resets the transformation matrix to 1,0,0,1,0,0
2147
        */
2148
            use_affine = FALSE;
8224 bpr 2149
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
7785 schaersvoo 2150
            break;
2151
        case AFFINE:
2152
        /*
2153
         @affine a,b,c,d,tx,ty
8224 bpr 2154
         @ defines a transformation matrix for subsequent objects
7785 schaersvoo 2155
         @ use keyword 'killaffine' to end the transformation
2156
         @ note 1: only 'draggable' / 'noclick' objects can be transformed.
2157
         @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
2158
         @ note 3: no matrix operations on the transformation matrix implemented (yet)
2159
         @ a : Scales the drawings horizontally
2160
         @ b : Skews the drawings horizontally
2161
         @ c : Skews the drawings vertically
2162
         @ d : Scales the drawings vertically
8071 schaersvoo 2163
         @ tx: Moves the drawings horizontally in xrange coordinate system
8224 bpr 2164
         @ ty: Moves the drawings vertically in yrange coordinate system
8071 schaersvoo 2165
         @ the data precision is 2 decimals (printf : %2.f)
7785 schaersvoo 2166
        */
2167
            for(i = 0 ; i<6;i++){
2168
                switch(i){
2169
                    case 0: double_data[0] = get_real(infile,0);break;
2170
                    case 1: double_data[1] = get_real(infile,0);break;
2171
                    case 2: double_data[2] = get_real(infile,0);break;
2172
                    case 3: double_data[3] = get_real(infile,0);break;
8071 schaersvoo 2173
                    case 4: double_data[4] = get_real(infile,0);break;
2174
                    case 5: double_data[5] = get_real(infile,1);
7785 schaersvoo 2175
                        use_affine = TRUE;
8071 schaersvoo 2176
                        string_length = snprintf(NULL,0,     "[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin));
7785 schaersvoo 2177
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
8224 bpr 2178
                        snprintf(affine_matrix,string_length,"[%.2f,%.2f,%.2f,%.2f,%.2f,%.2f] ",double_data[0],double_data[1],double_data[2],double_data[3],double_data[4]*xsize/(xmax - xmin),-1*double_data[5]*ysize/(ymax - ymin));
8071 schaersvoo 2179
                        break;
7785 schaersvoo 2180
                    default: break;
2181
                }
2182
            }
2183
        break;
7614 schaersvoo 2184
        case KILLTRANSLATION:
2185
        /*
2186
         killtranslation
2187
        */
8071 schaersvoo 2188
            use_affine = FALSE;
8224 bpr 2189
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
7614 schaersvoo 2190
            break;
2191
        case TRANSLATION:
2192
        /*
2193
         @translation tx,ty
8071 schaersvoo 2194
         @will translate the next object tx in xrange and ty in yrange
2195
         @uase command 'killtranstation' to end the command
7614 schaersvoo 2196
        */
8071 schaersvoo 2197
            for(i = 0 ; i<2;i++){
2198
                switch(i){
2199
                    case 0: double_data[0] = get_real(infile,0);break;
2200
                    case 1: double_data[1] = get_real(infile,1);
2201
                        use_affine = TRUE;
2202
                        string_length = snprintf(NULL,0, "[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
2203
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
2204
                        snprintf(affine_matrix,string_length,"[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
2205
                        break;
2206
                    default: break;
2207
                }
2208
            }
2209
        break;
2210
 
7614 schaersvoo 2211
        case DASHED:
2212
        /*
2213
        @ keyword "dashed"
2214
        @ next object will be drawn with a dashed line
2215
        @ change dashing scheme by using command "dashtype int,int)
2216
        */
2217
            use_dashed = TRUE;
2218
            break;
2219
        case FILLED:
2220
        /*
8224 bpr 2221
        @ keyword "filled"
2222
        @ the next 'fillable' object (only) will be filled
7614 schaersvoo 2223
        @ use command "fillcolor color" to set fillcolor
2224
        @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
2225
        @ use command "fill x,y,color" or "floodfill x,y,color" to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care !
2226
        */
2227
            use_filled = TRUE;
2228
            break;
2229
        case STYLE:
2230
        /*
2231
         @highlight color,opacity,linewidth
2232
         @ NOT IMPLEMENTED
2233
         @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
2234
        */
2235
            break;
2236
        case FILLCOLOR:
2237
        /*
2238
        @ fillcolor colorname or #hex
2239
        @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
2240
        @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
2241
        */
2242
            fill_color = get_color(infile,1);
2243
            break;
2244
        case STROKECOLOR:
2245
        /*
2246
        @ strokecolor colorname or #hex
2247
        @ to be used for commands that do not supply a color argument (like command 'linegraph')
2248
        */
2249
            stroke_color = get_color(infile,1);
2250
            break;
8224 bpr 2251
        case BGIMAGE:
7614 schaersvoo 2252
        /*
2253
         @bgimage image_location
2254
         @use an image as background .<br />(we use the background of 'canvas_div' )
2255
         @the background image will be resized to match "width = xsize" and "height = ysize"
2256
        */
2257
        URL = get_string(infile,1);
2258
        fprintf(js_include_file,"<!-- set background image to canvas div -->\ncanvas_div.style.backgroundImage = \"url(%s)\";canvas_div.style.backgroundSize = \"%dpx %dpx\";\n",URL,xsize,ysize);
2259
            break;
8224 bpr 2260
        case BGCOLOR:
7614 schaersvoo 2261
        /*
2262
         @bgcolor colorname or #hex
2263
         @use this color as background of the "div" containing the canvas(es)
2264
        */
2265
        /* [255,255,255]*/
2266
            bgcolor = get_string(infile,1);
2267
            if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
2268
                int found = 0;
2269
                for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
2270
                    if( strcmp( colors[i].name , bgcolor ) == 0 ){
2271
                        bgcolor = colors[i].hex;
2272
                        found = 1;
2273
                        break;
2274
                    }
2275
                }
2276
                if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
2277
            }
2278
            fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
2279
            break;
2280
        case COPY:
2281
        /*
2282
        @ copy x,y,x1,y1,x2,y2,[filename URL]
2283
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
2284
        @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
8224 bpr 2285
        @ [filename] is the URL of the image
7614 schaersvoo 2286
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
2287
        @ if command 'drag x/y/xy' is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valuid for the next image<br />draggable / non-draggable images may be mixed
8224 bpr 2288
        @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
7614 schaersvoo 2289
 
2290
        context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
2291
        draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
2292
        */
2293
            for(i = 0 ; i<7;i++){
2294
                switch(i){
2295
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
2296
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
2297
                    case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
2298
                    case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
2299
                    case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
2300
                    case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
2301
                    case 6: URL = get_string(infile,1);
2302
                            int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
2303
                            int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
2304
                            if( drag_type > -1 ){
2305
                                if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
7876 schaersvoo 2306
                                if(reply_format == 0 ){reply_format = 20;}
7614 schaersvoo 2307
                                string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1);
2308
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8224 bpr 2309
                                snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,1);
7614 schaersvoo 2310
                                drag_type = -1;
2311
                                ext_img_cnt++;
2312
                            }
2313
                            else
2314
                            {
2315
                                if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
2316
                                /*
2317
                                draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
2318
                                */
2319
                                string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7]);
2320
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2321
                                snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7]);
2322
                            }
2323
                            add_to_buffer(tmp_buffer);
2324
                            break;
2325
                    default: break;
2326
                }
2327
            }
2328
            reset();
2329
            break;
2330
/*
2331
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
2332
img     Specifies the image, canvas, or video element to use
2333
sx      The x coordinate where to start clipping : x1 = int_data[0]
2334
sy      The y coordinate where to start clipping : x2 = int_data[1]
8224 bpr 2335
swidth  The width of the clipped image : int_data[2] - int_data[0]
7614 schaersvoo 2336
sheight The height of the clipped image : int_data[3] - int_data[1]
2337
x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
2338
y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
2339
width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
2340
height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
2341
*/
2342
        case COPYRESIZED:
2343
        /*
2344
        @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
8224 bpr 2345
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [ filename], <br />possibly resized,<br />to the region of (dx1,dy1) to (dx2,dy2) in x/y-range
7614 schaersvoo 2346
        @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
2347
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
2348
        @ if command 'drag x/y/xy' is set before command 'copy', the images will be draggable<br />javascript function read_canvas(); will return the x/y coordinate data in xrange/yrange of all -including non draggable- images<br />the command drag is only valuid for the next image<br />draggable / non-draggable images may be mixed
8224 bpr 2349
        @ if you want to draw / userdraw  on an "imported" image, make sure it is transparent.<br />for example GNUPlot: set terminal gif transparent
7614 schaersvoo 2350
        */
2351
            for(i = 0 ; i<9;i++){
2352
                switch(i){
2353
                    case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
2354
                    case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
2355
                    case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
2356
                    case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
2357
                    case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
2358
                    case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
2359
                    case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
2360
                    case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
2361
                    case 8: URL = get_string(infile,1);
2362
                            if( drag_type > -1 ){
2363
                                if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
7876 schaersvoo 2364
                                if(reply_format == 0 ){reply_format = 20;}
7614 schaersvoo 2365
                                string_length = snprintf(NULL,0,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1);
2366
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2367
                                snprintf(tmp_buffer,string_length,"drag_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,1);
2368
                                drag_type = -1;
2369
                                ext_img_cnt++;
2370
                            }
2371
                            else
2372
                            {
2373
                                if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
2374
                                string_length = snprintf(NULL,0,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7]);
2375
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2376
                                snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,0);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7]);
2377
                            }
2378
                            add_to_buffer(tmp_buffer);
2379
                    default: break;
2380
                }
2381
            }
2382
            reset();
2383
            break;
8146 schaersvoo 2384
        case CLEARBUTTON:
7614 schaersvoo 2385
        /*
8146 schaersvoo 2386
         @clearbutton value
2387
         @adds a button to clear the userdraw canvas with text 'value'
8193 schaersvoo 2388
         @normally userdraw primitives have the option to use middle/right mouse button on<br /> a point of the object to remove this specific object...this clear button will remove all drawings
8146 schaersvoo 2389
         @uses the tooltip placeholder div element: may not be used with command 'intooltip'
8224 bpr 2390
         @use command 'inputstyle' to style the button...
7614 schaersvoo 2391
        */
8146 schaersvoo 2392
            add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
7614 schaersvoo 2393
        break;
2394
        case INPUTSTYLE:
2395
        /*
2396
        @ inputstyle style_description
2397
        @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
2398
        */
2399
            input_style = get_string(infile,1);
2400
            break;
2401
        case INPUT:
8224 bpr 2402
        /*
7614 schaersvoo 2403
         @ input x,y,size,editable,value
8224 bpr 2404
         @ to set inputfield "readonly", use editable = 0
7614 schaersvoo 2405
         @ only active inputfields (editable = 1) will be read with read_canvas();
8224 bpr 2406
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
7614 schaersvoo 2407
         @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
2408
         @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
2409
        */
8224 bpr 2410
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
7614 schaersvoo 2411
            for(i = 0 ; i<5;i++){
2412
                switch(i){
2413
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
2414
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
2415
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
2416
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
8224 bpr 2417
                    case 4:
7614 schaersvoo 2418
                            temp = get_string_argument(infile,1);
2419
                            string_length = snprintf(NULL,0,  "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp);
2420
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2421
                            snprintf(tmp_buffer,string_length,"draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp);
2422
                            add_to_buffer(tmp_buffer);
2423
                            input_cnt++;break;
2424
                    default: break;
2425
                }
2426
            }
7876 schaersvoo 2427
            if(reply_format == 0 ){reply_format = 15;}
7614 schaersvoo 2428
            reset();
2429
            break;
2430
        case TEXTAREA:
8224 bpr 2431
        /*
7614 schaersvoo 2432
         @ textarea x,y,cols,rows,readonly,value
2433
         @ may be further controlled by "inputstyle"
8224 bpr 2434
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
7614 schaersvoo 2435
         @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
2436
        */
8224 bpr 2437
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
7614 schaersvoo 2438
            for(i = 0 ; i<6;i++){
2439
                switch(i){
2440
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
2441
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
2442
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
2443
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
2444
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
2445
                    case 5: temp = get_string_argument(infile,1);
2446
                            string_length = snprintf(NULL,0,  "draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp);
2447
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2448
                            snprintf(tmp_buffer,string_length,"draw_textareas(%d,%d,%d,%d,%d,%d,%d,\"%s\",\"%s\");\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],input_style,temp);
2449
                            add_to_buffer(tmp_buffer);
2450
                            input_cnt++;break;
2451
                    default: break;
2452
                }
2453
            }
7876 schaersvoo 2454
            if(reply_format == 0 ){reply_format = 15;}
7614 schaersvoo 2455
            reset();
2456
            break;
2457
        case MOUSE_PRECISION:
2458
        /*
2459
            @ precision int
8074 schaersvoo 2460
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
7614 schaersvoo 2461
            @ may be used / changed before every object
8074 schaersvoo 2462
            @ In case of user interaction (like 'userdraw') this value will be used to determine the amount of decimals in the reply / answer
7614 schaersvoo 2463
        */
2464
            precision = (int) (get_real(infile,1));
8074 schaersvoo 2465
            if(precision < 1 ){precision = 1;};
7614 schaersvoo 2466
            break;
7838 schaersvoo 2467
        case SETLIMITS:
2468
        /*
8224 bpr 2469
            @setlimits
7838 schaersvoo 2470
            @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
2471
            @may be used for inputfield based zooming / panning
7858 schaersvoo 2472
            @use command xlabel / ylabel to change text from xmin to 'xlabel'min etc
8224 bpr 2473
            @note:the input value will not be checked on validity
7838 schaersvoo 2474
        */
7956 schaersvoo 2475
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7838 schaersvoo 2476
            add_setlimits(js_include_file,canvas_root_id);
2477
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
2478
            use_pan_and_zoom = TRUE;
2479
            done = TRUE;
2480
            break;
7614 schaersvoo 2481
        case ZOOM:
2482
        /*
2483
         @ zoom button_color
2484
         @ introduce a controlpanel at the lower right corner
2485
         @ giving six 15x15pixel 'active' rectangle areas<br />(for x,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
2486
         @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
2487
         @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
8224 bpr 2488
         @ command 'opacity' may be used to set stroke_opacity of 'buttons
2489
         @ NOTE: use command 'zoom' at the end of your script code (the same is true for commanmd 'mouse')
7614 schaersvoo 2490
         @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
2491
         @ NOTE: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !!
2492
        */
7653 schaersvoo 2493
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
7797 schaersvoo 2494
            use_pan_and_zoom = TRUE;
7988 schaersvoo 2495
            stroke_color = get_color(infile,1);
7614 schaersvoo 2496
            /* we use BG_CANVAS (0) */
7988 schaersvoo 2497
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
7614 schaersvoo 2498
            done = TRUE;
2499
            break;
2500
        case ONCLICK:
2501
        /*
2502
         @ onclick
2503
         @ keyword, no arguments
2504
         @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
8224 bpr 2505
         @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
7906 schaersvoo 2506
         @ NOTE: not all objects may be set clickable
7614 schaersvoo 2507
        */
8257 schaersvoo 2508
            fprintf(js_include_file,"use_dragdrop_reply = true;");
7614 schaersvoo 2509
            onclick = 1;
2510
            break;
2511
        case DRAG:
2512
        /*
2513
         @ drag [x][y][xy]
2514
         @ the next object will be draggable in x / y / xy direction
2515
         @ the displacement can be read by 'javascript:read_dragdrop();'
8074 schaersvoo 2516
         @ the precision (default 2 decimals) in the student reply may be set with command 'precision'.<br />Use this 'precision' command before this command 'drag x|y|xy' !
7906 schaersvoo 2517
         @ the answer is  : object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the place of the draggable object in your script.<br />Only draggable object will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc)
7881 schaersvoo 2518
         @ use keywordd 'snaptogrid' , 'xsnaptogrid' or 'ysnaptogrid' to switch from free to discrete movement
8224 bpr 2519
         @ in case of external images (commands copy / copyresized) the external image can be set draggable ; always xy. <br />The function javascript;read_canvas() will return the xy-coordinates of all images.
7614 schaersvoo 2520
         @ NOTE: in case an object is dragged , zooming or panning will cause the coordinates to be reset to the original position :( <br />e.g. dragging / panning will get lost. (array with 'drag data' is erased)<br />This is a design flaw and not a feature !!
2521
        */
2522
            temp = get_string(infile,1);
8224 bpr 2523
            if(strstr(temp,"xy") != NULL ){
7614 schaersvoo 2524
                drag_type = 0;
2525
            }
2526
            else
2527
            {
8224 bpr 2528
                if(strstr(temp,"x") != NULL ){
7614 schaersvoo 2529
                    drag_type = 1;
2530
                }
2531
                else
2532
                {
2533
                    drag_type = 2;
2534
                }
2535
            }
8257 schaersvoo 2536
            fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;",precision);
7614 schaersvoo 2537
            onclick = 2;
8257 schaersvoo 2538
 
7614 schaersvoo 2539
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
2540
            break;
2541
        case BLINK:
2542
        /*
2543
         @ blink time(seconds)
2544
         @ NOT IMPLEMETED -YET
2545
        */
2546
            break;
7996 schaersvoo 2547
        case XUNIT:
2548
        /*
2549
         @ xunit some_unit_for_x-values
2550
         @ unicode allowed (no html code)
2551
         @ use together with command mousex
2552
         @ will display the cursor x-coordinate 'unit'
2553
        */
2554
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
2555
            break;
2556
        case YUNIT:
2557
        /*
2558
         @ yunit some_unit_for_y-values
2559
         @ unicode allowed (no html code)
2560
         @ use together with command mousex
2561
         @ will display the cursor y-coordinate 'unit'
2562
        */
2563
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
2564
            break;
8071 schaersvoo 2565
        case MOUSE_DISPLAY:
2566
        /*
8129 schaersvoo 2567
         @display x|y|xy|degree|radius,color,fontsize
2568
         @will display the mouse cursor coordinates as x-only,y-only,(x:y),<br />the radius of a circle (this only in case 'userdraw circle(s),color' !!<br />or the angle in degrees ( rhe angle between x-axis;(0:0);(x:y)
2569
         @use commands 'xunit' and / or 'yunit' to add the units to the mouse values
8071 schaersvoo 2570
         @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
2571
        */
2572
        temp = get_string_argument(infile,0);
8112 schaersvoo 2573
        if( strstr(temp,"xy") != NULL ){
2574
            int_data[0] = 2;
8071 schaersvoo 2575
        }else{
8112 schaersvoo 2576
            if( strstr(temp,"y") != NULL ){
2577
                int_data[0] = 1;
8071 schaersvoo 2578
            }else{
8112 schaersvoo 2579
                if( strstr(temp,"x") != NULL ){
2580
                    int_data[0] = 0;
8129 schaersvoo 2581
                }else{
8112 schaersvoo 2582
                    if(strstr(temp,"degree") != NULL){
2583
                        int_data[0] = 3;
8071 schaersvoo 2584
                    }else{
8129 schaersvoo 2585
                        if(strstr(temp,"radius") != NULL){
2586
                            int_data[0] = 4;
2587
                        }else{
2588
                            int_data[0] = 2;
2589
                        }
8112 schaersvoo 2590
                    }
8129 schaersvoo 2591
                }
8071 schaersvoo 2592
            }
8129 schaersvoo 2593
        }
8071 schaersvoo 2594
        stroke_color = get_color(infile,0);
2595
        font_size = (int) (get_real(infile,1));
2596
        tmp_buffer = my_newmem(26);
2597
        snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2598
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2599
        break;
2600
        case MOUSE_DEGREE:
2601
        /*
2602
         @ mouse_degree color,fontsize
8099 schaersvoo 2603
         @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using default fontfamily Ariel
8071 schaersvoo 2604
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
8224 bpr 2605
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
8071 schaersvoo 2606
 
2607
        */
2608
            stroke_color = get_color(infile,0);
2609
            font_size = (int) (get_real(infile,1));
2610
            tmp_buffer = my_newmem(26);
2611
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2612
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2613
            break;
7991 schaersvoo 2614
        case MOUSEX:
2615
        /*
2616
         @ mousex color,fontsize
2617
         @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
8224 bpr 2618
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
7991 schaersvoo 2619
 
2620
        */
2621
            stroke_color = get_color(infile,0);
2622
            font_size = (int) (get_real(infile,1));
2623
            tmp_buffer = my_newmem(26);
2624
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2625
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2626
            break;
2627
        case MOUSEY:
2628
        /*
2629
         @ mousey color,fontsize
2630
         @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
8224 bpr 2631
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
7991 schaersvoo 2632
 
2633
        */
2634
            stroke_color = get_color(infile,0);
2635
            font_size = (int) (get_real(infile,1));
2636
            tmp_buffer = my_newmem(26);
2637
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2638
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2639
            break;
7614 schaersvoo 2640
        case MOUSE:
2641
        /*
2642
         @ mouse color,fontsize
7991 schaersvoo 2643
         @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
8224 bpr 2644
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom')
7988 schaersvoo 2645
 
7614 schaersvoo 2646
        */
2647
            stroke_color = get_color(infile,0);
2648
            font_size = (int) (get_real(infile,1));
7839 schaersvoo 2649
            tmp_buffer = my_newmem(26);
2650
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
7991 schaersvoo 2651
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
7614 schaersvoo 2652
            break;
2653
        case INTOOLTIP:
2654
            /*
2655
            @ intooltip link_text
2656
            @ link_text is a single line (span-element)
2657
            @ link_text may also be an image URL http://some_server/images/my_image.png
2658
            @ link_text may contain HTML markup
2659
            @ the canvas will be displayed in a tooltip on 'link_text'
2660
            @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
2661
            */
7823 schaersvoo 2662
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");}
7614 schaersvoo 2663
            use_tooltip = TRUE;
2664
            tooltip_text = get_string(infile,1);
2665
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
2666
            break;
2667
        case AUDIO:
2668
        /*
2669
        @ audio x,y,w,h,loop,visible,audiofile location
2670
        @ x,y : left top corner of audio element (in xrange / yrange)
2671
        @ w,y : width and height in pixels
2672
        @ loop : 0 or 1 ( 1 = loop audio fragment)
2673
        @ visible : 0 or 1 (1 = show controls)
2674
        @ audio format may be in *.mp3 or *.ogg
2675
        @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
2676
        @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
2677
        @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
2678
        @ example: upload both audio1.ogg and audio1.mp3 to http://server/files/<br />audio 0,0,http://server/files/audio1.mp3<br />svdraw will copy html-tag audio1.mp3 to audio1.ogg<br /> and the browser will play the compatible file (audio1.ogg or audio1.mp3)<br />
2679
        */
2680
            if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
2681
            for(i=0;i<7;i++){
2682
                switch(i){
2683
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
2684
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
2685
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
2686
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
2687
                    case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
2688
                    case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
8224 bpr 2689
                    case 6:
7614 schaersvoo 2690
                    temp = get_string(infile,1);
2691
                    if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
2692
                    if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
2693
                    string_length = snprintf(NULL,0,  "draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp);
2694
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2695
                    snprintf(tmp_buffer,string_length,"draw_audio(%d,%d,%d,%d,%d,%d,%d,\"%s.ogg\",\"%s.mp3\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],temp,temp);
2696
                    add_to_buffer(tmp_buffer);
2697
                    break;
2698
                    default:break;
2699
                }
2700
            }
2701
            reset();
2702
            break;
2703
        case VIDEO:
2704
        /*
2705
        @ video x,y,w,h,videofile location
2706
        @ x,y : left top corner of audio element (in xrange / yrange)
2707
        @ w,y : width and height in pixels
2708
        @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
2709
        @ video format may be in *.mp4 (todo:other formats)
2710
        */
2711
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
2712
            for(i=0;i<5;i++){
2713
                switch(i){
2714
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
2715
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
2716
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
2717
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
2718
                    case 4: temp = get_string(infile,1);
2719
                            string_length = snprintf(NULL,0,  "draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
2720
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2721
                            snprintf(tmp_buffer,string_length,"draw_video(%d,%d,%d,%d,%d,\"%s\");\n",canvas_root_id,int_data[0],int_data[1],int_data[2],int_data[3],temp);
2722
                            add_to_buffer(tmp_buffer);
2723
                            break;
2724
                    default:break;
2725
                }
2726
            }
2727
            reset();
2728
            break;
2729
        case HATCHFILL:
2730
        /*
2731
        @ hatchfill x0,y0,dx,dy,color
2732
        @ x0,y0 in xrange / yrange
2733
        @ distances dx,dy in pixels
2734
        */
2735
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
2736
            for(i=0;i<5;i++){
2737
                switch(i){
2738
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2739
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2740
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2741
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2742
                    case 4: stroke_color = get_color(infile,1);
2743
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2744
                    string_length = snprintf(NULL,0,  "draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2745
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2746
                    snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2747
                    add_to_buffer(tmp_buffer);
2748
                    break;
2749
                    default:break;
2750
                }
2751
            }
2752
            reset();
2753
        break;
7647 schaersvoo 2754
        case DIAMONDFILL:
2755
        /*
2756
        @ diamondfill x0,y0,dx,dy,color
2757
        @ x0,y0 in xrange / yrange
2758
        @ distances dx,dy in pixels
2759
        */
2760
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
2761
            for(i=0;i<5;i++){
2762
                switch(i){
2763
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2764
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2765
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2766
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2767
                    case 4: stroke_color = get_color(infile,1);
2768
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2769
                    string_length = snprintf(NULL,0,  "draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2770
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2771
                    snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2772
                    add_to_buffer(tmp_buffer);
2773
                    break;
2774
                    default:break;
2775
                }
2776
            }
2777
            reset();
2778
        break;
7614 schaersvoo 2779
        case GRIDFILL:
2780
        /*
2781
        @ gridfill x0,y0,dx,dy,color
2782
        @ x0,y0 in xrange / yrange
2783
        @ distances dx,dy in pixels
7883 schaersvoo 2784
        @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid)
2785
        @ userdraw object may snap_to_grid
7614 schaersvoo 2786
        */
2787
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
2788
            for(i=0;i<5;i++){
2789
                switch(i){
2790
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2791
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2792
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2793
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2794
                    case 4: stroke_color = get_color(infile,1);
2795
                    string_length = snprintf(NULL,0,  "draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2796
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2797
                    snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2798
                    add_to_buffer(tmp_buffer);
2799
                    break;
2800
                    default:break;
2801
                }
2802
            }
2803
            reset();
2804
        break;
2805
        case DOTFILL:
2806
        /*
2807
        @ dotfill x0,y0,dx,dy,color
2808
        @ x0,y0 in xrange / yrange
2809
        @ distances dx,dy in pixels
2810
        @ radius of dots is linewidth
2811
        */
2812
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
2813
            for(i=0;i<5;i++){
2814
                switch(i){
2815
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2816
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2817
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2818
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2819
                    case 4: stroke_color = get_color(infile,1);
2820
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
2821
                    string_length = snprintf(NULL,0,  "draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2822
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2823
                    snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],int_data[2],int_data[3],line_width,stroke_color,stroke_opacity,xsize,ysize);
2824
                    add_to_buffer(tmp_buffer);
2825
                    break;
2826
                    default:break;
2827
                }
2828
            }
2829
            reset();
2830
        break;
2831
        case IMAGEFILL:
2832
        /*
2833
        @ imagefill dx,dy,image_url
2834
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
2835
        @ After pattern filling ,the fill-color should be reset !
2836
        @ wims getins / image from class directory : imagefill 80,80,my_image.gif
2837
        @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
2838
        @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
2839
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
2840
        */
2841
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
2842
            for(i=0 ;i < 3 ; i++){
2843
                switch(i){
2844
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
2845
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
2846
                    case 2: URL = get_string_argument(infile,1);
2847
                            string_length = snprintf(NULL,0,  "draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize);
2848
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2849
                            snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],URL,xsize,ysize);
2850
                            add_to_buffer(tmp_buffer);
2851
                    break;
2852
                }
2853
            }
8083 schaersvoo 2854
            reset();
7614 schaersvoo 2855
        break;
2856
        case FILLTOBORDER:
2857
        /*
2858
        @ filltoborder x,y,bordercolor,color
8224 bpr 2859
        @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
7614 schaersvoo 2860
        @ any other color will not act as border to the bucket fill
2861
        @ use this command  after all boundary objects are declared.
2862
        @ NOTE: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU..
2863
        */
2864
            for(i=0 ;i < 4 ; i++){
2865
                switch(i){
2866
                    case 0:double_data[0] = get_real(infile,0);break;
2867
                    case 1:double_data[1] = get_real(infile,0);break;
2868
                    case 2:bgcolor = get_color(infile,0);break;
2869
                    case 3:fill_color = get_color(infile,1);
2870
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
2871
                                js_function[DRAW_FILLTOBORDER] = 1;
2872
                                add_js_filltoborder(js_include_file,canvas_root_id);
2873
                           }
2874
                           decimals = find_number_of_digits(precision);
7895 schaersvoo 2875
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
8071 schaersvoo 2876
                           string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2877
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 2878
                           snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2879
                           add_to_buffer(tmp_buffer);
2880
                           break;
2881
                    default:break;
8083 schaersvoo 2882
                }
2883
            }
2884
            reset();
7614 schaersvoo 2885
        break;
2886
        case FLOODFILL:
2887
        /*
2888
        @ floodfill x,y,color
2889
        @ alternative syntax: fill x,y,color
2890
        @ fill the region of point (x:y) with color 'color'
2891
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
2892
        @ use this command  after all boundary objects are declared.
2893
        @ Use command 'clickfill,color' for user click driven flood fill.
2894
        @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
2895
        @ NOTE: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel<br/>e.g. image size of 400x400 uses 160000 pixels : each pixel contains 4 data (R,G,B,Opacity) = 640000 data.<br />on every data a few operations / comparisons are done...<br />So have pity on your students CPU..
2896
        */
2897
            for(i=0 ;i < 4 ; i++){
2898
                switch(i){
2899
                    case 0:double_data[0] = get_real(infile,0);break;
2900
                    case 1:double_data[1] = get_real(infile,0);break;
2901
                    case 2:fill_color = get_color(infile,1);
2902
                           if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
2903
                                js_function[DRAW_FLOODFILL] = 1;
2904
                                add_js_floodfill(js_include_file,canvas_root_id);
2905
                           }
2906
                           decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
7895 schaersvoo 2907
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
2908
                           string_length = snprintf(NULL,0,  "setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2909
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7895 schaersvoo 2910
                           snprintf(tmp_buffer,string_length,"setTimeout(function(){floodfill(0,%.*f,%.*f,[%s,%d]);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215));
7614 schaersvoo 2911
                           add_to_buffer(tmp_buffer);
2912
                           break;
2913
                    default:break;
8083 schaersvoo 2914
                }
2915
            }
2916
            reset();
7614 schaersvoo 2917
        break;
2918
        case CLICKFILLMARGE:
2919
            clickfillmarge = (int) (get_real(infile,1));
2920
            break;
2921
        /*
2922
        @ clickfillmarge int
2923
        @ default 20 (pixels)
2924
        @ when using command "clickfill fillcolor" a coloured area my be reverted ("undo") <br />back to background colour with a middle mouse click<br />when the click is in a 40x40 rectangle around a stored m mouseclick (userdraw_x[] and userdraw_y[])
2925
        */
2926
        case CLICKFILL:
2927
        /*
2928
        @ clickfill fillcolor
2929
        @ user left mouse click will floodfill the area with fillcolor
2930
        @ multiple areas may be coloured
2931
        @ the coloured areas can be removed (changed to "bgcolor") by  middle / right mouse click <br />(if the click is in an 40x40 pixel area of the click coordinate that "painted" the area)
2932
        @ the answer will be read as the (x:y) click coordinates per coloured area
2933
        @ background color of main div may be set by using command "bgcolor color"
2934
        @ may not be combined with command "userdraw"
2935
        @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
2936
        */
2937
         fill_color = get_color(infile,1);
2938
         if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
2939
            js_function[DRAW_FLOODFILL] = 1;
2940
            add_js_floodfill(js_include_file,canvas_root_id);
2941
         }
8130 schaersvoo 2942
         fprintf(js_include_file,"\n<!-- begin command clickfill -->\nvar marge_xy = %d;userdraw_x = new Array();userdraw_y = new Array();var user_clickfill_cnt = 0;\ncanvas_div.addEventListener(\"mousedown\",clickfill,false);function clickfill(evt){var x = evt.clientX - findPosX(canvas_div) + document.body.scrollLeft + document.documentElement.scrollLeft;var y = evt.clientY - findPosY(canvas_div) + document.body.scrollTop + document.documentElement.scrollTop;if(evt.which != 1){for(var p=0; p < user_clickfill_cnt;p++){if(userdraw_x[p] + marge_xy > x && userdraw_x[p] - marge_xy < x){if(userdraw_y[p] + marge_xy > y && userdraw_y[p] - marge_xy < y){if(confirm(\"Clear ?\")){floodfill(1,userdraw_x[p],userdraw_y[p],canvas_div.style.backgroundColor || [255,255,255,0]);userdraw_x.splice(p,2);userdraw_y.splice(p,2);user_clickfill_cnt--;return;};};};};};userdraw_x[user_clickfill_cnt] = x;userdraw_y[user_clickfill_cnt] = y;user_clickfill_cnt++;floodfill(1,x,y,[%s,%d]);};",clickfillmarge,fill_color,(int) (fill_opacity/0.0039215));
8257 schaersvoo 2943
         add_read_canvas(canvas_root_id,1,reply_precision);
8083 schaersvoo 2944
         reset();
7614 schaersvoo 2945
        break;
2946
        case SETPIXEL:
2947
        /*
2948
        @ setpixel x,y,color
2949
        @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
2950
        @ pixels can not be dragged or clicked
2951
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2952
        */
2953
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2954
            for(i=0;i<3;i++){
2955
                switch(i){
2956
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
2957
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
2958
                    case 2: stroke_color = get_color(infile,1);
2959
                           string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
2960
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2961
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
2962
                           add_to_buffer(tmp_buffer);
2963
                           break;
2964
                    default:break;
2965
                }
2966
            }
2967
            reset();
2968
        break;
2969
        case PIXELSIZE:
2970
        /*
2971
        @ pixelsize int
2972
        @ in case you want to deviate from default pixelsize = 1...
2973
        */
2974
            pixelsize = (int) get_real(infile,1);
2975
        break;
2976
        case PIXELS:
2977
        /*
2978
        @ pixels color,x1,y1,x2,y2,x3,y3...
2979
        @ Draw  "points" with diameter 1 pixel
2980
        @ pixels can not be dragged or clicked
2981
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2982
        */
2983
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2984
            stroke_color=get_color(infile,0);
2985
            i=0;
2986
            c=0;
2987
            while( ! done ){     /* get next item until EOL*/
2988
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2989
                for( c = 0 ; c < 2; c++){
2990
                    if(c == 0 ){
2991
                        double_data[i] = get_real(infile,0);
2992
                        i++;
2993
                    }
2994
                    else
2995
                    {
2996
                        double_data[i] = get_real(infile,1);
2997
                        i++;
2998
                    }
2999
                }
3000
            }
3001
            decimals = find_number_of_digits(precision);
3002
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
3003
            string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
3004
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3005
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
3006
            add_to_buffer(tmp_buffer);
8083 schaersvoo 3007
            reset();
7614 schaersvoo 3008
            break;
3009
        case REPLYFORMAT:
3010
        /*
3011
        @ replyformat number
8257 schaersvoo 3012
        @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
7614 schaersvoo 3013
        @ default values should be fine !
8074 schaersvoo 3014
        @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
7963 schaersvoo 3015
        @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
8127 schaersvoo 3016
        @ choose<ul><li>1 = x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n<br /><br />x/y in pixels</li><li>2 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br /> x/y in xrange / yrange coordinate system<br /></li><li>3 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in pixels <br />  r in pixels</li><li>4 = x1,x2,x3,x4....x_n<br />  y1,y2,y3,y4....y_n<br />  r1,r2,r3,r4....r_n<br />  x/y in xrange / yrange coordinate system<br />  r in pixels</li><li>5 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in pixels<br /></li><li>6 = Ax1,Ax2,Ax3,Ax4....Ax_n<br />  Ay1,Ay2,Ay3,Ay4....Ay_n<br />  Bx1,Bx2,Bx3,Bx4....Bx_n<br />  By1,By2,By3,By4....By_n<br />  Cx1,Cx2,Cx3,Cx4....Cx_n<br />  Cy1,Cy2,Cy3,Cy4....Cy_n<br />  ....<br />  Zx1,Zx2,Zx3,Zx4....Zx_n<br />  Zy1,Zy2,Zy3,Zy4....Zy_n<br />  x/y in xrange / yrange coordinate system<br /></li><li>7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in pixels</li><li>8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n<br />  x/y in xrange / yrange coordinate system</li><li>9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in pixels</li><li>10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n<br />  x/y in xrange / yrange coordinate system</li><li>11 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />   Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in xrange / yrange coordinate system</li><li>12 = Ax1,Ay1,Ax2,Ay2<br />   Bx1,By1,Bx2,By2<br />Cx1,Cy1,Cx2,Cy2<br />   Dx1,Dy1,Dx2,Dy2<br />   ......<br />   Zx1,Zy1,Zx2,Zy2<br />  x/y in pixels</li><li>13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2<br />  x/y in xrange / yrange coordinate system</li><li>14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2<br />  x/y in pixels</li><li>15 = reply from inputfields,textareas<br />  reply1,reply2,reply3,...,reply_n</li><li>16 = mathml input fields </li><li>17 = read "userdraw text,color" only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n</li><li>18 = read_canvas() will read all interactive clocks in H1:M1:S1,H2:M2:S2...Hn:Mn:Sn</li><li>19 = read_canvas() will return the object number of marked / clicked object (clock)<br />analogue to (shape library) onclick command </li><li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li>22 = returns an array .... reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n<br />  x/y in xrange / yrange coordinate system</li><li>replyformat 23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline isx1,y1,x2,y2,x2,y2,x3,y3,x3,y3.....,x(n-1),y(n-1),x(n-1),y(n-1),xn,yn --replyformat 23--> x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn multiple occurences will be filtered out.The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24 = read all inputfield values: even those set 'readonly'</li><li>format 25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>format 26 = rad1,rad2...rad_n : will return the radius (one or many) of the user drawn circle segment in radians </li><li>27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...</li></ul>
7614 schaersvoo 3017
        @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
3018
        */
3019
         reply_format = (int) get_real(infile,1);
8074 schaersvoo 3020
         reply_precision = precision;
7614 schaersvoo 3021
        break;
3022
        case LEGENDCOLORS:
3023
        /*
3024
        @ legendcolors color1:color2:color3:...:color_n
7956 schaersvoo 3025
        @ will be used to colour a legend: use this command after the legend command ! e.g.<br />legend test1:test2:test3<br />legendcolors blue:red:orange<br />
7614 schaersvoo 3026
        @ make sure the number of colours match the number of legend items
8224 bpr 3027
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
7614 schaersvoo 3028
        */
7956 schaersvoo 3029
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
7614 schaersvoo 3030
            temp = get_string(infile,1);
3031
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7956 schaersvoo 3032
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
7614 schaersvoo 3033
            break;
3034
        case LEGEND:
3035
        /*
3036
        @ legend string1:string2:string3....string_n
3037
        @ will be used to create a legend for a graph
8224 bpr 3038
        @ also see command 'piechart'
7956 schaersvoo 3039
        @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default
7614 schaersvoo 3040
        */
3041
            temp = get_string(infile,1);
3042
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7956 schaersvoo 3043
            legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
3044
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
7614 schaersvoo 3045
            break;
3046
        case XLABEL:
3047
        /*
3048
        @ xlabel some_string
3049
        @ will be used to create a label for the x-axis (label is in quadrant I)
3050
        @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
8224 bpr 3051
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
7614 schaersvoo 3052
        */
3053
            temp = get_string(infile,1);
7653 schaersvoo 3054
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7614 schaersvoo 3055
            break;
3056
        case YLABEL:
3057
        /*
3058
        @ ylabel some_string
8224 bpr 3059
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
7614 schaersvoo 3060
        @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
8224 bpr 3061
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
7614 schaersvoo 3062
        */
3063
            temp = get_string(infile,1);
7653 schaersvoo 3064
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 3065
            break;
3066
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
3067
        /*
7996 schaersvoo 3068
        @ linegraph x1:y1;x2:y2...x_n:y_n
7614 schaersvoo 3069
        @ will plot your data in a graph
3070
        @ may only to be used together with command 'grid'
3071
        @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
3072
        @ use command 'legend' to provide an optional legend in right-top-corner
3073
        @ also see command 'piechart'
3074
        @ multiple linegraphs may be used in a single plot
7989 schaersvoo 3075
        @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
7614 schaersvoo 3076
        @ <ul><li>use command 'strokecolor' before command 'linegraph' to set the color of this graph</li><li>use command 'linewidth' before command 'linegraph' to set linewidth of this graph</li><li>use command 'dashed' before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command 'dashtype' before command 'linegraph' to set the type of dashing of the graph</li></ul>
8224 bpr 3077
        */
7614 schaersvoo 3078
            temp = get_string(infile,1);
3079
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7653 schaersvoo 3080
            fprintf(js_include_file,"var linegraph_%d = [\"%s\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\"];",linegraph_cnt,stroke_color,line_width,use_dashed,dashtype[0],dashtype[1],temp);
7614 schaersvoo 3081
            linegraph_cnt++;
3082
            reset();
3083
            break;
7989 schaersvoo 3084
        case BARCHART:
3085
        /*
3086
        @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
3087
        @ will be used to create a legend for bar graph
3088
        @ may only to be used together with command 'grid'
3089
        @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
3090
        @ use command 'legend' to provide an optional legend in right-top-corner
3091
        @ also see command 'piechart'
3092
        @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
3093
        */
3094
            temp = get_string(infile,1);
3095
            if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
3096
            fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
3097
            barchart_cnt++;
3098
            reset();
3099
            break;
7614 schaersvoo 3100
        case CLOCK:
3101
        /*
3102
        @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
7997 schaersvoo 3103
        @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
7614 schaersvoo 3104
        @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
3105
        @ colors are optional: if not defined, default values will be used<br />default colours: clock 0,0,60,4,35,45,1,2,[space]<br />default colours: clock 0,0,60,4,35,45,1,2,,,,,<br />custom colours: clock 0,0,60,4,35,45,1,2,,,,yellow,red<br />custom colours: clock 0,0,60,4,35,45,1,2,white,white,white,black,yellow
7862 schaersvoo 3106
        @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
7614 schaersvoo 3107
        @ interactive <ul><li>0 : not interactive, just clock(s)</li><li>1 : function read_canvas() will read all active clocks in H:M:S format<br />The active clock(s) can be adjusted by pupils</li><li>2 : function read_canvas() will return the clicked clock <br />(like multiplechoice; first clock in script in nr. 0 )</li></ul>
3108
        @ canvasdraw will not check validity of colornames...the javascript console is your best friend
3109
        @ no combinations with other reply_types allowed, for now
7783 schaersvoo 3110
        @ if interactive, 6 buttons per clock will be displayed for adjusting a clock (H+ M+ S+ H- M- S-)<br /> set_clock(clock_id,type,incr) <br />first clock has clock_id=0 ; type : H=1,M=2,S=3 ; incr : increment integer
7614 schaersvoo 3111
        */
3112
            if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
3113
 
3114
        /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
3115
            for(i=0;i<9;i++){
3116
             switch(i){
3117
              case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
3118
              case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
3119
              case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
3120
              case 3: int_data[3] = get_real(infile,0);break;/* hours */
3121
              case 4: int_data[4] = get_real(infile,0);break;/* minutes */
3122
              case 5: int_data[5] = get_real(infile,0);break;/* seconds */
7783 schaersvoo 3123
              case 6: int_data[6] = get_real(infile,0);if(int_data[6] < 0 || int_data[6] > 2){canvas_error("hourglass can be 0,1 or 2");}break;/* type hourglass */
7614 schaersvoo 3124
              case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
7783 schaersvoo 3125
                switch(int_data[7]){
3126
                    case 0:break;
3127
                    case 1:if(clock_cnt == 0){
3128
                                if( reply_format == 0 ){
7614 schaersvoo 3129
                                     reply_format = 18; /* user sets clock */
7783 schaersvoo 3130
                                    /* string_length = snprintf(NULL,0,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
7614 schaersvoo 3131
                                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3132
                                     snprintf(tmp_buffer,string_length,"set_clock = function(num,type,diff){var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
3133
                                     add_to_buffer(tmp_buffer);
7783 schaersvoo 3134
                                    */
8130 schaersvoo 3135
                                     fprintf(js_include_file,"set_clock = function(num,type,diff){if(wims_status == \"done\"){return;};var name = eval(\"clocks\"+num);switch(type){case 1:name.H = parseInt(name.H+diff);break;case 2:name.M = parseInt(name.M+diff);break;case 3:name.S = parseInt(name.S+diff);break;default: break;};name = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
7783 schaersvoo 3136
                                }
3137
                                else
3138
                                {
3139
                                    canvas_error("interactive clock may not be used together with other reply_types...");
3140
                                }
3141
                             }
8130 schaersvoo 3142
                            fprintf(stdout,"<p style=\"text-align:center\"><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,1)\" value=\"H+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,1)\" value=\"M+\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,1)\" value=\"S+\" /><br /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,1,-1)\" value=\"H&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,2,-1)\" value=\"M&minus;\" /><input style=\"%s\" type=\"button\" onclick=\"javascript:set_clock(%d,3,-1)\" value=\"S&minus;\" /></p>",input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt,input_style,clock_cnt);
7783 schaersvoo 3143
                    break;
3144
                    case 2:if( reply_format == 0 ){
3145
                                reply_format = 19; /* "onclick */
8130 schaersvoo 3146
                                fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();\n\ncanvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();\nvar x = evt.clientX - canvas_rect.left;\nvar y = evt.clientY - canvas_rect.top;\nvar p = 0;\nvar name;\nvar t = true;\nwhile(t){try{name = eval('clocks'+p);\nif( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;\nname = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,\"lightblue\",name.fg_color);\n};\n}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);\nname = new clock(name.xc,name.yc,name.radius,name.H,name.M,name.S,name.type,name.interaction,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);\n};\np++;\n}catch(e){t=false;\n};\n};\n};\n};\n\n<!-- end onclick handler for clocks -->\n ");
7783 schaersvoo 3147
                            }
3148
                            else
3149
                            {
3150
                                if( reply_format != 19){
7614 schaersvoo 3151
                                   canvas_error("clickable clock(s) may not be used together with other reply_types...");
3152
                                 }
7783 schaersvoo 3153
                            }
3154
                     break;
3155
                     default: canvas_error("interactive must be set 0,1 or 2");break;
3156
                }
3157
                break;
8224 bpr 3158
                case 8:
8130 schaersvoo 3159
                        if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
3160
                            fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
3161
                        }
7614 schaersvoo 3162
                        temp = get_string(infile,1);
3163
                        if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
3164
                        if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
8130 schaersvoo 3165
                        string_length = snprintf(NULL,0,"var clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
7614 schaersvoo 3166
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8130 schaersvoo 3167
                        snprintf(tmp_buffer,string_length,"var clocks%d = new clock(%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");\n",clock_cnt,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],temp);
7614 schaersvoo 3168
                        add_to_buffer(tmp_buffer);
3169
                        clock_cnt++;
3170
                        break;
3171
                default:break;
3172
             }
3173
            }
3174
            break;
3175
        case PIECHART:
3176
        /*
3177
        @ piechart xc,yc,radius,'data+colorlist'
3178
        @ (xc : yc) center of circle diagram in xrange/yrange
3179
        @ radius in pixels
3180
        @ data+color list: a colon separated list of raw data and corresponding colours<br />canvasdraw will not check validity of colornames...<br />in case of trouble look into javascript debugging of your browser
3181
        @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
3182
        @ the number of colors must match the number of data.
3183
        @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
8224 bpr 3184
        @ use command "legend string1:string2:...:string_n" to automatically create a legend <br />using the same colours as pie segments<br />unicode allowed in legend<br />expect javascript trouble if the amount of 'pie-slices', 'pie-colours' 'pie-legend-titles' do not match<br />a javascript console is your best friend...<br />use command 'fontfamily' to set the font of the legend.
7614 schaersvoo 3185
        */
8224 bpr 3186
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
7614 schaersvoo 3187
            for(i=0;i<5;i++){
3188
                switch(i){
3189
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
3190
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
3191
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
3192
                    case 3: temp = get_string(infile,1);
3193
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
7956 schaersvoo 3194
                            string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family);
7614 schaersvoo 3195
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7956 schaersvoo 3196
                            snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\");\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family);
7614 schaersvoo 3197
                            add_to_buffer(tmp_buffer);
3198
                           break;
3199
                    default:break;
3200
                }
3201
            }
3202
            reset();
3203
        break;
3204
        case STATUS:
7877 schaersvoo 3205
        /*
3206
        @status
3207
        @keyword
3208
        @alernative keyword: nostatus
3209
        @used to override the effects of "status=done" in wims (answer.phtml)
3210
        @affects inputfields / textarea's in canvasimage and all userdraw based commands
3211
        @e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims status variable' is set to 'done'
3212
        */
8224 bpr 3213
 
7877 schaersvoo 3214
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
7614 schaersvoo 3215
            break;
7735 schaersvoo 3216
        case XLOGBASE:
7729 schaersvoo 3217
        /*
7735 schaersvoo 3218
        @ xlogbase number
3219
        @ sets the logbase number for the x-axis
7729 schaersvoo 3220
        @ default value 10
7735 schaersvoo 3221
        @ use together with commands xlogscale / xylogscale
7729 schaersvoo 3222
        */
7735 schaersvoo 3223
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7729 schaersvoo 3224
            break;
7735 schaersvoo 3225
        case YLOGBASE:
3226
        /*
3227
        @ ylogbase number
3228
        @ sets the logbase number for the y-axis
3229
        @ default value 10
3230
        @ use together with commands ylogscale / xylogscale
3231
        */
3232
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
3233
            break;
7614 schaersvoo 3234
        case XLOGSCALE:
3235
        /*
7735 schaersvoo 3236
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
3237
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3238
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
3239
         @ the linewidth is set using command 'linewidth int'
3240
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
3241
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
8224 bpr 3242
         @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'xlogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
7735 schaersvoo 3243
         @ note: the complete canvas will be used for the 'log paper'
3244
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3245
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
8224 bpr 3246
         @ note: when using something like 'xrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')
7735 schaersvoo 3247
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3248
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 3249
        */
7735 schaersvoo 3250
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3251
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
3252
            for(i=0;i<4;i++){
3253
                switch(i){
3254
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
3255
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
3256
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 3257
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 3258
                        string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7735 schaersvoo 3259
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3260
                        snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7735 schaersvoo 3261
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
3262
                        add_to_buffer(tmp_buffer);
3263
                        break;
3264
                    default:break;
3265
                }
3266
            }
7614 schaersvoo 3267
            break;
3268
        case YLOGSCALE:
7729 schaersvoo 3269
        /*
3270
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
3271
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3272
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
3273
         @ the linewidth is set using command 'linewidth int'
3274
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
7735 schaersvoo 3275
         @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
8224 bpr 3276
         @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use command 'precision' before 'ylogscale' command to set the precision (decimals) of the axis numbering</li><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
7729 schaersvoo 3277
         @ note: the complete canvas will be used for the 'log paper'
3278
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3279
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
8224 bpr 3280
         @ note: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')
7735 schaersvoo 3281
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3282
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
7729 schaersvoo 3283
        */
3284
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3285
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
3286
            for(i=0;i<4;i++){
3287
                switch(i){
3288
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
3289
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
3290
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 3291
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 3292
                        string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7729 schaersvoo 3293
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3294
                        snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%f,%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,double_data[0],int_data[0],precision);
7735 schaersvoo 3295
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 3296
                        add_to_buffer(tmp_buffer);
3297
                        break;
3298
                    default:break;
3299
                }
3300
            }
7614 schaersvoo 3301
            break;
3302
        case XYLOGSCALE:
7735 schaersvoo 3303
        /*
3304
         @ xylogscale majorcolor,minorcolor
3305
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3306
         @ the linewidth is set using command 'linewidth int'
3307
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
3308
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
8224 bpr 3309
         @ the x/y- axis numbering is triggered by keyword 'axisnumbering'<ul><li>use commands 'xlabel some_text' and/or 'ylabel some_text' for text on axis : use command 'fontsize int' to set the fontsize (default 12px)</li><li>use command 'fontfamily fnt_family_string' to set the fonts for axis-numbering</li><li>use command'fontcolor' to set the colour</li></ul>
7735 schaersvoo 3310
         @ note: the complete canvas will be used for the 'log paper'
3311
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3312
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
8224 bpr 3313
         @ note: when using something like 'yrange 0.0001,0.01'...combined with commands 'mouse color,fontsize' and/or 'userdraw type,color'...<br /> make sure the precision is set accordingly (eg command 'precision 10000')
7735 schaersvoo 3314
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3315
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
3316
        */
3317
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3318
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
3319
            for(i=0;i<2;i++){
3320
                switch(i){
3321
                    case 0: stroke_color = get_color(infile,0); break;
8224 bpr 3322
                    case 1: fill_color = get_color(infile,1);
7779 schaersvoo 3323
                        string_length = snprintf(NULL,0,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision);
7735 schaersvoo 3324
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3325
                        snprintf(tmp_buffer,string_length,"draw_grid%d(%d,%d,\"%s\",\"%s\",%.2f,%.2f,%d,\"%s\",\"%s\",%d,%d); ",canvas_root_id,GRID_CANVAS,line_width,stroke_color,fill_color,stroke_opacity,fill_opacity,font_size,font_family,font_color,use_axis_numbering,precision);
7735 schaersvoo 3326
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
3327
                        add_to_buffer(tmp_buffer);
3328
                        break;
3329
                    default:break;
3330
                }
3331
            }
3332
        break;
7614 schaersvoo 3333
        default:sync_input(infile);
3334
        break;
3335
    }
8224 bpr 3336
  }
7614 schaersvoo 3337
  /* we are done parsing script file */
7983 schaersvoo 3338
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
3339
  if( found_size_command == 1 ){
3340
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
3341
  }
3342
  else
3343
  {
3344
    if( found_size_command != 3 ){
8222 schaersvoo 3345
     canvas_error("Please specify both xrange and yrange ...");
7983 schaersvoo 3346
    }
3347
  }
8257 schaersvoo 3348
 
8222 schaersvoo 3349
  /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
7614 schaersvoo 3350
  add_javascript_functions(js_function,canvas_root_id);
3351
   /* add read_canvas() etc functions if needed */
8257 schaersvoo 3352
  if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
7797 schaersvoo 3353
  if( use_pan_and_zoom == TRUE ){
3354
  /* in case of zooming ... */
7729 schaersvoo 3355
  fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
7797 schaersvoo 3356
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 3357
  var ymin_start=ymin;var ymax_start=xmax;\
3358
  var zoom_x_increment=0;var zoom_y_increment=0;\
3359
  var pan_x_increment=0;var pan_y_increment=0;\
3360
  if(use_ylogscale == 0 ){\
7956 schaersvoo 3361
   zoom_x_increment = (xmax - xmin)/20;zoom_y_increment = (ymax - ymin)/20;pan_x_increment = (xmax - xmin)/20;pan_y_increment = (ymax - ymin)/20;\
7729 schaersvoo 3362
  }else{\
3363
   zoom_x_increment = (xmax - xmin)/20;\
3364
   pan_x_increment = (xmax - xmin)/20;\
3365
  };\
7653 schaersvoo 3366
  function start_canvas%d(type){\
3367
   switch(type){\
7729 schaersvoo 3368
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
3369
    case 1:xmin = xmin - zoom_x_increment;ymin = ymin - zoom_y_increment;xmax = xmax + zoom_x_increment;ymax = ymax + zoom_y_increment;break;\
7653 schaersvoo 3370
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
3371
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
3372
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
3373
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
3374
    case 6:location.reload();break;\
3375
    default:break;\
3376
   };\
3377
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
3378
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
3379
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
3380
   %s\
3381
  };\
7797 schaersvoo 3382
  start_canvas%d(333);\
7614 schaersvoo 3383
 };\n\
3384
<!-- end wims_canvas_function -->\n\
7797 schaersvoo 3385
wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
3386
  }
3387
  else
3388
  {
3389
  /* no zoom, just add buffer */
3390
  fprintf(js_include_file,"\n<!-- add buffer -->\n\
3391
  %s\
3392
 };\n\
3393
<!-- end wims_canvas_function -->\n\
3394
wims_canvas_function%d();\n",buffer,canvas_root_id);
3395
  }
7614 schaersvoo 3396
/* done writing the javascript include file */
3397
fclose(js_include_file);
3398
 
3399
}
3400
 
3401
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
3402
if(use_tooltip == TRUE){
3403
  add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
3404
}
3405
exit(EXIT_SUCCESS);
3406
}
3407
/* end main() */
3408
 
3409
/******************************************************************************
3410
**
3411
**  sync_input
3412
**
3413
**  synchronises input line - reads to end of line, leaving file pointer
3414
**  at first character of next line.
3415
**
3416
**  Used by:
3417
**  main program - error handling.
3418
**
3419
******************************************************************************/
3420
void sync_input(FILE *infile)
3421
{
3422
        int c = 0;
3423
 
7658 schaersvoo 3424
        if( c == '\n' || c == ';' ) return;
3425
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 3426
        if( c == EOF ) finished = 1;
7658 schaersvoo 3427
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 3428
        return;
3429
}
3430
 
3431
/******************************************************************************/
3432
 
3433
char *str_replace(const char *str, const char *old, const char *new){
3434
/* http://creativeandcritical.net/str-replace-c/ */
3435
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
3436
    char *ret, *r;
3437
    const char *p, *q;
3438
    size_t oldlen = strlen(old);
3439
    size_t count = 0;
3440
    size_t retlen = 0;
3441
    size_t newlen = strlen(new);
3442
    if (oldlen != newlen){
3443
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
3444
            count++;
3445
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
3446
        }
8224 bpr 3447
    }
7614 schaersvoo 3448
    else
3449
    {
3450
        retlen = strlen(str);
3451
    }
8224 bpr 3452
 
7614 schaersvoo 3453
    if ((ret = malloc(retlen + 1)) == NULL){
3454
        ret = NULL;
3455
        canvas_error("string argument is NULL");
3456
    }
3457
    else
3458
    {
3459
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
3460
            size_t l = q - p;
3461
            memcpy(r, p, l);
3462
            r += l;
3463
            memcpy(r, new, newlen);
3464
            r += newlen;
3465
        }
3466
        strcpy(r, p);
3467
    }
3468
    return ret;
3469
}
3470
 
3471
/******************************************************************************/
7848 bpr 3472
 
7614 schaersvoo 3473
char *get_color(FILE *infile , int last){
3474
    int c,i = 0,is_hex = 0;
3475
    char temp[MAX_COLOR_STRING], *string;
7748 schaersvoo 3476
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
7614 schaersvoo 3477
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
3478
        if( c == '#' ){
3479
            is_hex = 1;
3480
        }
3481
        if( c != ' '){
3482
            temp[i]=tolower(c);
3483
            i++;
3484
        }
3485
    }
8224 bpr 3486
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3487
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
7614 schaersvoo 3488
    if( c == EOF ){finished = 1;}
3489
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
3490
    temp[i]='\0';
3491
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
3492
    if( is_hex == 1 ){
3493
        char red[3], green[3], blue[3];
3494
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
3495
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
3496
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
3497
        int r = (int) strtol(red,   NULL, 16);
3498
        int g = (int) strtol(green, NULL, 16);
3499
        int b = (int) strtol(blue,  NULL, 16);
3500
        string = (char *)my_newmem(12);
3501
        snprintf(string,11,"%d,%d,%d",r,g,b);
3502
        return string;
3503
    }
3504
    else
3505
    {
3506
        string = (char *)my_newmem(sizeof(temp));
3507
        snprintf(string,sizeof(temp),"%s",temp);
3508
        for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
3509
            if( strcmp( colors[i].name , string ) == 0 ){
3510
                return colors[i].rgb;
3511
            }
3512
        }
3513
    }
3514
    /* not found...return error */
3515
    free(string);string = NULL;
3516
    canvas_error("I was expecting a color name or hexnumber...but found nothing.");
3517
    return NULL;
3518
}
3519
 
3520
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
3521
    int c,i=0;
3522
    char  temp[MAX_BUFFER], *string;
7748 schaersvoo 3523
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
7614 schaersvoo 3524
        temp[i]=c;
3525
        i++;
3526
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
3527
    }
8224 bpr 3528
    if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3529
    if( c == '\n') { done = TRUE; line_number++; }
7614 schaersvoo 3530
    if( c == EOF ) {
3531
        finished = 1;
3532
        if( last != 1 ){ canvas_error("expected more arguments");}
3533
    }
3534
    temp[i]='\0';
3535
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
3536
    string=(char *)my_newmem(strlen(temp));
3537
    snprintf(string,sizeof(temp),"%s",temp);
3538
    return string;
3539
}
3540
 
3541
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
3542
    int c,i=0;
3543
    char temp[MAX_BUFFER], *string;
7748 schaersvoo 3544
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
7614 schaersvoo 3545
        temp[i]=c;
3546
        i++;
3547
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
3548
    }
8224 bpr 3549
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3550
    if( c == '\n') { line_number++; }
7614 schaersvoo 3551
    if( c == EOF ) {finished = 1;}
3552
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
3553
    temp[i]='\0';
3554
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
3555
    string=(char *)my_newmem(sizeof(temp));
3556
    snprintf(string,sizeof(temp),"%s",temp);
3557
    done = TRUE;
3558
    return string;
3559
}
3560
 
3561
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
3562
    int c,i=0,found_calc = 0;
3563
    double y;
3564
    char tmp[MAX_INT];
7658 schaersvoo 3565
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
7614 schaersvoo 3566
     if( c != ' ' ){
8224 bpr 3567
     /*
3568
     libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
7614 schaersvoo 3569
     We will check after assert() if it's a NULL pointer...and exit program via :
3570
     canvas_error("I'm having trouble parsing your \"expression\" ");
3571
     */
8224 bpr 3572
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 3573
       continue;
8224 bpr 3574
      }
7614 schaersvoo 3575
      else
3576
      {
3577
       if(canvas_iscalculation(c) != 0){
3578
        found_calc = 1;
3579
        c = tolower(c);
3580
       }
3581
       tmp[i] = c;
3582
       i++;
3583
      }
3584
     }
3585
     if( i > MAX_INT - 1){canvas_error("number too large");}
3586
    }
8224 bpr 3587
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
7658 schaersvoo 3588
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
7614 schaersvoo 3589
    if( c == EOF ){done = TRUE ; finished = 1;}
3590
    tmp[i]='\0';
3591
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
3592
    if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
7848 bpr 3593
     void *f = eval_create(tmp);
7614 schaersvoo 3594
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 3595
     y = eval_x(f, 1);
7614 schaersvoo 3596
     /* if function is bogus; y = 1 : so no core dumps */
7848 bpr 3597
     eval_destroy(f);
7614 schaersvoo 3598
    }
3599
    else
3600
    {
3601
     y = atof(tmp);
3602
    }
3603
    return y;
3604
}
3605
void canvas_error(char *msg){
7748 schaersvoo 3606
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
7614 schaersvoo 3607
    finished = 1;
3608
    exit(EXIT_SUCCESS);
3609
}
3610
 
3611
 
3612
/* convert x/y coordinates to pixel */
3613
int x2px(double x){
3614
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
3615
}
3616
 
3617
int y2px(double y){
3618
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
3619
}
3620
 
3621
double px2x(int x){
3622
 return (x*(xmax - xmin)/xsize + xmin);
3623
}
3624
double px2y(int y){
3625
 return (y*(ymax - ymin)/ysize + ymin);
3626
}
3627
 
3628
void add_to_buffer(char *tmp){
3629
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
3630
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
3631
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
3632
 if( space_left > strlen(tmp)){
3633
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
3634
 }
3635
 else
3636
 {
3637
  canvas_error("buffer is too big\n");
3638
 }
3639
 tmp = NULL;free(tmp);
3640
 return;
3641
}
3642
 
3643
void reset(){
3644
 if(use_filled == TRUE){use_filled = FALSE;}
3645
 if(use_dashed == TRUE){use_dashed = FALSE;}
3646
 if(use_rotate == TRUE){use_rotate = FALSE;}
8101 schaersvoo 3647
   onclick = 0;
7614 schaersvoo 3648
}
3649
 
3650
 
3651
 
3652
/* What reply format in read_canvas();
3653
 
3654
note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
3655
1 = x1,x2,x3,x4....x_n
3656
    y1,y2,y3,y4....y_n
3657
 
3658
    x/y in pixels
3659
 
3660
2 = x1,x2,x3,x4....x_n
3661
    y1,y2,y3,y4....y_n
3662
    x/y in  xrange / yrange coordinate system
3663
 
3664
3 = x1,x2,x3,x4....x_n
3665
    y1,y2,y3,y4....y_n
3666
    r1,r2,r3,r4....r_n
3667
 
8224 bpr 3668
    x/y in pixels
7614 schaersvoo 3669
    r in pixels
3670
 
3671
4 = x1,x2,x3,x4....x_n
3672
    y1,y2,y3,y4....y_n
3673
    r1,r2,r3,r4....r_n
3674
 
3675
    x/y in  xrange / yrange coordinate system
3676
    r in pixels
3677
 
3678
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
3679
    Ay1,Ay2,Ay3,Ay4....Ay_n
3680
    Bx1,Bx2,Bx3,Bx4....Bx_n
3681
    By1,By2,By3,By4....By_n
3682
    Cx1,Cx2,Cx3,Cx4....Cx_n
3683
    Cy1,Cy2,Cy3,Cy4....Cy_n
3684
    ....
3685
    Zx1,Zx2,Zx3,Zx4....Zx_n
3686
    Zy1,Zy2,Zy3,Zy4....Zy_n
8224 bpr 3687
 
7614 schaersvoo 3688
    x/y in pixels
3689
 
3690
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
3691
    Ay1,Ay2,Ay3,Ay4....Ay_n
3692
    Bx1,Bx2,Bx3,Bx4....Bx_n
3693
    By1,By2,By3,By4....By_n
3694
    Cx1,Cx2,Cx3,Cx4....Cx_n
3695
    Cy1,Cy2,Cy3,Cy4....Cy_n
3696
    ....
3697
    Zx1,Zx2,Zx3,Zx4....Zx_n
3698
    Zy1,Zy2,Zy3,Zy4....Zy_n
3699
 
3700
    x/y in  xrange / yrange coordinate system
8224 bpr 3701
 
7614 schaersvoo 3702
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 3703
 
7614 schaersvoo 3704
    x/y in pixels
3705
 
3706
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 3707
 
7614 schaersvoo 3708
    x/y in  xrange / yrange coordinate system
3709
 
8224 bpr 3710
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 3711
 
3712
    x/y in pixels
3713
 
8224 bpr 3714
10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 3715
 
3716
    x/y in  xrange / yrange coordinate system
3717
 
3718
11 = Ax1,Ay1,Ax2,Ay2
3719
     Bx1,By1,Bx2,By2
3720
     Cx1,Cy1,Cx2,Cy2
3721
     Dx1,Dy1,Dx2,Dy2
3722
     ......
3723
     Zx1,Zy1,Zx2,Zy2
8224 bpr 3724
 
7614 schaersvoo 3725
    x/y in  xrange / yrange coordinate system
3726
 
3727
12 = Ax1,Ay1,Ax2,Ay2
3728
     Bx1,By1,Bx2,By2
3729
     Cx1,Cy1,Cx2,Cy2
3730
     Dx1,Dy1,Dx2,Dy2
3731
     ......
3732
     Zx1,Zy1,Zx2,Zy2
8224 bpr 3733
 
7614 schaersvoo 3734
    x/y in pixels
3735
 
3736
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
3737
 
3738
    x/y in  xrange / yrange coordinate system
3739
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
3740
    x/y in pixels
3741
15 = reply from inputfields,textareas
3742
    reply1,reply2,reply3,...,reply_n
7984 schaersvoo 3743
    only fields set write (a.g. will not read 'readonly' inputfield values'
7614 schaersvoo 3744
 
3745
16 = read mathml inputfields only
3746
 
3747
17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
3748
 when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
3749
 
3750
18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
3751
19 = return clicked object number (analogue to shape-library onclick)
3752
20 = return x/y-data in x-range/y-range of all 'draggable' images
3753
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
3754
22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
3755
    x/y in  xrange / yrange coordinate system
8224 bpr 3756
23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
7984 schaersvoo 3757
24 = read all inputfield values: even those set 'readonly'
8224 bpr 3758
25 = return all userdrawn arcs in degrees:
3759
26 = return all userdrawn arcs in radians:
8127 schaersvoo 3760
27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...
7614 schaersvoo 3761
*/
3762
 
3763
 
8257 schaersvoo 3764
void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
7614 schaersvoo 3765
/* just 1 reply type allowed */
8074 schaersvoo 3766
fprintf(js_include_file,"\
3767
\n<!-- begin set_reply_precision() -->\n\
3768
function set_reply_precision(){\
3769
 var len = userdraw_x.length;\
3770
 var prec = %d;\
3771
 for(var p = 0 ; p < len ; p++ ){\
3772
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
3773
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
3774
 };\
3775
 len = userdraw_radius.length;\
3776
 if( len > 0 ){\
3777
  for(var p = 0 ; p < len ; p++ ){\
3778
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
3779
  };\
3780
 };\
3781
};",reply_precision);
7963 schaersvoo 3782
 
7614 schaersvoo 3783
switch(type_reply){
8224 bpr 3784
/*
7614 schaersvoo 3785
answers may have:
3786
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
3787
*/
3788
    case 1: fprintf(js_include_file,"\
8257 schaersvoo 3789
\n<!-- begin function 1 read_canvas%d() -->\n\
3790
read_canvas%d = function(){\
7614 schaersvoo 3791
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3792
 set_reply_precision();\
7614 schaersvoo 3793
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3794
  var p = 0;var input_reply = new Array();\
3795
  if( document.getElementById(\"canvas_input0\")){\
3796
   var t = 0;\
3797
   while(document.getElementById(\"canvas_input\"+t)){\
3798
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3799
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3800
     p++;\
3801
    };\
3802
    t++;\
3803
   };\
3804
  };\
3805
  if( typeof userdraw_text != 'undefined' ){\
3806
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
3807
  }\
3808
  else\
3809
  {\
3810
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
3811
  }\
3812
 }\
3813
 else\
3814
 {\
3815
  if( typeof userdraw_text != 'undefined' ){\
3816
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
3817
  }\
3818
  else\
3819
  {\
3820
   return userdraw_x+\"\\n\"+userdraw_y;\
3821
  }\
3822
 };\
8108 schaersvoo 3823
};\n\
8257 schaersvoo 3824
<!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 3825
    break;
3826
    case 2: fprintf(js_include_file,"\
8257 schaersvoo 3827
\n<!-- begin function 2 read_canvas%d() -->\n\
3828
read_canvas%d = function(){\
7614 schaersvoo 3829
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3830
 set_reply_precision();\
7614 schaersvoo 3831
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 3832
 var prec = %d;\
7614 schaersvoo 3833
 while(userdraw_x[p]){\
8074 schaersvoo 3834
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
3835
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 3836
  p++;\
3837
 };\
3838
 if(p == 0){alert(\"nothing drawn...\");return;};\
3839
 if( document.getElementById(\"canvas_input0\")){\
3840
  var p = 0;var input_reply = new Array();\
3841
  if( document.getElementById(\"canvas_input0\")){\
3842
   var t = 0;\
3843
   while(document.getElementById(\"canvas_input\"+t)){\
3844
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3845
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3846
     p++;\
3847
    };\
3848
    t++;\
3849
   };\
3850
  };\
3851
  if( typeof userdraw_text != 'undefined' ){\
3852
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3853
  }\
3854
  else\
3855
  {\
3856
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
3857
  }\
3858
 }\
3859
 else\
3860
 {\
3861
  if( typeof userdraw_text != 'undefined' ){\
3862
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
3863
  }\
3864
  else\
3865
  {\
3866
   return reply_x+\"\\n\"+reply_y;\
3867
  };\
3868
 };\
8108 schaersvoo 3869
};\n\
8257 schaersvoo 3870
<!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 3871
    break;
3872
    case 3: fprintf(js_include_file,"\
8257 schaersvoo 3873
\n<!-- begin function 3 read_canvas%d() -->\n\
3874
read_canvas%d = function(){\
7614 schaersvoo 3875
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3876
 set_reply_precision();\
7614 schaersvoo 3877
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3878
  var p = 0;var input_reply = new Array();\
3879
  if( document.getElementById(\"canvas_input0\")){\
3880
   var t = 0;\
3881
   while(document.getElementById(\"canvas_input\"+t)){\
3882
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3883
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3884
     p++;\
3885
    };\
3886
    t++;\
3887
   };\
3888
  };\
3889
  if( typeof userdraw_text != 'undefined' ){\
3890
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3891
  }\
3892
  else\
3893
  {\
3894
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
3895
  }\
3896
 }\
3897
 else\
3898
 {\
3899
  if( typeof userdraw_text != 'undefined' ){\
3900
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
3901
  }\
3902
  else\
3903
  {\
3904
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
3905
  }\
3906
 }\
8108 schaersvoo 3907
};\n\
8257 schaersvoo 3908
<!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 3909
    break;
3910
    case 4: fprintf(js_include_file,"\
8257 schaersvoo 3911
\n<!-- begin function 4 read_canvas%d() -->\n\
3912
read_canvas%d = function(){\
8074 schaersvoo 3913
 var prec = %d;\
7614 schaersvoo 3914
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
3915
 while(userdraw_x[p]){\
8074 schaersvoo 3916
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
3917
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 3918
  p++;\
3919
 };\
3920
 if(p == 0){alert(\"nothing drawn...\");return;};\
3921
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3922
  var p = 0;var input_reply = new Array();\
3923
  if( document.getElementById(\"canvas_input0\")){\
3924
   var t = 0;\
3925
   while(document.getElementById(\"canvas_input\"+t)){\
3926
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3927
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3928
     p++;\
3929
    };\
3930
    t++;\
3931
   };\
3932
  };\
3933
  if( typeof userdraw_text != 'undefined' ){\
3934
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3935
  }\
3936
  else\
3937
  {\
3938
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
3939
  }\
3940
 }\
3941
 else\
3942
 {\
3943
  if( typeof userdraw_text != 'undefined' ){\
3944
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
3945
  }\
3946
  else\
3947
  {\
3948
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
3949
  }\
3950
 };\
8108 schaersvoo 3951
};\n\
8257 schaersvoo 3952
<!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 3953
    break;
8224 bpr 3954
    /*
3955
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
3956
        used for userdraw multiple paths
7614 schaersvoo 3957
    */
3958
    case 5: fprintf(js_include_file,"\
8257 schaersvoo 3959
\n<!-- begin function 5 read_canvas%d() -->\n\
3960
read_canvas%d = function(){\
8074 schaersvoo 3961
 set_reply_precision();\
7614 schaersvoo 3962
 var p = 0;\
3963
 var reply = \"\";\
3964
 for(p = 0; p < userdraw_x.length;p++){\
3965
  if(userdraw_x[p] != null ){\
3966
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
3967
  };\
3968
 };\
3969
 if(p == 0){alert(\"nothing drawn...\");return;};\
3970
 userdraw_x = [];userdraw_y = [];\
3971
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3972
  var p = 0;var input_reply = new Array();\
3973
  if( document.getElementById(\"canvas_input0\")){\
3974
   var t = 0;\
3975
   while(document.getElementById(\"canvas_input\"+t)){\
3976
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3977
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3978
     p++;\
3979
    };\
3980
    t++;\
3981
   };\
3982
  };\
3983
  if( typeof userdraw_text != 'undefined' ){\
3984
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3985
  }\
3986
  else\
3987
  {\
3988
   return reply +\"\\n\"+input_reply;\
3989
  }\
3990
 }\
3991
 else\
3992
 {\
3993
  if( typeof userdraw_text != 'undefined' ){\
3994
   return reply+\"\\n\"+userdraw_text;\
3995
  }\
3996
  else\
3997
  {\
3998
   return reply;\
3999
  }\
4000
 };\
8108 schaersvoo 4001
};\n\
8257 schaersvoo 4002
<!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4003
    break;
8224 bpr 4004
    /*
4005
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
4006
        used for userdraw multiple paths
7614 schaersvoo 4007
    */
4008
    case 6: fprintf(js_include_file,"\
8257 schaersvoo 4009
\n<!-- begin function 6 read_canvas%d() -->\n\
4010
read_canvas%d = function(){\
7614 schaersvoo 4011
 var p = 0;\
4012
 var reply = \"\";\
4013
 var tmp_x = new Array();\
4014
 var tmp_y = new Array();\
8074 schaersvoo 4015
 var prec = %d;\
7614 schaersvoo 4016
 for(p = 0 ; p < userdraw_x.length; p++){\
4017
  tmp_x = userdraw_x[p];\
4018
  tmp_y = userdraw_y[p];\
4019
  if(tmp_x != null){\
4020
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 4021
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
4022
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 4023
   };\
4024
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
4025
  };\
4026
 };\
4027
 if(p == 0){alert(\"nothing drawn...\");return;};\
4028
 userdraw_x = [];userdraw_y = [];\
4029
 if( document.getElementById(\"canvas_input0\") ){\
4030
  var p = 0;var input_reply = new Array();\
4031
  if( document.getElementById(\"canvas_input0\")){\
4032
   var t = 0;\
4033
   while(document.getElementById(\"canvas_input\"+t)){\
4034
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4035
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4036
     p++;\
4037
    };\
4038
    t++;\
4039
   };\
4040
  };\
4041
  if( typeof userdraw_text != 'undefined' ){\
4042
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4043
  }\
4044
  else\
4045
  {\
4046
   return reply +\"\\n\"+input_reply;\
4047
  }\
4048
 }\
4049
 else\
4050
 {\
4051
  if( typeof userdraw_text != 'undefined' ){\
4052
   return reply +\"\\n\"+userdraw_text;\
4053
  }\
4054
  else\
4055
  {\
4056
   return reply;\
4057
  }\
4058
 };\
8108 schaersvoo 4059
};\n\
8257 schaersvoo 4060
<!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4061
    break;
4062
    case 7: fprintf(js_include_file,"\
8257 schaersvoo 4063
\n<!-- begin function 7 read_canvas%d() -->\n\
4064
read_canvas%d = function(){\
8074 schaersvoo 4065
 set_reply_precision();\
7614 schaersvoo 4066
 var reply = new Array();\
4067
 var p = 0;\
4068
 while(userdraw_x[p]){\
4069
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
4070
  p++;\
4071
 };\
4072
 if(p == 0){alert(\"nothing drawn...\");return;};\
4073
 if( document.getElementById(\"canvas_input0\") ){\
4074
  var p = 0;var input_reply = new Array();\
4075
  if( document.getElementById(\"canvas_input0\")){\
4076
   var t = 0;\
4077
   while(document.getElementById(\"canvas_input\"+t)){\
4078
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4079
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4080
     p++;\
4081
    };\
4082
    t++;\
4083
   };\
4084
  };\
4085
  if( typeof userdraw_text != 'undefined' ){\
4086
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4087
  }\
4088
  else\
4089
  {\
4090
   return reply+\"\\n\"+input_reply;\
4091
  }\
7862 schaersvoo 4092
 }\
7614 schaersvoo 4093
 else\
4094
 {\
4095
  if( typeof userdraw_text != 'undefined' ){\
4096
   return reply+\"\\n\"+userdraw_text;\
4097
  }\
4098
  else\
4099
  {\
4100
   return reply;\
4101
  }\
4102
 };\
8108 schaersvoo 4103
};\n\
8257 schaersvoo 4104
<!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4105
    break;
4106
    case 8: fprintf(js_include_file,"\
8257 schaersvoo 4107
\n<!-- begin function 8 read_canvas%d() -->\n\
4108
read_canvas%d = function(){\
7614 schaersvoo 4109
 var reply = new Array();\
4110
 var p = 0;\
8074 schaersvoo 4111
 var prec = %d;\
7614 schaersvoo 4112
 while(userdraw_x[p]){\
8074 schaersvoo 4113
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 4114
  p++;\
4115
 };\
4116
 if(p == 0){alert(\"nothing drawn...\");return;};\
4117
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
4118
  var p = 0;var input_reply = new Array();\
4119
  if( document.getElementById(\"canvas_input0\")){\
4120
   var t = 0;\
4121
   while(document.getElementById(\"canvas_input\"+t)){\
4122
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4123
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4124
     p++;\
4125
    };\
4126
    t++;\
4127
   };\
4128
  };\
4129
  if( typeof userdraw_text != 'undefined' ){\
4130
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4131
  }\
4132
  else\
4133
  {\
4134
   return reply +\"\\n\"+input_reply;\
4135
  }\
4136
 }\
4137
 else\
4138
 {\
4139
  if( typeof userdraw_text != 'undefined' ){\
4140
   return reply +\"\\n\"+userdraw_text;\
4141
  }\
4142
  else\
4143
  {\
4144
   return reply;\
4145
  }\
4146
 };\
8108 schaersvoo 4147
};\n\
8257 schaersvoo 4148
<!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4149
    break;
4150
    case 9: fprintf(js_include_file,"\
8257 schaersvoo 4151
\n<!-- begin function 9 read_canvas%d() -->\n\
4152
read_canvas%d = function(){\
8074 schaersvoo 4153
 set_reply_precision();\
7614 schaersvoo 4154
 var reply = new Array();\
4155
 var p = 0;\
4156
 while(userdraw_x[p]){\
4157
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
4158
  p++;\
4159
 };\
4160
 if(p == 0){alert(\"nothing drawn...\");return;};\
4161
 if( document.getElementById(\"canvas_input0\") ){\
4162
  var p = 0;var input_reply = new Array();\
4163
  if( document.getElementById(\"canvas_input0\")){\
4164
   var t = 0;\
4165
   while(document.getElementById(\"canvas_input\"+t)){\
4166
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4167
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4168
     p++;\
4169
    };\
4170
    t++;\
4171
   };\
4172
  };\
4173
  if( typeof userdraw_text != 'undefined' ){\
4174
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4175
  }\
4176
  else\
4177
  {\
4178
   return reply +\"\\n\"+input_reply;\
4179
  }\
4180
 }\
4181
 else\
4182
 {\
4183
  if( typeof userdraw_text != 'undefined' ){\
4184
   return reply +\"\\n\"+userdraw_text;\
4185
  }\
4186
  else\
4187
  {\
4188
   return reply;\
4189
  }\
4190
 };\
8108 schaersvoo 4191
};\n\
8257 schaersvoo 4192
<!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4193
    break;
4194
    case 10: fprintf(js_include_file,"\
8257 schaersvoo 4195
\n<!-- begin function 10 read_canvas%d() -->\n\
4196
read_canvas%d = function(){\
7614 schaersvoo 4197
 var reply = new Array();\
4198
 var p = 0;\
8074 schaersvoo 4199
 var prec = %d;\
7614 schaersvoo 4200
 while(userdraw_x[p]){\
8074 schaersvoo 4201
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*userdraw_radius[p]))/prec;\
7614 schaersvoo 4202
  p++;\
4203
 };\
4204
 if(p == 0){alert(\"nothing drawn...\");return;};\
4205
 if( document.getElementById(\"canvas_input0\") ){\
4206
  var p = 0;var input_reply = new Array();\
4207
  if( document.getElementById(\"canvas_input0\")){\
4208
   var t = 0;\
4209
   while(document.getElementById(\"canvas_input\"+t)){\
4210
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4211
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4212
     p++;\
4213
    };\
4214
    t++;\
4215
   };\
4216
  };\
4217
  if( typeof userdraw_text != 'undefined' ){\
4218
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4219
  }\
4220
  else\
4221
  {\
4222
   return reply +\"\\n\"+input_reply;\
4223
  }\
4224
 }\
4225
 else\
4226
 {\
4227
  if( typeof userdraw_text != 'undefined' ){\
4228
   return reply +\"\\n\"+userdraw_text;\
4229
  }\
4230
  else\
4231
  {\
4232
   return reply;\
4233
  }\
4234
 };\
8108 schaersvoo 4235
};\n\
8257 schaersvoo 4236
<!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4237
    break;
4238
    case 11: fprintf(js_include_file,"\
8257 schaersvoo 4239
\n<!-- begin function 11 read_canvas%d() -->\n\
4240
read_canvas%d = function(){\
7614 schaersvoo 4241
 var reply = \"\";\
4242
 var p = 0;\
8074 schaersvoo 4243
 var prec = %d;\
7614 schaersvoo 4244
 while(userdraw_x[p]){\
8074 schaersvoo 4245
  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\
7614 schaersvoo 4246
  p = p+2;\
4247
 };\
4248
 if(p == 0){alert(\"nothing drawn...\");return;};\
4249
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
4250
  var p = 0;var input_reply = new Array();\
4251
  if( document.getElementById(\"canvas_input0\")){\
4252
   var t = 0;\
4253
   while(document.getElementById(\"canvas_input\"+t)){\
4254
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4255
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4256
     p++;\
4257
    };\
4258
    t++;\
4259
   };\
4260
  };\
4261
  if( typeof userdraw_text != 'undefined' ){\
4262
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4263
  }\
4264
  else\
4265
  {\
4266
   return reply +\"\\n\"+input_reply;\
4267
  }\
4268
 }\
4269
 else\
4270
 {\
4271
  if( typeof userdraw_text != 'undefined' ){\
4272
   return reply +\"\\n\"+userdraw_text;\
4273
  }\
4274
  else\
4275
  {\
4276
   return reply;\
4277
  }\
4278
 };\
8108 schaersvoo 4279
};\n\
8257 schaersvoo 4280
<!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4281
    break;
4282
    case 12: fprintf(js_include_file,"\
8257 schaersvoo 4283
\n<!-- begin function 12 read_canvas%d() -->\n\
4284
read_canvas%d = function(){\
8074 schaersvoo 4285
 set_reply_precision();\
7614 schaersvoo 4286
 var reply = \"\";\
4287
 var p = 0;\
4288
 for(p = 0; p< userdraw_x.lenght;p = p+2){\
4289
  if(userdraw_x[p] != null){\
4290
    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
4291
  };\
4292
 };\
4293
 if(p == 0){alert(\"nothing drawn...\");return;};\
4294
 if( document.getElementById(\"canvas_input0\") ){\
4295
  var p = 0;var input_reply = new Array();\
4296
  if( document.getElementById(\"canvas_input0\")){\
4297
   var t = 0;\
4298
   while(document.getElementById(\"canvas_input\"+t)){\
4299
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4300
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4301
     p++;\
4302
    };\
4303
    t++;\
4304
   };\
4305
  };\
4306
  if( typeof userdraw_text != 'undefined' ){\
4307
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4308
  }\
4309
  else\
4310
  {\
4311
   return reply +\"\\n\"+input_reply;\
4312
  }\
4313
 }\
4314
 else\
4315
 {\
4316
  if( typeof userdraw_text != 'undefined' ){\
4317
   return reply +\"\\n\"+userdraw_text\
4318
  }\
4319
  else\
4320
  {\
4321
   return reply;\
4322
  }\
4323
 };\
8108 schaersvoo 4324
};\n\
8257 schaersvoo 4325
<!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4326
    break;
4327
    case 13: fprintf(js_include_file,"\
8257 schaersvoo 4328
\n<!-- begin function 13 read_canvas%d() -->\n\
4329
read_canvas%d = function(){\
7614 schaersvoo 4330
 var reply = new Array();\
4331
 var p = 0;var i = 0;\
8074 schaersvoo 4332
 var prec = %d;\
7614 schaersvoo 4333
 while(userdraw_x[p]){\
8074 schaersvoo 4334
  reply[i] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\":\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec;\
7614 schaersvoo 4335
  p = p+2;i++;\
4336
 };\
4337
 if(p == 0){alert(\"nothing drawn...\");return;};\
4338
 if( document.getElementById(\"canvas_input0\") ){\
4339
  var p = 0;var input_reply = new Array();\
4340
  if( document.getElementById(\"canvas_input0\")){\
4341
   var t = 0;\
4342
   while(document.getElementById(\"canvas_input\"+t)){\
4343
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4344
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4345
     p++;\
4346
    };\
4347
    t++;\
4348
   };\
4349
  };\
4350
  if( typeof userdraw_text != 'undefined' ){\
4351
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4352
  }\
4353
  else\
4354
  {\
4355
   return reply +\"\\n\"+input_reply;\
4356
  }\
4357
 }\
4358
 else\
4359
 {\
4360
  if( typeof userdraw_text != 'undefined' ){\
4361
   return reply +\"\\n\"+userdraw_text\
4362
  }\
4363
  else\
4364
  {\
4365
   return reply;\
4366
  }\
4367
 };\
8108 schaersvoo 4368
};\n\
8257 schaersvoo 4369
<!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4370
    break;
4371
    case 14: fprintf(js_include_file,"\
8257 schaersvoo 4372
\n<!-- begin function 14 read_canvas%d() -->\n\
4373
read_canvas%d = function(){\
8074 schaersvoo 4374
 set_reply_precision();\
7614 schaersvoo 4375
 var reply = new Array();\
4376
 var p = 0;var i = 0;\
4377
 while(userdraw_x[p]){\
4378
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
4379
  p = p+2;i++;\
4380
 };\
4381
 if(p == 0){alert(\"nothing drawn...\");return;};\
4382
 if( document.getElementById(\"canvas_input0\") ){\
4383
  var p = 0;var input_reply = new Array();\
4384
  if( document.getElementById(\"canvas_input0\")){\
4385
   var t = 0;\
4386
   while(document.getElementById(\"canvas_input\"+t)){\
4387
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4388
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4389
     p++;\
4390
    };\
4391
    t++;\
4392
   };\
4393
  };\
4394
  if( typeof userdraw_text != 'undefined' ){\
4395
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4396
  }\
4397
  else\
4398
  {\
4399
   return reply +\"\\n\"+input_reply;\
4400
  }\
4401
 }\
4402
 else\
4403
 {\
4404
  if( typeof userdraw_text != 'undefined' ){\
4405
   return reply +\"\\n\"+userdraw_text;\
4406
  }\
4407
  else\
4408
  {\
4409
   return reply;\
4410
  }\
4411
 };\
8108 schaersvoo 4412
};\n\
8257 schaersvoo 4413
<!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4414
    break;
4415
    case 15: fprintf(js_include_file,"\
8257 schaersvoo 4416
\n<!-- begin function 15  read_canvas%d() -->\n\
4417
read_canvas%d = function(){\
7614 schaersvoo 4418
 var input_reply = new Array();\
4419
 var p = 0;\
4420
 if( document.getElementById(\"canvas_input0\")){\
4421
  var t = 0;\
4422
  while(document.getElementById(\"canvas_input\"+t)){\
4423
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4424
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4425
    p++;\
4426
   };\
4427
   t++;\
4428
  };\
4429
 };\
4430
 if( typeof userdraw_text != 'undefined' ){\
4431
   return input_reply +\"\\n\"+userdraw_text;\
4432
 }\
4433
 else\
4434
 {\
4435
  return input_reply;\
4436
 };\
8108 schaersvoo 4437
};\n\
8257 schaersvoo 4438
<!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4439
    break;
4440
    case 16: fprintf(js_include_file,"\
7653 schaersvoo 4441
\n<!-- begin function 16 read_mathml() -->\n\
7614 schaersvoo 4442
function read_mathml(){\
4443
 var reply = new Array();\
4444
 var p = 0;\
4445
 if( document.getElementById(\"mathml0\")){\
4446
  while(document.getElementById(\"mathml\"+p)){\
4447
   reply[p] = document.getElementById(\"mathml\"+p).value;\
4448
   p++;\
4449
  };\
4450
 };\
4451
return reply;\
4452
};\
4453
this.read_mathml = read_mathml;\n\
7653 schaersvoo 4454
<!-- end function 16 read_mathml() -->");
7614 schaersvoo 4455
    break;
4456
    case 17:  fprintf(js_include_file,"\
8257 schaersvoo 4457
\n<!-- begin function 17 read_canvas%d() -->\n\
4458
read_canvas%d = function(){\
7614 schaersvoo 4459
 if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
4460
 return userdraw_text;\
8108 schaersvoo 4461
};\n\
8257 schaersvoo 4462
<!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4463
    break;
4464
    case 18: fprintf(js_include_file,"\
8257 schaersvoo 4465
\n<!-- begin function 18 read_canvas%d() -->\n\
4466
read_canvas%d = function(){\
7614 schaersvoo 4467
 var p = 0;\
4468
 var reply = new Array();\
4469
 var name;\
4470
 var t = true;\
8000 schaersvoo 4471
 var h;var m;var s;\
7614 schaersvoo 4472
 while(t){\
8000 schaersvoo 4473
  try{\
4474
   name = eval('clocks'+p);\
4475
   h = name.H;m = name.M;s = name.S;\
4476
   if(s < 0){s = 60 + s;m = m - 1;};\
4477
   if(m < 0){m = 60 + m;h = h - 1;};\
4478
   if(h < 0){h = 12 + h;};\
4479
   h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\
4480
   reply[p] = h+\":\"+m+\":\"+s;\
4481
   p++;\
4482
  }catch(e){t=false;};\
7614 schaersvoo 4483
 };\
8000 schaersvoo 4484
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 4485
 return reply;\
8108 schaersvoo 4486
};\n\
8257 schaersvoo 4487
<!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4488
    break;
4489
    case 19: fprintf(js_include_file,"\
8257 schaersvoo 4490
\n<!-- begin function 19 read_canvas%d() -->\n\
4491
read_canvas%d = function(){\
7614 schaersvoo 4492
 return reply[0];\
8108 schaersvoo 4493
};\n\
8257 schaersvoo 4494
<!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
8130 schaersvoo 4495
    break;
7614 schaersvoo 4496
    case 20: fprintf(js_include_file,"\
8257 schaersvoo 4497
\n<!-- begin function 20 read_canvas%d() -->\n\
4498
read_canvas%d = function(){\
8074 schaersvoo 4499
 var prec = %d;\
7614 schaersvoo 4500
 var len  = ext_drag_images.length;\
4501
 var reply = new Array(len);\
4502
 for(var p = 0 ; p < len ; p++){\
4503
    var img = ext_drag_images[p];\
8074 schaersvoo 4504
    reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 4505
 };\
4506
 return reply;\
8108 schaersvoo 4507
};\n\
8257 schaersvoo 4508
<!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4509
    break;
4510
    case 21: fprintf(js_include_file,"\
8257 schaersvoo 4511
\n<!-- begin function 21 read_canvas%d() -->\n\
4512
read_canvas%d = function(){\
7614 schaersvoo 4513
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
4514
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 4515
 var prec = %d;\
7614 schaersvoo 4516
 while(userdraw_x[p]){\
8074 schaersvoo 4517
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 4518
  p++;\
4519
 };\
4520
 if(p == 0){alert(\"nothing drawn...\");return;};\
4521
 if( document.getElementById(\"canvas_input0\") ){\
4522
  var p = 0;var input_reply = new Array();\
4523
  if( document.getElementById(\"canvas_input0\")){\
4524
   var t = 0;\
4525
   while(document.getElementById(\"canvas_input\"+t)){\
4526
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4527
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4528
     p++;\
4529
    };\
4530
    t++;\
4531
   };\
4532
  };\
4533
  if( typeof userdraw_text != 'undefined' ){\
4534
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4535
  }\
4536
  else\
4537
  {\
4538
   return reply_coord+\"\\n\"+input_reply;\
4539
  }\
4540
 }\
4541
 else\
4542
 {\
4543
  if( typeof userdraw_text != 'undefined' ){\
4544
   return reply_coord+\"\\n\"+userdraw_text;\
4545
  }\
4546
  else\
4547
  {\
4548
   return reply_coord;\
4549
  };\
4550
 };\
8108 schaersvoo 4551
};\n\
8257 schaersvoo 4552
<!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4553
    break;
4554
    case 22: fprintf(js_include_file,"\
8257 schaersvoo 4555
\n<!-- begin function 22 read_canvas%d() -->\n\
4556
read_canvas%d = function(){\
7614 schaersvoo 4557
 var reply = new Array();\
7963 schaersvoo 4558
 var lu = userdraw_x.length;\
4559
 if(lu == 0){alert(\"nothing drawn...\");return;};\
7614 schaersvoo 4560
 var idx = 0;\
8074 schaersvoo 4561
 var prec = %d;\
7963 schaersvoo 4562
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 4563
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
4564
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 4565
 };\
4566
 if( document.getElementById(\"canvas_input0\") ){\
4567
  var p = 0;var input_reply = new Array();\
4568
  if( document.getElementById(\"canvas_input0\")){\
4569
   var t = 0;\
4570
   while(document.getElementById(\"canvas_input\"+t)){\
4571
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4572
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4573
     p++;\
4574
    };\
4575
    t++;\
4576
   };\
4577
  };\
4578
  if( typeof userdraw_text != 'undefined' ){\
4579
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4580
  }\
4581
  else\
4582
  {\
4583
   return reply +\"\\n\"+input_reply;\
4584
  }\
4585
 }\
4586
 else\
4587
 {\
4588
  if( typeof userdraw_text != 'undefined' ){\
4589
   return reply +\"\\n\"+userdraw_text;\
4590
  }\
4591
  else\
4592
  {\
4593
   return reply;\
4594
  }\
4595
 };\
8108 schaersvoo 4596
};\n\
8257 schaersvoo 4597
<!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 4598
    break;
7782 schaersvoo 4599
    case 23: fprintf(js_include_file,"\
8257 schaersvoo 4600
\n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\
4601
read_canvas%d = function(){\
7782 schaersvoo 4602
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
4603
 var lu = userdraw_x.length;\
4604
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 4605
 var reply_x = new Array();var reply_y = new Array();\
4606
 var marge = 5;var p = 0;\
8074 schaersvoo 4607
 var prec = %d;\
7782 schaersvoo 4608
 for(var i = 0; i < lu - 1 ; i++ ){\
7962 schaersvoo 4609
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\
8074 schaersvoo 4610
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 4611
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
4612
   p++;\
7782 schaersvoo 4613
  };\
8074 schaersvoo 4614
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
7782 schaersvoo 4615
 };\
4616
 if( document.getElementById(\"canvas_input0\")){\
4617
  var p = 0;var input_reply = new Array();\
4618
  if( document.getElementById(\"canvas_input0\")){\
4619
   var t = 0;\
4620
   while(document.getElementById(\"canvas_input\"+t)){\
4621
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4622
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4623
     p++;\
4624
    };\
4625
    t++;\
4626
   };\
4627
  };\
4628
  if( typeof userdraw_text != 'undefined' ){\
4629
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4630
  }\
4631
  else\
4632
  {\
4633
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
4634
  }\
4635
 }\
4636
 else\
4637
 {\
4638
  if( typeof userdraw_text != 'undefined' ){\
4639
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
4640
  }\
4641
  else\
4642
  {\
4643
   return reply_x+\"\\n\"+reply_y;\
4644
  };\
4645
 };\
8108 schaersvoo 4646
};\n\
8257 schaersvoo 4647
<!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7782 schaersvoo 4648
    break;
7984 schaersvoo 4649
    case 24: fprintf(js_include_file,"\n\
8257 schaersvoo 4650
<!-- begin function 24  read_canvas%d() -->\n\
4651
read_canvas%d = function(){\
7984 schaersvoo 4652
 var input_reply = new Array();\
4653
 var p = 0;\
4654
 if( document.getElementById(\"canvas_input0\")){\
4655
  while(document.getElementById(\"canvas_input\"+p)){\
4656
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
4657
    p++;\
4658
  };\
4659
  return input_reply;\
4660
 };\
8108 schaersvoo 4661
};\n\
8257 schaersvoo 4662
<!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7984 schaersvoo 4663
    break;
8083 schaersvoo 4664
    case 25:
8257 schaersvoo 4665
    fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\
4666
read_canvas%d = function(){\
8083 schaersvoo 4667
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
4668
 var lu = userdraw_radius.length;\
4669
 var prec = %d;\
4670
 var angle_reply = new Array(lu);\
4671
 for(var p = 0 ; p < lu ; p++){\
4672
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
4673
 };\
4674
 return angle_reply;\
8108 schaersvoo 4675
};\n\
8257 schaersvoo 4676
<!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 4677
    break;
4678
    case 26:
8257 schaersvoo 4679
    fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\
4680
read_canvas%d = function(){\
8083 schaersvoo 4681
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
4682
 var lu = userdraw_radius.length;\
4683
 var prec = %d;\
4684
 var angle_reply = new Array(lu);\
4685
 for(var p = 0 ; p < lu ; p++){\
4686
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
4687
 };\
4688
 return angle_reply;\
8108 schaersvoo 4689
};\n\
8257 schaersvoo 4690
<!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 4691
    break;
8127 schaersvoo 4692
    case 27:
8257 schaersvoo 4693
    fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d()  : inputfield(s) location and their values : -->\n\
4694
read_canvas%d = function(){\
8127 schaersvoo 4695
 var lu = userdraw_x.length;\
4696
 if( lu < 1){alert(\"nothing drawn...\");return;}\
4697
 set_reply_precision();\
4698
 var prec = %d;\
4699
 for(var p = 0 ; p < lu ; p++){\
4700
   reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
4701
 };\
4702
 return reply;\
4703
};\n\
8257 schaersvoo 4704
<!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8127 schaersvoo 4705
    break;
7614 schaersvoo 4706
    default: canvas_error("hmmm unknown replyformat...");break;
4707
}
4708
 return;
4709
}
4710
 
4711
 
8224 bpr 4712
/*
4713
 add drawfunction :
7614 schaersvoo 4714
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
4715
 - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
4716
 - grid / mathml
4717
 - will not scale or zoom in
4718
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
8224 bpr 4719
 - is printed directly into 'js_include_file'
7614 schaersvoo 4720
*/
4721
 
4722
void add_javascript_functions(int js_functions[],int canvas_root_id){
4723
int i;
4724
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
4725
 if( js_functions[i] == 1){
4726
    switch(i){
4727
    case DRAG_EXTERNAL_IMAGE:
4728
fprintf(js_include_file,"\n<!-- drag external images --->\n\
7653 schaersvoo 4729
var external_canvas = create_canvas%d(7,xsize,ysize);\
4730
var external_ctx = external_canvas.getContext(\"2d\");\
4731
var external_canvas_rect = external_canvas.getBoundingClientRect();\
4732
canvas_div.addEventListener(\"mousedown\",setxy,false);\
4733
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
4734
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
4735
var selected_image = null;\
4736
var ext_image_cnt = 0;\
4737
var ext_drag_images = new Array();\
4738
function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
4739
 ext_image_cnt = idx;\
4740
 var image = new Image();\
4741
 image.src = URL;\
4742
 image.onload = function(){\
4743
  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
4744
  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
4745
  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
8112 schaersvoo 4746
  var img = new Array(10);\
7653 schaersvoo 4747
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
4748
  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
4749
  ext_drag_images[idx] = img;\
4750
  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
4751
 };\
4752
};\
4753
function dragstop(evt){\
4754
 selected_image = null;return;\
4755
};\
4756
function dragxy(evt){\
4757
 if( selected_image != null ){\
4758
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
4759
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
4760
  var s_img = ext_drag_images[selected_image];\
4761
  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
4762
  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
4763
  ext_drag_images[selected_image] = s_img;\
4764
  external_ctx.clearRect(0,0,xsize,ysize);\
4765
  for(var i = 0; i <= ext_image_cnt ; i++){\
4766
   var img = ext_drag_images[i];\
4767
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
4768
  };\
4769
 };\
4770
};\
4771
function setxy(evt){\
4772
 if( ! selected_image && evt.which == 1 ){\
4773
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
4774
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
4775
  var xm = evt.clientX - external_canvas_rect.left + xoff;\
4776
  var ym = evt.clientY - external_canvas_rect.top + yoff;\
4777
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
4778
   var img = ext_drag_images[p];\
4779
   if( img[0] == 1 ){\
4780
    var w = img.width;\
4781
    var h = img.height;\
4782
    if( xm > img[6] && xm < img[6] + img[4]){\
4783
     if( ym > img[7] && ym < img[7] + img[5]){\
4784
      img[6] = xm;\
4785
      img[7] = ym;\
4786
      ext_drag_images[p] = img;\
4787
      selected_image = p;\
4788
      dragxy(evt);\
4789
     };\
4790
    };\
4791
   };\
4792
  };\
4793
 }\
4794
 else\
4795
 {\
4796
  selected_image = null;\
4797
 };\
7614 schaersvoo 4798
};",canvas_root_id);
4799
    break;
4800
 
4801
    case DRAW_EXTERNAL_IMAGE:
4802
fprintf(js_include_file,"\n<!-- draw external images -->\n\
8105 schaersvoo 4803
var draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
7614 schaersvoo 4804
 var image = new Image();\
4805
 image.src = URL;\
4806
 var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
4807
 image.onload = function(){\
4808
  if( x0 < 1 ){ x0 = 0; };\
4809
  if( y0 < 1 ){ y0 = 0; };\
4810
  if( sx < 1 ){ sx = 0; };\
4811
  if( sy < 1 ){ sy = 0; };\
4812
  if( width < 1 ){ width = image.width;};\
4813
  if( height < 1 ){ height = image.height;};\
4814
  if( swidth < 1 ){ swidth = image.width;};\
4815
  if( sheight < 1 ){ sheight = image.height;};\
4816
  var ml = x0 - sx;\
4817
  var mh = y0 - sy;\
4818
  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
4819
  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
4820
  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
4821
  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
4822
  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
4823
 };\
8224 bpr 4824
};",canvas_root_id);
7614 schaersvoo 4825
    break;
4826
    case DRAW_GRIDFILL:/* not used for userdraw */
4827
fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
8105 schaersvoo 4828
var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
7614 schaersvoo 4829
 var obj;\
4830
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4831
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4832
 }\
4833
 else\
4834
 {\
4835
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4836
 };\
4837
 var ctx = obj.getContext(\"2d\");\
4838
 var x,y;\
7883 schaersvoo 4839
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 4840
 ctx.save();\
4841
 ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
4842
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
4843
    ctx.moveTo(x,y0);\
4844
    ctx.lineTo(x,ysize);\
4845
 };\
7645 schaersvoo 4846
 for( y = y0 ; y < ysize+dy; y = y + dy ){\
7614 schaersvoo 4847
    ctx.moveTo(x0,y);\
4848
    ctx.lineTo(xsize,y);\
4849
 };\
4850
 ctx.stroke();\
4851
 ctx.restore();\
7653 schaersvoo 4852
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4853
    break;
8224 bpr 4854
 
7614 schaersvoo 4855
    case DRAW_IMAGEFILL:/* not  used for userdraw */
4856
fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
8105 schaersvoo 4857
var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
7614 schaersvoo 4858
 var obj;\
4859
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4860
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4861
 }\
4862
 else\
4863
 {\
4864
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4865
 };\
4866
 var ctx = obj.getContext(\"2d\");\
4867
 ctx.save();\
4868
 var img = new Image();\
4869
 img.src = URL;\
4870
 img.onload = function(){\
4871
  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
4872
    ctx.drawImage(img,x0,y0,xsize,ysize);\
4873
  }\
4874
  else\
4875
  {\
4876
    var repeat = \"repeat\";\
4877
    if(img.width > xsize - x0){\
4878
        repeat = \"repeat-y\";\
4879
    }\
4880
    else\
4881
    {\
4882
     if( img.height > ysize -x0 ){\
4883
      repeat = \"repeat-x\";\
4884
     }\
4885
    }\
4886
    var pattern = ctx.createPattern(img,repeat);\
4887
    ctx.rect(x0,y0,xsize,ysize);\
4888
    ctx.fillStyle = pattern;\
4889
  }\
4890
  ctx.fill();\
4891
 };\
4892
 ctx.restore();\
4893
 return;\
7653 schaersvoo 4894
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4895
    break;
8224 bpr 4896
 
7614 schaersvoo 4897
    case DRAW_DOTFILL:/* not  used for userdraw */
4898
fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
8105 schaersvoo 4899
var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
7614 schaersvoo 4900
 var obj;\
4901
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4902
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4903
 }\
4904
 else\
4905
 {\
4906
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4907
 };\
4908
 var ctx = obj.getContext(\"2d\");\
4909
 var x,y;\
4910
 ctx.closePath();\
4911
 ctx.save();\
7645 schaersvoo 4912
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 4913
 ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
4914
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
4915
  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
4916
   ctx.arc(x,y,radius,0,2*Math.PI,false);\
4917
   ctx.closePath();\
4918
  }\
4919
 }\
4920
 ctx.fill();\
4921
 ctx.restore();\
7653 schaersvoo 4922
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4923
    break;
7645 schaersvoo 4924
 
7647 schaersvoo 4925
    case DRAW_DIAMONDFILL:/* not used for userdraw */
7614 schaersvoo 4926
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
8105 schaersvoo 4927
var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7614 schaersvoo 4928
  var obj;\
4929
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4930
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4931
 }\
4932
 else\
4933
 {\
4934
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4935
 };\
4936
 var ctx = obj.getContext(\"2d\");\
4937
 var x;\
4938
 var y;\
4939
 ctx.save();\
4940
 ctx.lineWidth = linewidth;\
4941
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4942
 y = ysize;\
4943
 for( x = x0 ; x < xsize ; x = x + dx ){\
4944
  ctx.moveTo(x,y0);\
4945
  ctx.lineTo(xsize,y);\
4946
  y = y - dy;\
4947
 };\
4948
 y = y0;\
4949
 for( x = xsize ; x > 0 ; x = x - dx){\
4950
  ctx.moveTo(x,ysize);\
4951
  ctx.lineTo(x0,y);\
4952
  y = y + dy;\
4953
 };\
4954
 x = x0;\
4955
 for( y = y0 ; y < ysize ; y = y + dy ){\
4956
  ctx.moveTo(xsize,y);\
4957
  ctx.lineTo(x,ysize);\
4958
  x = x + dx;\
4959
 };\
4960
 x = xsize;\
4961
 for( y = ysize ; y > y0 ; y = y - dy ){\
4962
  ctx.moveTo(x,y0);\
4963
  ctx.lineTo(x0,y);\
4964
  x = x - dx;\
4965
 };\
4966
 ctx.stroke();\
4967
 ctx.restore();\
4968
 return;\
7653 schaersvoo 4969
 }",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4970
    break;
8224 bpr 4971
 
7647 schaersvoo 4972
    case DRAW_HATCHFILL:/* not used for userdraw */
4973
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
8105 schaersvoo 4974
var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7647 schaersvoo 4975
  var obj;\
4976
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4977
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4978
 }\
4979
 else\
4980
 {\
4981
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4982
 };\
4983
 var ctx = obj.getContext(\"2d\");\
4984
 var x;\
4985
 var y;\
4986
 ctx.save();\
4987
 ctx.lineWidth = linewidth;\
4988
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4989
 y = ysize;\
4990
 for( x = x0 ; x < xsize ; x = x + dx ){\
4991
  ctx.moveTo(x,y0);\
4992
  ctx.lineTo(xsize,y);\
4993
  y = y - dy;\
4994
 };\
4995
 y = y0;\
4996
 for( x = xsize ; x >= dx ; x = x - dx){\
4997
  ctx.moveTo(x,ysize);\
4998
  ctx.lineTo(x0,y);\
4999
  y = y + dy;\
5000
 };\
5001
 ctx.stroke();\
5002
 ctx.restore();\
5003
 return;\
7653 schaersvoo 5004
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7647 schaersvoo 5005
    break;
7614 schaersvoo 5006
    case DRAW_CIRCLES:/*  used for userdraw */
5007
fprintf(js_include_file,"\n<!-- draw circles -->\n\
8105 schaersvoo 5008
var draw_circles = function(ctx,x_points,y_points,radius,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5009
 ctx.save();\
8071 schaersvoo 5010
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5011
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5012
 ctx.lineWidth = line_width;\
5013
 for(var p = 0 ; p < x_points.length ; p++ ){\
5014
  ctx.beginPath();\
5015
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
5016
  ctx.closePath();\
5017
  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5018
  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5019
  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5020
  ctx.stroke();\
5021
 }\
5022
 ctx.restore();\
5023
 return;\
7653 schaersvoo 5024
};");
7614 schaersvoo 5025
    break;
7663 schaersvoo 5026
    case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
5027
fprintf(js_include_file,"\n<!-- draw polyline -->\n\
8105 schaersvoo 5028
var draw_polyline = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7663 schaersvoo 5029
 ctx.save();\
8071 schaersvoo 5030
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 5031
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5032
 ctx.lineWidth = line_width;\
5033
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5034
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5035
 ctx.clearRect(0,0,xsize,ysize);\
5036
 ctx.beginPath();\
5037
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
5038
  ctx.moveTo(x_points[p],y_points[p]);\
5039
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
5040
 }\
5041
 ctx.closePath();\
5042
 ctx.stroke();\
5043
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5044
 for(var p = 0 ; p < x_points.length ; p++ ){\
5045
  ctx.beginPath();\
5046
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
5047
  ctx.closePath();ctx.fill();ctx.stroke();\
5048
 };\
5049
 ctx.restore();\
5050
 return;\
5051
};");
5052
    break;
8224 bpr 5053
 
7614 schaersvoo 5054
    case DRAW_SEGMENTS:/*  used for userdraw */
5055
fprintf(js_include_file,"\n<!-- draw segments -->\n\
8105 schaersvoo 5056
var draw_segments = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5057
 ctx.save();\
8071 schaersvoo 5058
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5059
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5060
 ctx.lineWidth = line_width;\
5061
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5062
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5063
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
5064
  ctx.beginPath();\
5065
  ctx.moveTo(x_points[p],y_points[p]);\
5066
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
5067
  ctx.closePath();\
5068
  ctx.stroke();\
5069
  }\
5070
  ctx.restore();\
5071
  return;\
5072
 };");
5073
    break;
8224 bpr 5074
 
7614 schaersvoo 5075
    case DRAW_LINES:/*  used for userdraw */
5076
fprintf(js_include_file,"\n<!-- draw lines -->\n\
5077
function calc_line(x1,x2,y1,y2){\
5078
 var marge = 2;\
5079
 if(x1 < x2+marge && x1>x2-marge){\
5080
  return [x1,0,x1,ysize];\
5081
 };\
5082
 if(y1 < y2+marge && y1>y2-marge){\
5083
  return [0,y1,xsize,y1];\
5084
 };\
5085
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
5086
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
5087
 return [0,Y1,xsize,Y2];\
5088
};\
8105 schaersvoo 5089
var draw_lines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5090
 ctx.save();\
5091
 var line = new Array(4);\
8071 schaersvoo 5092
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5093
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5094
 ctx.lineWidth = line_width;\
5095
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5096
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5097
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
5098
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
5099
  ctx.beginPath();\
5100
  ctx.moveTo(line[0],line[1]);\
5101
  ctx.lineTo(line[2],line[3]);\
5102
  ctx.closePath();\
5103
  ctx.stroke();\
5104
  }\
5105
  ctx.restore();\
5106
  return;\
5107
 };");
5108
    break;
5109
 
8244 schaersvoo 5110
    case DRAW_DEMILINES:/*  used for userdraw */
5111
fprintf(js_include_file,"\n<!-- draw demilines -->\n\
5112
function find_inf_point(x1,y1,x2,y2){\
5113
 if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
5114
 var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
5115
 if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
5116
};\
5117
var draw_demilines = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
5118
 ctx.save();\
5119
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
5120
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5121
 ctx.lineWidth = line_width;\
5122
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5123
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5124
 var pair = new Array(4);\
5125
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
5126
  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
5127
  ctx.beginPath();\
5128
  ctx.moveTo(pair[0],pair[1]);\
5129
  ctx.lineTo(pair[2],pair[3]);\
5130
  ctx.closePath();\
5131
  ctx.stroke();\
5132
  }\
5133
  ctx.restore();\
5134
  return;\
5135
 };");
5136
    break;
5137
 
7614 schaersvoo 5138
    case DRAW_CROSSHAIRS:/*  used for userdraw */
5139
fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
8105 schaersvoo 5140
var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
8071 schaersvoo 5141
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5142
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5143
 ctx.lineWidth = line_width;\
5144
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5145
 var x1,x2,y1,y2;\
5146
 for(var p = 0 ; p < x_points.length ; p++ ){\
5147
  x1 = x_points[p] - crosshair_size;\
5148
  x2 = x_points[p] + crosshair_size;\
5149
  y1 = y_points[p] - crosshair_size;\
5150
  y2 = y_points[p] + crosshair_size;\
5151
  ctx.beginPath();\
5152
  ctx.moveTo(x1,y1);\
5153
  ctx.lineTo(x2,y2);\
5154
  ctx.closePath();\
5155
  ctx.stroke();\
5156
  ctx.beginPath();\
5157
  ctx.moveTo(x2,y1);\
5158
  ctx.lineTo(x1,y2);\
5159
  ctx.closePath();\
5160
  ctx.stroke();\
5161
 }\
5162
 ctx.restore();\
5163
  return;\
7653 schaersvoo 5164
};");
7614 schaersvoo 5165
    break;
5166
 
5167
    case DRAW_RECTS:/*  used for userdraw */
5168
fprintf(js_include_file,"\n<!-- draw rects -->\n\
8105 schaersvoo 5169
var draw_rects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5170
 ctx.save();\
8071 schaersvoo 5171
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5172
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5173
 ctx.lineWidth = line_width;\
5174
 ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
5175
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
5176
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
5177
  ctx.beginPath();\
5178
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
5179
  ctx.closePath();\
5180
  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5181
  ctx.stroke();\
5182
 };\
5183
 ctx.restore();\
5184
 return;\
7653 schaersvoo 5185
};");
7614 schaersvoo 5186
    break;
5187
 
5188
    case DRAW_ROUNDRECTS:/*  used for userdraw */
5189
fprintf(js_include_file,"\n<!-- draw round rects -->\n\
8105 schaersvoo 5190
var draw_roundrects = function(ctx,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5191
 ctx.save();\
8071 schaersvoo 5192
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5193
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5194
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5195
 var x,y,w,h,r;\
5196
 for(var p = 0; p < x_points.length; p = p+2){\
5197
  x = x_points[p];y = y_points[p];w = x_points[p+1] - x;h = y_points[p+1] - y;r = parseInt(0.1*w);\
5198
  ctx.beginPath();ctx.moveTo(x + r, y);\
5199
  ctx.lineTo(x + w - r, y);\
5200
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
5201
  ctx.lineTo(x + w, y + h - r);\
5202
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
5203
  ctx.lineTo(x + r, y + h);\
5204
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
5205
  ctx.lineTo(x, y + r);\
5206
  ctx.quadraticCurveTo(x, y, x + r, y);\
5207
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
5208
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5209
  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
5210
  ctx.stroke();\
5211
 }\
5212
 ctx.restore();\
7653 schaersvoo 5213
};");
8224 bpr 5214
    break;
7614 schaersvoo 5215
 
5216
    case DRAW_ELLIPSES:/* not  used for userdraw */
5217
fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
8105 schaersvoo 5218
var draw_ellipses = function(canvas_type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5219
 var obj;\
5220
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5221
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5222
 }\
5223
 else\
5224
 {\
5225
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5226
 };\
5227
 var ctx = obj.getContext(\"2d\");\
5228
 ctx.save();\
8071 schaersvoo 5229
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5230
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5231
 var cx,cy,ry,rx;\
5232
 ctx.lineWidth = line_width;\
5233
 if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
5234
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5235
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5236
 for(var p=0;p< x_points.length;p = p+2){\
5237
  ctx.beginPath();\
5238
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
5239
  ctx.translate(cx - rx, cy - ry);\
5240
  ctx.scale(rx, ry);\
5241
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
5242
  if( use_filled == 1 ){ctx.fill();}\
5243
  ctx.stroke();\
5244
 };\
5245
 ctx.restore();\
7653 schaersvoo 5246
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5247
    break;
5248
 
5249
    case DRAW_PATHS: /*  used for userdraw */
5250
fprintf(js_include_file,"\n<!-- draw paths -->\n\
8105 schaersvoo 5251
var draw_paths = function(ctx,x_points,y_points,line_width,closed_path,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5252
 ctx.save();\
8071 schaersvoo 5253
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5254
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5255
 ctx.lineWidth = line_width;\
5256
 ctx.lineJoin = \"round\";\
5257
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5258
 ctx.beginPath();\
5259
 ctx.moveTo(x_points[0],y_points[0]);\
5260
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
5261
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
5262
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5263
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5264
 ctx.stroke();\
5265
 ctx.restore();\
5266
 return;\
5267
};");
8224 bpr 5268
 
7614 schaersvoo 5269
    break;
5270
    case DRAW_ARROWS:/*  used for userdraw */
5271
fprintf(js_include_file,"\n<!-- draw arrows -->\n\
8105 schaersvoo 5272
var draw_arrows = function(ctx,x_points,y_points,arrow_head,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,dashtype1,type,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 5273
 ctx.save();\
8071 schaersvoo 5274
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5275
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5276
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5277
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5278
 ctx.lineWidth = line_width;\
5279
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5280
 ctx.lineCap = \"round\";\
5281
 var x1,y1,x2,y2,dx,dy,len;\
5282
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 5283
   ctx.save();\
7614 schaersvoo 5284
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
5285
   len = Math.sqrt(dx*dx+dy*dy);\
5286
   ctx.translate(x2,y2);\
5287
   ctx.rotate(Math.atan2(dy,dx));\
5288
   ctx.lineCap = \"round\";\
5289
   ctx.beginPath();\
5290
   ctx.moveTo(0,0);\
5291
   ctx.lineTo(-len,0);\
5292
   ctx.closePath();\
5293
   ctx.stroke();\
5294
   ctx.beginPath();\
5295
   ctx.moveTo(0,0);\
5296
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
5297
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
5298
   ctx.closePath();\
5299
   ctx.fill();\
7874 schaersvoo 5300
   ctx.restore();\
7614 schaersvoo 5301
   if( type == 2 ){\
5302
     ctx.save();\
5303
     ctx.translate(x1,y1);\
5304
     ctx.rotate(Math.atan2(-dy,-dx));\
5305
     ctx.beginPath();\
5306
     ctx.moveTo(0,0);\
5307
     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
5308
     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
5309
     ctx.closePath();\
5310
     ctx.stroke();\
5311
     ctx.fill();\
7874 schaersvoo 5312
     ctx.restore();\
7614 schaersvoo 5313
   }\
5314
  }\
5315
  ctx.restore();\
5316
  return;\
7653 schaersvoo 5317
};");
7614 schaersvoo 5318
    break;
5319
 
5320
    case DRAW_VIDEO:/* not  used for userdraw */
5321
fprintf(js_include_file,"\n<!-- draw video -->\n\
8105 schaersvoo 5322
var draw_video = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 5323
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5324
 var video_div = document.createElement(\"div\");\
5325
 canvas_div.appendChild(video_div);\
5326
 video_div.style.position = \"absolute\";\
5327
 video_div.style.left = x+\"px\";\
5328
 video_div.style.top = y+\"px\";\
5329
 video_div.style.width = w+\"px\";\
5330
 video_div.style.height = h+\"px\";\
5331
 var video = document.createElement(\"video\");\
5332
 video_div.appendChild(video);\
5333
 video.style.width = w+\"px\";\
5334
 video.style.height = h+\"px\";\
5335
 video.autobuffer = true;\
5336
 video.controls = true;video.autoplay = false;\
5337
 var src = document.createElement(\"source\");\
5338
 src.type = \"video/mp4\";\
5339
 src.src = URL;\
5340
 video.appendChild(src);\
5341
 video.load();\
5342
 return;\
8224 bpr 5343
};");
7614 schaersvoo 5344
    break;
8224 bpr 5345
 
7614 schaersvoo 5346
    case DRAW_AUDIO:/* not used for userdraw */
5347
fprintf(js_include_file,"\n<!-- draw audio -->\n\
8105 schaersvoo 5348
var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
7614 schaersvoo 5349
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5350
 var audio_div = document.createElement(\"div\");\
5351
 canvas_div.appendChild(audio_div);\
5352
 audio_div.style.position = \"absolute\";\
5353
 audio_div.style.left = x+\"px\";\
5354
 audio_div.style.top = y+\"px\";\
5355
 audio_div.style.width = w+\"px\";\
5356
 audio_div.style.height = h+\"px\";\
5357
 var audio = document.createElement(\"audio\");\
5358
 audio_div.appendChild(audio);\
5359
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
5360
 audio.autobuffer = true;\
5361
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
5362
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
5363
 var src1 = document.createElement(\"source\");\
5364
 src1.type = \"audio/ogg\";\
5365
 src1.src = URL1;\
5366
 audio.appendChild(src1);\
5367
 var src2 = document.createElement(\"source\");\
5368
 src2.type = \"audio/mpeg\";\
5369
 src2.src = URL2;\
5370
 audio.appendChild(src2);\
5371
 audio.load();\
5372
 return;\
7653 schaersvoo 5373
};");
7614 schaersvoo 5374
    break;
8224 bpr 5375
 
7614 schaersvoo 5376
    case DRAW_HTTP:/* not  used for userdraw */
5377
fprintf(js_include_file,"\n<!-- draw http -->\n\
8105 schaersvoo 5378
var draw_http = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 5379
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5380
 var http_div = document.createElement(\"div\");\
5381
 var iframe = document.createElement(\"iframe\");\
5382
 canvas_div.appendChild(http_div);\
5383
 http_div.appendChild(iframe);\
5384
 iframe.src = URL;\
5385
 iframe.setAttribute(\"width\",w);\
5386
 iframe.setAttribute(\"height\",h);\
5387
 return;\
7653 schaersvoo 5388
};");
7614 schaersvoo 5389
    break;
8224 bpr 5390
 
7614 schaersvoo 5391
    case DRAW_XML:
5392
fprintf(js_include_file,"\n<!-- draw xml -->\n\
8105 schaersvoo 5393
var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
7614 schaersvoo 5394
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5395
 var xml_div = document.createElement(\"div\");\
5396
 canvas_div.appendChild(xml_div);\
5397
 xml_div.innerHTML = mathml;\
5398
 if(onclick != 0){\
5399
  xml_div.onclick = function(){\
5400
   reply[0] = onclick;\
5401
   alert(\"send \"+onclick+\" ?\");\
5402
  };\
5403
 };\
5404
 xml_div.style.position = \"absolute\";\
5405
 xml_div.style.left = x+\"px\";\
5406
 xml_div.style.top = y+\"px\";\
5407
 xml_div.style.width = w+\"px\";\
5408
 xml_div.style.height = h+\"px\";\
5409
 return;\
7653 schaersvoo 5410
};"
7614 schaersvoo 5411
);
5412
    break;
7654 schaersvoo 5413
    case DRAW_SGRAPH:
8224 bpr 5414
/*
7654 schaersvoo 5415
 xstart = given
5416
 ystart = given
5417
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
5418
*/
5419
fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
8105 schaersvoo 5420
var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
7658 schaersvoo 5421
 var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{ obj = create_canvas%d(canvas_type,xsize,ysize);};\
5422
 var ctx = obj.getContext(\"2d\");\
5423
 ctx.font = fontfamily;\
5424
 var minor_opacity = 0.8*opacity;\
5425
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 5426
 var zero_x = 0.1*xsize;\
5427
 var zero_y = 0.9*ysize;\
8129 schaersvoo 5428
 var snor_x;var snor_y;\
7654 schaersvoo 5429
 if( xstart != xmin){\
7658 schaersvoo 5430
  snor_x = 0.1*xsize;\
5431
 }\
5432
 else\
5433
 {\
5434
  snor_x = 0;\
5435
  xstart = xmin;\
5436
 };\
5437
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5438
 ctx.lineWidth = 2;\
5439
 ctx.beginPath();\
5440
 ctx.moveTo(xsize,zero_y);\
5441
 ctx.lineTo(zero_x,zero_y);\
5442
 ctx.lineTo(zero_x,0);\
5443
 ctx.stroke();\
5444
 ctx.closePath();\
5445
 ctx.beginPath();\
5446
 ctx.moveTo(zero_x,zero_y);\
5447
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
5448
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
5449
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
5450
 ctx.lineTo(zero_x + snor_x,zero_y);\
5451
 ctx.stroke();\
5452
 ctx.closePath();\
5453
 ctx.beginPath();\
5454
 var num = xstart;\
7660 schaersvoo 5455
 var flipflop = 1;\
7658 schaersvoo 5456
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 5457
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 5458
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 5459
  txtsize = ctx.measureText(num).width;\
5460
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
5461
  if( flipflop == 1){\
5462
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
5463
  }\
5464
  else\
5465
  {\
5466
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
5467
  }\
5468
  num = num + xmajor;\
7658 schaersvoo 5469
 };\
5470
 ctx.stroke();\
5471
 ctx.closePath();\
5472
 ctx.lineWidth = 1;\
5473
 ctx.beginPath();\
5474
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
5475
   ctx.moveTo(x,zero_y);\
5476
   ctx.lineTo(x,0);\
5477
 };\
5478
 ctx.stroke();\
5479
 ctx.closePath();\
5480
 if( xminor > 1){\
5481
  ctx.lineWidth = 0.5;\
5482
  ctx.beginPath();\
5483
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
5484
  var minor_step_x = step_x / xminor;\
5485
  var nx;\
5486
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
5487
    num = 1;\
5488
    for(var p = 1 ; p < xminor ; p++){\
5489
     nx = x + num*minor_step_x;\
5490
     ctx.moveTo(nx,zero_y);\
5491
     ctx.lineTo(nx,0);\
5492
     num++;\
5493
    };\
5494
  };\
5495
  ctx.stroke();\
5496
  ctx.closePath();\
5497
  ctx.beginPath();\
5498
  ctx.lineWidth = 2;\
5499
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5500
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
5501
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
5502
  };\
5503
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
5504
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
5505
  };\
5506
  ctx.stroke();\
5507
  ctx.closePath();\
5508
  ctx.lineWidth = 0.5;\
5509
 };\
5510
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
5511
 if( ystart != ymin){\
5512
  snor_y = 0.1*ysize;\
5513
 }\
5514
 else\
5515
 {\
5516
  snor_y = 0;\
5517
  ystart = ymin;\
5518
 };\
5519
 ctx.lineWidth = 2;\
5520
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5521
 ctx.beginPath();\
5522
 ctx.moveTo(zero_x,zero_y);\
5523
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
5524
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
5525
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
5526
 ctx.lineTo(zero_x,zero_y - snor_y);\
5527
 ctx.stroke();\
5528
 ctx.closePath();\
5529
 ctx.beginPath();\
5530
 ctx.lineWidth = 1;\
5531
 num = ystart;\
5532
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
5533
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
5534
  ctx.moveTo(zero_x,y);\
5535
  ctx.lineTo(xsize,y);\
5536
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
5537
  num = num + ymajor;\
5538
 };\
5539
 ctx.stroke();\
5540
 ctx.closePath();\
5541
 if( yminor > 1){\
5542
  ctx.lineWidth = 0.5;\
5543
  ctx.beginPath();\
5544
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
5545
  var minor_step_y = step_y / yminor;\
5546
  var ny;\
5547
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
5548
   num = 1;\
5549
   for(var p = 1 ;p < yminor;p++){\
5550
     ny = y + num*minor_step_y;\
5551
     ctx.moveTo(zero_x,ny);\
5552
     ctx.lineTo(xsize,ny);\
5553
     num++;\
5554
    };\
5555
  };\
5556
  ctx.stroke();\
5557
  ctx.closePath();\
5558
  ctx.lineWidth = 2;\
5559
  ctx.beginPath();\
5560
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5561
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
5562
   ctx.moveTo(zero_x,y);\
5563
   ctx.lineTo(zero_x+12,y);\
5564
  };\
5565
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
5566
   ctx.moveTo(zero_x,y);\
5567
   ctx.lineTo(zero_x+6,y);\
5568
  };\
5569
  ctx.stroke();\
5570
  ctx.closePath();\
5571
 };\
5572
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
7654 schaersvoo 5573
 if( typeof legend%d  !== 'undefined' ){\
5574
  ctx.globalAlpha = 1.0;\
5575
  var y_offset = 2*font_size;\
5576
  var txt;var txt_size;\
5577
  var x_offset = xsize - 2*font_size;\
5578
  var l_length = legend%d.length;var barcolor = new Array();\
5579
  if( typeof legendcolors%d !== 'undefined' ){\
5580
   for(var p = 0 ; p < l_length ; p++){\
5581
    barcolor[p] = legendcolors%d[p];\
5582
   };\
5583
  }else{\
5584
   if( barcolor.length == 0 ){\
5585
    for(var p = 0 ; p < l_length ; p++){\
5586
     barcolor[p] = stroke_color;\
5587
    };\
5588
   };\
5589
  };\
5590
  for(var p = 0; p < l_length; p++){\
5591
   ctx.fillStyle = barcolor[p];\
5592
   txt = legend%d[p];\
5593
   txt_size = ctx.measureText(txt).width;\
5594
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
5595
   y_offset = parseInt(y_offset + 1.5*font_size);\
5596
  };\
5597
 };\
7660 schaersvoo 5598
 if( typeof xaxislabel !== 'undefined' ){\
7658 schaersvoo 5599
   ctx.fillStyle = \'#000000\';\
5600
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
5601
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
5602
 };\
7660 schaersvoo 5603
 if( typeof yaxislabel !== 'undefined'){\
7658 schaersvoo 5604
   ctx.save();\
5605
   ctx.fillStyle = \'#000000\';\
5606
   var txt_size = ctx.measureText(yaxislabel).width;\
5607
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
5608
   ctx.rotate(-0.5*Math.PI);\
5609
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 5610
   ctx.restore();\
7658 schaersvoo 5611
 };\
7654 schaersvoo 5612
};\n",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
5613
    break;
7614 schaersvoo 5614
 
5615
    case DRAW_GRID:/* not used for userdraw */
5616
fprintf(js_include_file,"\n<!-- draw grid -->\n\
8105 schaersvoo 5617
var draw_grid%d = function(canvas_type,precision,stroke_opacity,xmajor,ymajor,xminor,yminor,tics_length,line_width,stroke_color,axis_color,font_size,font_family,use_axis,use_axis_numbering,use_rotate,angle,use_affine,affine_matrix,use_dashed,dashtype0,dashtype1,font_color,fill_opacity){\
7988 schaersvoo 5618
var obj;if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){obj = document.getElementById(\"wims_canvas%d\"+canvas_type);}else{obj = create_canvas%d(canvas_type,xsize,ysize);};\
5619
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 5620
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5621
ctx.save();\
8071 schaersvoo 5622
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 5623
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
5624
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5625
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
5626
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
5627
ctx.font = font_family;\
7988 schaersvoo 5628
var barcolor = new Array();\
7614 schaersvoo 5629
var xstep = xsize*xmajor/(xmax - xmin);\
5630
var ystep = ysize*ymajor/(ymax - ymin);\
5631
var x2step = xstep / xminor;\
5632
var y2step = ystep / yminor;\
7996 schaersvoo 5633
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
5634
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
5635
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
7614 schaersvoo 5636
ctx.beginPath();\
5637
ctx.lineWidth = line_width;\
5638
ctx.strokeStyle = stroke_color;\
5639
for(var p = zero_x ; p < xsize; p = p + xstep){\
5640
 ctx.moveTo(p,0);\
5641
 ctx.lineTo(p,ysize);\
5642
};\
5643
for(var p = zero_x ; p > 0; p = p - xstep){\
5644
 ctx.moveTo(p,0);\
5645
 ctx.lineTo(p,ysize);\
5646
};\
5647
for(var p = zero_y ; p < ysize; p = p + ystep){\
5648
 ctx.moveTo(0,p);\
5649
 ctx.lineTo(xsize,p);\
5650
};\
5651
for(var p = zero_y ; p > 0; p = p - ystep){\
5652
 ctx.moveTo(0,p);\
5653
 ctx.lineTo(xsize,p);\
5654
};\
5655
if( typeof xaxislabel !== 'undefined' ){\
5656
 ctx.save();\
5657
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
5658
 var corr =  ctx.measureText(xaxislabel).width;\
5659
 ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
5660
 ctx.restore();\
5661
};\
5662
if( typeof yaxislabel !== 'undefined' ){\
5663
 ctx.save();\
5664
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7988 schaersvoo 5665
 var corr =  ctx.measureText(yaxislabel).width;\
7614 schaersvoo 5666
 ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
5667
 ctx.rotate(-0.5*Math.PI);\
5668
 ctx.fillText(yaxislabel,0,0);\
5669
 ctx.restore();\
5670
};\
5671
ctx.stroke();\
5672
ctx.closePath();\
5673
if( use_axis == 1 ){\
7988 schaersvoo 5674
 ctx.save();\
7614 schaersvoo 5675
 ctx.beginPath();\
5676
 ctx.strokeStyle = stroke_color;\
5677
 ctx.lineWidth = 0.6*line_width;\
5678
 for(var p = zero_x ; p < xsize; p = p + x2step){\
5679
  ctx.moveTo(p,0);\
5680
  ctx.lineTo(p,ysize);\
5681
 };\
5682
 for(var p = zero_x ; p > 0; p = p - x2step){\
5683
  ctx.moveTo(p,0);\
5684
  ctx.lineTo(p,ysize);\
5685
 };\
5686
 for(var p = zero_y ; p < ysize; p = p + y2step){\
5687
  ctx.moveTo(0,p);\
5688
  ctx.lineTo(xsize,p);\
5689
 };\
5690
 for(var p = zero_y ; p > 0; p = p - y2step){\
5691
  ctx.moveTo(0,p);\
5692
  ctx.lineTo(xsize,p);\
5693
 };\
5694
 ctx.stroke();\
5695
 ctx.closePath();\
5696
 ctx.beginPath();\
5697
 ctx.lineWidth = 2*line_width;\
5698
 ctx.strokeStyle = axis_color;\
5699
 ctx.moveTo(0,zero_y);\
5700
 ctx.lineTo(xsize,zero_y);\
5701
 ctx.moveTo(zero_x,0);\
5702
 ctx.lineTo(zero_x,ysize);\
5703
 ctx.stroke();\
5704
 ctx.closePath();\
5705
 ctx.lineWidth = line_width+0.5;\
5706
 ctx.beginPath();\
5707
 for(var p = zero_x ; p < xsize; p = p + xstep){\
5708
  ctx.moveTo(p,zero_y-tics_length);\
5709
  ctx.lineTo(p,zero_y+tics_length);\
5710
 };\
5711
 for(var p = zero_x ; p > 0; p = p - xstep){\
5712
  ctx.moveTo(p,zero_y-tics_length);\
5713
  ctx.lineTo(p,zero_y+tics_length);\
5714
 };\
5715
 for(var p = zero_y ; p < ysize; p = p + ystep){\
5716
  ctx.moveTo(zero_x-tics_length,p);\
5717
  ctx.lineTo(zero_x+tics_length,p);\
5718
 };\
5719
 for(var p = zero_y ; p > 0; p = p - ystep){\
5720
  ctx.moveTo(zero_x-tics_length,p);\
5721
  ctx.lineTo(zero_x+tics_length,p);\
5722
 };\
5723
 for(var p = zero_x ; p < xsize; p = p + x2step){\
5724
  ctx.moveTo(p,zero_y-0.5*tics_length);\
5725
  ctx.lineTo(p,zero_y+0.5*tics_length);\
5726
 };\
5727
 for(var p = zero_x ; p > 0; p = p - x2step){\
5728
  ctx.moveTo(p,zero_y-0.5*tics_length);\
5729
  ctx.lineTo(p,zero_y+0.5*tics_length);\
5730
 };\
5731
 for(var p = zero_y ; p < ysize; p = p + y2step){\
5732
  ctx.moveTo(zero_x-0.5*tics_length,p);\
5733
  ctx.lineTo(zero_x+0.5*tics_length,p);\
5734
 };\
5735
 for(var p = zero_y ; p > 0; p = p - y2step){\
5736
  ctx.moveTo(zero_x-0.5*tics_length,p);\
5737
  ctx.lineTo(zero_x+0.5*tics_length,p);\
5738
 };\
5739
 ctx.stroke();\
5740
 ctx.closePath();\
7988 schaersvoo 5741
 ctx.restore();\
5742
};\
5743
if( use_axis_numbering == 1 ){\
5744
 ctx.save();\
5745
 ctx.fillColor = axis_color;\
8110 schaersvoo 5746
 ctx.strokeStyle = axis_color;\
5747
 ctx.lineWidth = 2*line_width;\
7988 schaersvoo 5748
 ctx.font = font_family;\
5749
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
5750
 if( x_strings != null ){\
5751
  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 5752
  ctx.beginPath();\
7988 schaersvoo 5753
  for(var p = 0 ; p < len ; p = p+2){\
5754
   var x_nums = x2px(eval(x_strings[p]));\
5755
   var x_text = x_strings[p+1];\
5756
   corr = ctx.measureText(x_text).width;\
5757
   skip = 1.2*corr/xstep;\
5758
   if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
5759
   if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
5760
   ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
8110 schaersvoo 5761
   ctx.moveTo(x_nums,zero_y - tics_length);\
5762
   ctx.lineTo(x_nums,zero_y + tics_length);\
7988 schaersvoo 5763
  };\
8110 schaersvoo 5764
  ctx.closePath();\
7988 schaersvoo 5765
 }\
5766
 else\
5767
 {\
5768
  skip = 1;cnt = px2x(zero_x);\
5769
  prec = Math.log(precision)/(Math.log(10));\
5770
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
5771
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
5772
   if(skip == 0 ){\
7990 schaersvoo 5773
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5774
    corr = ctx.measureText(disp_cnt).width;\
5775
    skip = parseInt(1.2*corr/xstep);\
5776
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 5777
   }\
7988 schaersvoo 5778
   else\
5779
   {\
5780
    skip--;\
7614 schaersvoo 5781
   };\
7988 schaersvoo 5782
   cnt = cnt + xmajor;\
7614 schaersvoo 5783
  };\
7988 schaersvoo 5784
  cnt = px2x(zero_x);skip = 1;\
5785
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
5786
   if(skip == 0 ){\
7990 schaersvoo 5787
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5788
    corr = ctx.measureText(disp_cnt).width;\
5789
    skip = parseInt(1.2*corr/xstep);\
5790
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
5791
   }\
5792
   else\
5793
   {\
5794
    skip--;\
7614 schaersvoo 5795
   };\
7988 schaersvoo 5796
   cnt = cnt - xmajor;\
7614 schaersvoo 5797
  };\
5798
 };\
7988 schaersvoo 5799
 if( y_strings != null ){\
5800
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 5801
  ctx.beginPath();\
7988 schaersvoo 5802
  for(var p = 0 ; p < len ; p = p+2){\
5803
   var y_nums = y2px(eval(y_strings[p]));\
5804
   var y_text = y_strings[p+1];\
5805
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
5806
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
8110 schaersvoo 5807
   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
5808
   ctx.moveTo(zero_x - tics_length,y_nums);\
5809
   ctx.lineTo(zero_x + tics_length,y_nums);\
7614 schaersvoo 5810
  };\
8110 schaersvoo 5811
  ctx.closePath();\
7988 schaersvoo 5812
 }\
5813
 else\
5814
 {\
7991 schaersvoo 5815
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 5816
  cnt = px2y(zero_y);skip = 1;\
5817
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
5818
   if(skip == 0 ){\
5819
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 5820
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5821
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
5822
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
5823
   }\
5824
   else\
5825
   {\
5826
    skip--;\
5827
   };\
5828
   cnt = cnt - ymajor;\
7614 schaersvoo 5829
  };\
7988 schaersvoo 5830
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 5831
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 5832
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
5833
   if(skip == 0 ){\
5834
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 5835
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5836
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
5837
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
5838
   }\
5839
   else\
5840
   {\
5841
    skip--;\
5842
   };\
5843
   cnt = cnt + ymajor;\
7614 schaersvoo 5844
  };\
5845
 };\
7988 schaersvoo 5846
 ctx.stroke();\
7614 schaersvoo 5847
 ctx.restore();\
5848
};\
7956 schaersvoo 5849
if( typeof legend0  !== 'undefined' ){\
7988 schaersvoo 5850
 ctx.save();\
7614 schaersvoo 5851
 ctx.globalAlpha = 1.0;\
5852
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
5853
 var y_offset = 2*font_size;\
5854
 var txt;var txt_size;\
5855
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 5856
 var l_length = legend0.length;\
5857
 if( typeof legendcolors0 !== 'undefined' ){\
7614 schaersvoo 5858
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 5859
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 5860
  };\
7988 schaersvoo 5861
 }\
5862
 else\
5863
 {\
7614 schaersvoo 5864
  if( barcolor.length == 0 ){\
5865
   for(var p = 0 ; p < l_length ; p++){\
5866
    barcolor[p] = stroke_color;\
5867
   };\
5868
  };\
5869
 };\
5870
 for(var p = 0; p < l_length; p++){\
5871
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 5872
  txt = legend0[p];\
7614 schaersvoo 5873
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 5874
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 5875
  y_offset = parseInt(y_offset + 1.5*font_size);\
5876
 };\
7988 schaersvoo 5877
 ctx.restore();\
7614 schaersvoo 5878
};\
7991 schaersvoo 5879
if( typeof barchart_0  !== 'undefined' ){\
5880
 ctx.save();\
5881
 var num_barcharts = 0;\
5882
 var bar_name = eval('barchart_0');\
5883
 while( typeof bar_name !== 'undefined' ){\
5884
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
5885
 };\
5886
 var bar_width = parseInt(0.8*xstep/(num_barcharts));\
5887
 for(var i=0 ; i< num_barcharts ; i++){\
5888
  bar_name = eval('barchart_'+i);\
5889
  var bar_x = new Array();\
5890
  var bar_y = new Array();\
5891
  var lb = bar_name.length;\
5892
  var idx = 0;\
5893
  var dx = parseInt(0.5*i*bar_width);\
5894
  for( var p = 0 ; p < lb ; p = p + 3 ){\
5895
   bar_x[idx] = x2px(bar_name[p]);\
5896
   bar_y[idx] = y2px(bar_name[p+1]);\
5897
   barcolor[idx] = bar_name[p+2];\
5898
   idx++;\
5899
  };\
5900
  ctx.globalAlpha = fill_opacity;\
5901
  ctx.beginPath();\
5902
  for( var p = 0; p < idx ; p++ ){\
5903
   ctx.strokeStyle = barcolor[p];\
5904
   ctx.fillStyle = barcolor[p];\
5905
   ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
5906
  };\
5907
  ctx.fill();\
5908
  ctx.stroke();\
5909
  ctx.closePath();\
5910
 };\
5911
 ctx.restore();\
5912
};\
7996 schaersvoo 5913
if( typeof linegraph_0 !== 'undefined' ){\
5914
 ctx.save();\
5915
 ctx.globalAlpha = 1.0;\
5916
 var i = 0;\
5917
 var line_name = eval('linegraph_'+i);\
5918
 while ( typeof line_name !== 'undefined' ){\
5919
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
5920
  ctx.lineWidth = parseInt(line_name[1]);\
5921
  if(line_name[2] == \"1\"){\
5922
   var d1 = parseInt(line_name[3]);\
5923
   var d2 = parseInt(line_name[4]);\
5924
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
5925
  }\
5926
  else\
5927
  {\
5928
  if(ctx.setLineDash){ctx.setLineDash = null;}\
5929
  if(ctx.mozDash){ctx.mozDash = null;}\
5930
  };\
5931
  var data_x = new Array();\
5932
  var data_y = new Array();\
5933
  var lb = line_name.length;\
5934
  var idx = 0;\
5935
  for( var p = 5 ; p < lb ; p = p + 2 ){\
5936
   data_x[idx] = x2px(line_name[p]);\
5937
   data_y[idx] = y2px(line_name[p+1]);\
5938
   idx++;\
5939
  };\
5940
  for( var p = 0; p < idx ; p++){\
5941
   ctx.beginPath();\
5942
   ctx.moveTo(data_x[p],data_y[p]);\
5943
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
5944
   ctx.stroke();\
5945
   ctx.closePath();\
5946
  };\
5947
  i++;\
5948
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
5949
 };\
5950
 ctx.restore();\
5951
};\
7614 schaersvoo 5952
return;\
7989 schaersvoo 5953
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5954
    break;
8224 bpr 5955
 
7614 schaersvoo 5956
    case DRAW_PIECHART:
7987 schaersvoo 5957
fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
7956 schaersvoo 5958
function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
7614 schaersvoo 5959
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5960
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5961
 }\
5962
 else\
5963
 {\
5964
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5965
 };\
5966
 var ld = data_color_list.length;\
5967
 var sum = 0;\
5968
 var idx = 0;\
7956 schaersvoo 5969
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 5970
 var colors = new Array();\
5971
 var data = new Array();\
5972
 for(var p = 0;p < ld; p = p + 2){\
5973
  data[idx] = parseFloat(data_color_list[p]);\
5974
  sum = sum + data[idx];\
5975
  colors[idx] = data_color_list[p+1];\
5976
  idx++;\
5977
 };\
5978
 var ctx = obj.getContext(\"2d\");\
5979
 ctx.save();\
5980
 var angle;\
5981
 var angle_end = 0;\
5982
 var offset = Math.PI / 2;\
5983
 ctx.globalAlpha = fill_opacity;\
5984
 for(var p=0; p < idx; p++){\
5985
  ctx.beginPath();\
5986
  ctx.fillStyle = colors[p];\
5987
  ctx.moveTo(x_center,y_center);\
5988
  angle = Math.PI * (2 * data[p] / sum);\
5989
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
5990
  ctx.lineTo(x_center, y_center);\
5991
  ctx.fill();\
5992
  ctx.closePath();\
5993
  angle_end  = angle_end + angle;\
5994
 };\
7956 schaersvoo 5995
 if(typeof legend0 !== 'undefined'){\
5996
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 5997
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 5998
  ctx.font = font_family;\
7614 schaersvoo 5999
  var y_offset = font_size; \
6000
  var x_offset = 0;\
6001
  var txt;var txt_size;\
6002
  for(var p = 0; p < idx; p++){\
6003
   ctx.fillStyle = colors[p];\
7956 schaersvoo 6004
   txt = legenda[p];\
7614 schaersvoo 6005
   txt_size = ctx.measureText(txt).width;\
6006
   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
7956 schaersvoo 6007
   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
7614 schaersvoo 6008
   y_offset = parseInt(y_offset + 1.5*font_size);\
6009
  };\
6010
 };\
6011
 ctx.restore();\
7956 schaersvoo 6012
};",canvas_root_id,canvas_root_id,canvas_root_id);
8224 bpr 6013
 
7614 schaersvoo 6014
    break;
6015
    case DRAW_ARCS:
6016
fprintf(js_include_file,"\n<!-- draw arcs -->\n\
8105 schaersvoo 6017
var draw_arc = function(ctx,xc,yc,r,start,end,line_width,stroke_color,stroke_opacity,use_filled,fill_color,fill_opacity,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 6018
 ctx.save();\
6019
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 6020
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 6021
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
6022
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 6023
 start = 360 - start;\
6024
 end = 360 - end;\
7614 schaersvoo 6025
 ctx.lineWidth = line_width;\
6026
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8071 schaersvoo 6027
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
6028
 ctx.beginPath();\
6029
 ctx.moveTo(xc,yc);\
6030
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
6031
 ctx.lineTo(xc,yc);\
6032
 ctx.closePath();\
7614 schaersvoo 6033
 if( use_filled == 1 ){\
6034
  ctx.fill();\
8071 schaersvoo 6035
 };\
6036
 ctx.stroke();\
7614 schaersvoo 6037
 ctx.restore();\
8071 schaersvoo 6038
};");
8224 bpr 6039
 
7614 schaersvoo 6040
    break;
7983 schaersvoo 6041
    case DRAW_CENTERSTRING:
6042
fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
8105 schaersvoo 6043
var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
7983 schaersvoo 6044
 var obj;\
6045
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6046
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6047
 }\
6048
 else\
6049
 {\
6050
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6051
 };\
6052
 var ctx = obj.getContext(\"2d\");\
6053
 ctx.save();\
6054
 ctx.font = font_family;\
6055
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6056
 var stringwidth = ctx.measureText(text).width;\
6057
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
6058
 ctx.fillText(text,x,y2px(y));\
6059
return;\
6060
};",canvas_root_id,canvas_root_id,canvas_root_id);
6061
    break;
7614 schaersvoo 6062
    case DRAW_TEXTS:
6063
fprintf(js_include_file,"\n<!-- draw text -->\n\
8105 schaersvoo 6064
var draw_text = function(canvas_type,x,y,font_size,font_family,stroke_color,stroke_opacity,angle2,text,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 6065
  var obj;\
6066
  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6067
   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6068
  }\
6069
  else\
6070
  {\
6071
   obj = create_canvas%d(canvas_type,xsize,ysize);\
6072
  };\
6073
  var ctx = obj.getContext(\"2d\");\
6074
  if(angle2 == 0 && angle != 0){\
6075
   ctx.save();\
8071 schaersvoo 6076
   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6077
   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6078
  };\
6079
  if( font_family.indexOf('px') != null ){\
6080
   ctx.font = font_family;\
6081
  }\
6082
  else\
6083
  {\
7956 schaersvoo 6084
   ctx.font = font_family;\
7614 schaersvoo 6085
  };\
6086
  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6087
  if(angle2 != 0){\
6088
   ctx.save();\
6089
   ctx.translate(x,y);\
6090
   ctx.rotate((360-angle2)*(Math.PI / 180));\
6091
   ctx.fillText(text,0,0);\
6092
   ctx.restore();\
6093
  }else{ctx.fillText(text,x,y);};\
6094
 ctx.restore();\
6095
 return;\
7653 schaersvoo 6096
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6097
    break;
6098
    case DRAW_CURVE:
6099
fprintf(js_include_file,"\n<!-- draw curve -->\n\
8105 schaersvoo 6100
var draw_curve = function(canvas_type,type,x_points,y_points,line_width,stroke_color,stroke_opacity,use_dashed,dashtype0,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 6101
 var obj;\
6102
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6103
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6104
 }\
6105
 else\
6106
 {\
6107
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6108
 };\
6109
 var ctx = obj.getContext(\"2d\");\
6110
 ctx.save();\
8071 schaersvoo 6111
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6112
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6113
 ctx.beginPath();ctx.lineWidth = line_width;\
6114
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6115
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6116
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
6117
 for(var p = 1 ; p < x_points.length ; p++){\
6118
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
6119
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
6120
  }\
6121
  else\
6122
  {\
6123
   ctx.stroke();\
6124
   ctx.beginPath();\
6125
   p++;\
6126
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
6127
  };\
6128
 };\
6129
 ctx.stroke();\
6130
 ctx.restore();\
7653 schaersvoo 6131
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6132
    break;
8224 bpr 6133
 
7614 schaersvoo 6134
    case DRAW_INPUTS:
6135
fprintf(js_include_file,"\n<!-- draw input fields -->\n\
8105 schaersvoo 6136
var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
7614 schaersvoo 6137
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
6138
var input = document.createElement(\"input\");\
6139
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
6140
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
6141
input.setAttribute(\"size\",size);\
6142
input.setAttribute(\"value\",value);\
7877 schaersvoo 6143
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
7653 schaersvoo 6144
canvas_div.appendChild(input);};");
7614 schaersvoo 6145
    break;
8224 bpr 6146
 
7614 schaersvoo 6147
    case DRAW_TEXTAREAS:
6148
fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
8105 schaersvoo 6149
var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
7614 schaersvoo 6150
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
6151
var textarea = document.createElement(\"textarea\");\
6152
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
6153
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
6154
textarea.setAttribute(\"cols\",cols);\
6155
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 6156
textarea.value = value;\
6157
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 6158
canvas_div.appendChild(textarea);};");
7614 schaersvoo 6159
    break;
8224 bpr 6160
 
7614 schaersvoo 6161
case DRAW_PIXELS:
6162
fprintf(js_include_file,"\n<!-- draw pixel -->\n\
8105 schaersvoo 6163
var draw_setpixel = function(x,y,color,opacity,pixelsize){\
7614 schaersvoo 6164
 var canvas = create_canvas%d(10,xsize,ysize);\
6165
 var d = 0.5*pixelsize;\
6166
 var ctx = canvas.getContext(\"2d\");\
6167
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
6168
 ctx.clearRect(0,0,xsize,ysize);\
6169
 for(var p=0; p<x.length;p++){\
6170
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
6171
 };\
6172
 ctx.fill();ctx.stroke();\
6173
};",canvas_root_id);
6174
break;
6175
 
6176
case DRAW_CLOCK:
6177
fprintf(js_include_file,"\n<!-- begin command clock -->\n\
6178
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
6179
var clock_ctx = clock_canvas.getContext(\"2d\");\
6180
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
8130 schaersvoo 6181
 clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
7614 schaersvoo 6182
 clock_ctx.save();\
7997 schaersvoo 6183
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 6184
 this.type = type || 0;\
6185
 this.interaction = interaction || 0;\
7862 schaersvoo 6186
 this.H = H;\
6187
 this.M = M;\
6188
 this.S = S;\
8000 schaersvoo 6189
 if(this.S == -1){this.S = 59;this.M = this.M - 1;};\
6190
 if(this.M == -1){this.M = 59;this.H = this.H - 1;};\
6191
 if(this.H == -1){this.H = 11;};\
7614 schaersvoo 6192
 this.xc = xc || xsize/2;\
6193
 this.yc = yc || ysize/2;\
6194
 this.radius = radius || xsize/4;\
6195
 var font_size = parseInt(0.2*this.radius);\
6196
 this.H_color = h_color || \"blue\";\
6197
 this.M_color = m_color || \"blue\";\
6198
 this.S_color = s_color || \"blue\";\
6199
 this.fg_color = fg_color || \"red\";\
6200
 this.bg_color = bg_color || \"white\";\
6201
 clock_ctx.translate(this.xc,this.yc);\
6202
 clock_ctx.beginPath();\
6203
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
6204
 clock_ctx.fillStyle = this.bg_color;\
6205
 clock_ctx.fill();\
6206
 clock_ctx.closePath();\
6207
 clock_ctx.beginPath();\
6208
 clock_ctx.font = font_size+\"px Arial\";\
6209
 clock_ctx.fillStyle = this.fg_color;\
6210
 clock_ctx.textAlign = \"center\";\
6211
 clock_ctx.textBaseline = 'middle';\
6212
 var angle;var x1,y1,x2,y2;\
6213
 var angle_cos;var angle_sin;\
7997 schaersvoo 6214
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 6215
 switch(type){\
6216
 case 0:clock_ctx.beginPath();\
6217
 for(var p = 1; p <= 12 ; p++){\
6218
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
6219
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
6220
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6221
  clock_ctx.moveTo(x1,y1);\
6222
  clock_ctx.lineTo(x2,y2);\
6223
 };\
6224
 for(var p = 1; p <= 60 ; p++){\
6225
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
6226
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
6227
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6228
  clock_ctx.moveTo(x1,y1);\
6229
  clock_ctx.lineTo(x2,y2);\
6230
 };\
6231
 clock_ctx.closePath();\
6232
 clock_ctx.stroke();\
6233
 break;\
6234
 case 1:\
6235
 for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.9*this.radius*Math.cos(angle);y1 = 0.9*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};break;\
7862 schaersvoo 6236
 case 2:\
6237
 for(var p= 1; p <= 12 ; p++){ angle = (p - 3) * (Math.PI * 2) / 12;x1 = 0.8*this.radius*Math.cos(angle);y1 = 0.8*this.radius*Math.sin(angle);clock_ctx.fillText(p, x1, y1);};\
7614 schaersvoo 6238
 clock_ctx.beginPath();\
6239
 for(var p = 1; p <= 12 ; p++){\
6240
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
6241
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
6242
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6243
  clock_ctx.moveTo(x1,y1);\
6244
  clock_ctx.lineTo(x2,y2);\
6245
 };\
6246
 for(var p = 1; p <= 60 ; p++){\
6247
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
6248
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
6249
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6250
  clock_ctx.moveTo(x1,y1);\
6251
  clock_ctx.lineTo(x2,y2);\
6252
 };\
6253
 clock_ctx.closePath();\
6254
 clock_ctx.stroke();\
6255
 break;\
6256
 };\
6257
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
6258
 clock_ctx.rotate(angle);\
6259
 clock_ctx.beginPath();\
6260
 clock_ctx.moveTo(-3, -2);\
6261
 clock_ctx.lineTo(-3, 2);\
6262
 clock_ctx.lineTo(this.radius * 0.7, 1);\
6263
 clock_ctx.lineTo(this.radius  * 0.7, -1);\
6264
 clock_ctx.fillStyle = this.H_color;\
6265
 clock_ctx.fill();\
6266
 clock_ctx.rotate(-angle);\
6267
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
6268
 clock_ctx.rotate(angle);\
6269
 clock_ctx.beginPath();\
6270
 clock_ctx.moveTo(-3, -2);\
6271
 clock_ctx.lineTo(-3, 2);\
6272
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
6273
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
6274
 clock_ctx.fillStyle = this.M_color;\
6275
 clock_ctx.fill();\
6276
 clock_ctx.rotate(-angle);\
6277
 angle = (this.S - 15) * 2 * Math.PI / 60;\
6278
 clock_ctx.rotate(angle);\
6279
 clock_ctx.beginPath();\
6280
 clock_ctx.moveTo(0,0);\
6281
 clock_ctx.lineTo(this.radius  * 0.95, 0);\
6282
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
6283
 clock_ctx.strokeStyle = this.S_color;\
6284
 clock_ctx.stroke();\
6285
 clock_ctx.restore();\
7653 schaersvoo 6286
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 6287
break;
6288
 
6289
case DRAW_LATTICE:
6290
fprintf(js_include_file,"\n<!-- draw lattice -->\n\
8105 schaersvoo 6291
var draw_lattice = function(canvas_type,line_width,x0,y0,dx1,dy1,dx2,dy2,n1,n2,fill_color,fill_opacity,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
7614 schaersvoo 6292
 var obj;\
6293
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6294
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6295
 }\
6296
 else\
6297
 {\
6298
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6299
 };\
6300
 var ctx = obj.getContext(\"2d\");\
6301
 ctx.save();\
8071 schaersvoo 6302
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6303
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6304
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6305
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6306
 var radius = line_width;\
6307
 var x = 0;\
6308
 var y = 0;\
6309
 var x_step_px = xsize/(xmax-xmin);\
6310
 var y_step_px = ysize/(ymax-ymin);\
6311
 var xv1 = dx1*x_step_px;\
6312
 var yv1 = dy1*y_step_px;\
6313
 var xv2 = dx2*x_step_px;\
6314
 var yv2 = dy2*y_step_px;\
6315
 for(var p = 0; p < n1 ;p++){\
6316
  x = p*xv1 + x0;\
6317
  y = p*yv1 + y0;\
6318
  for(var c = 0; c < n2 ; c++){\
6319
   ctx.beginPath();\
6320
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
6321
   ctx.fill();\
6322
   ctx.stroke();\
6323
   ctx.closePath();\
6324
  };\
6325
 };\
6326
 ctx.restore();\
6327
 return;\
7653 schaersvoo 6328
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6329
    break;
7735 schaersvoo 6330
case DRAW_XYLOGSCALE:
6331
fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
8105 schaersvoo 6332
var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,precision){\
7956 schaersvoo 6333
 var obj;\
6334
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6335
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6336
 }\
6337
 else\
6338
 {\
6339
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6340
 };\
6341
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 6342
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6343
 ctx.save();\
7739 schaersvoo 6344
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 6345
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
6346
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
6347
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
6348
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
7739 schaersvoo 6349
 if(use_axis_numbering == 1){\
7956 schaersvoo 6350
  ctx.font = font_family;\
6351
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
6352
  ymarge = parseInt(1.5*font_size);\
6353
  ctx.save();\
6354
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6355
  ctx.rect(0,0,xmarge,ysize);\
6356
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6357
  ctx.fill();\
6358
  ctx.restore();\
6359
 }else{xmarge = 0;ymarge = 0;};\
7735 schaersvoo 6360
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6361
  ctx.save();\
6362
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6363
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6364
  corr =  ctx.measureText(xaxislabel).width;\
6365
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6366
  ctx.restore();\
6367
 };\
7735 schaersvoo 6368
 if( typeof yaxislabel !== 'undefined' ){\
7956 schaersvoo 6369
  ctx.save();\
6370
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6371
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6372
  corr = ctx.measureText(yaxislabel).width;\
6373
  ctx.translate(xmarge+font_size,corr+font_size);\
6374
  ctx.rotate(-0.5*Math.PI);\
6375
  ctx.fillText(yaxislabel,0,0);\
6376
  ctx.restore();\
6377
 };\
6378
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6379
 ctx.lineWidth = line_width;\
6380
 for(var p = x_min; p <= x_max ; p++){\
6381
  num = Math.pow(xlogbase,p);\
6382
  for(var i = 1 ; i < xlogbase ; i++){\
6383
   x_e = x2px(i*num);\
7735 schaersvoo 6384
   if( i == 1 ){\
7956 schaersvoo 6385
    ctx.lineWidth = line_width;\
6386
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7738 schaersvoo 6387
    if( use_axis_numbering == 1 && p > x_min){\
7956 schaersvoo 6388
      xtxt = xlogbase+'^'+p.toFixed(0);\
6389
      corr = 0.5*(ctx.measureText(xtxt).width);\
6390
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
6391
    };\
7735 schaersvoo 6392
   }else{\
7956 schaersvoo 6393
    ctx.lineWidth = 0.2*line_width;\
6394
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6395
   };\
7738 schaersvoo 6396
   if( x_e >= xmarge ){\
7956 schaersvoo 6397
    ctx.beginPath();\
6398
    ctx.moveTo(x_e,0);\
6399
    ctx.lineTo(x_e,ysize - ymarge);\
6400
    ctx.stroke();\
6401
    ctx.closePath();\
7738 schaersvoo 6402
   };\
7956 schaersvoo 6403
  };\
6404
 };\
6405
 for(var p = y_min; p <= y_max ; p++){\
6406
  num = Math.pow(ylogbase,p);\
6407
  for(var i = 1 ; i < ylogbase ; i++){\
6408
   y_e = y2px(i*num);\
6409
   if( i == 1 ){\
6410
    ctx.lineWidth = line_width;\
7735 schaersvoo 6411
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6412
    if( use_axis_numbering == 1 && p > y_min){\
6413
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
6414
    };\
6415
   }else{\
6416
    ctx.lineWidth = 0.2*line_width;\
6417
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6418
   };\
6419
   ctx.beginPath();\
6420
   ctx.moveTo(xmarge,y_e);\
6421
   ctx.lineTo(xsize,y_e);\
6422
   ctx.stroke();\
6423
   ctx.closePath();\
6424
  };\
6425
 };\
7735 schaersvoo 6426
 ctx.restore();\
6427
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
6428
    break;
7614 schaersvoo 6429
 
7735 schaersvoo 6430
case DRAW_XLOGSCALE:
6431
fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
8105 schaersvoo 6432
var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,ymajor,yminor,precision){\
7956 schaersvoo 6433
 var obj;\
6434
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6435
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6436
 }\
6437
 else\
6438
 {\
6439
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6440
 };\
6441
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 6442
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6443
 ctx.save();\
6444
 ctx.lineWidth = line_width;\
7739 schaersvoo 6445
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 6446
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
6447
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
6448
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 6449
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
6450
 if(use_axis_numbering == 1){\
7956 schaersvoo 6451
  ctx.font = font_family;\
6452
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
6453
  ymarge = parseInt(1.5*font_size);\
6454
  ctx.save();\
6455
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6456
  ctx.rect(0,0,xmarge,ysize);\
6457
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6458
  ctx.fill();\
6459
  ctx.restore();\
6460
 }else{xmarge = 0;ymarge = 0;};\
7739 schaersvoo 6461
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6462
  ctx.save();\
6463
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6464
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6465
  corr =  ctx.measureText(xaxislabel).width;\
6466
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6467
  ctx.restore();\
6468
 };\
7739 schaersvoo 6469
 if( typeof yaxislabel !== 'undefined' ){\
7956 schaersvoo 6470
  ctx.save();\
6471
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6472
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6473
  corr = ctx.measureText(yaxislabel).width;\
6474
  ctx.translate(xmarge+font_size,corr+font_size);\
6475
  ctx.rotate(-0.5*Math.PI);\
6476
  ctx.fillText(yaxislabel,0,0);\
6477
  ctx.restore();\
6478
 };\
6479
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6480
 ctx.lineWidth = line_width;\
6481
 for(var p = x_min; p <= x_max ; p++){\
6482
  num = Math.pow(xlogbase,p);\
6483
  for(var i = 1 ; i < xlogbase ; i++){\
6484
   x_e = x2px(i*num);\
7735 schaersvoo 6485
   if( i == 1 ){\
7956 schaersvoo 6486
     ctx.lineWidth = line_width;\
7739 schaersvoo 6487
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
6488
    if( use_axis_numbering == 1 && p > x_min ){\
7735 schaersvoo 6489
      xtxt = xlogbase+'^'+p.toFixed(0);\
6490
      corr = 0.5*(ctx.measureText(xtxt).width);\
6491
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
6492
    };\
6493
   }else{\
7956 schaersvoo 6494
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 6495
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6496
   };\
7739 schaersvoo 6497
   if( x_e >= xmarge ){\
7956 schaersvoo 6498
    ctx.beginPath();\
6499
    ctx.moveTo(x_e,0);\
6500
    ctx.lineTo(x_e,ysize - ymarge);\
6501
    ctx.stroke();\
6502
    ctx.closePath();\
7739 schaersvoo 6503
   };\
6504
  };\
7956 schaersvoo 6505
 };\
7735 schaersvoo 6506
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
6507
 var minor_step = stepy / yminor;\
7749 schaersvoo 6508
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 6509
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6510
  ctx.lineWidth = line_width;\
6511
  ctx.beginPath();\
6512
  ctx.moveTo(xmarge,y);\
6513
  ctx.lineTo(xsize,y);\
6514
  ctx.stroke();\
6515
  ctx.closePath();\
7735 schaersvoo 6516
  if( use_axis_numbering == 1){\
6517
   ytxt = (px2y(y)).toFixed(prec);\
6518
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
6519
  };\
6520
  for(var dy = 1 ; dy < yminor ; dy++){\
6521
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 6522
   ctx.lineWidth = 0.2*line_width;\
6523
   ctx.beginPath();\
7739 schaersvoo 6524
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 6525
   ctx.lineTo(xsize,y+dy*minor_step);\
6526
   ctx.stroke();\
6527
   ctx.closePath();\
7735 schaersvoo 6528
  };\
6529
 };\
7956 schaersvoo 6530
 ctx.restore();\
6531
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 6532
    break;
7729 schaersvoo 6533
case DRAW_YLOGSCALE:
6534
fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
8105 schaersvoo 6535
var draw_grid%d = function(canvas_type,line_width,major_color,minor_color,major_opacity,minor_opacity,font_size,font_family,font_color,use_axis_numbering,xmajor,xminor,precision){\
7956 schaersvoo 6536
 var obj;\
6537
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6538
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6539
 }\
6540
 else\
6541
 {\
6542
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6543
 };\
6544
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 6545
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6546
 ctx.save();\
6547
 ctx.lineWidth = line_width;\
7735 schaersvoo 6548
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
6549
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
8109 schaersvoo 6550
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
7739 schaersvoo 6551
 if(use_axis_numbering == 1){\
7956 schaersvoo 6552
  ctx.font = font_family;\
6553
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
6554
  ymarge = 2*font_size;\
6555
  ctx.save();\
6556
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6557
  ctx.rect(0,0,xmarge,ysize);\
6558
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6559
  ctx.fill();\
6560
  ctx.restore();\
6561
 }else{xmarge = 0;ymarge = 0;};\
7739 schaersvoo 6562
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6563
  ctx.save();\
6564
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6565
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6566
  corr =  ctx.measureText(xaxislabel).width;\
6567
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6568
  ctx.restore();\
6569
 };\
7739 schaersvoo 6570
 if( typeof yaxislabel !== 'undefined' ){\
7956 schaersvoo 6571
  ctx.save();\
6572
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6573
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6574
  corr = ctx.measureText(yaxislabel).width;\
6575
  ctx.translate(xmarge+font_size,corr+font_size);\
6576
  ctx.rotate(-0.5*Math.PI);\
6577
  ctx.fillText(yaxislabel,0,0);\
6578
  ctx.restore();\
6579
 };\
6580
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6581
 ctx.lineWidth = line_width;\
6582
 for(var p = y_min; p <= y_max ; p++){\
6583
  num = Math.pow(ylogbase,p);\
6584
  for(var i = 1 ; i < ylogbase ; i++){\
6585
   y_e = y2px(i*num);\
7729 schaersvoo 6586
   if( i == 1 ){\
7956 schaersvoo 6587
    ctx.lineWidth = line_width;\
7729 schaersvoo 6588
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7739 schaersvoo 6589
    if( use_axis_numbering == 1 && p > y_min){\
7735 schaersvoo 6590
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 6591
    };\
6592
   }else{\
7956 schaersvoo 6593
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 6594
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6595
   };\
7956 schaersvoo 6596
   ctx.beginPath();\
6597
   ctx.moveTo(xmarge,y_e);\
6598
   ctx.lineTo(xsize,y_e);\
6599
   ctx.stroke();\
6600
   ctx.closePath();\
6601
  };\
6602
 };\
7729 schaersvoo 6603
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
6604
 var minor_step = stepx / xminor;\
6605
 var prec = Math.log(precision)/Math.log(10);\
6606
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 6607
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 6608
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6609
  ctx.lineWidth = line_width;\
6610
  ctx.beginPath();\
6611
  ctx.moveTo(x,ysize-ymarge);\
6612
  ctx.lineTo(x,0);\
6613
  ctx.stroke();\
6614
  ctx.closePath();\
7729 schaersvoo 6615
  if( use_axis_numbering == 1){\
6616
   xtxt = (px2x(x)).toFixed(prec);\
6617
   corr = 0.5*(ctx.measureText(xtxt).width);\
6618
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
6619
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
6620
  };\
6621
  for(var dx = 1 ; dx < xminor ; dx++){\
6622
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 6623
   ctx.lineWidth = 0.2*line_width;\
6624
   ctx.beginPath();\
7739 schaersvoo 6625
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 6626
   ctx.lineTo(x+dx*minor_step,0);\
6627
   ctx.stroke();\
6628
   ctx.closePath();\
7735 schaersvoo 6629
  };\
6630
 };\
7956 schaersvoo 6631
 ctx.restore();\
6632
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 6633
    break;
7614 schaersvoo 6634
    default:break;
6635
   }
6636
  }
6637
 }
6638
  return;
6639
}
6640
 
6641
void check_string_length(int L){
6642
 if(L<1 || L > MAX_BUFFER-1){
6643
  canvas_error("problem with your arguments to command...");
6644
 }
6645
 return;
6646
}
6647
 
6648
 
6649
int get_token(FILE *infile){
6650
        int     c,i=0;
6651
        char    temp[MAX_INT], *input_type;
6652
        char    *line="line",
6653
        *audio="audio",
6654
        *blink="blink",
6655
        *arrowhead="arrowhead",
6656
        *crosshairsize="crosshairsize",
6657
        *crosshair="crosshair",
6658
        *crosshairs="crosshairs",
6659
        *audioobject="audioobject",
6660
        *style="style",
6661
        *mouse="mouse",
7991 schaersvoo 6662
        *mousex="mousex",
6663
        *mousey="mousey",
8071 schaersvoo 6664
        *mouse_display="display",
6665
        *mouse_degree="mouse_degree",
7614 schaersvoo 6666
        *userdraw="userdraw",
6667
        *highlight="highlight",
6668
        *http="http",
6669
        *rays="rays",
6670
        *dashtype="dashtype",
6671
        *dashed="dashed",
6672
        *filled="filled",
6673
        *lattice="lattice",
6674
        *parallel="parallel",
6675
        *segment="segment",
6676
        *dsegment="dsegment",
6677
        *seg="seg",
6678
        *bgimage="bgimage",
6679
        *bgcolor="bgcolor",
6680
        *strokecolor="strokecolor",
6681
        *backgroundimage="backgroundimage",
6682
        *text="text",
6683
        *textup="textup",
6684
        *mouseprecision="mouseprecision",
6685
        *precision="precision",
6686
        *plotsteps="plotsteps",
6687
        *plotstep="plotstep",
6688
        *tsteps="tsteps",
6689
        *curve="curve",
6690
        *dcurve="dcurve",
6691
        *plot="plot",
6692
        *dplot="dplot",
7788 schaersvoo 6693
        *levelcurve="levelcurve",
7614 schaersvoo 6694
        *fontsize="fontsize",
6695
        *fontcolor="fontcolor",
6696
        *axis="axis",
6697
        *axisnumbering="axisnumbering",
6698
        *axisnumbers="axisnumbers",
6699
        *arrow="arrow",
6700
        *darrow="darrow",
6701
        *arrow2="arrow2",
6702
        *darrow2="darrow2",
6703
        *zoom="zoom",
6704
        *grid="grid",
6705
        *hline="hline",
7786 schaersvoo 6706
        *dhline="dhline",
7614 schaersvoo 6707
        *drag="drag",
6708
        *horizontalline="horizontalline",
6709
        *vline="vline",
7786 schaersvoo 6710
        *dvline="dvline",
7614 schaersvoo 6711
        *verticalline="verticalline",
6712
        *triangle="triangle",
6713
        *ftriangle="ftriangle",
6714
        *mathml="mathml",
6715
        *html="html",
6716
        *input="input",
8146 schaersvoo 6717
        *clearbutton="clearbutton",
7614 schaersvoo 6718
        *inputstyle="inputstyle",
6719
        *textarea="textarea",
6720
        *trange="trange",
6721
        *ranget="ranget",
6722
        *xrange="xrange",
6723
        *yrange="yrange",
6724
        *rangex="rangex",
6725
        *rangey="rangey",
6726
        *polyline="polyline",
6727
        *lines="lines",
6728
        *poly="poly",
6729
        *polygon="polygon",
6730
        *fpolygon="fpolygon",
6731
        *fpoly="fpoly",
6732
        *filledpoly="filledpoly",
6733
        *filledpolygon="filledpolygon",
6734
        *rect="rect",
6735
        *frect="frect",
6736
        *rectangle="rectangle",
6737
        *frectangle="frectangle",
6738
        *square="square",
6739
        *fsquare="fsquare",
6740
        *dline="dline",
6741
        *arc="arc",
6742
        *filledarc="filledarc",
6743
        *size="size",
6744
        *string="string",
6745
        *stringup="stringup",
6746
        *copy="copy",
6747
        *copyresized="copyresized",
6748
        *opacity="opacity",
6749
        *transparent="transparent",
6750
        *fill="fill",
6751
        *point="point",
6752
        *points="points",
6753
        *linewidth="linewidth",
6754
        *circle="circle",
6755
        *fcircle="fcircle",
6756
        *disk="disk",
6757
        *comment="#",
6758
        *end="end",
6759
        *ellipse="ellipse",
6760
        *fellipse="fellipse",
6761
        *rotate="rotate",
7785 schaersvoo 6762
        *affine="affine",
6763
        *killaffine="killaffine",
7614 schaersvoo 6764
        *fontfamily="fontfamily",
6765
        *fillcolor="fillcolor",
6766
        *clicktile="clicktile",
6767
        *clicktile_colors="clicktile_colors",
6768
        *translation="translation",
6769
        *translate="translate",
6770
        *killtranslation="killtranslation",
6771
        *killtranslate="killtranslate",
6772
        *onclick="onclick",
6773
        *roundrect="roundrect",
6774
        *froundrect="froundrect",
6775
        *roundrectangle="roundrectangle",
6776
        *patternfill="patternfill",
6777
        *hatchfill="hatchfill",
6778
        *diafill="diafill",
7647 schaersvoo 6779
        *diamondfill="diamondfill",
7614 schaersvoo 6780
        *dotfill="dotfill",
6781
        *gridfill="gridfill",
6782
        *imagefill="imagefill",
7735 schaersvoo 6783
        *xlogbase="xlogbase",
6784
        *ylogbase="ylogbase",
7614 schaersvoo 6785
        *xlogscale="xlogscale",
6786
        *ylogscale="ylogscale",
6787
        *xylogscale="xylogscale",
6788
        *intooltip="intooltip",
6789
        *replyformat="replyformat",
6790
        *floodfill="floodfill",
6791
        *filltoborder="filltoborder",
6792
        *clickfill="clickfill",
6793
        *setpixel="setpixel",
6794
        *pixels="pixels",
6795
        *pixelsize="pixelsize",
6796
        *clickfillmarge="clickfillmarge",
6797
        *xaxis="xaxis",
6798
        *yaxis="yaxis",
6799
        *xaxistext="xaxistext",
6800
        *yaxistext="yaxistext",
6801
        *piechart="piechart",
6802
        *legend="legend",
6803
        *legendcolors="legendcolors",
6804
        *xlabel="xlabel",
6805
        *ylabel="ylabel",
6806
        *barchart="barchart",
6807
        *linegraph="linegraph",
6808
        *clock="clock",
6809
        *animate="animate",
6810
        *video="video",
6811
        *status="status",
7877 schaersvoo 6812
        *nostatus="nostatus",
7652 schaersvoo 6813
        *snaptogrid="snaptogrid",
7784 schaersvoo 6814
        *xsnaptogrid="xsnaptogrid",
6815
        *ysnaptogrid="ysnaptogrid",
7654 schaersvoo 6816
        *userinput_xy="userinput_xy",
8193 schaersvoo 6817
        *userinput_function="userinput_function",
7663 schaersvoo 6818
        *usertextarea_xy="usertextarea_xy",
8222 schaersvoo 6819
        *userinput="userinput",
7823 schaersvoo 6820
        *jsmath="jsmath",
7858 schaersvoo 6821
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 6822
        *setlimits="setlimits",
7858 schaersvoo 6823
        *jscurve="jscurve",
6824
        *jsplot="jsplot",
7983 schaersvoo 6825
        *sgraph="sgraph",
7984 schaersvoo 6826
        *title="title",
7996 schaersvoo 6827
        *centerstring="centerstring",
6828
        *xunit="xunit",
8071 schaersvoo 6829
        *yunit="yunit",
8101 schaersvoo 6830
        *slider="slider",
8105 schaersvoo 6831
        *killslider="killslider",
8244 schaersvoo 6832
        *angle="angle",
6833
        *halfline="halfline",
6834
        *demiline="demiline";
7614 schaersvoo 6835
 
6836
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
6837
            if( i == 0 && (c == ' ' || c == '\t') ){
6838
        continue; /* white spaces or tabs allowed before first command identifier */
6839
            }
6840
            else
6841
            {
6842
        if( c == ' ' || c == '\t' ){
6843
            break;
6844
        }
6845
        else
6846
        {
6847
            temp[i] = c;
6848
            if(i > MAX_INT - 2){canvas_error("command string too long !");}
6849
            i++;
6850
        }
6851
            }
6852
            if(temp[0] == '#') break;
6853
        }
6854
        if (c == EOF) finished = 1;
6855
 
6856
        if (c == '\n' || c == '\r') {
6857
        line_number++;
6858
        if (i == 0) { return EMPTY; }
6859
        } else if (c == EOF) {
6860
        return 0;
6861
        }
6862
 
6863
        temp[i]='\0';
6864
        input_type=(char*)my_newmem(strlen(temp));
6865
        snprintf(input_type,sizeof(temp),"%s",temp);
6866
 
6867
        if( strcmp(input_type, size) == 0 ){
6868
        free(input_type);
6869
        return SIZE;
6870
        }
6871
        if( strcmp(input_type, xrange) == 0 ){
6872
        free(input_type);
6873
        return XRANGE;
6874
        }
6875
        if( strcmp(input_type, rangex) == 0 ){
6876
        free(input_type);
6877
        return XRANGE;
6878
        }
6879
        if( strcmp(input_type, trange) == 0 ){
6880
        free(input_type);
6881
        return TRANGE;
6882
        }
6883
        if( strcmp(input_type, ranget) == 0 ){
6884
        free(input_type);
6885
        return TRANGE;
6886
        }
6887
        if( strcmp(input_type, yrange) == 0 ){
6888
        free(input_type);
6889
        return YRANGE;
6890
        }
6891
        if( strcmp(input_type, rangey) == 0 ){
6892
        free(input_type);
6893
        return YRANGE;
6894
        }
6895
        if( strcmp(input_type, linewidth) == 0 ){
6896
        free(input_type);
6897
        return LINEWIDTH;
6898
        }
6899
        if( strcmp(input_type, dashed) == 0 ){
6900
        free(input_type);
6901
        return DASHED;
6902
        }
6903
        if( strcmp(input_type, dashtype) == 0 ){
6904
        free(input_type);
6905
        return DASHTYPE;
6906
        }
6907
        if( strcmp(input_type, axisnumbering) == 0 ){
6908
        free(input_type);
6909
        return AXIS_NUMBERING;
6910
        }
6911
        if( strcmp(input_type, axisnumbers) == 0 ){
6912
        free(input_type);
6913
        return AXIS_NUMBERING;
6914
        }
6915
        if( strcmp(input_type, axis) == 0 ){
6916
        free(input_type);
6917
        return AXIS;
6918
        }
6919
        if( strcmp(input_type, grid) == 0 ){
6920
        free(input_type);
6921
        return GRID;
6922
        }
6923
        if( strcmp(input_type, parallel) == 0 ){
6924
        free(input_type);
6925
        return PARALLEL;
6926
        }
6927
        if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
6928
        free(input_type);
6929
        return HLINE;
6930
        }
6931
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
6932
        free(input_type);
6933
        return VLINE;
6934
        }
6935
        if( strcmp(input_type, line) == 0 ){
6936
        free(input_type);
6937
        return LINE;
6938
        }
6939
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
6940
        free(input_type);
6941
        return SEGMENT;
6942
        }
6943
        if( strcmp(input_type, dsegment) == 0 ){
6944
        free(input_type);
6945
        use_dashed = TRUE;
6946
        return SEGMENT;
6947
        }
6948
        if( strcmp(input_type, crosshairsize) == 0 ){
6949
        free(input_type);
6950
        return CROSSHAIRSIZE;
6951
        }
6952
        if( strcmp(input_type, arrowhead) == 0 ){
6953
        free(input_type);
6954
        return ARROWHEAD;
6955
        }
6956
        if( strcmp(input_type, crosshairs) == 0 ){
6957
        free(input_type);
6958
        return CROSSHAIRS;
6959
        }
6960
        if( strcmp(input_type, crosshair) == 0 ){
6961
        free(input_type);
6962
        return CROSSHAIR;
6963
        }
6964
        if( strcmp(input_type, onclick) == 0 ){
6965
        free(input_type);
6966
        return ONCLICK;
6967
        }
6968
        if( strcmp(input_type, drag) == 0 ){
6969
        free(input_type);
6970
        return DRAG;
6971
        }
6972
        if( strcmp(input_type, userdraw) == 0 ){
6973
        free(input_type);
6974
        return USERDRAW;
6975
        }
6976
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
6977
        free(input_type);
6978
        return STYLE;
6979
        }
6980
        if( strcmp(input_type, fillcolor) == 0 ){
6981
        free(input_type);
6982
        return FILLCOLOR;
6983
        }
6984
        if( strcmp(input_type, strokecolor) == 0 ){
6985
        free(input_type);
6986
        return STROKECOLOR;
6987
        }
6988
        if( strcmp(input_type, filled) == 0  ){
6989
        free(input_type);
6990
        return FILLED;
6991
        }
6992
        if( strcmp(input_type, http) == 0 ){
6993
        free(input_type);
6994
        return HTTP;
6995
        }
6996
        if( strcmp(input_type, rays) == 0 ){
6997
        free(input_type);
6998
        return RAYS;
6999
        }
7000
        if( strcmp(input_type, lattice) == 0 ){
7001
        free(input_type);
7002
        return LATTICE;
7003
        }
7004
        if( strcmp(input_type, bgimage) == 0 ){
7005
        free(input_type);
7006
        return BGIMAGE;
7007
        }
7008
        if( strcmp(input_type, bgcolor) == 0 ){
7009
        free(input_type);
7010
        return BGCOLOR;
7011
        }
7012
        if( strcmp(input_type, backgroundimage) == 0 ){
7013
        free(input_type);
7014
        return BGIMAGE;
7015
        }
7016
        if( strcmp(input_type, text) == 0 ){
7017
        free(input_type);
7018
        return FLY_TEXT;
7019
        }
7020
        if( strcmp(input_type, textup) == 0 ){
7021
        free(input_type);
7022
        return FLY_TEXTUP;
7023
        }
7024
        if( strcmp(input_type, mouse) == 0 ){
7025
        free(input_type);
7026
        return MOUSE;
7027
        }
7991 schaersvoo 7028
        if( strcmp(input_type, mousex) == 0 ){
7029
        free(input_type);
7030
        return MOUSEX;
7031
        }
7032
        if( strcmp(input_type, mousey) == 0 ){
7033
        free(input_type);
7034
        return MOUSEY;
7035
        }
8071 schaersvoo 7036
        if( strcmp(input_type, mouse_degree) == 0 ){
7037
        free(input_type);
7038
        return MOUSE_DEGREE;
7039
        }
7040
        if( strcmp(input_type, mouse_display) == 0 ){
7041
        free(input_type);
7042
        return MOUSE_DISPLAY;
7043
        }
7614 schaersvoo 7044
        if( strcmp(input_type, mouseprecision) == 0 ){
7045
        free(input_type);
7046
        return MOUSE_PRECISION;
7047
        }
7048
        if( strcmp(input_type, precision) == 0 ){
7049
        free(input_type);
7050
        return MOUSE_PRECISION;
7051
        }
7052
        if( strcmp(input_type, curve) == 0 ){
7053
        free(input_type);
7054
        return CURVE;
7055
        }
7056
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 7057
        use_dashed = TRUE;
7614 schaersvoo 7058
        free(input_type);
7059
        return CURVE;
7060
        }
7061
        if( strcmp(input_type, plot) == 0 ){
7062
        free(input_type);
7063
        return CURVE;
7064
        }
7065
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 7066
        use_dashed = TRUE;
7614 schaersvoo 7067
        free(input_type);
7068
        return CURVE;
7069
        }
7788 schaersvoo 7070
        if( strcmp(input_type, levelcurve) == 0 ){
7071
        free(input_type);
7072
        return LEVELCURVE;
7073
        }
7614 schaersvoo 7074
        if( strcmp(input_type, plotsteps) == 0 ){
7075
        free(input_type);
7076
        return PLOTSTEPS;
7077
        }
7078
        if( strcmp(input_type, plotstep) == 0 ){
7079
        free(input_type);
7080
        return PLOTSTEPS;
7081
        }
7082
        if( strcmp(input_type, tsteps) == 0 ){
7083
        free(input_type);
7084
        return PLOTSTEPS;
7085
        }
7086
        if( strcmp(input_type, fontsize) == 0 ){
7087
        free(input_type);
7088
        return FONTSIZE;
7089
        }
7090
        if( strcmp(input_type, fontcolor) == 0 ){
7091
        free(input_type);
7092
        return FONTCOLOR;
7093
        }
7094
        if( strcmp(input_type, arrow) == 0 ){
7095
        free(input_type);
7096
        return ARROW;
7097
        }
7098
        if( strcmp(input_type, arrow2) == 0 ){
7099
        free(input_type);
7100
        return ARROW2;
7101
        }
7102
        if( strcmp(input_type, darrow) == 0 ){
7103
        free(input_type);
8071 schaersvoo 7104
        use_dashed = TRUE;
7614 schaersvoo 7105
        return ARROW;
7106
        }
7107
        if( strcmp(input_type, darrow2) == 0 ){
7108
        free(input_type);
7109
        use_dashed = TRUE;
7110
        return ARROW2;
7111
        }
7112
        if( strcmp(input_type, zoom) == 0 ){
7113
        free(input_type);
7114
        return ZOOM;
7115
        }
7116
        if( strcmp(input_type, triangle) == 0 ){
7117
        free(input_type);
7118
        return TRIANGLE;
7119
        }
7120
        if( strcmp(input_type, ftriangle) == 0 ){
7121
        free(input_type);
7122
        use_filled = TRUE;
7123
        return TRIANGLE;
7124
        }
7125
        if( strcmp(input_type, input) == 0 ){
7126
        free(input_type);
7127
        return INPUT;
7128
        }
7129
        if( strcmp(input_type, inputstyle) == 0 ){
7130
        free(input_type);
7131
        return INPUTSTYLE;
7132
        }
7133
        if( strcmp(input_type, textarea) == 0 ){
7134
        free(input_type);
7135
        return TEXTAREA;
7136
        }
7137
        if( strcmp(input_type, mathml) == 0 ){
7138
        free(input_type);
7139
        return MATHML;
7140
        }
7141
        if( strcmp(input_type, html) == 0 ){
7142
        free(input_type);
7143
        return MATHML;
7144
        }
7145
        if( strcmp(input_type, fontfamily) == 0 ){
7146
        free(input_type);
7147
        return FONTFAMILY;
7148
        }
7149
        if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
7150
        free(input_type);
7151
        return POLYLINE;
7152
        }
7153
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
7154
        free(input_type);
7155
        return RECT;
7156
        }
7157
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
7158
        free(input_type);
7159
        return ROUNDRECT;
7160
        }
7161
        if( strcmp(input_type, froundrect) == 0 ){
7162
        free(input_type);
7163
        use_filled = TRUE;
7164
        return ROUNDRECT;
7165
        }
7166
        if( strcmp(input_type, square) == 0 ){
7167
        free(input_type);
7168
        return SQUARE;
7169
        }
7170
        if( strcmp(input_type, fsquare) == 0 ){
7171
        free(input_type);
7172
        use_filled = TRUE;
7173
        return SQUARE;
7174
        }
7175
        if( strcmp(input_type, dline) == 0 ){
7176
        use_dashed = TRUE;
7177
        free(input_type);
7178
        return LINE;
7179
        }
7786 schaersvoo 7180
        if( strcmp(input_type, dvline) == 0 ){
7181
        use_dashed = TRUE;
7182
        free(input_type);
7183
        return VLINE;
7184
        }
7185
        if( strcmp(input_type, dhline) == 0 ){
7186
        use_dashed = TRUE;
7187
        free(input_type);
7188
        return HLINE;
7189
        }
7614 schaersvoo 7190
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
7191
        use_filled = TRUE;
7192
        free(input_type);
7193
        return RECT;
7194
        }
7195
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
7196
        use_filled = TRUE;
7197
        free(input_type);
7198
        return CIRCLE;
7199
        }
7200
        if( strcmp(input_type, circle) == 0 ){
7201
        free(input_type);
7202
        return CIRCLE;
7203
        }
7204
        if( strcmp(input_type, point) == 0 ){
7205
        free(input_type);
7206
        return POINT;
7207
        }
7208
        if( strcmp(input_type, points) == 0 ){
7209
        free(input_type);
7210
        return POINTS;
7211
        }
7212
        if( strcmp(input_type, filledarc) == 0 ){
7213
        use_filled = TRUE;
7214
        free(input_type);
7215
        return ARC;
7216
        }
7217
        if( strcmp(input_type, arc) == 0 ){
7218
        free(input_type);
7219
        return ARC;
7220
        }
7221
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
7222
        free(input_type);
7223
        return POLY;
7224
        }
7225
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
7226
        use_filled = TRUE;
7227
        free(input_type);
7228
        return POLY;
7229
        }
7230
        if( strcmp(input_type, ellipse) == 0){
7231
        free(input_type);
7232
        return ELLIPSE;
7233
        }
7234
        if( strcmp(input_type, fill) == 0 ){
7235
        free(input_type);
7236
        return FLOODFILL;
7237
        }
7238
        if( strcmp(input_type, string) == 0 ){
7239
        free(input_type);
7240
        return STRING;
7241
        }
7242
        if( strcmp(input_type, stringup) == 0 ){
7243
        free(input_type);
7244
        return STRINGUP;
7245
        }
7246
        if( strcmp(input_type, opacity) == 0 ){
7247
        free(input_type);
7248
        return OPACITY;
7249
        }
7250
        if( strcmp(input_type, comment) == 0){
7251
        free(input_type);
7252
        return COMMENT;
7253
        }
7254
        if( strcmp(input_type, end) == 0){
7255
        free(input_type);
7256
        return END;
7257
        }
7258
        if( strcmp(input_type, fellipse) == 0){
7259
        free(input_type);
7260
        use_filled = TRUE;
7261
        return ELLIPSE;
8224 bpr 7262
        }
7614 schaersvoo 7263
        if( strcmp(input_type, blink) == 0 ){
7264
        free(input_type);
7265
        return BLINK;
7266
        }
8146 schaersvoo 7267
        if( strcmp(input_type, clearbutton) == 0){
7614 schaersvoo 7268
        free(input_type);
8146 schaersvoo 7269
        return CLEARBUTTON;
7614 schaersvoo 7270
        }
7271
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
7272
        free(input_type);
7273
        return TRANSLATION;
7274
        }
7275
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
7276
        free(input_type);
7277
        return KILLTRANSLATION;
7278
        }
7279
        if( strcmp(input_type, rotate) == 0){
7280
        free(input_type);
7281
        return ROTATE;
7282
        }
7785 schaersvoo 7283
        if( strcmp(input_type, affine) == 0){
7284
        free(input_type);
7285
        return AFFINE;
7286
        }
7287
        if( strcmp(input_type, killaffine) == 0){
7288
        free(input_type);
7289
        return KILLAFFINE;
7290
        }
7614 schaersvoo 7291
        if( strcmp(input_type, audio) == 0 ){
7292
        free(input_type);
7293
        return AUDIO;
7294
        }
7295
        if( strcmp(input_type, audioobject) == 0 ){
7296
        free(input_type);
7297
        return AUDIOOBJECT;
7298
        }
7299
        if( strcmp(input_type, slider) == 0 ){
7300
        free(input_type);
7301
        return SLIDER;
7302
        }
8101 schaersvoo 7303
        if( strcmp(input_type, killslider) == 0 ){
7304
        free(input_type);
7305
        return KILLSLIDER;
7306
        }
7614 schaersvoo 7307
        if( strcmp(input_type, copy) == 0 ){
7308
        free(input_type);
7309
        return COPY;
7310
        }
7311
        if( strcmp(input_type, copyresized) == 0 ){
7312
        free(input_type);
7313
        return COPYRESIZED;
7314
        }
7315
        if( strcmp(input_type, patternfill) == 0 ){
7316
        free(input_type);
7317
        return PATTERNFILL;
7318
        }
7319
        if( strcmp(input_type, hatchfill) == 0 ){
7320
        free(input_type);
7321
        return HATCHFILL;
7322
        }
7647 schaersvoo 7323
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
7614 schaersvoo 7324
        free(input_type);
7647 schaersvoo 7325
        return DIAMONDFILL;
7614 schaersvoo 7326
        }
7327
        if( strcmp(input_type, dotfill) == 0 ){
7328
        free(input_type);
7329
        return DOTFILL;
7330
        }
7331
        if( strcmp(input_type, gridfill) == 0 ){
7332
        free(input_type);
7333
        return GRIDFILL;
7334
        }
7335
        if( strcmp(input_type, imagefill) == 0 ){
7336
        free(input_type);
7337
        return IMAGEFILL;
7338
        }
7339
        if( strcmp(input_type, clicktile_colors) == 0 ){
7340
        free(input_type);
7341
        return CLICKTILE_COLORS;
7342
        }
7343
        if( strcmp(input_type, clicktile) == 0 ){
7344
        free(input_type);
7345
        return CLICKTILE;
7346
        }
7347
        if( strcmp(input_type, xlogscale) == 0 ){
7348
        free(input_type);
7349
        return XLOGSCALE;
7350
        }
7351
        if( strcmp(input_type, ylogscale) == 0 ){
7352
        free(input_type);
7353
        return YLOGSCALE;
7354
        }
7355
        if( strcmp(input_type, xylogscale) == 0 ){
7356
        free(input_type);
7357
        return XYLOGSCALE;
7358
        }
7359
        if( strcmp(input_type, ylogscale) == 0 ){
7360
        free(input_type);
7361
        return YLOGSCALE;
7362
        }
7735 schaersvoo 7363
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 7364
        free(input_type);
7735 schaersvoo 7365
        return XLOGBASE;
7614 schaersvoo 7366
        }
7735 schaersvoo 7367
        if( strcmp(input_type, ylogbase) == 0 ){
7368
        free(input_type);
7369
        return YLOGBASE;
7370
        }
7614 schaersvoo 7371
        if( strcmp(input_type, intooltip) == 0 ){
7372
        free(input_type);
7373
        return INTOOLTIP;
7374
        }
7375
        if( strcmp(input_type,video) == 0 ){
7376
        free(input_type);
7377
        return VIDEO;
7378
        }
7379
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
7380
        free(input_type);
7381
        return FLOODFILL;
8224 bpr 7382
        }
7614 schaersvoo 7383
        if( strcmp(input_type,filltoborder) == 0 ){
7384
        free(input_type);
7385
        return FILLTOBORDER;
8224 bpr 7386
        }
7614 schaersvoo 7387
        if( strcmp(input_type,clickfill) == 0 ){
7388
        free(input_type);
7389
        return CLICKFILL;
8224 bpr 7390
        }
7614 schaersvoo 7391
        if( strcmp(input_type, replyformat) == 0 ){
7392
        free(input_type);
7393
        return REPLYFORMAT;
7394
        }
7395
        if( strcmp(input_type, pixelsize) == 0 ){
7396
        free(input_type);
7397
        return PIXELSIZE;
7398
        }
7399
        if( strcmp(input_type, setpixel) == 0 ){
7400
        free(input_type);
7401
        return SETPIXEL;
7402
        }
7403
        if( strcmp(input_type, pixels) == 0 ){
7404
        free(input_type);
7405
        return PIXELS;
7406
        }
7407
        if( strcmp(input_type, clickfillmarge) == 0 ){
7408
        free(input_type);
7409
        return CLICKFILLMARGE;
7410
        }
7411
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
7412
        free(input_type);
7413
        return X_AXIS_STRINGS;
7414
        }
7415
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
7416
        free(input_type);
7417
        return Y_AXIS_STRINGS;
7418
        }
7419
        if( strcmp(input_type, piechart) == 0  ){
7420
        free(input_type);
7421
        return PIECHART;
7422
        }
7423
        if( strcmp(input_type, barchart) == 0  ){
7424
        free(input_type);
7425
        return BARCHART;
7426
        }
7427
        if( strcmp(input_type, linegraph) == 0  ){
7428
        free(input_type);
7429
        return LINEGRAPH;
7430
        }
7431
        if( strcmp(input_type, clock) == 0  ){
7432
        free(input_type);
7433
        return CLOCK;
7434
        }
7435
        if( strcmp(input_type, legend) == 0  ){
7436
        free(input_type);
7437
        return LEGEND;
7438
        }
7439
        if( strcmp(input_type, legendcolors) == 0  ){
7440
        free(input_type);
7441
        return LEGENDCOLORS;
7442
        }
7443
        if( strcmp(input_type, xlabel) == 0  ){
7444
        free(input_type);
7445
        return XLABEL;
7446
        }
7447
        if( strcmp(input_type, ylabel) == 0  ){
7448
        free(input_type);
7449
        return YLABEL;
7450
        }
7451
        if( strcmp(input_type, animate) == 0  ){
7452
        free(input_type);
7453
        return ANIMATE;
7454
        }
7455
        /* these are bitmap related flydraw commmands...must be removed. eventually */
7456
        if( strcmp(input_type, transparent) == 0 ){
7457
        free(input_type);
7458
        return TRANSPARENT;
7459
        }
7877 schaersvoo 7460
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 7461
        free(input_type);
7462
        return STATUS;
7463
        }
7464
        if( strcmp(input_type, snaptogrid) == 0 ){
7465
        free(input_type);
7466
        return SNAPTOGRID;
7467
        }
7784 schaersvoo 7468
        if( strcmp(input_type, xsnaptogrid) == 0 ){
7469
        free(input_type);
7470
        return XSNAPTOGRID;
7471
        }
7472
        if( strcmp(input_type, ysnaptogrid) == 0 ){
7473
        free(input_type);
7474
        return YSNAPTOGRID;
7475
        }
7652 schaersvoo 7476
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 7477
        free(input_type);
7652 schaersvoo 7478
        return USERINPUT_XY;
7479
        }
8193 schaersvoo 7480
        if( strcmp(input_type, userinput_function) == 0 ){
7481
        free(input_type);
7482
        return USERINPUT_FUNCTION;
7483
        }
7663 schaersvoo 7484
        if( strcmp(input_type, usertextarea_xy) == 0 ){
7485
        free(input_type);
7486
        return USERTEXTAREA_XY;
7487
        }
8222 schaersvoo 7488
        if( strcmp(input_type, userinput) == 0 ){
7489
        free(input_type);
7490
        return USERINPUT;
7491
        }
7654 schaersvoo 7492
        if( strcmp(input_type, sgraph) == 0 ){
7652 schaersvoo 7493
        free(input_type);
7654 schaersvoo 7494
        return SGRAPH;
7495
        }
7823 schaersvoo 7496
        if( strcmp(input_type, jsmath) == 0 ){
7654 schaersvoo 7497
        free(input_type);
7823 schaersvoo 7498
        return JSMATH;
7499
        }
7858 schaersvoo 7500
        if( strcmp(input_type, trace_jscurve) == 0 ){
7823 schaersvoo 7501
        free(input_type);
7858 schaersvoo 7502
        return TRACE_JSCURVE;
7823 schaersvoo 7503
        }
7858 schaersvoo 7504
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
7505
        free(input_type);
7506
        return JSCURVE;
7507
        }
7984 schaersvoo 7508
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
7983 schaersvoo 7509
        free(input_type);
7510
        return CENTERSTRING;
7511
        }
7838 schaersvoo 7512
        if( strcmp(input_type, setlimits) == 0 ){
7823 schaersvoo 7513
        free(input_type);
7838 schaersvoo 7514
        return SETLIMITS;
7515
        }
7996 schaersvoo 7516
        if( strcmp(input_type, xunit) == 0 ){
7838 schaersvoo 7517
        free(input_type);
7996 schaersvoo 7518
        return XUNIT;
7519
        }
7520
        if( strcmp(input_type, yunit) == 0 ){
7521
        free(input_type);
7522
        return YUNIT;
7523
        }
8105 schaersvoo 7524
        if( strcmp(input_type, angle) == 0 ){
7996 schaersvoo 7525
        free(input_type);
8105 schaersvoo 7526
        return ANGLE;
7527
        }
8244 schaersvoo 7528
        if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
8105 schaersvoo 7529
        free(input_type);
8244 schaersvoo 7530
        return HALFLINE;
7531
        }
7532
        free(input_type);
7614 schaersvoo 7533
        ungetc(c,infile);
7534
        return 0;
7535
}
7856 schaersvoo 7536