Subversion Repositories wimsdev

Rev

Rev 8225 | Rev 8257 | 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);
8074 schaersvoo 34
void    add_read_canvas(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...)
8116 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>
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
*/
7997 schaersvoo 203
fprintf(stdout,"\n<script type=\"text/javascript\">var wims_status = \"$status\";</script>\n<!-- 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,xsize,ysize,canvas_root_id,canvas_root_id);
7614 schaersvoo 204
fprintf(stdout,"<!-- include actual object code via include file -->\n<script type=\"text/javascript\" src=\"%s\"></script>\n",getfile_cmd);
8146 schaersvoo 205
fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
8108 schaersvoo 206
\"use strict\";\n\
8146 schaersvoo 207
<!-- these variables and functions must be global -->\n\
8108 schaersvoo 208
var read_dragdrop;\
209
var read_canvas;\
8130 schaersvoo 210
var set_clock;\
8146 schaersvoo 211
var clear_draw_area;\
212
var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
8108 schaersvoo 213
var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
7729 schaersvoo 214
var xsize = %d;\
215
var ysize = %d;\
7797 schaersvoo 216
var precision = 100;\
7729 schaersvoo 217
var canvas_div = document.getElementById(\"canvas_div%d\");\
8105 schaersvoo 218
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 219
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 220
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);};};\
221
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);};};\
222
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);};};\
223
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 224
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
225
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
7729 schaersvoo 226
function distance(x1,y1,x2,y2){return parseInt(Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ));};\
227
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 228
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;};\
229
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 230
var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
231
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
232
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
7735 schaersvoo 233
var xlogbase = 10;\
234
var ylogbase = 10;\
7729 schaersvoo 235
var use_xlogscale = 0;\
236
var use_ylogscale = 0;\
237
var x_strings = null;\
238
var y_strings = null;\
239
var use_pan_and_zoom = 0;\
7858 schaersvoo 240
var use_jsmath = 0;\
7729 schaersvoo 241
var xstart = 0;\
7996 schaersvoo 242
var ystart = 0;\
243
var unit_x=\" \";\
244
var unit_y=\" \";",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 245
/* default add the drag code : nearly always used ...*/
246
add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
247
            break;
248
        case XRANGE:
249
        /*
250
        @ xrange xmin,xmax
8224 bpr 251
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 252
        */
253
            for(i = 0 ; i<2; i++){
254
                switch(i){
255
                    case 0: xmin = get_real(infile,0);break;
256
                    case 1: xmax = get_real(infile,1);break;
257
                    default: break;
258
                }
259
            }
260
            if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
261
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;",xmin,xmax);
7983 schaersvoo 262
            found_size_command++;
7614 schaersvoo 263
            break;
264
        case YRANGE:
265
        /*
266
        @ yrange ymin,ymax
267
        @ if not given 0,ysize (eg in pixels)
268
        */
269
            for(i = 0 ; i<2; i++){
270
                switch(i){
271
                    case 0: ymin = get_real(infile,0);break;
272
                    case 1: ymax = get_real(infile,1);break;
273
                    default: break;
274
                }
275
            }
276
            if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
277
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;",ymin,ymax);
7983 schaersvoo 278
            found_size_command++;
7614 schaersvoo 279
            break;
280
        case TRANGE:
281
        /*
282
        @ trange tmin,tmax
283
        @ default -2,2
284
        */
285
            use_parametric = TRUE;
286
            for(i = 0 ; i<2; i++){
287
                switch(i){
288
                    case 0: tmin = get_real(infile,0);break;
289
                    case 1: tmax = get_real(infile,1);break;
290
                    default: break;
291
                }
292
            }
293
            if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
294
            break;
295
        case LINEWIDTH:
296
        /*
297
        @ linewidth int
298
        @ default 1
299
        */
300
            line_width = (int) (get_real(infile,1));
301
            break;
302
        case ARROWHEAD:
303
        /*
304
        @ arrowhead int
305
        @ default 8 (pixels)
306
        */
307
            arrow_head = (int) (get_real(infile,1));
308
            break;
309
        case CROSSHAIRSIZE:
310
        /*
311
        @ crosshairsize int
312
        @ default 10 (px)
313
        */
314
            crosshair_size = (int) (get_real(infile,1));
315
            break;
316
        case CROSSHAIR:
317
        /*
318
        @ crosshair x,y,color
319
        @ draw a single crosshair point at (x;y) in color 'color'
7956 schaersvoo 320
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
7614 schaersvoo 321
        @ may be set draggable / onclick
322
        */
323
            for(i=0;i<3;i++){
324
                switch(i){
325
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
326
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
327
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
328
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 329
                        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 330
                        click_cnt++;reset();
331
                        break;
332
                    default:break;
333
                }
334
            }
335
            break;
336
        case CROSSHAIRS:
337
        /*
338
        @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
339
        @ draw multiple crosshair points at given coordinates in color 'color'
7956 schaersvoo 340
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
7614 schaersvoo 341
        @ may be set draggable / onclick individually (!)
342
        */
343
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
344
            fill_color = stroke_color;
345
            i=0;
346
            while( ! done ){     /* get next item until EOL*/
347
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
348
                if(i%2 == 0 ){
349
                    double_data[i] = get_real(infile,0); /* x */
350
                }
351
                else
352
                {
353
                    double_data[i] = get_real(infile,1); /* y */
354
                }
355
                i++;
356
            }
357
            decimals = find_number_of_digits(precision);
358
            for(c=0 ; c < i-1 ; c = c+2){
8097 schaersvoo 359
                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 360
                click_cnt++;
361
            }
362
            reset();
363
            break;
364
        case POINT:
365
        /*
366
        @ point x,y,color
367
        @ draw a single point at (x;y) in color 'color'
7956 schaersvoo 368
        @ use command 'linewidth int'  to adust size
7614 schaersvoo 369
        @ may be set draggable / onclick
8224 bpr 370
        @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
7614 schaersvoo 371
        */
372
            for(i=0;i<3;i++){
373
                switch(i){
374
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
375
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
376
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
377
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 378
                    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 379
                    click_cnt++;break;
380
                    default: break;
381
                }
382
            }
383
            reset();
384
            break;
385
        case POINTS:
386
        /*
7634 schaersvoo 387
        @ points color,x1,y1,x2,y2,...,x_n,y_n
7614 schaersvoo 388
        @ draw multiple points at given coordinates in color 'color'
7956 schaersvoo 389
        @ use command 'linewidth int'  to adust size
7614 schaersvoo 390
        @ may be set draggable / onclick individually (!)
391
        */
392
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
393
            fill_color = stroke_color;
394
            i=0;
395
            while( ! done ){     /* get next item until EOL*/
396
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
397
                if(i%2 == 0 ){
398
                    double_data[i] = get_real(infile,0); /* x */
399
                }
400
                else
401
                {
402
                    double_data[i] = get_real(infile,1); /* y */
403
                }
404
                i++;
405
            }
8224 bpr 406
            decimals = find_number_of_digits(precision);
7614 schaersvoo 407
            for(c = 0 ; c < i-1 ; c = c+2){
8097 schaersvoo 408
                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 409
                click_cnt++;
410
            }
411
            reset();
412
            break;
413
        case SEGMENT:
414
        /*
415
        @ segment x1,y1,x2,y2,color
416
        @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
417
        @ may be set draggable / onclick
418
        */
419
            for(i=0;i<5;i++) {
420
                switch(i){
421
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
422
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
423
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
424
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
425
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
426
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 427
                        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 428
                        click_cnt++;reset();
429
                        break;
430
                    default: break;
431
                }
432
            }
433
            break;
434
        case LINE:
435
        /*
436
        @ line x1,y1,x2,y2,color
437
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
438
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
439
        @ may be set draggable / onclick
440
        */
441
            for(i=0;i<5;i++){
442
                switch(i){
443
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
444
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
445
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
446
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
447
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
448
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
449
                        double_data[1] = xmin;
450
                        double_data[3] = ymax;
451
                        double_data[0] = double_data[10];
452
                        double_data[2] = double_data[10];
453
                    }
454
                    else
455
                    {
456
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
457
                            double_data[1] = double_data[11];
458
                            double_data[3] = double_data[11];
459
                            double_data[0] = ymin;
460
                            double_data[2] = xmax;
461
                        }
462
                        else
463
                        {
464
                        /* m */
465
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
466
                        /* q */
467
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
8224 bpr 468
 
7614 schaersvoo 469
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
8224 bpr 470
 
7614 schaersvoo 471
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
472
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
473
                            double_data[0] = xmin;
474
                            double_data[2] = xmax;
475
                        }
476
                    }
477
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 478
                    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 479
                    click_cnt++;reset();
480
                    break;
481
                }
482
            }
483
            break;
8244 schaersvoo 484
        case HALFLINE:
485
        /*
486
        @ demiline x1,y1,x2,y2,color
487
        @ alternative : halfline
488
        @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
489
        @ may be set draggable / onclick
490
        */
491
            for(i=0;i<5;i++){
492
                switch(i){
493
                    case 0: double_data[0]= get_real(infile,0);break; /* x-values */
494
                    case 1: double_data[1]= get_real(infile,0);break; /* y-values */
495
                    case 2: double_data[10]= get_real(infile,0);break; /* x-values */
496
                    case 3: double_data[11]= get_real(infile,0);break; /* y-values */
497
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
498
                    if(double_data[0] == double_data[10]){ /* vertical halfline */
499
                        if(double_data[1] < double_data[11]){
500
                         double_data[3] = ymax + 1000;
501
                        }
502
                        else
503
                        {
504
                         double_data[3] = ymin - 1000;
505
                        }
506
                        double_data[2] = double_data[0];
507
                    }
508
                    else
509
                    { /* horizontal halfline*/
510
                     if( double_data[1] == double_data[11] ){
511
                      if( double_data[0] < double_data[10] ){
512
                        double_data[2] = xmax + 1000; /* halfline to the right */
513
                      }
514
                      else
515
                      {
516
                        double_data[2] = xmin - 1000; /* halfline to the left */
517
                      }
518
                      double_data[3] = double_data[1];
519
                     }
520
                     else
521
                     {
522
                      /* any other halfline */
523
                      /* slope */
524
                      double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
525
                      /* const */
526
                      double_data[13] = double_data[1] - double_data[12]*double_data[0];
527
                      if( double_data[0] < double_data[10] ){
528
                       double_data[2] = double_data[2] + 1000;
529
                      }
530
                      else
531
                      {
532
                       double_data[2] = double_data[2] - 1000;
533
                      }
534
                      double_data[3] = double_data[12]*double_data[2] + double_data[13];
535
                     }
536
                    }    
537
                    decimals = find_number_of_digits(precision);
538
                    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);
539
                    click_cnt++;reset();
540
                    break;
541
                }
542
            }
543
 
544
            break;
8224 bpr 545
        case HLINE:
7614 schaersvoo 546
        /*
547
        @ hline x,y,color
548
        @ draw a horizontal line through point (x:y) in color 'color'
549
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
550
        @ may be set draggable / onclick
551
        */
552
            for(i=0;i<3;i++) {
553
                switch(i){
554
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
555
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
556
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
557
                    double_data[3] = double_data[1];
558
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 559
                    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 560
                    click_cnt++;reset();
561
                    break;
562
                }
563
            }
564
            break;
565
        case VLINE:
566
        /*
567
        @ vline x,y,color
568
        @ draw a vertical line through point (x:y) in color 'color'
569
        @ may be set draggable / onclick
570
        */
571
            for(i=0;i<3;i++) {
572
                switch(i){
573
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
574
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
575
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
576
                        double_data[2] = double_data[0];
577
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 578
                        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 579
                        click_cnt++;reset();
580
                    break;
581
                }
582
            }
583
            break;
584
        case SQUARE:
585
        /*
8071 schaersvoo 586
        @ square x,y,side (px) ,color
7614 schaersvoo 587
        @ draw a square with left top corner (x:y) with side 'side' in color 'color'
588
        @ use command 'fsquare x,y,side,color' for a filled square
589
        @ use command/keyword  'filled' before command 'square x,y,side,color'
590
        @ use command 'fillcolor color' before 'fsquare' to set the fill colour.
591
        @ may be set draggable / onclick
592
        */
593
            for(i=0;i<5;i++){
594
                switch(i){
8071 schaersvoo 595
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
596
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
597
                    case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
598
                    case 3:
599
                        stroke_color = get_color(infile,1);/* name or hex color */
7614 schaersvoo 600
                        decimals = find_number_of_digits(precision);
8071 schaersvoo 601
                        double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
602
                        double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
8097 schaersvoo 603
                        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 604
                        click_cnt++;reset();
605
                        break;
606
                }
607
            }
608
            break;
609
        case ROUNDRECT:
610
        /*
611
        @ roundrect x1,y1,x2,y2,radius,color
612
        @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
613
        @ use command/keyword  'filled' before command 'roundrect x1,y1,x2,y2,radius,color'
614
        @ use command 'fillcolor color' before 'froundrect' to set the fill colour.
615
        @ may be set draggable / onclick
616
        */
617
            for(i=0;i<6;i++){
618
                switch(i){
619
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
620
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
621
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
622
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
623
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
624
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
8071 schaersvoo 625
                        /* ensure no inverted roundrect is produced... */
626
                        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 627
                        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 628
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 629
                        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 630
                        click_cnt++;reset();
631
                    break;
632
                }
633
            }
634
            break;
635
        case RECT:
636
        /*
637
        @ rect x1,y1,x2,y2,color
638
        @ use command 'rect x1,y1,x2,y2,color' for a filled rectangle
639
        @ use command/keyword  'filled' before command 'rect x1,y1,x2,y2,color'
640
        @ use command 'fillcolor color' before 'frect' to set the fill colour.
641
        @ may be set draggable / onclick
642
        */
643
            for(i=0;i<5;i++){
644
                switch(i){
645
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
646
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
647
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
648
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
649
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
650
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 651
                        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 652
                        click_cnt++;reset();
653
                        break;
654
                }
655
            }
656
            break;
657
        case POLYLINE:
658
        /*
659
        @ polyline color,x1,y1,x2,y2...x_n,y_n
660
        @ may be set draggable / onclick
661
        */
662
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
663
            i=0;
664
            c=0;
665
            while( ! done ){     /* get next item until EOL*/
666
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
667
                for( c = 0 ; c < 2; c++){
668
                    if(c == 0 ){
669
                        double_data[i] = get_real(infile,0);
670
                        i++;
671
                    }
672
                    else
673
                    {
674
                        double_data[i] = get_real(infile,1);
675
                        i++;
676
                    }
677
                }
678
            }
679
            /* draw path : not closed & not filled */
680
            decimals = find_number_of_digits(precision);
8097 schaersvoo 681
            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 682
            click_cnt++;reset();
683
            break;
684
        case POLY:
685
        /*
686
        @ poly color,x1,y1,x2,y2...x_n,y_n
687
        @ draw closed polygon
688
        @ use command 'fpoly' to fill it, use command 'fillcolor color' to set the fill color
689
        @ may be set draggable / onclick
690
        */
691
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
692
            i=0;
693
            c=0;
694
            while( ! done ){     /* get next item until EOL*/
695
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
696
                for( c = 0 ; c < 2; c++){
697
                    if(c == 0 ){
698
                        double_data[i] = get_real(infile,0);
699
                        i++;
700
                    }
701
                    else
702
                    {
703
                        double_data[i] = get_real(infile,1);
704
                        i++;
705
                    }
706
                }
707
            }
708
            /* draw path :  closed & optional filled */
709
                decimals = find_number_of_digits(precision);
8097 schaersvoo 710
                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 711
                click_cnt++;reset();
712
            break;
8224 bpr 713
        case ARC:
7614 schaersvoo 714
        /*
715
         @ arc xc,yc,width,height,start_angle,end_angle,color
716
         @ can not be set "onclick" or "drag xy"
8105 schaersvoo 717
         @ attention: width == height == radius in pixels
718
         @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work
719
         @ use command 'angle' for scalable angle
7614 schaersvoo 720
        */
721
            for(i=0;i<7;i++){
722
                switch(i){
723
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
724
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
725
                    case 2:int_data[0] = (int)(get_real(infile,0));break; /* width in pixels ! */
726
                    case 3:int_data[1] = (int)(get_real(infile,0));break; /* height in pixels ! */
727
                    case 4:double_data[2] = get_real(infile,0);break; /* start angle in degrees */
728
                    case 5:double_data[3] = get_real(infile,0);break; /* end angle in degrees */
729
                    case 6:stroke_color = get_color(infile,1);/* name or hex color */
730
                    /* in Shape library:
731
                        x[0] = x[1] = xc
732
                        y[0] = y[1] = yc
8224 bpr 733
                        w[0] = w[1] = radius = width = height
734
                        h[0] = start_angle ; h[1] = end_engle
7614 schaersvoo 735
                    */
736
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 737
                        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 738
                        reset();
739
                    break;
740
                }
741
            }
742
            break;
8224 bpr 743
        case ANGLE:
8105 schaersvoo 744
        /*
745
         @ angle xc,yc,width,start_angle,end_angle,color
746
         @ width is in x-range
747
         @ will zoom in/out
748
         @ if size is controlled by command 'slider' use radians to set limits of slider.
749
        */
750
            for(i=0;i<7;i++){
751
                switch(i){
752
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
753
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
754
                    case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
755
                    case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
756
                    case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
757
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
758
                        decimals = find_number_of_digits(precision);
759
                        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);
760
                        reset();
761
                    break;
762
                }
763
            }
764
            break;
765
 
7614 schaersvoo 766
        case ELLIPSE:
767
        /*
768
        @ ellipse xc,yc,radius_x,radius_y,color
8224 bpr 769
        @ a ellipse with center xc/yc in x/y-range
7614 schaersvoo 770
        @ radius_x and radius_y are in pixels
771
        @ may be set draggable / onclick
8224 bpr 772
        @ will shrink / expand on zoom out / zoom in
7614 schaersvoo 773
        */
774
            for(i=0;i<5;i++){
775
                switch(i){
776
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
777
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
778
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
8224 bpr 779
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
7614 schaersvoo 780
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
781
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 782
                        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 783
                        click_cnt++;reset();
784
                    break;
785
                }
786
            }
787
            break;
788
        case DASHTYPE:
789
        /*
790
        @ dashtype int ,int
7956 schaersvoo 791
        @ When dashed is set, the objects will be drawn with this dashtyp
7614 schaersvoo 792
        @ default value "dashtype 2,2"
793
        */
794
            for(i=0;i<2;i++){
795
                switch(i){
796
                    case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
797
                    case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
798
                }
799
            }
800
        break;
801
        case CIRCLE:
802
        /*
803
        @ circle xc,yc,width (2*r in pixels),color
804
        @ use command 'fcircle xc,yc,d,color' or command 'filled' for a filled disk
805
        @ use command 'fillcolor color' to set the fillcolor
806
        @ may be set draggable / onclick
8224 bpr 807
        @ will shrink / expand on zoom out / zoom in
7614 schaersvoo 808
        */
809
            for(i=0;i<4;i++){
810
                switch(i){
811
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
812
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
8116 schaersvoo 813
                    case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
7614 schaersvoo 814
                    case 3: stroke_color = get_color(infile,1);/* name or hex color */
815
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 816
                        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 817
                        click_cnt++;reset();
818
                    break;
819
                }
820
            }
821
            break;
822
        case RAYS:
823
        /*
824
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
825
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 826
         @ may be set draggable or onclick (every individual ray)
7614 schaersvoo 827
        */
828
            stroke_color=get_color(infile,0);
7786 schaersvoo 829
            fill_color = stroke_color;
830
            double_data[0] = get_real(infile,0);/* xc */
831
            double_data[1] = get_real(infile,0);/* yc */
832
            i=2;
833
            while( ! done ){     /* get next item until EOL*/
834
                if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
835
                if(i%2 == 0 ){
836
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 837
                }
7786 schaersvoo 838
                else
839
                {
840
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 841
                }
7786 schaersvoo 842
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
843
                i++;
7614 schaersvoo 844
            }
8224 bpr 845
 
846
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
847
            decimals = find_number_of_digits(precision);
7786 schaersvoo 848
            for(c=2; c<i;c = c+2){
7614 schaersvoo 849
                click_cnt++;
8097 schaersvoo 850
                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 851
            }
852
            reset();
853
            break;
854
        case ARROW:
855
        /*
856
        @ arrow x1,y1,x2,y2,h,color
857
        @ draw a single headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
858
        @ use command 'linewidth int' to adjust thickness of the arrow
859
        @ may be set draggable / onclick
860
        */
861
            for(i=0;i<6;i++){
862
                switch(i){
863
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
864
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
865
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
866
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
867
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
868
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
869
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 870
                        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 871
                        click_cnt++;
872
                        reset();
873
                        break;
874
                }
875
            }
876
            break;
877
        case ARROW2:
878
        /*
879
        @ arrow2 x1,y1,x2,y2,h,color
880
        @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
881
        @ use command 'arrowhead int' to adjust the arrow head size
882
        @ use command 'linewidth int' to adjust thickness of the arrow
883
        @ may be set draggable / onclick
884
        */
885
            for(i=0;i<6;i++){
886
                switch(i){
887
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
888
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
889
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
890
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
891
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
892
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
893
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 894
                        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 895
                        click_cnt++;reset();
896
                        break;
897
                }
898
            }
899
            break;
8224 bpr 900
        case PARALLEL:
7614 schaersvoo 901
        /*
902
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
8224 bpr 903
         @ can not be set "onclick" or "drag xy"
7614 schaersvoo 904
        */
905
            for( i = 0;i < 8; i++ ){
906
                switch(i){
907
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
908
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
909
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
910
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
911
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
912
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
913
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
914
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
915
                    decimals = find_number_of_digits(precision);
8097 schaersvoo 916
                    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 917
                    click_cnt++;reset();
918
                    break;
919
                    default: break;
920
                }
921
            }
922
            break;
923
        case TRIANGLE:
924
        /*
925
         @triangle x1,y1,x2,y2,x3,y3,color
7956 schaersvoo 926
         @may be set draggable / onclic
7614 schaersvoo 927
        */
928
            for(i=0;i<7;i++){
929
                switch(i){
930
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
931
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
932
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
933
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
934
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
935
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
936
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
937
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 938
                        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 939
                        click_cnt++;reset();
940
                        break;
941
                    default: break;
942
                }
943
            }
944
            break;
945
        case LATTICE:
946
        /*
947
         @lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
8224 bpr 948
         @can not be set "onclick" or "drag xy"
7614 schaersvoo 949
        */
950
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
951
            for( i = 0; i<9; i++){
952
                switch(i){
953
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
954
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
955
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
8071 schaersvoo 956
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
7614 schaersvoo 957
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
8071 schaersvoo 958
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
7614 schaersvoo 959
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
960
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
961
                    case 8: stroke_color=get_color(infile,1);
962
                        decimals = find_number_of_digits(precision);
8071 schaersvoo 963
                        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 964
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 965
                        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 966
                        add_to_buffer(tmp_buffer);
967
                    break;
968
                    default:break;
969
                }
970
            }
971
            reset();
972
            break;
973
        case SNAPTOGRID:
974
        /*
975
         @ snaptogrid
976
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
977
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
7784 schaersvoo 978
         @ 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 979
        */
7881 schaersvoo 980
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
7614 schaersvoo 981
        break;
7784 schaersvoo 982
        case XSNAPTOGRID:
983
        /*
984
         @ xsnaptogrid
985
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
986
         @ in case of userdraw the drawn points will snap to xmajor grid
7856 schaersvoo 987
         @ 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 988
        */
7881 schaersvoo 989
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
7784 schaersvoo 990
        break;
991
        case YSNAPTOGRID:
992
        /*
993
         @ ysnaptogrid
994
         @ keyword (no arguments rewquired) needs to be defined before command 'userdraw' and after command 'grid'
995
         @ in case of userdraw the drawn points will snap to ymajor grid
7856 schaersvoo 996
         @ 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 997
        */
7881 schaersvoo 998
        fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
7784 schaersvoo 999
        break;
8222 schaersvoo 1000
        case USERINPUT:
1001
        /*
1002
         @ userinput function | textarea | inputfield
1003
         @ alternative command + argment to keywords "userinput_function","userinput_textarea" and "userinput_xy"
1004
         @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
1005
         @ function may be used any time (e.g. without userdraw)
1006
        */
1007
            temp = get_string_argument(infile,1);
1008
            if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
8224 bpr 1009
             if( js_function[DRAW_JSFUNCTION] != 1 ){
8222 schaersvoo 1010
              js_function[DRAW_JSFUNCTION] = 1;
1011
              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
1012
              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]);
1013
              input_cnt++;
1014
             }
1015
             if( use_js_math == FALSE){/* add this stuff only once...*/
1016
              add_to_js_math(js_include_file);
1017
              use_js_math = TRUE;
1018
             }
1019
             if( use_js_plot == FALSE){
1020
              use_js_plot = TRUE;
1021
              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1022
             }
1023
            }
1024
            else
1025
            {
1026
             if(strstr(temp,"inputfield") != 0 ){
1027
              if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
1028
              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
1029
              use_input_xy = 1;
1030
             }
1031
             else
1032
             {
1033
              if(strstr(temp,"textarea") != 0 ){
1034
               if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
1035
               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
1036
               use_input_xy = 2;
1037
              }
1038
              else
1039
              {
1040
                canvas_error("userinput argument may be \"function,inputfield,textarea\"");
1041
              }
1042
             }
1043
            }
1044
            break;
7663 schaersvoo 1045
        case USERTEXTAREA_XY:
1046
        /*
1047
        @ usertextarea_xy
8224 bpr 1048
        @ keyword
7663 schaersvoo 1049
        @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
8224 bpr 1050
        @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
7663 schaersvoo 1051
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
8224 bpr 1052
        @ user drawings will not zoom on zooming (or pan on panning)
7663 schaersvoo 1053
        */
7856 schaersvoo 1054
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
7956 schaersvoo 1055
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7749 schaersvoo 1056
            use_input_xy = 2;
1057
            break;
7652 schaersvoo 1058
        case USERINPUT_XY:
1059
        /*
1060
        @ userinput_xy
8224 bpr 1061
        @ keyword
7652 schaersvoo 1062
        @ to be used in combination with command "userdraw object_type,color"
8224 bpr 1063
        @ 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 1064
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
7749 schaersvoo 1065
        @ 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 1066
        @ can not be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
8224 bpr 1067
        @ user drawings will not zoom on zooming (or pan on panning)
7652 schaersvoo 1068
        */
7749 schaersvoo 1069
            /* add simple eval check to avoid code injection with unprotected eval(string) */
7856 schaersvoo 1070
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
7956 schaersvoo 1071
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7749 schaersvoo 1072
            use_input_xy = 1;
1073
            break;
8193 schaersvoo 1074
        case USERINPUT_FUNCTION:
1075
        /*
1076
        @ userinput_function
1077
        @ keyword
1078
        @ if set , a inputfield will be added to the page
1079
        @ the userinput value will be plotted in the canvas
1080
        @ 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
1081
        @ 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
1082
        @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
1083
        */
8224 bpr 1084
            if( js_function[DRAW_JSFUNCTION] != 1 ){
8193 schaersvoo 1085
             js_function[DRAW_JSFUNCTION] = 1;
1086
             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
1087
             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]);
1088
             input_cnt++;
1089
            }
1090
            if( use_js_math == FALSE){/* add this stuff only once...*/
1091
             add_to_js_math(js_include_file);
1092
             use_js_math = TRUE;
1093
            }
1094
            if( use_js_plot == FALSE){
1095
             use_js_plot = TRUE;
1096
             add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1097
            }
1098
            break;
7614 schaersvoo 1099
        case USERDRAW:
1100
        /*
1101
        @ userdraw object_type,color
8244 schaersvoo 1102
        @ 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 1103
        @ 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 1104
        @ 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 1105
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
7614 schaersvoo 1106
        @ 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)
1107
        @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
8224 bpr 1108
        @ use command "dashed" and/or "dashtype int,int" to trigger dashing
7614 schaersvoo 1109
        @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
1110
        @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
8224 bpr 1111
        @ may be combined with keyword 'userinput_xy' or
7653 schaersvoo 1112
        @ 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 1113
        */
1114
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
1115
                canvas_error("Only one userdraw primitive may be used: read documentation !!");
1116
            }
8074 schaersvoo 1117
            reply_precision = precision;
7614 schaersvoo 1118
            use_userdraw = TRUE;
8130 schaersvoo 1119
            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 1120
            draw_type = get_string_argument(infile,0);
1121
            stroke_color = get_color(infile,1);
1122
            if( strcmp(draw_type,"point") == 0 ){
1123
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1124
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 1125
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 1126
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1127
                if(use_input_xy == 1){
7652 schaersvoo 1128
                    add_input_circle(js_include_file,1,1);
1129
                    add_input_xy(js_include_file,canvas_root_id);
1130
                }
7614 schaersvoo 1131
                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);
1132
            }
1133
            else
1134
            if( strcmp(draw_type,"points") == 0 ){
1135
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1136
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 1137
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 1138
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1139
                if(use_input_xy == 1){
7652 schaersvoo 1140
                    add_input_circle(js_include_file,1,2);
1141
                    add_input_xy(js_include_file,canvas_root_id);
1142
                }
7614 schaersvoo 1143
                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);
1144
            }
1145
            else
1146
            if( strcmp(draw_type,"segment") == 0 ){
1147
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1148
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 1149
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 1150
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1151
                if(use_input_xy == 1){
7652 schaersvoo 1152
                    add_input_segment(js_include_file,1);
1153
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1154
                }
7614 schaersvoo 1155
                add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1156
            }
1157
            else
7663 schaersvoo 1158
            if( strcmp(draw_type,"polyline") == 0 ){
1159
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 1160
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 1161
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 1162
                if( use_input_xy == 1 ){
1163
                    add_input_polyline(js_include_file);
1164
                    add_input_xy(js_include_file,canvas_root_id);
7663 schaersvoo 1165
                }
1166
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1167
            }
1168
            else
7614 schaersvoo 1169
            if( strcmp(draw_type,"segments") == 0 ){
1170
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1171
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 1172
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 1173
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1174
                if(use_input_xy == 1){
7652 schaersvoo 1175
                    add_input_segment(js_include_file,2);
1176
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1177
                }
7614 schaersvoo 1178
                add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1179
            }
1180
            else
1181
            if( strcmp(draw_type,"circle") == 0 ){
1182
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1183
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 1184
                /* 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 1185
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1186
                if(use_input_xy == 1){
7652 schaersvoo 1187
                    add_input_circle(js_include_file,2,1);
1188
                    add_input_xyr(js_include_file,canvas_root_id);
1189
                }
7614 schaersvoo 1190
                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]);
1191
            }
1192
            else
1193
            if( strcmp(draw_type,"circles") == 0 ){
1194
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 1195
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 1196
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
1197
                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 1198
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1199
                if(use_input_xy == 1){
7652 schaersvoo 1200
                    add_input_circle(js_include_file,2,2);
1201
                    add_input_xyr(js_include_file,canvas_root_id);
1202
                }
7614 schaersvoo 1203
            }
1204
            else
1205
            if(strcmp(draw_type,"crosshair") == 0 ){
1206
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 1207
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 1208
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
1209
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 1210
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1211
                if(use_input_xy == 1){
7654 schaersvoo 1212
                    add_input_crosshair(js_include_file,1);
1213
                    add_input_xy(js_include_file,canvas_root_id);
1214
                }
7614 schaersvoo 1215
            }
1216
            else
1217
            if(strcmp(draw_type,"crosshairs") == 0 ){
1218
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 1219
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 1220
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
1221
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 1222
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 1223
                if(use_input_xy == 1){
7654 schaersvoo 1224
                    add_input_crosshair(js_include_file,2);
1225
                    add_input_xy(js_include_file,canvas_root_id);
1226
                }
7614 schaersvoo 1227
            }
1228
            else
1229
            if(strcmp(draw_type,"freehandline") == 0 ){
1230
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1231
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1232
                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 1233
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1234
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1235
            }
1236
            else
1237
            if(strcmp(draw_type,"freehandlines") == 0 ){
1238
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1239
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1240
                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 1241
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1242
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1243
            }
1244
            else
1245
            if(strcmp(draw_type,"path") == 0 ){
1246
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1247
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1248
                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 1249
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1250
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1251
            }
1252
            else
1253
            if(strcmp(draw_type,"paths") == 0 ){
1254
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1255
                if(reply_format == 0){reply_format = 6;}
8224 bpr 1256
                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 1257
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1258
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1259
            }
1260
            else
1261
            if(strcmp(draw_type,"arrows") == 0 ){
1262
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1263
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1264
                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 1265
                if(use_input_xy == 1){
7654 schaersvoo 1266
                    add_input_arrow(js_include_file,2);
1267
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1268
                }
8071 schaersvoo 1269
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1270
            }
1271
            else
7874 schaersvoo 1272
            if(strcmp(draw_type,"arrows2") == 0 ){
1273
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1274
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1275
                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 1276
                if(use_input_xy == 1){
7874 schaersvoo 1277
                    add_input_arrow(js_include_file,1);
1278
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1279
                }
8071 schaersvoo 1280
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 1281
            }
1282
            else
1283
            if(strcmp(draw_type,"arrow2") == 0 ){
1284
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1285
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1286
                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 1287
                if(use_input_xy == 1){
7874 schaersvoo 1288
                    add_input_arrow(js_include_file,1);
1289
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1290
                }
8071 schaersvoo 1291
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 1292
            }
1293
            else
7614 schaersvoo 1294
            if(strcmp(draw_type,"arrow") == 0 ){
1295
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 1296
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 1297
                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 1298
                if(use_input_xy == 1){
7654 schaersvoo 1299
                    add_input_arrow(js_include_file,1);
1300
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1301
                }
8071 schaersvoo 1302
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1303
            }
1304
            else
1305
            if(strcmp(draw_type,"polygon") == 0){
1306
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1307
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1308
                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 1309
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1310
                if(use_input_xy == 2){
7780 schaersvoo 1311
                  add_textarea_polygon(js_include_file);
1312
                  add_textarea_xy(js_include_file,canvas_root_id);
7746 schaersvoo 1313
                }
7614 schaersvoo 1314
            }
8224 bpr 1315
            else
7614 schaersvoo 1316
            if(strncmp(draw_type,"poly",4) == 0){
1317
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
1318
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1319
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1320
                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 1321
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1322
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1323
            }
8224 bpr 1324
            else
7614 schaersvoo 1325
            if(strcmp(draw_type,"triangle") == 0){
1326
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 1327
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1328
                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 1329
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1330
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1331
            }
8224 bpr 1332
            else
7989 schaersvoo 1333
            if( strcmp(draw_type,"hline") == 0 ){
1334
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1335
                if(reply_format == 0){reply_format = 11;}
1336
                add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1337
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1338
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1339
            }
1340
            else
1341
            if( strcmp(draw_type,"hlines") == 0 ){
1342
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1343
                if(reply_format == 0){reply_format = 11;}
1344
                add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1345
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1346
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1347
            }
1348
            else
1349
            if( strcmp(draw_type,"vline") == 0 ){
1350
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1351
                if(reply_format == 0){reply_format = 11;}
1352
                add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1353
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1354
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1355
            }
1356
            else
1357
            if( strcmp(draw_type,"vlines") == 0 ){
1358
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
1359
                if(reply_format == 0){reply_format = 11;}
1360
                add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 1361
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1362
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 1363
            }
1364
            else
7614 schaersvoo 1365
            if( strcmp(draw_type,"line") == 0 ){
1366
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1367
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 1368
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 1369
                add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 1370
                if( use_input_xy == 1 ){
7780 schaersvoo 1371
                    add_input_line(js_include_file,1);
7747 schaersvoo 1372
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1373
                }
8071 schaersvoo 1374
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1375
            }
1376
            else
1377
            if( strcmp(draw_type,"lines") == 0 ){
1378
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1379
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 1380
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 1381
                add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 1382
                if( use_input_xy == 1 ){
7780 schaersvoo 1383
                    add_input_line(js_include_file,2);
7747 schaersvoo 1384
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
7746 schaersvoo 1385
                }
8071 schaersvoo 1386
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1387
            }
1388
            else
8244 schaersvoo 1389
            if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"demilines") == 0 ){
1390
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1391
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
1392
                if(reply_format == 0){reply_format = 11;}
1393
                add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1394
                if( use_input_xy == 1 ){
1395
                    add_input_demiline(js_include_file,2);
1396
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1397
                }
1398
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1399
            }
1400
            else
1401
            if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"demilines") == 0 ){
1402
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
1403
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
1404
                if(reply_format == 0){reply_format = 11;}
1405
                add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1406
                if( use_input_xy == 1 ){
1407
                    add_input_demiline(js_include_file,1);
1408
                    add_input_x1y1x2y2(js_include_file,canvas_root_id);
1409
                }
1410
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1411
            }
1412
            else
7614 schaersvoo 1413
            if( strcmp(draw_type,"rects") == 0){
1414
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 1415
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1416
                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 1417
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1418
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1419
            }
8224 bpr 1420
            else
7614 schaersvoo 1421
            if( strcmp(draw_type,"roundrects") == 0){
1422
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 1423
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1424
                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 1425
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1426
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1427
            }
8224 bpr 1428
            else
7614 schaersvoo 1429
            if( strcmp(draw_type,"rect") == 0){
1430
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 1431
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1432
                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 1433
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1434
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1435
            }
8224 bpr 1436
            else
7614 schaersvoo 1437
            if( strcmp(draw_type,"roundrect") == 0){
1438
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 1439
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 1440
                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 1441
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1442
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1443
            }
1444
            else
8083 schaersvoo 1445
            if( strcmp(draw_type,"arcs") == 0){
1446
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
1447
                if(reply_format == 0){reply_format = 25;}
1448
                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]);
1449
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1450
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1451
            }
1452
            else
8071 schaersvoo 1453
            if( strcmp(draw_type,"arc") == 0){
1454
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
8083 schaersvoo 1455
                if(reply_format == 0){reply_format = 25;}
1456
                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 1457
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1458
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1459
            }
1460
            else
7614 schaersvoo 1461
            if( strcmp(draw_type,"text") == 0){
8224 bpr 1462
                if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
7876 schaersvoo 1463
                if(reply_format == 0){reply_format = 17;}
8071 schaersvoo 1464
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,font_color,stroke_opacity);
7652 schaersvoo 1465
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 1466
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 1467
            }
8116 schaersvoo 1468
            else
1469
            if( strcmp(draw_type,"inputs") == 0){
8224 bpr 1470
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 1471
                if(reply_format == 0){reply_format = 27;}
8116 schaersvoo 1472
                add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width);
1473
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1474
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1475
            }
1476
            else
1477
            if( strcmp(draw_type,"input") == 0){
8224 bpr 1478
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 1479
                if(reply_format == 0){reply_format = 27;}
8116 schaersvoo 1480
                add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width);
1481
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
1482
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
1483
            }
8193 schaersvoo 1484
            else
7614 schaersvoo 1485
            {
1486
                canvas_error("unknown drawtype or typo? ");
1487
            }
1488
            reset();
1489
        break;
1490
        case PLOTSTEPS:
1491
            /*
1492
             @ plotsteps a_number
1493
             @ default 150
1494
             @ use with care !
1495
            */
1496
            plot_steps = (int) (get_real(infile,1));
1497
            break;
1498
        case FONTSIZE:
1499
        /*
1500
         @fontsize font_size
1501
         @default value 12
1502
        */
1503
            font_size = (int) (get_real(infile,1));
1504
            break;
1505
        case FONTCOLOR:
1506
        /*
1507
         @fontcolor color
1508
         @color: hexcolor or colorname
1509
         @default: black
1510
         @example usage: x/y-axis text
1511
        */
1512
            font_color = get_color(infile,1);
1513
            break;
1514
        case ANIMATE:
1515
        /*
1516
         @animate type
8109 schaersvoo 1517
         @REMOVED : this should be done with a slider
7614 schaersvoo 1518
         @type may be "point" (nothing else , yet...)
1519
         @the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
1520
         @will animate a point on the next plot/curve command
1521
         @the curve will not be draw
1522
         @moves repeatedly from xmin to xmax
1523
        */
1524
            if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
1525
            break;
7788 schaersvoo 1526
        case LEVELCURVE:
1527
        /*
1528
        @levelcurve color,expression in x/y,l1,l2,...
7792 schaersvoo 1529
        @draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
1530
        @the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
1531
        @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
1532
        @note : the arrays for holding the javascript data are limited in size
1533
        @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 1534
        */
7792 schaersvoo 1535
            fill_color = get_color(infile,0);
7788 schaersvoo 1536
            char *fun1 = get_string_argument(infile,0);
1537
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
1538
            i = 0;
1539
            done = FALSE;
1540
            while( !done ){
1541
             double_data[i] = get_real(infile,1);
1542
             i++;
1543
            }
1544
            for(c = 0 ; c < i; c++){
8097 schaersvoo 1545
             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 1546
             click_cnt++;
1547
            }
1548
            reset();
1549
            break;
7858 schaersvoo 1550
        case TRACE_JSCURVE:
7823 schaersvoo 1551
        /*
7858 schaersvoo 1552
         @trace_jscurve some_math_function
7823 schaersvoo 1553
         @will use a crosshair to trace the jsmath curve
7856 schaersvoo 1554
         @two inputfields will display the current x/y-values (numerical evaluation by javascript)
8224 bpr 1555
         @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 1556
         @use linewidth,strokecolor,crosshairsize to adjust the corsshair.
7858 schaersvoo 1557
         @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 1558
        */
1559
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7833 schaersvoo 1560
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7858 schaersvoo 1561
            if( use_js_math == FALSE){
1562
                add_to_js_math(js_include_file);
1563
                use_js_math = TRUE;
1564
            }
7823 schaersvoo 1565
            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);
1566
            break;
1567
        case JSMATH:
1568
        /*
7858 schaersvoo 1569
            @jsmath some_math_function
7856 schaersvoo 1570
            @will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
8224 bpr 1571
            @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 1572
            @example: jsmath sin(x^2)
1573
            @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 1574
        */
1575
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7858 schaersvoo 1576
            if( use_js_math == FALSE){
1577
                add_to_js_math(js_include_file);
1578
                use_js_math = TRUE;
1579
            }
7823 schaersvoo 1580
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1));
1581
            break;
7858 schaersvoo 1582
        case JSCURVE:
1583
        /*
1584
         @jscurve color,formula(x)
1585
         @your function will be plotted by the javascript engine of the client browser.
7983 schaersvoo 1586
         @use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
7858 schaersvoo 1587
         @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 1588
         @Attention : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
7858 schaersvoo 1589
         @no validity check is done by wims.
1590
         @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
1591
         @use command 'trace_jscurve formula(x)` for tracing
1592
         @use commmand 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
1593
         @can not be set draggable / onclick (yet)
8224 bpr 1594
         @commands plotjump / plotstep are not active for 'jscurve'
7858 schaersvoo 1595
        */
1596
            stroke_color = get_color(infile,0);
1597
            if( use_js_math == FALSE){/* add this stuff only once...*/
1598
                add_to_js_math(js_include_file);
1599
                use_js_math = TRUE;
1600
            }
1601
            if( use_js_plot == FALSE){
1602
                use_js_plot = TRUE;
1603
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1604
            }
1605
            temp = get_string_argument(infile,1);
1606
            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]);
1607
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1608
            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]);
1609
            add_to_buffer(tmp_buffer);
1610
            use_js_plot++; /* we need to create multiple canvasses, so we may zoom and pan ?? */
1611
 
1612
        break;
7614 schaersvoo 1613
        case CURVE:
1614
        /*
1615
         @curve color,formula(x)
1616
         @plot color,formula(x)
1617
         @use command trange before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
1618
         @use command "precision" to increase the number of digits of the plotted points
1619
         @use command "plotsteps" to increase / decrease the amount of plotted points (default 150)
1620
         @may be set draggable / onclick
1621
        */
1622
            if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
1623
                use_parametric = FALSE;
1624
                stroke_color = get_color(infile,0);
1625
                char *fun1 = get_string_argument(infile,0);
1626
                char *fun2 = get_string_argument(infile,1);
1627
                if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
8097 schaersvoo 1628
                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 1629
                click_cnt++;
1630
            }
1631
            else
1632
            {
1633
                stroke_color = get_color(infile,0);
1634
                char *fun1 = get_string_argument(infile,1);
8224 bpr 1635
                if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
8097 schaersvoo 1636
                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 1637
                click_cnt++;
1638
            }
7788 schaersvoo 1639
            animation_type = 9;/* reset to curve plotting without animation */
7614 schaersvoo 1640
            reset();
1641
            break;
1642
        case FLY_TEXT:
1643
        /*
1644
        @ text fontcolor,x,y,font,text_string
1645
        @ font may be described by keywords : giant,huge,normal,small,tiny
8224 bpr 1646
        @ use command 'fontsize' to increase base fontsize for these keywords
7614 schaersvoo 1647
        @ may be set "onclick" or "drag xy"
1648
        @ backwards compatible with flydraw
1649
        @ unicode supported: text red,0,0,huge,\\u2232
7874 schaersvoo 1650
        @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
1651
        @ 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 1652
        */
1653
            for(i = 0; i < 5 ;i++){
1654
                switch(i){
1655
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
1656
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
1657
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
1658
                    case 3: fly_font = get_string_argument(infile,0);
1659
                            if(strcmp(fly_font,"giant") == 0){
1660
                                font_size = (int)(font_size + 24);
1661
                            }
1662
                            else
1663
                            {
1664
                                if(strcmp(fly_font,"huge") == 0){
1665
                                    font_size = (int)(font_size + 14);
1666
                                }
1667
                                else
1668
                                {
1669
                                    if(strcmp(fly_font,"large") == 0){
1670
                                        font_size = (int)(font_size + 6);
1671
                                        }
1672
                                        else
1673
                                        {
1674
                                            if(strcmp(fly_font,"small") == 0){
1675
                                                font_size = (int)(font_size - 4);
1676
                                                if(font_size<0){font_size = 8;}
1677
                                        }
1678
                                    }
1679
                                }
1680
                            }
1681
                            break; /* font_size ! */
8224 bpr 1682
                    case 4:
7614 schaersvoo 1683
                        temp = get_string_argument(infile,1);
1684
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 1685
                        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 1686
                        click_cnt++;reset();break;
1687
                    default:break;
1688
                }
1689
            }
1690
            break;
1691
        case FLY_TEXTUP:
1692
        /*
1693
         @ textup fontcolor,x,y,font,text_string
1694
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
1695
         @ font may be described by keywords : giant,huge,normal,small,tiny
8224 bpr 1696
         @ use command 'fontsize' to increase base fontsize for the keywords
7614 schaersvoo 1697
         @ backwards compatible with flydraw
1698
         @ unicode supported: textup red,0,0,huge,\\u2232
1699
         @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
7874 schaersvoo 1700
         @ 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 1701
        */
8224 bpr 1702
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
7614 schaersvoo 1703
            for(i = 0; i<5 ;i++){
1704
                switch(i){
1705
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
1706
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
1707
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
1708
                    case 3: fly_font = get_string_argument(infile,0);
1709
                            if(strcmp(fly_font,"giant") == 0){
1710
                                font_size = (int)(font_size + 24);
1711
                            }
1712
                            else
1713
                            {
1714
                                if(strcmp(fly_font,"huge") == 0){
1715
                                    font_size = (int)(font_size + 14);
1716
                                }
1717
                                else
1718
                                {
1719
                                    if(strcmp(fly_font,"large") == 0){
1720
                                        font_size = (int)(font_size + 6);
1721
                                        }
1722
                                        else
1723
                                        {
1724
                                            if(strcmp(fly_font,"small") == 0){
1725
                                                font_size = (int)(font_size - 4);
1726
                                                if(font_size<0){font_size = 8;}
1727
                                        }
1728
                                    }
1729
                                }
1730
                            }
1731
                            break; /* font_size ! */
8224 bpr 1732
                    case 4:
7614 schaersvoo 1733
                    decimals = find_number_of_digits(precision);
1734
                    temp = get_string_argument(infile,1);
8071 schaersvoo 1735
                    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 1736
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1737
                    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 1738
                    add_to_buffer(tmp_buffer);
1739
                    break;
1740
                    default:break;
1741
                }
1742
            }
1743
            reset();
1744
            break;
1745
        case FONTFAMILY:
1746
        /*
1747
         @ fontfamily font_description
1748
         @ set the font family; for browsers that support it
1749
         @ font_description: Ariel ,Courier, Helvetica etc
1750
         @ 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
1751
         @ use correct syntax : 'font style' 'font size'px 'fontfamily'
1752
        */
1753
            font_family = get_string(infile,1);
1754
            break;
1755
        case STRINGUP:
8224 bpr 1756
        /*
1757
         @ stringup color,x,y,rotation_degrees,the text string
7614 schaersvoo 1758
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
1759
         @ unicode supported: stringup red,0,0,45,\\u2232
1760
         @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
1761
 
1762
        */
1763
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
1764
            for(i=0;i<6;i++){
1765
                switch(i){
1766
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
1767
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
1768
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
1769
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
1770
                    case 4: decimals = find_number_of_digits(precision);
1771
                            temp = get_string_argument(infile,1);
8071 schaersvoo 1772
                            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 1773
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 1774
                            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 1775
                            add_to_buffer(tmp_buffer);
1776
                            break;
1777
                    default:break;
1778
                }
1779
            }
1780
            reset();
1781
            break;
1782
        case STRING:
8224 bpr 1783
        /*
7614 schaersvoo 1784
         @ string color,x,y,the text string
1785
         @ may be set "onclick" or "drag xy"
1786
         @ unicode supported: string red,0,0,\\u2232
8224 bpr 1787
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
7614 schaersvoo 1788
        */
1789
            for(i=0;i<5;i++){
1790
                switch(i){
1791
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
1792
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
1793
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
1794
                    case 3: decimals = find_number_of_digits(precision);
1795
                        temp = get_string_argument(infile,1);
1796
                        decimals = find_number_of_digits(precision);
8097 schaersvoo 1797
                        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 1798
                        click_cnt++;reset();break;
1799
                    default:break;
1800
                }
1801
            }
1802
            break;
7983 schaersvoo 1803
        case CENTERSTRING:
8224 bpr 1804
        /*
7983 schaersvoo 1805
         @ centerstring color,y-value,the text string
7984 schaersvoo 1806
         @ title color,y-value,the text string
7983 schaersvoo 1807
         @ draw a string centered on the canvas at y = y-value
1808
         @ can not set "onclick" or "drag xy" (...)
1809
         @ unicode supported: centerstring red,5,\\u2232
8224 bpr 1810
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
7983 schaersvoo 1811
        */
1812
            if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
1813
            for(i=0;i<3;i++){
1814
                switch(i){
1815
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
1816
                    case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
1817
                    case 2: temp = get_string_argument(infile,1);
1818
                            /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
1819
                            decimals = find_number_of_digits(precision);
1820
                            string_length = snprintf(NULL,0,
1821
                            "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
1822
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1823
                            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);
1824
                            add_to_buffer(tmp_buffer);
1825
                            break;
1826
                    default:break;
1827
                }
1828
            }
1829
            break;
7614 schaersvoo 1830
        case MATHML:
1831
        /*
1832
        @ mathml x1,y1,x2,y2,mathml_string
8224 bpr 1833
        @ mathml will be displayed in a rectangle left top (x1:y1) , right bottom (x2:y2)
7614 schaersvoo 1834
        @ can be set onclick <br />(however dragging is not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
8224 bpr 1835
        @ 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 1836
        @ 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 1837
 
7614 schaersvoo 1838
        */
1839
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
1840
            for(i=0;i<5;i++){
1841
                switch(i){
1842
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1843
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1844
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1845
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1846
                    case 4: decimals = find_number_of_digits(precision);
8224 bpr 1847
                            if(onclick == 1 ){ onclick = click_cnt;click_cnt++;}
7614 schaersvoo 1848
                            temp = get_string(infile,1);
1849
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
1850
                            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);
1851
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1852
                            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);
1853
                            add_to_buffer(tmp_buffer);
8224 bpr 1854
                            /*
1855
                             in case inputs are present , trigger adding the read_mathml()
7614 schaersvoo 1856
                             if no other reply_format is defined
1857
                             note: all other reply types will include a reading of elements with id='mathml'+p)
1858
                             */
1859
                            if(strstr(temp,"mathml0") != NULL){
7876 schaersvoo 1860
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
7614 schaersvoo 1861
                            }
1862
                            break;
1863
                    default:break;
1864
                }
1865
            }
1866
            reset();
1867
            break;
1868
        case HTTP:
1869
        /*
1870
         @http x1,y1,x2,y2,http://some_adress.com
8224 bpr 1871
         @an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
7614 schaersvoo 1872
         @do not use interactivity (or mouse) if the mouse needs to be active in the iframe
1873
         @can not be 'set onclick' or 'drag xy'
1874
        */
8224 bpr 1875
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
7614 schaersvoo 1876
            for(i=0;i<5;i++){
1877
                switch(i){
1878
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1879
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1880
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1881
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1882
                    case 4: decimals = find_number_of_digits(precision);
1883
                            temp = get_string(infile,1);
1884
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
1885
                            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);
1886
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1887
                            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);
1888
                            add_to_buffer(tmp_buffer);
1889
                    break;
1890
                }
1891
            }
1892
            reset();
1893
            break;
1894
        case HTML:
1895
        /*
1896
         @ html x1,y1,x2,y2,html_string
1897
         @ all tags are allowed
1898
         @ can be set onclick <br />(dragging not supported)<br />javascript:read_dragdrop(); will return click number of mathml-object
1899
         @ 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 1900
 
7614 schaersvoo 1901
         note: uses the same code as 'mathml'
1902
        */
1903
            break;
1904
        case X_AXIS_STRINGS:
1905
        /*
1906
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1907
         @ xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1908
         @ use these x-axis values in stead of default xmin...xmax
1909
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1910
         @ if the 'x-axis words' are to big amd will overlap, a simple alternating offset will be applied
1911
         @ 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
1912
         @ 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
1913
        */
1914
            temp = get_string(infile,1);
1915
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
1916
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
1917
            fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
1918
            use_axis_numbering = 1;
1919
            break;
1920
        case Y_AXIS_STRINGS:
1921
        /*
1922
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1923
         @ yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
1924
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
1925
         @ use these y-axis values in stead of default ymin...ymax
1926
         @ 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
1927
        */
1928
            temp = get_string(infile,1);
1929
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
1930
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
1931
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
1932
            use_axis_numbering = 1;
1933
            break;
8224 bpr 1934
 
7614 schaersvoo 1935
        case AXIS_NUMBERING:
1936
        /*
8224 bpr 1937
            @ axisnumbering
8101 schaersvoo 1938
            @ keyword, no arguments required
7614 schaersvoo 1939
        */
1940
            use_axis_numbering = 1;
1941
            break;
1942
        case AXIS:
1943
        /*
1944
            @ axis
8101 schaersvoo 1945
            @ keyword, no arguments required
7614 schaersvoo 1946
 
1947
        */
1948
            use_axis = TRUE;
1949
            break;
8101 schaersvoo 1950
        case KILLSLIDER:
1951
        /*
1952
         @ killslider
1953
         @ keyword, no arguments required
1954
         @ ends grouping of object under a preciously defined slider
1955
        */
1956
            slider = 0;
1957
            break;
8071 schaersvoo 1958
        case SLIDER:
1959
        /*
8097 schaersvoo 1960
        @ slider start_value,end_value,width px,height px,type,label
1961
        @ type: xy,x,y,angle
8112 schaersvoo 1962
        @ if a value display is desired, use<br />type:xy display,x display,y display,angle radian,angle degree
1963
        @ is a unit for x / y value display is needed, use commands 'xunit' and / or 'yunit'
8101 schaersvoo 1964
        @ use commmand 'slider' before draggable/clickable objects.
1965
        @ 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 1966
        @ amount of sliders is not limited.
8101 schaersvoo 1967
        @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
8097 schaersvoo 1968
        @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
1969
        @ every draggable object may have it's own slider (no limit in amount of sliders)
8071 schaersvoo 1970
        @ label: some slider text
1971
        @ use fillcolor for slider ball
1972
        @ use strokecolor for slider bar
8097 schaersvoo 1973
        @ use fontfamily / fontcolor to set used fonts
8071 schaersvoo 1974
        @ use opacity (only fill opacity will be used) to set transparency
8111 schaersvoo 1975
        @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
8071 schaersvoo 1976
        */
1977
            for(i=0; i<6 ; i++){
1978
                switch(i){
1979
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
1980
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
1981
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
1982
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
8111 schaersvoo 1983
                    case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
8112 schaersvoo 1984
                    /* xy display*/
1985
                    if(strstr(temp,"xy")!= 0){
8097 schaersvoo 1986
                     slider = 4;
1987
                    }
1988
                    else
1989
                    {
8112 schaersvoo 1990
                     if(strstr(temp,"x") != 0){
8097 schaersvoo 1991
                      slider = 1;
1992
                     }
1993
                     else
1994
                     {
8112 schaersvoo 1995
                      if(strstr(temp,"y") != 0){
8097 schaersvoo 1996
                       slider = 2;
1997
                      }
1998
                      else
1999
                      {
8112 schaersvoo 2000
                       if(strstr(temp,"angle") != 0){ /* angle diplay radian */
8097 schaersvoo 2001
                        slider = 3;
2002
                       }
2003
                       else
8112 schaersvoo 2004
                       {
8097 schaersvoo 2005
                        canvas_error("slider types may be : x , y , xy , angle");
8112 schaersvoo 2006
                       }
8097 schaersvoo 2007
                      }
2008
                     }
2009
                    }
8112 schaersvoo 2010
                    if(strstr(temp,"display")!=0){
2011
                     use_slider_display = 1; /* show x xy values in canvas window */
2012
                    }
2013
                    else
2014
                    {
2015
                     if(strstr(temp,"degree")!= 0){
2016
                      use_slider_display = 2; /* show angle values in canvas window */
2017
                     }
2018
                     else
2019
                     {
2020
                      if(strstr(temp,"radian")!=0){
2021
                       use_slider_display = 3; /* show radian values in canvas window */
2022
                      }
2023
                     }
2024
                    }
2025
                    if(use_slider_display != 0 && slider_cnt == 0){ /*add just once the display js-code */
2026
                     add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
2027
                    }
8097 schaersvoo 2028
                    break;
2029
                    case 5: /* some string used for slider description  */
8071 schaersvoo 2030
                    slider_cnt++;
8097 schaersvoo 2031
                    if(slider == 4){
8112 schaersvoo 2032
                     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 2033
                    }else{
8112 schaersvoo 2034
                     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 2035
                    }
8071 schaersvoo 2036
                    break;
2037
                }
8097 schaersvoo 2038
             }
8071 schaersvoo 2039
            break;
7654 schaersvoo 2040
        case SGRAPH:
2041
        /*
2042
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
2043
         @ primitive implementation of a 'broken scale' graph...
7976 schaersvoo 2044
         @ 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 2045
         @ 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 2046
        */
8224 bpr 2047
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
7654 schaersvoo 2048
            for(i = 0 ; i < 8 ;i++){
2049
                switch(i){
2050
                    case 0:double_data[0] = get_real(infile,0);break;
2051
                    case 1:double_data[1] = get_real(infile,0);break;
2052
                    case 2:double_data[2] = get_real(infile,0);break;
2053
                    case 3:double_data[3] = get_real(infile,0);break;
2054
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
2055
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
2056
                    case 6:stroke_color = get_color(infile,0);break;
2057
                    case 7:font_color = get_color(infile,1);
7658 schaersvoo 2058
                    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 2059
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7658 schaersvoo 2060
                    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 2061
                    add_to_buffer(tmp_buffer);
2062
                    break;
2063
                    default:break;
2064
                }
2065
            }
2066
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
2067
            break;
7614 schaersvoo 2068
        case GRID:/* xmajor,ymajor,color [,xminor,yminor,tick length (px) ,color]*/
2069
        /*
2070
         @ grid step_x,step_y,gridcolor
2071
         @ use command "fontcolor", "fontsize" , "fontfamily" to adjust font <br />defaults: black,12,Ariel
2072
         @ 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 2073
         @ 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 2074
         @ can not be set "onclick" or "drag xy"
2075
         @ 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')
2076
         @ 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')
2077
         @ 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')
2078
        */
7729 schaersvoo 2079
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
7614 schaersvoo 2080
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
2081
            for(i=0;i<4;i++){
2082
                switch(i){
2083
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
2084
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
2085
                    case 2:
2086
                    if( use_axis == TRUE ){
2087
                        stroke_color = get_color(infile,0);
2088
                        done = FALSE;
2089
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
2090
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
2091
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
2092
                        fill_color = get_color(infile,1); /* used as axis_color*/
2093
                    }
2094
                    else
2095
                    {
2096
                        int_data[0] = 1;
2097
                        int_data[1] = 1;
2098
                        stroke_color = get_color(infile,1);
2099
                        fill_color = stroke_color;
2100
                    }
2101
                    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 2102
                    /* set snap_x snap_y values in pixels */
7988 schaersvoo 2103
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
8071 schaersvoo 2104
                    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 2105
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 2106
                    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 2107
                    add_to_buffer(tmp_buffer);
2108
                    break;
2109
                }
2110
            }
2111
            reset();
2112
            break;
2113
        case OPACITY:
2114
        /*
2115
        @ opacity 0-255,0-255
2116
        @
2117
        */
2118
            for(i = 0 ; i<2;i++){
2119
                switch(i){
2120
                    case 0: double_data[0]=(int)(get_real(infile,0));break;
2121
                    case 1: double_data[1]=(int)(get_real(infile,1));break;
2122
                    default: break;
2123
                }
2124
            }
2125
            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 ? */
2126
            stroke_opacity = (double) (0.0039215*double_data[0]);/* 0.0 - 1.0 */
2127
            fill_opacity = (double) (0.0039215*double_data[1]);/* 0.0 - 1.0 */
2128
            break;
2129
        case ROTATE:
2130
        /*
2131
         @rotate rotation_angle
8097 schaersvoo 2132
         @angle in degrees
7614 schaersvoo 2133
        */
2134
            use_rotate = TRUE;
8097 schaersvoo 2135
            angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
7614 schaersvoo 2136
            break;
7785 schaersvoo 2137
        case KILLAFFINE:
2138
        /*
2139
        @ killaffine
2140
        @ keyword : resets the transformation matrix to 1,0,0,1,0,0
2141
        */
2142
            use_affine = FALSE;
8224 bpr 2143
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
7785 schaersvoo 2144
            break;
2145
        case AFFINE:
2146
        /*
2147
         @affine a,b,c,d,tx,ty
8224 bpr 2148
         @ defines a transformation matrix for subsequent objects
7785 schaersvoo 2149
         @ use keyword 'killaffine' to end the transformation
2150
         @ note 1: only 'draggable' / 'noclick' objects can be transformed.
2151
         @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
2152
         @ note 3: no matrix operations on the transformation matrix implemented (yet)
2153
         @ a : Scales the drawings horizontally
2154
         @ b : Skews the drawings horizontally
2155
         @ c : Skews the drawings vertically
2156
         @ d : Scales the drawings vertically
8071 schaersvoo 2157
         @ tx: Moves the drawings horizontally in xrange coordinate system
8224 bpr 2158
         @ ty: Moves the drawings vertically in yrange coordinate system
8071 schaersvoo 2159
         @ the data precision is 2 decimals (printf : %2.f)
7785 schaersvoo 2160
        */
2161
            for(i = 0 ; i<6;i++){
2162
                switch(i){
2163
                    case 0: double_data[0] = get_real(infile,0);break;
2164
                    case 1: double_data[1] = get_real(infile,0);break;
2165
                    case 2: double_data[2] = get_real(infile,0);break;
2166
                    case 3: double_data[3] = get_real(infile,0);break;
8071 schaersvoo 2167
                    case 4: double_data[4] = get_real(infile,0);break;
2168
                    case 5: double_data[5] = get_real(infile,1);
7785 schaersvoo 2169
                        use_affine = TRUE;
8071 schaersvoo 2170
                        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 2171
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
8224 bpr 2172
                        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 2173
                        break;
7785 schaersvoo 2174
                    default: break;
2175
                }
2176
            }
2177
        break;
7614 schaersvoo 2178
        case KILLTRANSLATION:
2179
        /*
2180
         killtranslation
2181
        */
8071 schaersvoo 2182
            use_affine = FALSE;
8224 bpr 2183
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
7614 schaersvoo 2184
            break;
2185
        case TRANSLATION:
2186
        /*
2187
         @translation tx,ty
8071 schaersvoo 2188
         @will translate the next object tx in xrange and ty in yrange
2189
         @uase command 'killtranstation' to end the command
7614 schaersvoo 2190
        */
8071 schaersvoo 2191
            for(i = 0 ; i<2;i++){
2192
                switch(i){
2193
                    case 0: double_data[0] = get_real(infile,0);break;
2194
                    case 1: double_data[1] = get_real(infile,1);
2195
                        use_affine = TRUE;
2196
                        string_length = snprintf(NULL,0, "[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
2197
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
2198
                        snprintf(affine_matrix,string_length,"[1,0,0,1,%.2f,%.2f] ",double_data[0]*xsize/(xmax - xmin),-1*double_data[1]*ysize/(ymax - ymin));
2199
                        break;
2200
                    default: break;
2201
                }
2202
            }
2203
        break;
2204
 
7614 schaersvoo 2205
        case DASHED:
2206
        /*
2207
        @ keyword "dashed"
2208
        @ next object will be drawn with a dashed line
2209
        @ change dashing scheme by using command "dashtype int,int)
2210
        */
2211
            use_dashed = TRUE;
2212
            break;
2213
        case FILLED:
2214
        /*
8224 bpr 2215
        @ keyword "filled"
2216
        @ the next 'fillable' object (only) will be filled
7614 schaersvoo 2217
        @ use command "fillcolor color" to set fillcolor
2218
        @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
2219
        @ 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 !
2220
        */
2221
            use_filled = TRUE;
2222
            break;
2223
        case STYLE:
2224
        /*
2225
         @highlight color,opacity,linewidth
2226
         @ NOT IMPLEMENTED
2227
         @ use command "onclick" : when the object receives a userclick it will increase it's linewidth
2228
        */
2229
            break;
2230
        case FILLCOLOR:
2231
        /*
2232
        @ fillcolor colorname or #hex
2233
        @ Set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
2234
        @ All fillable massive object will have a fillcolor == strokecolor (just to be compatible with flydraw...)
2235
        */
2236
            fill_color = get_color(infile,1);
2237
            break;
2238
        case STROKECOLOR:
2239
        /*
2240
        @ strokecolor colorname or #hex
2241
        @ to be used for commands that do not supply a color argument (like command 'linegraph')
2242
        */
2243
            stroke_color = get_color(infile,1);
2244
            break;
8224 bpr 2245
        case BGIMAGE:
7614 schaersvoo 2246
        /*
2247
         @bgimage image_location
2248
         @use an image as background .<br />(we use the background of 'canvas_div' )
2249
         @the background image will be resized to match "width = xsize" and "height = ysize"
2250
        */
2251
        URL = get_string(infile,1);
2252
        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);
2253
            break;
8224 bpr 2254
        case BGCOLOR:
7614 schaersvoo 2255
        /*
2256
         @bgcolor colorname or #hex
2257
         @use this color as background of the "div" containing the canvas(es)
2258
        */
2259
        /* [255,255,255]*/
2260
            bgcolor = get_string(infile,1);
2261
            if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
2262
                int found = 0;
2263
                for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
2264
                    if( strcmp( colors[i].name , bgcolor ) == 0 ){
2265
                        bgcolor = colors[i].hex;
2266
                        found = 1;
2267
                        break;
2268
                    }
2269
                }
2270
                if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
2271
            }
2272
            fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
2273
            break;
2274
        case COPY:
2275
        /*
2276
        @ copy x,y,x1,y1,x2,y2,[filename URL]
2277
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
2278
        @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
8224 bpr 2279
        @ [filename] is the URL of the image
7614 schaersvoo 2280
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
2281
        @ 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 2282
        @ 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 2283
 
2284
        context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
2285
        draw_external_image(canvas_type,URL,sx,sy,swidth,sheight,x,y,width,height,drag_drop){
2286
        */
2287
            for(i = 0 ; i<7;i++){
2288
                switch(i){
2289
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
2290
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
2291
                    case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
2292
                    case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
2293
                    case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
2294
                    case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
2295
                    case 6: URL = get_string(infile,1);
2296
                            int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
2297
                            int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
2298
                            if( drag_type > -1 ){
2299
                                if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
7876 schaersvoo 2300
                                if(reply_format == 0 ){reply_format = 20;}
7614 schaersvoo 2301
                                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);
2302
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8224 bpr 2303
                                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 2304
                                drag_type = -1;
2305
                                ext_img_cnt++;
2306
                            }
2307
                            else
2308
                            {
2309
                                if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
2310
                                /*
2311
                                draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\n\
2312
                                */
2313
                                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]);
2314
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2315
                                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]);
2316
                            }
2317
                            add_to_buffer(tmp_buffer);
2318
                            break;
2319
                    default: break;
2320
                }
2321
            }
2322
            reset();
2323
            break;
2324
/*
2325
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
2326
img     Specifies the image, canvas, or video element to use
2327
sx      The x coordinate where to start clipping : x1 = int_data[0]
2328
sy      The y coordinate where to start clipping : x2 = int_data[1]
8224 bpr 2329
swidth  The width of the clipped image : int_data[2] - int_data[0]
7614 schaersvoo 2330
sheight The height of the clipped image : int_data[3] - int_data[1]
2331
x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
2332
y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
2333
width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
2334
height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
2335
*/
2336
        case COPYRESIZED:
2337
        /*
2338
        @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
8224 bpr 2339
        @ 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 2340
        @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
2341
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
2342
        @ 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 2343
        @ 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 2344
        */
2345
            for(i = 0 ; i<9;i++){
2346
                switch(i){
2347
                    case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
2348
                    case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
2349
                    case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
2350
                    case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
2351
                    case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
2352
                    case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
2353
                    case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
2354
                    case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
2355
                    case 8: URL = get_string(infile,1);
2356
                            if( drag_type > -1 ){
2357
                                if( js_function[DRAG_EXTERNAL_IMAGE] != 1 ){ js_function[DRAG_EXTERNAL_IMAGE] = 1;}
7876 schaersvoo 2358
                                if(reply_format == 0 ){reply_format = 20;}
7614 schaersvoo 2359
                                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);
2360
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2361
                                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);
2362
                                drag_type = -1;
2363
                                ext_img_cnt++;
2364
                            }
2365
                            else
2366
                            {
2367
                                if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
2368
                                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]);
2369
                                check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2370
                                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]);
2371
                            }
2372
                            add_to_buffer(tmp_buffer);
2373
                    default: break;
2374
                }
2375
            }
2376
            reset();
2377
            break;
8146 schaersvoo 2378
        case CLEARBUTTON:
7614 schaersvoo 2379
        /*
8146 schaersvoo 2380
         @clearbutton value
2381
         @adds a button to clear the userdraw canvas with text 'value'
8193 schaersvoo 2382
         @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 2383
         @uses the tooltip placeholder div element: may not be used with command 'intooltip'
8224 bpr 2384
         @use command 'inputstyle' to style the button...
7614 schaersvoo 2385
        */
8146 schaersvoo 2386
            add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
7614 schaersvoo 2387
        break;
2388
        case INPUTSTYLE:
2389
        /*
2390
        @ inputstyle style_description
2391
        @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
2392
        */
2393
            input_style = get_string(infile,1);
2394
            break;
2395
        case INPUT:
8224 bpr 2396
        /*
7614 schaersvoo 2397
         @ input x,y,size,editable,value
8224 bpr 2398
         @ to set inputfield "readonly", use editable = 0
7614 schaersvoo 2399
         @ only active inputfields (editable = 1) will be read with read_canvas();
8224 bpr 2400
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
7614 schaersvoo 2401
         @ may be further controlled by "inputstyle" (inputcss is not yet implemented...)
2402
         @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
2403
        */
8224 bpr 2404
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
7614 schaersvoo 2405
            for(i = 0 ; i<5;i++){
2406
                switch(i){
2407
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
2408
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
2409
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
2410
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
8224 bpr 2411
                    case 4:
7614 schaersvoo 2412
                            temp = get_string_argument(infile,1);
2413
                            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);
2414
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2415
                            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);
2416
                            add_to_buffer(tmp_buffer);
2417
                            input_cnt++;break;
2418
                    default: break;
2419
                }
2420
            }
7876 schaersvoo 2421
            if(reply_format == 0 ){reply_format = 15;}
7614 schaersvoo 2422
            reset();
2423
            break;
2424
        case TEXTAREA:
8224 bpr 2425
        /*
7614 schaersvoo 2426
         @ textarea x,y,cols,rows,readonly,value
2427
         @ may be further controlled by "inputstyle"
8224 bpr 2428
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be clearedand set readonly<br />Override this by keyword 'status'
7614 schaersvoo 2429
         @ if mathml inputfields are present and / or some userdraw is performed, these data will NOT be send as well (javascript:read_canvas();)
2430
        */
8224 bpr 2431
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
7614 schaersvoo 2432
            for(i = 0 ; i<6;i++){
2433
                switch(i){
2434
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
2435
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
2436
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
2437
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
2438
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
2439
                    case 5: temp = get_string_argument(infile,1);
2440
                            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);
2441
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2442
                            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);
2443
                            add_to_buffer(tmp_buffer);
2444
                            input_cnt++;break;
2445
                    default: break;
2446
                }
2447
            }
7876 schaersvoo 2448
            if(reply_format == 0 ){reply_format = 15;}
7614 schaersvoo 2449
            reset();
2450
            break;
2451
        case MOUSE_PRECISION:
2452
        /*
2453
            @ precision int
8074 schaersvoo 2454
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
7614 schaersvoo 2455
            @ may be used / changed before every object
8074 schaersvoo 2456
            @ In case of user interaction (like 'userdraw') this value will be used to determine the amount of decimals in the reply / answer
7614 schaersvoo 2457
        */
2458
            precision = (int) (get_real(infile,1));
8074 schaersvoo 2459
            if(precision < 1 ){precision = 1;};
7614 schaersvoo 2460
            break;
7838 schaersvoo 2461
        case SETLIMITS:
2462
        /*
8224 bpr 2463
            @setlimits
7838 schaersvoo 2464
            @keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
2465
            @may be used for inputfield based zooming / panning
7858 schaersvoo 2466
            @use command xlabel / ylabel to change text from xmin to 'xlabel'min etc
8224 bpr 2467
            @note:the input value will not be checked on validity
7838 schaersvoo 2468
        */
7956 schaersvoo 2469
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
7838 schaersvoo 2470
            add_setlimits(js_include_file,canvas_root_id);
2471
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
2472
            use_pan_and_zoom = TRUE;
2473
            done = TRUE;
2474
            break;
7614 schaersvoo 2475
        case ZOOM:
2476
        /*
2477
         @ zoom button_color
2478
         @ introduce a controlpanel at the lower right corner
2479
         @ 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
2480
         @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
2481
         @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
8224 bpr 2482
         @ command 'opacity' may be used to set stroke_opacity of 'buttons
2483
         @ NOTE: use command 'zoom' at the end of your script code (the same is true for commanmd 'mouse')
7614 schaersvoo 2484
         @ NOTE: only objects that may be set draggable / clickable will be zoomed / panned
2485
         @ 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 !!
2486
        */
7653 schaersvoo 2487
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
7797 schaersvoo 2488
            use_pan_and_zoom = TRUE;
7988 schaersvoo 2489
            stroke_color = get_color(infile,1);
7614 schaersvoo 2490
            /* we use BG_CANVAS (0) */
7988 schaersvoo 2491
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
7614 schaersvoo 2492
            done = TRUE;
2493
            break;
2494
        case ONCLICK:
2495
        /*
2496
         @ onclick
2497
         @ keyword, no arguments
2498
         @ if the next object is clicked, it's 'object sequence number' in fly script is returned <br /> by javascript:read_canvas();
8224 bpr 2499
         @ Line based object will show an increase in linewidth<br />Font based objects will show the text in 'bold' when clicked.
7906 schaersvoo 2500
         @ NOTE: not all objects may be set clickable
7614 schaersvoo 2501
        */
8224 bpr 2502
 
7614 schaersvoo 2503
            onclick = 1;
2504
            break;
2505
        case DRAG:
2506
        /*
2507
         @ drag [x][y][xy]
2508
         @ the next object will be draggable in x / y / xy direction
2509
         @ the displacement can be read by 'javascript:read_dragdrop();'
8074 schaersvoo 2510
         @ 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 2511
         @ 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 2512
         @ use keywordd 'snaptogrid' , 'xsnaptogrid' or 'ysnaptogrid' to switch from free to discrete movement
8224 bpr 2513
         @ 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 2514
         @ 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 !!
2515
        */
2516
            temp = get_string(infile,1);
8224 bpr 2517
            if(strstr(temp,"xy") != NULL ){
7614 schaersvoo 2518
                drag_type = 0;
2519
            }
2520
            else
2521
            {
8224 bpr 2522
                if(strstr(temp,"x") != NULL ){
7614 schaersvoo 2523
                    drag_type = 1;
2524
                }
2525
                else
2526
                {
2527
                    drag_type = 2;
2528
                }
2529
            }
8074 schaersvoo 2530
            fprintf(js_include_file,"var dragdrop_precision = %d;",precision);
7614 schaersvoo 2531
            onclick = 2;
2532
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
2533
            break;
2534
        case BLINK:
2535
        /*
2536
         @ blink time(seconds)
2537
         @ NOT IMPLEMETED -YET
2538
        */
2539
            break;
7996 schaersvoo 2540
        case XUNIT:
2541
        /*
2542
         @ xunit some_unit_for_x-values
2543
         @ unicode allowed (no html code)
2544
         @ use together with command mousex
2545
         @ will display the cursor x-coordinate 'unit'
2546
        */
2547
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
2548
            break;
2549
        case YUNIT:
2550
        /*
2551
         @ yunit some_unit_for_y-values
2552
         @ unicode allowed (no html code)
2553
         @ use together with command mousex
2554
         @ will display the cursor y-coordinate 'unit'
2555
        */
2556
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
2557
            break;
8071 schaersvoo 2558
        case MOUSE_DISPLAY:
2559
        /*
8129 schaersvoo 2560
         @display x|y|xy|degree|radius,color,fontsize
2561
         @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)
2562
         @use commands 'xunit' and / or 'yunit' to add the units to the mouse values
8071 schaersvoo 2563
         @just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
2564
        */
2565
        temp = get_string_argument(infile,0);
8112 schaersvoo 2566
        if( strstr(temp,"xy") != NULL ){
2567
            int_data[0] = 2;
8071 schaersvoo 2568
        }else{
8112 schaersvoo 2569
            if( strstr(temp,"y") != NULL ){
2570
                int_data[0] = 1;
8071 schaersvoo 2571
            }else{
8112 schaersvoo 2572
                if( strstr(temp,"x") != NULL ){
2573
                    int_data[0] = 0;
8129 schaersvoo 2574
                }else{
8112 schaersvoo 2575
                    if(strstr(temp,"degree") != NULL){
2576
                        int_data[0] = 3;
8071 schaersvoo 2577
                    }else{
8129 schaersvoo 2578
                        if(strstr(temp,"radius") != NULL){
2579
                            int_data[0] = 4;
2580
                        }else{
2581
                            int_data[0] = 2;
2582
                        }
8112 schaersvoo 2583
                    }
8129 schaersvoo 2584
                }
8071 schaersvoo 2585
            }
8129 schaersvoo 2586
        }
8071 schaersvoo 2587
        stroke_color = get_color(infile,0);
2588
        font_size = (int) (get_real(infile,1));
2589
        tmp_buffer = my_newmem(26);
2590
        snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2591
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2592
        break;
2593
        case MOUSE_DEGREE:
2594
        /*
2595
         @ mouse_degree color,fontsize
8099 schaersvoo 2596
         @ 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 2597
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
8224 bpr 2598
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
8071 schaersvoo 2599
 
2600
        */
2601
            stroke_color = get_color(infile,0);
2602
            font_size = (int) (get_real(infile,1));
2603
            tmp_buffer = my_newmem(26);
2604
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2605
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2606
            break;
7991 schaersvoo 2607
        case MOUSEX:
2608
        /*
2609
         @ mousex color,fontsize
2610
         @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
8224 bpr 2611
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
7991 schaersvoo 2612
 
2613
        */
2614
            stroke_color = get_color(infile,0);
2615
            font_size = (int) (get_real(infile,1));
2616
            tmp_buffer = my_newmem(26);
2617
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2618
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2619
            break;
2620
        case MOUSEY:
2621
        /*
2622
         @ mousey color,fontsize
2623
         @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
8224 bpr 2624
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
7991 schaersvoo 2625
 
2626
        */
2627
            stroke_color = get_color(infile,0);
2628
            font_size = (int) (get_real(infile,1));
2629
            tmp_buffer = my_newmem(26);
2630
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2631
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2632
            break;
7614 schaersvoo 2633
        case MOUSE:
2634
        /*
2635
         @ mouse color,fontsize
7991 schaersvoo 2636
         @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
8224 bpr 2637
         @ NOTE: use command 'mouse' at the end of your script code (the same is true for commanmd 'zoom')
7988 schaersvoo 2638
 
7614 schaersvoo 2639
        */
2640
            stroke_color = get_color(infile,0);
2641
            font_size = (int) (get_real(infile,1));
7839 schaersvoo 2642
            tmp_buffer = my_newmem(26);
2643
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
7991 schaersvoo 2644
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
7614 schaersvoo 2645
            break;
2646
        case INTOOLTIP:
2647
            /*
2648
            @ intooltip link_text
2649
            @ link_text is a single line (span-element)
2650
            @ link_text may also be an image URL http://some_server/images/my_image.png
2651
            @ link_text may contain HTML markup
2652
            @ the canvas will be displayed in a tooltip on 'link_text'
2653
            @ the canvas is default transparent: use command 'bgcolor color' to adjust background-color<br />the link test will alos be shown with this bgcolor.
2654
            */
7823 schaersvoo 2655
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy command");}
7614 schaersvoo 2656
            use_tooltip = TRUE;
2657
            tooltip_text = get_string(infile,1);
2658
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
2659
            break;
2660
        case AUDIO:
2661
        /*
2662
        @ audio x,y,w,h,loop,visible,audiofile location
2663
        @ x,y : left top corner of audio element (in xrange / yrange)
2664
        @ w,y : width and height in pixels
2665
        @ loop : 0 or 1 ( 1 = loop audio fragment)
2666
        @ visible : 0 or 1 (1 = show controls)
2667
        @ audio format may be in *.mp3 or *.ogg
2668
        @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
2669
        @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
2670
        @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
2671
        @ 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 />
2672
        */
2673
            if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
2674
            for(i=0;i<7;i++){
2675
                switch(i){
2676
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
2677
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
2678
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
2679
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
2680
                    case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
2681
                    case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
8224 bpr 2682
                    case 6:
7614 schaersvoo 2683
                    temp = get_string(infile,1);
2684
                    if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
2685
                    if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
2686
                    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);
2687
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2688
                    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);
2689
                    add_to_buffer(tmp_buffer);
2690
                    break;
2691
                    default:break;
2692
                }
2693
            }
2694
            reset();
2695
            break;
2696
        case VIDEO:
2697
        /*
2698
        @ video x,y,w,h,videofile location
2699
        @ x,y : left top corner of audio element (in xrange / yrange)
2700
        @ w,y : width and height in pixels
2701
        @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
2702
        @ video format may be in *.mp4 (todo:other formats)
2703
        */
2704
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
2705
            for(i=0;i<5;i++){
2706
                switch(i){
2707
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
2708
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
2709
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
2710
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
2711
                    case 4: temp = get_string(infile,1);
2712
                            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);
2713
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2714
                            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);
2715
                            add_to_buffer(tmp_buffer);
2716
                            break;
2717
                    default:break;
2718
                }
2719
            }
2720
            reset();
2721
            break;
2722
        case HATCHFILL:
2723
        /*
2724
        @ hatchfill x0,y0,dx,dy,color
2725
        @ x0,y0 in xrange / yrange
2726
        @ distances dx,dy in pixels
2727
        */
2728
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
2729
            for(i=0;i<5;i++){
2730
                switch(i){
2731
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2732
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2733
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2734
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2735
                    case 4: stroke_color = get_color(infile,1);
2736
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2737
                    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);
2738
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2739
                    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);
2740
                    add_to_buffer(tmp_buffer);
2741
                    break;
2742
                    default:break;
2743
                }
2744
            }
2745
            reset();
2746
        break;
7647 schaersvoo 2747
        case DIAMONDFILL:
2748
        /*
2749
        @ diamondfill x0,y0,dx,dy,color
2750
        @ x0,y0 in xrange / yrange
2751
        @ distances dx,dy in pixels
2752
        */
2753
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
2754
            for(i=0;i<5;i++){
2755
                switch(i){
2756
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2757
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2758
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2759
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2760
                    case 4: stroke_color = get_color(infile,1);
2761
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
2762
                    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);
2763
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2764
                    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);
2765
                    add_to_buffer(tmp_buffer);
2766
                    break;
2767
                    default:break;
2768
                }
2769
            }
2770
            reset();
2771
        break;
7614 schaersvoo 2772
        case GRIDFILL:
2773
        /*
2774
        @ gridfill x0,y0,dx,dy,color
2775
        @ x0,y0 in xrange / yrange
2776
        @ distances dx,dy in pixels
7883 schaersvoo 2777
        @ a draggable object may snap_to_grid (using keywords xysnaptogrid,xsnaprogrid, ysnaptogrid)
2778
        @ userdraw object may snap_to_grid
7614 schaersvoo 2779
        */
2780
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
2781
            for(i=0;i<5;i++){
2782
                switch(i){
2783
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2784
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2785
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2786
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2787
                    case 4: stroke_color = get_color(infile,1);
2788
                    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);
2789
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2790
                    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);
2791
                    add_to_buffer(tmp_buffer);
2792
                    break;
2793
                    default:break;
2794
                }
2795
            }
2796
            reset();
2797
        break;
2798
        case DOTFILL:
2799
        /*
2800
        @ dotfill x0,y0,dx,dy,color
2801
        @ x0,y0 in xrange / yrange
2802
        @ distances dx,dy in pixels
2803
        @ radius of dots is linewidth
2804
        */
2805
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
2806
            for(i=0;i<5;i++){
2807
                switch(i){
2808
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2809
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2810
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
2811
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
2812
                    case 4: stroke_color = get_color(infile,1);
2813
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
2814
                    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);
2815
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2816
                    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);
2817
                    add_to_buffer(tmp_buffer);
2818
                    break;
2819
                    default:break;
2820
                }
2821
            }
2822
            reset();
2823
        break;
2824
        case IMAGEFILL:
2825
        /*
2826
        @ imagefill dx,dy,image_url
2827
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
2828
        @ After pattern filling ,the fill-color should be reset !
2829
        @ wims getins / image from class directory : imagefill 80,80,my_image.gif
2830
        @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
2831
        @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
2832
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
2833
        */
2834
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
2835
            for(i=0 ;i < 3 ; i++){
2836
                switch(i){
2837
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
2838
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
2839
                    case 2: URL = get_string_argument(infile,1);
2840
                            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);
2841
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2842
                            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);
2843
                            add_to_buffer(tmp_buffer);
2844
                    break;
2845
                }
2846
            }
8083 schaersvoo 2847
            reset();
7614 schaersvoo 2848
        break;
2849
        case FILLTOBORDER:
2850
        /*
2851
        @ filltoborder x,y,bordercolor,color
8224 bpr 2852
        @ fill the region  of point (x:y) bounded by 'bordercolor' with color 'color'
7614 schaersvoo 2853
        @ any other color will not act as border to the bucket fill
2854
        @ use this command  after all boundary objects are declared.
2855
        @ 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..
2856
        */
2857
            for(i=0 ;i < 4 ; i++){
2858
                switch(i){
2859
                    case 0:double_data[0] = get_real(infile,0);break;
2860
                    case 1:double_data[1] = get_real(infile,0);break;
2861
                    case 2:bgcolor = get_color(infile,0);break;
2862
                    case 3:fill_color = get_color(infile,1);
2863
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
2864
                                js_function[DRAW_FILLTOBORDER] = 1;
2865
                                add_js_filltoborder(js_include_file,canvas_root_id);
2866
                           }
2867
                           decimals = find_number_of_digits(precision);
7895 schaersvoo 2868
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
8071 schaersvoo 2869
                           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 2870
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8071 schaersvoo 2871
                           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 2872
                           add_to_buffer(tmp_buffer);
2873
                           break;
2874
                    default:break;
8083 schaersvoo 2875
                }
2876
            }
2877
            reset();
7614 schaersvoo 2878
        break;
2879
        case FLOODFILL:
2880
        /*
2881
        @ floodfill x,y,color
2882
        @ alternative syntax: fill x,y,color
2883
        @ fill the region of point (x:y) with color 'color'
2884
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
2885
        @ use this command  after all boundary objects are declared.
2886
        @ Use command 'clickfill,color' for user click driven flood fill.
2887
        @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
2888
        @ 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..
2889
        */
2890
            for(i=0 ;i < 4 ; i++){
2891
                switch(i){
2892
                    case 0:double_data[0] = get_real(infile,0);break;
2893
                    case 1:double_data[1] = get_real(infile,0);break;
2894
                    case 2:fill_color = get_color(infile,1);
2895
                           if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
2896
                                js_function[DRAW_FLOODFILL] = 1;
2897
                                add_js_floodfill(js_include_file,canvas_root_id);
2898
                           }
2899
                           decimals = find_number_of_digits(precision);/*floodfill(interaction,x,y,[R,G,B,A]) */
7895 schaersvoo 2900
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
2901
                           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 2902
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7895 schaersvoo 2903
                           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 2904
                           add_to_buffer(tmp_buffer);
2905
                           break;
2906
                    default:break;
8083 schaersvoo 2907
                }
2908
            }
2909
            reset();
7614 schaersvoo 2910
        break;
2911
        case CLICKFILLMARGE:
2912
            clickfillmarge = (int) (get_real(infile,1));
2913
            break;
2914
        /*
2915
        @ clickfillmarge int
2916
        @ default 20 (pixels)
2917
        @ 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[])
2918
        */
2919
        case CLICKFILL:
2920
        /*
2921
        @ clickfill fillcolor
2922
        @ user left mouse click will floodfill the area with fillcolor
2923
        @ multiple areas may be coloured
2924
        @ 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)
2925
        @ the answer will be read as the (x:y) click coordinates per coloured area
2926
        @ background color of main div may be set by using command "bgcolor color"
2927
        @ may not be combined with command "userdraw"
2928
        @ NOTE: recognised colour boundaries are in the "drag canvas" e.g. only for objects that can be set draggable / clickable
2929
        */
2930
         fill_color = get_color(infile,1);
2931
         if(js_function[DRAW_FLOODFILL] != 1 ){/* use only once */
2932
            js_function[DRAW_FLOODFILL] = 1;
2933
            add_js_floodfill(js_include_file,canvas_root_id);
2934
         }
8130 schaersvoo 2935
         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));
8074 schaersvoo 2936
         add_read_canvas(1,reply_precision);
8083 schaersvoo 2937
         reset();
7614 schaersvoo 2938
        break;
2939
        case SETPIXEL:
2940
        /*
2941
        @ setpixel x,y,color
2942
        @ A "point" with diameter 1 pixel centeres at (x:y) in xrange / yrange
2943
        @ pixels can not be dragged or clicked
2944
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2945
        */
2946
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2947
            for(i=0;i<3;i++){
2948
                switch(i){
2949
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
2950
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
2951
                    case 2: stroke_color = get_color(infile,1);
2952
                           string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
2953
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2954
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
2955
                           add_to_buffer(tmp_buffer);
2956
                           break;
2957
                    default:break;
2958
                }
2959
            }
2960
            reset();
2961
        break;
2962
        case PIXELSIZE:
2963
        /*
2964
        @ pixelsize int
2965
        @ in case you want to deviate from default pixelsize = 1...
2966
        */
2967
            pixelsize = (int) get_real(infile,1);
2968
        break;
2969
        case PIXELS:
2970
        /*
2971
        @ pixels color,x1,y1,x2,y2,x3,y3...
2972
        @ Draw  "points" with diameter 1 pixel
2973
        @ pixels can not be dragged or clicked
2974
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2975
        */
2976
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2977
            stroke_color=get_color(infile,0);
2978
            i=0;
2979
            c=0;
2980
            while( ! done ){     /* get next item until EOL*/
2981
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2982
                for( c = 0 ; c < 2; c++){
2983
                    if(c == 0 ){
2984
                        double_data[i] = get_real(infile,0);
2985
                        i++;
2986
                    }
2987
                    else
2988
                    {
2989
                        double_data[i] = get_real(infile,1);
2990
                        i++;
2991
                    }
2992
                }
2993
            }
2994
            decimals = find_number_of_digits(precision);
2995
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
2996
            string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2997
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2998
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2999
            add_to_buffer(tmp_buffer);
8083 schaersvoo 3000
            reset();
7614 schaersvoo 3001
            break;
3002
        case REPLYFORMAT:
3003
        /*
3004
        @ replyformat number
7876 schaersvoo 3005
        @ use number=-1 to deactivate the js-function read_canvas()
7614 schaersvoo 3006
        @ default values should be fine !
8074 schaersvoo 3007
        @ 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 3008
        @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
8127 schaersvoo 3009
        @ 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 3010
        @ note to 'userdraw text,color' : the x / y-values are in pixels ! (this to avoid too lengthy calculations in javascript...)
3011
        */
3012
         reply_format = (int) get_real(infile,1);
8074 schaersvoo 3013
         reply_precision = precision;
7614 schaersvoo 3014
        break;
3015
        case LEGENDCOLORS:
3016
        /*
3017
        @ legendcolors color1:color2:color3:...:color_n
7956 schaersvoo 3018
        @ 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 3019
        @ make sure the number of colours match the number of legend items
8224 bpr 3020
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
7614 schaersvoo 3021
        */
7956 schaersvoo 3022
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
7614 schaersvoo 3023
            temp = get_string(infile,1);
3024
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7956 schaersvoo 3025
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
7614 schaersvoo 3026
            break;
3027
        case LEGEND:
3028
        /*
3029
        @ legend string1:string2:string3....string_n
3030
        @ will be used to create a legend for a graph
8224 bpr 3031
        @ also see command 'piechart'
7956 schaersvoo 3032
        @ will use the same colors per default as used in the graphs : use command 'legendcolors' to override the default
7614 schaersvoo 3033
        */
3034
            temp = get_string(infile,1);
3035
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7956 schaersvoo 3036
            legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
3037
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
7614 schaersvoo 3038
            break;
3039
        case XLABEL:
3040
        /*
3041
        @ xlabel some_string
3042
        @ will be used to create a label for the x-axis (label is in quadrant I)
3043
        @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
8224 bpr 3044
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
7614 schaersvoo 3045
        */
3046
            temp = get_string(infile,1);
7653 schaersvoo 3047
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7614 schaersvoo 3048
            break;
3049
        case YLABEL:
3050
        /*
3051
        @ ylabel some_string
8224 bpr 3052
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
7614 schaersvoo 3053
        @ can only be used together with command 'grid'<br />not depending on keywords 'axis' and 'axisnumbering'
8224 bpr 3054
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)
7614 schaersvoo 3055
        */
3056
            temp = get_string(infile,1);
7653 schaersvoo 3057
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 3058
            break;
3059
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
3060
        /*
7996 schaersvoo 3061
        @ linegraph x1:y1;x2:y2...x_n:y_n
7614 schaersvoo 3062
        @ will plot your data in a graph
3063
        @ may only to be used together with command 'grid'
3064
        @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
3065
        @ use command 'legend' to provide an optional legend in right-top-corner
3066
        @ also see command 'piechart'
3067
        @ multiple linegraphs may be used in a single plot
7989 schaersvoo 3068
        @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
7614 schaersvoo 3069
        @ <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 3070
        */
7614 schaersvoo 3071
            temp = get_string(infile,1);
3072
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
7653 schaersvoo 3073
            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 3074
            linegraph_cnt++;
3075
            reset();
3076
            break;
7989 schaersvoo 3077
        case BARCHART:
3078
        /*
3079
        @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
3080
        @ will be used to create a legend for bar graph
3081
        @ may only to be used together with command 'grid'
3082
        @ can be used together with freestyle x-axis/y-axis texts : see commands 'xaxis' and 'yaxis'
3083
        @ use command 'legend' to provide an optional legend in right-top-corner
3084
        @ also see command 'piechart'
3085
        @ NOTE: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
3086
        */
3087
            temp = get_string(infile,1);
3088
            if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
3089
            fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
3090
            barchart_cnt++;
3091
            reset();
3092
            break;
7614 schaersvoo 3093
        case CLOCK:
3094
        /*
3095
        @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
7997 schaersvoo 3096
        @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
7614 schaersvoo 3097
        @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
3098
        @ 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 3099
        @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
7614 schaersvoo 3100
        @ 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>
3101
        @ canvasdraw will not check validity of colornames...the javascript console is your best friend
3102
        @ no combinations with other reply_types allowed, for now
7783 schaersvoo 3103
        @ 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 3104
        */
3105
            if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
3106
 
3107
        /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
3108
            for(i=0;i<9;i++){
3109
             switch(i){
3110
              case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
3111
              case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
3112
              case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
3113
              case 3: int_data[3] = get_real(infile,0);break;/* hours */
3114
              case 4: int_data[4] = get_real(infile,0);break;/* minutes */
3115
              case 5: int_data[5] = get_real(infile,0);break;/* seconds */
7783 schaersvoo 3116
              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 3117
              case 7: int_data[7] = (int)(get_real(infile,0));/* interactive 0,1,2*/
7783 schaersvoo 3118
                switch(int_data[7]){
3119
                    case 0:break;
3120
                    case 1:if(clock_cnt == 0){
3121
                                if( reply_format == 0 ){
7614 schaersvoo 3122
                                     reply_format = 18; /* user sets clock */
7783 schaersvoo 3123
                                    /* 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 3124
                                     check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3125
                                     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");
3126
                                     add_to_buffer(tmp_buffer);
7783 schaersvoo 3127
                                    */
8130 schaersvoo 3128
                                     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 3129
                                }
3130
                                else
3131
                                {
3132
                                    canvas_error("interactive clock may not be used together with other reply_types...");
3133
                                }
3134
                             }
8130 schaersvoo 3135
                            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 3136
                    break;
3137
                    case 2:if( reply_format == 0 ){
3138
                                reply_format = 19; /* "onclick */
8130 schaersvoo 3139
                                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 3140
                            }
3141
                            else
3142
                            {
3143
                                if( reply_format != 19){
7614 schaersvoo 3144
                                   canvas_error("clickable clock(s) may not be used together with other reply_types...");
3145
                                 }
7783 schaersvoo 3146
                            }
3147
                     break;
3148
                     default: canvas_error("interactive must be set 0,1 or 2");break;
3149
                }
3150
                break;
8224 bpr 3151
                case 8:
8130 schaersvoo 3152
                        if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
3153
                            fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
3154
                        }
7614 schaersvoo 3155
                        temp = get_string(infile,1);
3156
                        if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
3157
                        if( strlen(temp) < 1 ){temp = ",\"\",\"\",\"\",\"\",\"\"";}
8130 schaersvoo 3158
                        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 3159
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
8130 schaersvoo 3160
                        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 3161
                        add_to_buffer(tmp_buffer);
3162
                        clock_cnt++;
3163
                        break;
3164
                default:break;
3165
             }
3166
            }
3167
            break;
3168
        case PIECHART:
3169
        /*
3170
        @ piechart xc,yc,radius,'data+colorlist'
3171
        @ (xc : yc) center of circle diagram in xrange/yrange
3172
        @ radius in pixels
3173
        @ 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
3174
        @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
3175
        @ the number of colors must match the number of data.
3176
        @ use command "opacity 0-255,0-255" to adjust fill_opacity of colours
8224 bpr 3177
        @ 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 3178
        */
8224 bpr 3179
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
7614 schaersvoo 3180
            for(i=0;i<5;i++){
3181
                switch(i){
3182
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
3183
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
3184
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
3185
                    case 3: temp = get_string(infile,1);
3186
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
7956 schaersvoo 3187
                            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 3188
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
7956 schaersvoo 3189
                            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 3190
                            add_to_buffer(tmp_buffer);
3191
                           break;
3192
                    default:break;
3193
                }
3194
            }
3195
            reset();
3196
        break;
3197
        case STATUS:
7877 schaersvoo 3198
        /*
3199
        @status
3200
        @keyword
3201
        @alernative keyword: nostatus
3202
        @used to override the effects of "status=done" in wims (answer.phtml)
3203
        @affects inputfields / textarea's in canvasimage and all userdraw based commands
3204
        @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'
3205
        */
8224 bpr 3206
 
7877 schaersvoo 3207
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
7614 schaersvoo 3208
            break;
7735 schaersvoo 3209
        case XLOGBASE:
7729 schaersvoo 3210
        /*
7735 schaersvoo 3211
        @ xlogbase number
3212
        @ sets the logbase number for the x-axis
7729 schaersvoo 3213
        @ default value 10
7735 schaersvoo 3214
        @ use together with commands xlogscale / xylogscale
7729 schaersvoo 3215
        */
7735 schaersvoo 3216
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7729 schaersvoo 3217
            break;
7735 schaersvoo 3218
        case YLOGBASE:
3219
        /*
3220
        @ ylogbase number
3221
        @ sets the logbase number for the y-axis
3222
        @ default value 10
3223
        @ use together with commands ylogscale / xylogscale
3224
        */
3225
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
3226
            break;
7614 schaersvoo 3227
        case XLOGSCALE:
3228
        /*
7735 schaersvoo 3229
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
3230
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3231
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
3232
         @ the linewidth is set using command 'linewidth int'
3233
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
3234
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
8224 bpr 3235
         @ 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 3236
         @ note: the complete canvas will be used for the 'log paper'
3237
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3238
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
8224 bpr 3239
         @ 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 3240
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3241
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 3242
        */
7735 schaersvoo 3243
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3244
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
3245
            for(i=0;i<4;i++){
3246
                switch(i){
3247
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
3248
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
3249
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 3250
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 3251
                        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 3252
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3253
                        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 3254
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
3255
                        add_to_buffer(tmp_buffer);
3256
                        break;
3257
                    default:break;
3258
                }
3259
            }
7614 schaersvoo 3260
            break;
3261
        case YLOGSCALE:
7729 schaersvoo 3262
        /*
3263
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
3264
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3265
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
3266
         @ the linewidth is set using command 'linewidth int'
3267
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
7735 schaersvoo 3268
         @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
8224 bpr 3269
         @ 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 3270
         @ note: the complete canvas will be used for the 'log paper'
3271
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3272
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
8224 bpr 3273
         @ 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 3274
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3275
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
7729 schaersvoo 3276
        */
3277
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3278
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
3279
            for(i=0;i<4;i++){
3280
                switch(i){
3281
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
3282
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
3283
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 3284
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 3285
                        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 3286
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3287
                        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 3288
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 3289
                        add_to_buffer(tmp_buffer);
3290
                        break;
3291
                    default:break;
3292
                }
3293
            }
7614 schaersvoo 3294
            break;
3295
        case XYLOGSCALE:
7735 schaersvoo 3296
        /*
3297
         @ xylogscale majorcolor,minorcolor
3298
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
3299
         @ the linewidth is set using command 'linewidth int'
3300
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
3301
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
8224 bpr 3302
         @ 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 3303
         @ note: the complete canvas will be used for the 'log paper'
3304
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
3305
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
8224 bpr 3306
         @ 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 3307
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
3308
         @ attention: keyword 'snaptogrid' may not lead to the desired result...
3309
        */
3310
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
3311
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
3312
            for(i=0;i<2;i++){
3313
                switch(i){
3314
                    case 0: stroke_color = get_color(infile,0); break;
8224 bpr 3315
                    case 1: fill_color = get_color(infile,1);
7779 schaersvoo 3316
                        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 3317
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 3318
                        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 3319
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
3320
                        add_to_buffer(tmp_buffer);
3321
                        break;
3322
                    default:break;
3323
                }
3324
            }
3325
        break;
7614 schaersvoo 3326
        default:sync_input(infile);
3327
        break;
3328
    }
8224 bpr 3329
  }
7614 schaersvoo 3330
  /* we are done parsing script file */
7983 schaersvoo 3331
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
3332
  if( found_size_command == 1 ){
3333
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
3334
  }
3335
  else
3336
  {
3337
    if( found_size_command != 3 ){
8222 schaersvoo 3338
     canvas_error("Please specify both xrange and yrange ...");
7983 schaersvoo 3339
    }
3340
  }
8222 schaersvoo 3341
  /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
7614 schaersvoo 3342
  add_javascript_functions(js_function,canvas_root_id);
3343
   /* add read_canvas() etc functions if needed */
8074 schaersvoo 3344
  if( reply_format > 0 ){ add_read_canvas(reply_format,reply_precision);}
7797 schaersvoo 3345
  if( use_pan_and_zoom == TRUE ){
3346
  /* in case of zooming ... */
7729 schaersvoo 3347
  fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
7797 schaersvoo 3348
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 3349
  var ymin_start=ymin;var ymax_start=xmax;\
3350
  var zoom_x_increment=0;var zoom_y_increment=0;\
3351
  var pan_x_increment=0;var pan_y_increment=0;\
3352
  if(use_ylogscale == 0 ){\
7956 schaersvoo 3353
   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 3354
  }else{\
3355
   zoom_x_increment = (xmax - xmin)/20;\
3356
   pan_x_increment = (xmax - xmin)/20;\
3357
  };\
7653 schaersvoo 3358
  function start_canvas%d(type){\
3359
   switch(type){\
7729 schaersvoo 3360
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
3361
    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 3362
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
3363
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
3364
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
3365
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
3366
    case 6:location.reload();break;\
3367
    default:break;\
3368
   };\
3369
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
3370
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
3371
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){}\
3372
   %s\
3373
  };\
7797 schaersvoo 3374
  start_canvas%d(333);\
7614 schaersvoo 3375
 };\n\
3376
<!-- end wims_canvas_function -->\n\
7797 schaersvoo 3377
wims_canvas_function%d();\n",precision,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
3378
  }
3379
  else
3380
  {
3381
  /* no zoom, just add buffer */
3382
  fprintf(js_include_file,"\n<!-- add buffer -->\n\
3383
  %s\
3384
 };\n\
3385
<!-- end wims_canvas_function -->\n\
3386
wims_canvas_function%d();\n",buffer,canvas_root_id);
3387
  }
7614 schaersvoo 3388
/* done writing the javascript include file */
3389
fclose(js_include_file);
3390
 
3391
}
3392
 
3393
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
3394
if(use_tooltip == TRUE){
3395
  add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
3396
}
3397
exit(EXIT_SUCCESS);
3398
}
3399
/* end main() */
3400
 
3401
/******************************************************************************
3402
**
3403
**  sync_input
3404
**
3405
**  synchronises input line - reads to end of line, leaving file pointer
3406
**  at first character of next line.
3407
**
3408
**  Used by:
3409
**  main program - error handling.
3410
**
3411
******************************************************************************/
3412
void sync_input(FILE *infile)
3413
{
3414
        int c = 0;
3415
 
7658 schaersvoo 3416
        if( c == '\n' || c == ';' ) return;
3417
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 3418
        if( c == EOF ) finished = 1;
7658 schaersvoo 3419
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 3420
        return;
3421
}
3422
 
3423
/******************************************************************************/
3424
 
3425
char *str_replace(const char *str, const char *old, const char *new){
3426
/* http://creativeandcritical.net/str-replace-c/ */
3427
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
3428
    char *ret, *r;
3429
    const char *p, *q;
3430
    size_t oldlen = strlen(old);
3431
    size_t count = 0;
3432
    size_t retlen = 0;
3433
    size_t newlen = strlen(new);
3434
    if (oldlen != newlen){
3435
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
3436
            count++;
3437
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
3438
        }
8224 bpr 3439
    }
7614 schaersvoo 3440
    else
3441
    {
3442
        retlen = strlen(str);
3443
    }
8224 bpr 3444
 
7614 schaersvoo 3445
    if ((ret = malloc(retlen + 1)) == NULL){
3446
        ret = NULL;
3447
        canvas_error("string argument is NULL");
3448
    }
3449
    else
3450
    {
3451
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
3452
            size_t l = q - p;
3453
            memcpy(r, p, l);
3454
            r += l;
3455
            memcpy(r, new, newlen);
3456
            r += newlen;
3457
        }
3458
        strcpy(r, p);
3459
    }
3460
    return ret;
3461
}
3462
 
3463
/******************************************************************************/
7848 bpr 3464
 
7614 schaersvoo 3465
char *get_color(FILE *infile , int last){
3466
    int c,i = 0,is_hex = 0;
3467
    char temp[MAX_COLOR_STRING], *string;
7748 schaersvoo 3468
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' ) ){
7614 schaersvoo 3469
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
3470
        if( c == '#' ){
3471
            is_hex = 1;
3472
        }
3473
        if( c != ' '){
3474
            temp[i]=tolower(c);
3475
            i++;
3476
        }
3477
    }
8224 bpr 3478
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3479
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
7614 schaersvoo 3480
    if( c == EOF ){finished = 1;}
3481
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
3482
    temp[i]='\0';
3483
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
3484
    if( is_hex == 1 ){
3485
        char red[3], green[3], blue[3];
3486
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
3487
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
3488
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
3489
        int r = (int) strtol(red,   NULL, 16);
3490
        int g = (int) strtol(green, NULL, 16);
3491
        int b = (int) strtol(blue,  NULL, 16);
3492
        string = (char *)my_newmem(12);
3493
        snprintf(string,11,"%d,%d,%d",r,g,b);
3494
        return string;
3495
    }
3496
    else
3497
    {
3498
        string = (char *)my_newmem(sizeof(temp));
3499
        snprintf(string,sizeof(temp),"%s",temp);
3500
        for( i = 0; i <= NUMBER_OF_COLORNAMES ; i++ ){
3501
            if( strcmp( colors[i].name , string ) == 0 ){
3502
                return colors[i].rgb;
3503
            }
3504
        }
3505
    }
3506
    /* not found...return error */
3507
    free(string);string = NULL;
3508
    canvas_error("I was expecting a color name or hexnumber...but found nothing.");
3509
    return NULL;
3510
}
3511
 
3512
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
3513
    int c,i=0;
3514
    char  temp[MAX_BUFFER], *string;
7748 schaersvoo 3515
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') ){
7614 schaersvoo 3516
        temp[i]=c;
3517
        i++;
3518
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
3519
    }
8224 bpr 3520
    if( ( c == '\n' || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3521
    if( c == '\n') { done = TRUE; line_number++; }
7614 schaersvoo 3522
    if( c == EOF ) {
3523
        finished = 1;
3524
        if( last != 1 ){ canvas_error("expected more arguments");}
3525
    }
3526
    temp[i]='\0';
3527
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string, but found nothing !!");}
3528
    string=(char *)my_newmem(strlen(temp));
3529
    snprintf(string,sizeof(temp),"%s",temp);
3530
    return string;
3531
}
3532
 
3533
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
3534
    int c,i=0;
3535
    char temp[MAX_BUFFER], *string;
7748 schaersvoo 3536
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',')){
7614 schaersvoo 3537
        temp[i]=c;
3538
        i++;
3539
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
3540
    }
8224 bpr 3541
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
7748 schaersvoo 3542
    if( c == '\n') { line_number++; }
7614 schaersvoo 3543
    if( c == EOF ) {finished = 1;}
3544
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
3545
    temp[i]='\0';
3546
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
3547
    string=(char *)my_newmem(sizeof(temp));
3548
    snprintf(string,sizeof(temp),"%s",temp);
3549
    done = TRUE;
3550
    return string;
3551
}
3552
 
3553
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
3554
    int c,i=0,found_calc = 0;
3555
    double y;
3556
    char tmp[MAX_INT];
7658 schaersvoo 3557
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && ( c != ';')){
7614 schaersvoo 3558
     if( c != ' ' ){
8224 bpr 3559
     /*
3560
     libmatheval will segfault when for example: "xrange -10,+10" or "xrange -10,10+" is used
7614 schaersvoo 3561
     We will check after assert() if it's a NULL pointer...and exit program via :
3562
     canvas_error("I'm having trouble parsing your \"expression\" ");
3563
     */
8224 bpr 3564
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 3565
       continue;
8224 bpr 3566
      }
7614 schaersvoo 3567
      else
3568
      {
3569
       if(canvas_iscalculation(c) != 0){
3570
        found_calc = 1;
3571
        c = tolower(c);
3572
       }
3573
       tmp[i] = c;
3574
       i++;
3575
      }
3576
     }
3577
     if( i > MAX_INT - 1){canvas_error("number too large");}
3578
    }
8224 bpr 3579
    if( ( c == '\n' || c == EOF || c == ';' ) && last == 0){canvas_error("expecting more arguments in command");}
7658 schaersvoo 3580
    if( c == '\n' || c == ';' ){ done = TRUE; line_number++; }
7614 schaersvoo 3581
    if( c == EOF ){done = TRUE ; finished = 1;}
3582
    tmp[i]='\0';
3583
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
3584
    if( found_calc == 1 ){ /* use libmatheval to calculate 2*pi/3 */
7848 bpr 3585
     void *f = eval_create(tmp);
7614 schaersvoo 3586
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 3587
     y = eval_x(f, 1);
7614 schaersvoo 3588
     /* if function is bogus; y = 1 : so no core dumps */
7848 bpr 3589
     eval_destroy(f);
7614 schaersvoo 3590
    }
3591
    else
3592
    {
3593
     y = atof(tmp);
3594
    }
3595
    return y;
3596
}
3597
void canvas_error(char *msg){
7748 schaersvoo 3598
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number-1,msg);
7614 schaersvoo 3599
    finished = 1;
3600
    exit(EXIT_SUCCESS);
3601
}
3602
 
3603
 
3604
/* convert x/y coordinates to pixel */
3605
int x2px(double x){
3606
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
3607
}
3608
 
3609
int y2px(double y){
3610
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
3611
}
3612
 
3613
double px2x(int x){
3614
 return (x*(xmax - xmin)/xsize + xmin);
3615
}
3616
double px2y(int y){
3617
 return (y*(ymax - ymin)/ysize + ymin);
3618
}
3619
 
3620
void add_to_buffer(char *tmp){
3621
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
3622
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
3623
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
3624
 if( space_left > strlen(tmp)){
3625
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
3626
 }
3627
 else
3628
 {
3629
  canvas_error("buffer is too big\n");
3630
 }
3631
 tmp = NULL;free(tmp);
3632
 return;
3633
}
3634
 
3635
void reset(){
3636
 if(use_filled == TRUE){use_filled = FALSE;}
3637
 if(use_dashed == TRUE){use_dashed = FALSE;}
3638
 if(use_rotate == TRUE){use_rotate = FALSE;}
8101 schaersvoo 3639
   onclick = 0;
7614 schaersvoo 3640
}
3641
 
3642
 
3643
 
3644
/* What reply format in read_canvas();
3645
 
3646
note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
3647
1 = x1,x2,x3,x4....x_n
3648
    y1,y2,y3,y4....y_n
3649
 
3650
    x/y in pixels
3651
 
3652
2 = x1,x2,x3,x4....x_n
3653
    y1,y2,y3,y4....y_n
3654
    x/y in  xrange / yrange coordinate system
3655
 
3656
3 = x1,x2,x3,x4....x_n
3657
    y1,y2,y3,y4....y_n
3658
    r1,r2,r3,r4....r_n
3659
 
8224 bpr 3660
    x/y in pixels
7614 schaersvoo 3661
    r in pixels
3662
 
3663
4 = x1,x2,x3,x4....x_n
3664
    y1,y2,y3,y4....y_n
3665
    r1,r2,r3,r4....r_n
3666
 
3667
    x/y in  xrange / yrange coordinate system
3668
    r in pixels
3669
 
3670
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
3671
    Ay1,Ay2,Ay3,Ay4....Ay_n
3672
    Bx1,Bx2,Bx3,Bx4....Bx_n
3673
    By1,By2,By3,By4....By_n
3674
    Cx1,Cx2,Cx3,Cx4....Cx_n
3675
    Cy1,Cy2,Cy3,Cy4....Cy_n
3676
    ....
3677
    Zx1,Zx2,Zx3,Zx4....Zx_n
3678
    Zy1,Zy2,Zy3,Zy4....Zy_n
8224 bpr 3679
 
7614 schaersvoo 3680
    x/y in pixels
3681
 
3682
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
3683
    Ay1,Ay2,Ay3,Ay4....Ay_n
3684
    Bx1,Bx2,Bx3,Bx4....Bx_n
3685
    By1,By2,By3,By4....By_n
3686
    Cx1,Cx2,Cx3,Cx4....Cx_n
3687
    Cy1,Cy2,Cy3,Cy4....Cy_n
3688
    ....
3689
    Zx1,Zx2,Zx3,Zx4....Zx_n
3690
    Zy1,Zy2,Zy3,Zy4....Zy_n
3691
 
3692
    x/y in  xrange / yrange coordinate system
8224 bpr 3693
 
7614 schaersvoo 3694
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 3695
 
7614 schaersvoo 3696
    x/y in pixels
3697
 
3698
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 3699
 
7614 schaersvoo 3700
    x/y in  xrange / yrange coordinate system
3701
 
8224 bpr 3702
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 3703
 
3704
    x/y in pixels
3705
 
8224 bpr 3706
10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 3707
 
3708
    x/y in  xrange / yrange coordinate system
3709
 
3710
11 = Ax1,Ay1,Ax2,Ay2
3711
     Bx1,By1,Bx2,By2
3712
     Cx1,Cy1,Cx2,Cy2
3713
     Dx1,Dy1,Dx2,Dy2
3714
     ......
3715
     Zx1,Zy1,Zx2,Zy2
8224 bpr 3716
 
7614 schaersvoo 3717
    x/y in  xrange / yrange coordinate system
3718
 
3719
12 = Ax1,Ay1,Ax2,Ay2
3720
     Bx1,By1,Bx2,By2
3721
     Cx1,Cy1,Cx2,Cy2
3722
     Dx1,Dy1,Dx2,Dy2
3723
     ......
3724
     Zx1,Zy1,Zx2,Zy2
8224 bpr 3725
 
7614 schaersvoo 3726
    x/y in pixels
3727
 
3728
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
3729
 
3730
    x/y in  xrange / yrange coordinate system
3731
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
3732
    x/y in pixels
3733
15 = reply from inputfields,textareas
3734
    reply1,reply2,reply3,...,reply_n
7984 schaersvoo 3735
    only fields set write (a.g. will not read 'readonly' inputfield values'
7614 schaersvoo 3736
 
3737
16 = read mathml inputfields only
3738
 
3739
17 = read userdraw text only (x1:y1:text1,x2:y2:text2...x_n:y_n:text_n
3740
 when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
3741
 
3742
18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
3743
19 = return clicked object number (analogue to shape-library onclick)
3744
20 = return x/y-data in x-range/y-range of all 'draggable' images
3745
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
3746
22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
3747
    x/y in  xrange / yrange coordinate system
8224 bpr 3748
23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
7984 schaersvoo 3749
24 = read all inputfield values: even those set 'readonly'
8224 bpr 3750
25 = return all userdrawn arcs in degrees:
3751
26 = return all userdrawn arcs in radians:
8127 schaersvoo 3752
27 = return (only) userdraw inputfields array: x1:y1:text1,x2:y2:text2...
7614 schaersvoo 3753
*/
3754
 
3755
 
8074 schaersvoo 3756
void add_read_canvas(int type_reply,int reply_precision){
7614 schaersvoo 3757
/* just 1 reply type allowed */
8074 schaersvoo 3758
fprintf(js_include_file,"\
3759
\n<!-- begin set_reply_precision() -->\n\
3760
function set_reply_precision(){\
3761
 var len = userdraw_x.length;\
3762
 var prec = %d;\
3763
 for(var p = 0 ; p < len ; p++ ){\
3764
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
3765
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
3766
 };\
3767
 len = userdraw_radius.length;\
3768
 if( len > 0 ){\
3769
  for(var p = 0 ; p < len ; p++ ){\
3770
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
3771
  };\
3772
 };\
3773
};",reply_precision);
7963 schaersvoo 3774
 
7614 schaersvoo 3775
switch(type_reply){
8224 bpr 3776
/*
7614 schaersvoo 3777
answers may have:
3778
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
3779
*/
3780
    case 1: fprintf(js_include_file,"\
7653 schaersvoo 3781
\n<!-- begin function 1 read_canvas() -->\n\
8108 schaersvoo 3782
read_canvas = function(){\
7614 schaersvoo 3783
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3784
 set_reply_precision();\
7614 schaersvoo 3785
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3786
  var p = 0;var input_reply = new Array();\
3787
  if( document.getElementById(\"canvas_input0\")){\
3788
   var t = 0;\
3789
   while(document.getElementById(\"canvas_input\"+t)){\
3790
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3791
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3792
     p++;\
3793
    };\
3794
    t++;\
3795
   };\
3796
  };\
3797
  if( typeof userdraw_text != 'undefined' ){\
3798
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
3799
  }\
3800
  else\
3801
  {\
3802
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
3803
  }\
3804
 }\
3805
 else\
3806
 {\
3807
  if( typeof userdraw_text != 'undefined' ){\
3808
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
3809
  }\
3810
  else\
3811
  {\
3812
   return userdraw_x+\"\\n\"+userdraw_y;\
3813
  }\
3814
 };\
8108 schaersvoo 3815
};\n\
7653 schaersvoo 3816
<!-- end function 1 read_canvas() -->");
7614 schaersvoo 3817
    break;
3818
    case 2: fprintf(js_include_file,"\
7653 schaersvoo 3819
\n<!-- begin function 2 read_canvas() -->\n\
8108 schaersvoo 3820
read_canvas = function(){\
7614 schaersvoo 3821
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3822
 set_reply_precision();\
7614 schaersvoo 3823
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 3824
 var prec = %d;\
7614 schaersvoo 3825
 while(userdraw_x[p]){\
8074 schaersvoo 3826
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
3827
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 3828
  p++;\
3829
 };\
3830
 if(p == 0){alert(\"nothing drawn...\");return;};\
3831
 if( document.getElementById(\"canvas_input0\")){\
3832
  var p = 0;var input_reply = new Array();\
3833
  if( document.getElementById(\"canvas_input0\")){\
3834
   var t = 0;\
3835
   while(document.getElementById(\"canvas_input\"+t)){\
3836
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3837
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3838
     p++;\
3839
    };\
3840
    t++;\
3841
   };\
3842
  };\
3843
  if( typeof userdraw_text != 'undefined' ){\
3844
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3845
  }\
3846
  else\
3847
  {\
3848
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
3849
  }\
3850
 }\
3851
 else\
3852
 {\
3853
  if( typeof userdraw_text != 'undefined' ){\
3854
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
3855
  }\
3856
  else\
3857
  {\
3858
   return reply_x+\"\\n\"+reply_y;\
3859
  };\
3860
 };\
8108 schaersvoo 3861
};\n\
8074 schaersvoo 3862
<!-- end function 2 read_canvas() -->",reply_precision);
7614 schaersvoo 3863
    break;
3864
    case 3: fprintf(js_include_file,"\
7653 schaersvoo 3865
\n<!-- begin function 3 read_canvas() -->\n\
8108 schaersvoo 3866
read_canvas = function(){\
7614 schaersvoo 3867
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 3868
 set_reply_precision();\
7614 schaersvoo 3869
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3870
  var p = 0;var input_reply = new Array();\
3871
  if( document.getElementById(\"canvas_input0\")){\
3872
   var t = 0;\
3873
   while(document.getElementById(\"canvas_input\"+t)){\
3874
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3875
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3876
     p++;\
3877
    };\
3878
    t++;\
3879
   };\
3880
  };\
3881
  if( typeof userdraw_text != 'undefined' ){\
3882
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3883
  }\
3884
  else\
3885
  {\
3886
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
3887
  }\
3888
 }\
3889
 else\
3890
 {\
3891
  if( typeof userdraw_text != 'undefined' ){\
3892
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
3893
  }\
3894
  else\
3895
  {\
3896
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
3897
  }\
3898
 }\
8108 schaersvoo 3899
};\n\
7653 schaersvoo 3900
<!-- end function 3 read_canvas() -->");
7614 schaersvoo 3901
    break;
3902
    case 4: fprintf(js_include_file,"\
7653 schaersvoo 3903
\n<!-- begin function 4 read_canvas() -->\n\
8108 schaersvoo 3904
read_canvas = function(){\
8074 schaersvoo 3905
 var prec = %d;\
7614 schaersvoo 3906
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
3907
 while(userdraw_x[p]){\
8074 schaersvoo 3908
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
3909
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 3910
  p++;\
3911
 };\
3912
 if(p == 0){alert(\"nothing drawn...\");return;};\
3913
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3914
  var p = 0;var input_reply = new Array();\
3915
  if( document.getElementById(\"canvas_input0\")){\
3916
   var t = 0;\
3917
   while(document.getElementById(\"canvas_input\"+t)){\
3918
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3919
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3920
     p++;\
3921
    };\
3922
    t++;\
3923
   };\
3924
  };\
3925
  if( typeof userdraw_text != 'undefined' ){\
3926
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3927
  }\
3928
  else\
3929
  {\
3930
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
3931
  }\
3932
 }\
3933
 else\
3934
 {\
3935
  if( typeof userdraw_text != 'undefined' ){\
3936
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
3937
  }\
3938
  else\
3939
  {\
3940
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
3941
  }\
3942
 };\
8108 schaersvoo 3943
};\n\
8074 schaersvoo 3944
<!-- end function 4 read_canvas() -->",reply_precision);
7614 schaersvoo 3945
    break;
8224 bpr 3946
    /*
3947
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
3948
        used for userdraw multiple paths
7614 schaersvoo 3949
    */
3950
    case 5: fprintf(js_include_file,"\
7653 schaersvoo 3951
\n<!-- begin function 5 read_canvas() -->\n\
8108 schaersvoo 3952
read_canvas = function(){\
8074 schaersvoo 3953
 set_reply_precision();\
7614 schaersvoo 3954
 var p = 0;\
3955
 var reply = \"\";\
3956
 for(p = 0; p < userdraw_x.length;p++){\
3957
  if(userdraw_x[p] != null ){\
3958
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
3959
  };\
3960
 };\
3961
 if(p == 0){alert(\"nothing drawn...\");return;};\
3962
 userdraw_x = [];userdraw_y = [];\
3963
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
3964
  var p = 0;var input_reply = new Array();\
3965
  if( document.getElementById(\"canvas_input0\")){\
3966
   var t = 0;\
3967
   while(document.getElementById(\"canvas_input\"+t)){\
3968
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
3969
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
3970
     p++;\
3971
    };\
3972
    t++;\
3973
   };\
3974
  };\
3975
  if( typeof userdraw_text != 'undefined' ){\
3976
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
3977
  }\
3978
  else\
3979
  {\
3980
   return reply +\"\\n\"+input_reply;\
3981
  }\
3982
 }\
3983
 else\
3984
 {\
3985
  if( typeof userdraw_text != 'undefined' ){\
3986
   return reply+\"\\n\"+userdraw_text;\
3987
  }\
3988
  else\
3989
  {\
3990
   return reply;\
3991
  }\
3992
 };\
8108 schaersvoo 3993
};\n\
7653 schaersvoo 3994
<!-- end function 5 read_canvas() -->");
7614 schaersvoo 3995
    break;
8224 bpr 3996
    /*
3997
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
3998
        used for userdraw multiple paths
7614 schaersvoo 3999
    */
4000
    case 6: fprintf(js_include_file,"\
7653 schaersvoo 4001
\n<!-- begin function 6 read_canvas() -->\n\
8108 schaersvoo 4002
read_canvas = function(){\
7614 schaersvoo 4003
 var p = 0;\
4004
 var reply = \"\";\
4005
 var tmp_x = new Array();\
4006
 var tmp_y = new Array();\
8074 schaersvoo 4007
 var prec = %d;\
7614 schaersvoo 4008
 for(p = 0 ; p < userdraw_x.length; p++){\
4009
  tmp_x = userdraw_x[p];\
4010
  tmp_y = userdraw_y[p];\
4011
  if(tmp_x != null){\
4012
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 4013
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
4014
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 4015
   };\
4016
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
4017
  };\
4018
 };\
4019
 if(p == 0){alert(\"nothing drawn...\");return;};\
4020
 userdraw_x = [];userdraw_y = [];\
4021
 if( document.getElementById(\"canvas_input0\") ){\
4022
  var p = 0;var input_reply = new Array();\
4023
  if( document.getElementById(\"canvas_input0\")){\
4024
   var t = 0;\
4025
   while(document.getElementById(\"canvas_input\"+t)){\
4026
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4027
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4028
     p++;\
4029
    };\
4030
    t++;\
4031
   };\
4032
  };\
4033
  if( typeof userdraw_text != 'undefined' ){\
4034
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4035
  }\
4036
  else\
4037
  {\
4038
   return reply +\"\\n\"+input_reply;\
4039
  }\
4040
 }\
4041
 else\
4042
 {\
4043
  if( typeof userdraw_text != 'undefined' ){\
4044
   return reply +\"\\n\"+userdraw_text;\
4045
  }\
4046
  else\
4047
  {\
4048
   return reply;\
4049
  }\
4050
 };\
8108 schaersvoo 4051
};\n\
8074 schaersvoo 4052
<!-- end function 6 read_canvas() -->",reply_precision);
7614 schaersvoo 4053
    break;
4054
    case 7: fprintf(js_include_file,"\
7653 schaersvoo 4055
\n<!-- begin function 7 read_canvas() -->\n\
8108 schaersvoo 4056
read_canvas = function(){\
8074 schaersvoo 4057
 set_reply_precision();\
7614 schaersvoo 4058
 var reply = new Array();\
4059
 var p = 0;\
4060
 while(userdraw_x[p]){\
4061
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
4062
  p++;\
4063
 };\
4064
 if(p == 0){alert(\"nothing drawn...\");return;};\
4065
 if( document.getElementById(\"canvas_input0\") ){\
4066
  var p = 0;var input_reply = new Array();\
4067
  if( document.getElementById(\"canvas_input0\")){\
4068
   var t = 0;\
4069
   while(document.getElementById(\"canvas_input\"+t)){\
4070
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4071
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4072
     p++;\
4073
    };\
4074
    t++;\
4075
   };\
4076
  };\
4077
  if( typeof userdraw_text != 'undefined' ){\
4078
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4079
  }\
4080
  else\
4081
  {\
4082
   return reply+\"\\n\"+input_reply;\
4083
  }\
7862 schaersvoo 4084
 }\
7614 schaersvoo 4085
 else\
4086
 {\
4087
  if( typeof userdraw_text != 'undefined' ){\
4088
   return reply+\"\\n\"+userdraw_text;\
4089
  }\
4090
  else\
4091
  {\
4092
   return reply;\
4093
  }\
4094
 };\
8108 schaersvoo 4095
};\n\
7653 schaersvoo 4096
<!-- end function 7 read_canvas() -->");
7614 schaersvoo 4097
    break;
4098
    case 8: fprintf(js_include_file,"\
7653 schaersvoo 4099
\n<!-- begin function 8 read_canvas() -->\n\
8108 schaersvoo 4100
read_canvas = function(){\
7614 schaersvoo 4101
 var reply = new Array();\
4102
 var p = 0;\
8074 schaersvoo 4103
 var prec = %d;\
7614 schaersvoo 4104
 while(userdraw_x[p]){\
8074 schaersvoo 4105
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 4106
  p++;\
4107
 };\
4108
 if(p == 0){alert(\"nothing drawn...\");return;};\
4109
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
4110
  var p = 0;var input_reply = new Array();\
4111
  if( document.getElementById(\"canvas_input0\")){\
4112
   var t = 0;\
4113
   while(document.getElementById(\"canvas_input\"+t)){\
4114
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4115
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4116
     p++;\
4117
    };\
4118
    t++;\
4119
   };\
4120
  };\
4121
  if( typeof userdraw_text != 'undefined' ){\
4122
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4123
  }\
4124
  else\
4125
  {\
4126
   return reply +\"\\n\"+input_reply;\
4127
  }\
4128
 }\
4129
 else\
4130
 {\
4131
  if( typeof userdraw_text != 'undefined' ){\
4132
   return reply +\"\\n\"+userdraw_text;\
4133
  }\
4134
  else\
4135
  {\
4136
   return reply;\
4137
  }\
4138
 };\
8108 schaersvoo 4139
};\n\
8074 schaersvoo 4140
<!-- end function 8 read_canvas() -->",reply_precision);
7614 schaersvoo 4141
    break;
4142
    case 9: fprintf(js_include_file,"\
7653 schaersvoo 4143
\n<!-- begin function 9 read_canvas() -->\n\
8108 schaersvoo 4144
read_canvas = function(){\
8074 schaersvoo 4145
 set_reply_precision();\
7614 schaersvoo 4146
 var reply = new Array();\
4147
 var p = 0;\
4148
 while(userdraw_x[p]){\
4149
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
4150
  p++;\
4151
 };\
4152
 if(p == 0){alert(\"nothing drawn...\");return;};\
4153
 if( document.getElementById(\"canvas_input0\") ){\
4154
  var p = 0;var input_reply = new Array();\
4155
  if( document.getElementById(\"canvas_input0\")){\
4156
   var t = 0;\
4157
   while(document.getElementById(\"canvas_input\"+t)){\
4158
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4159
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4160
     p++;\
4161
    };\
4162
    t++;\
4163
   };\
4164
  };\
4165
  if( typeof userdraw_text != 'undefined' ){\
4166
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4167
  }\
4168
  else\
4169
  {\
4170
   return reply +\"\\n\"+input_reply;\
4171
  }\
4172
 }\
4173
 else\
4174
 {\
4175
  if( typeof userdraw_text != 'undefined' ){\
4176
   return reply +\"\\n\"+userdraw_text;\
4177
  }\
4178
  else\
4179
  {\
4180
   return reply;\
4181
  }\
4182
 };\
8108 schaersvoo 4183
};\n\
7653 schaersvoo 4184
<!-- end function 9 read_canvas() -->");
7614 schaersvoo 4185
    break;
4186
    case 10: fprintf(js_include_file,"\
7653 schaersvoo 4187
\n<!-- begin function 10 read_canvas() -->\n\
8108 schaersvoo 4188
read_canvas = function(){\
7614 schaersvoo 4189
 var reply = new Array();\
4190
 var p = 0;\
8074 schaersvoo 4191
 var prec = %d;\
7614 schaersvoo 4192
 while(userdraw_x[p]){\
8074 schaersvoo 4193
  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 4194
  p++;\
4195
 };\
4196
 if(p == 0){alert(\"nothing drawn...\");return;};\
4197
 if( document.getElementById(\"canvas_input0\") ){\
4198
  var p = 0;var input_reply = new Array();\
4199
  if( document.getElementById(\"canvas_input0\")){\
4200
   var t = 0;\
4201
   while(document.getElementById(\"canvas_input\"+t)){\
4202
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4203
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4204
     p++;\
4205
    };\
4206
    t++;\
4207
   };\
4208
  };\
4209
  if( typeof userdraw_text != 'undefined' ){\
4210
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4211
  }\
4212
  else\
4213
  {\
4214
   return reply +\"\\n\"+input_reply;\
4215
  }\
4216
 }\
4217
 else\
4218
 {\
4219
  if( typeof userdraw_text != 'undefined' ){\
4220
   return reply +\"\\n\"+userdraw_text;\
4221
  }\
4222
  else\
4223
  {\
4224
   return reply;\
4225
  }\
4226
 };\
8108 schaersvoo 4227
};\n\
8074 schaersvoo 4228
<!-- end function 10 read_canvas() -->",reply_precision);
7614 schaersvoo 4229
    break;
4230
    case 11: fprintf(js_include_file,"\
7653 schaersvoo 4231
\n<!-- begin function 11 read_canvas() -->\n\
8108 schaersvoo 4232
read_canvas = function(){\
7614 schaersvoo 4233
 var reply = \"\";\
4234
 var p = 0;\
8074 schaersvoo 4235
 var prec = %d;\
7614 schaersvoo 4236
 while(userdraw_x[p]){\
8074 schaersvoo 4237
  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 4238
  p = p+2;\
4239
 };\
4240
 if(p == 0){alert(\"nothing drawn...\");return;};\
4241
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
4242
  var p = 0;var input_reply = new Array();\
4243
  if( document.getElementById(\"canvas_input0\")){\
4244
   var t = 0;\
4245
   while(document.getElementById(\"canvas_input\"+t)){\
4246
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4247
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4248
     p++;\
4249
    };\
4250
    t++;\
4251
   };\
4252
  };\
4253
  if( typeof userdraw_text != 'undefined' ){\
4254
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4255
  }\
4256
  else\
4257
  {\
4258
   return reply +\"\\n\"+input_reply;\
4259
  }\
4260
 }\
4261
 else\
4262
 {\
4263
  if( typeof userdraw_text != 'undefined' ){\
4264
   return reply +\"\\n\"+userdraw_text;\
4265
  }\
4266
  else\
4267
  {\
4268
   return reply;\
4269
  }\
4270
 };\
8108 schaersvoo 4271
};\n\
8074 schaersvoo 4272
<!-- end function 11 read_canvas() -->",reply_precision);
7614 schaersvoo 4273
    break;
4274
    case 12: fprintf(js_include_file,"\
7653 schaersvoo 4275
\n<!-- begin function 12 read_canvas() -->\n\
8108 schaersvoo 4276
read_canvas = function(){\
8074 schaersvoo 4277
 set_reply_precision();\
7614 schaersvoo 4278
 var reply = \"\";\
4279
 var p = 0;\
4280
 for(p = 0; p< userdraw_x.lenght;p = p+2){\
4281
  if(userdraw_x[p] != null){\
4282
    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
4283
  };\
4284
 };\
4285
 if(p == 0){alert(\"nothing drawn...\");return;};\
4286
 if( document.getElementById(\"canvas_input0\") ){\
4287
  var p = 0;var input_reply = new Array();\
4288
  if( document.getElementById(\"canvas_input0\")){\
4289
   var t = 0;\
4290
   while(document.getElementById(\"canvas_input\"+t)){\
4291
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4292
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4293
     p++;\
4294
    };\
4295
    t++;\
4296
   };\
4297
  };\
4298
  if( typeof userdraw_text != 'undefined' ){\
4299
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4300
  }\
4301
  else\
4302
  {\
4303
   return reply +\"\\n\"+input_reply;\
4304
  }\
4305
 }\
4306
 else\
4307
 {\
4308
  if( typeof userdraw_text != 'undefined' ){\
4309
   return reply +\"\\n\"+userdraw_text\
4310
  }\
4311
  else\
4312
  {\
4313
   return reply;\
4314
  }\
4315
 };\
8108 schaersvoo 4316
};\n\
7653 schaersvoo 4317
<!-- end function 12 read_canvas() -->");
7614 schaersvoo 4318
    break;
4319
    case 13: fprintf(js_include_file,"\
7653 schaersvoo 4320
\n<!-- begin function 13 read_canvas() -->\n\
8108 schaersvoo 4321
read_canvas = function(){\
7614 schaersvoo 4322
 var reply = new Array();\
4323
 var p = 0;var i = 0;\
8074 schaersvoo 4324
 var prec = %d;\
7614 schaersvoo 4325
 while(userdraw_x[p]){\
8074 schaersvoo 4326
  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 4327
  p = p+2;i++;\
4328
 };\
4329
 if(p == 0){alert(\"nothing drawn...\");return;};\
4330
 if( document.getElementById(\"canvas_input0\") ){\
4331
  var p = 0;var input_reply = new Array();\
4332
  if( document.getElementById(\"canvas_input0\")){\
4333
   var t = 0;\
4334
   while(document.getElementById(\"canvas_input\"+t)){\
4335
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4336
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4337
     p++;\
4338
    };\
4339
    t++;\
4340
   };\
4341
  };\
4342
  if( typeof userdraw_text != 'undefined' ){\
4343
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4344
  }\
4345
  else\
4346
  {\
4347
   return reply +\"\\n\"+input_reply;\
4348
  }\
4349
 }\
4350
 else\
4351
 {\
4352
  if( typeof userdraw_text != 'undefined' ){\
4353
   return reply +\"\\n\"+userdraw_text\
4354
  }\
4355
  else\
4356
  {\
4357
   return reply;\
4358
  }\
4359
 };\
8108 schaersvoo 4360
};\n\
8074 schaersvoo 4361
<!-- end function 13 read_canvas() -->",reply_precision);
7614 schaersvoo 4362
    break;
4363
    case 14: fprintf(js_include_file,"\
7653 schaersvoo 4364
\n<!-- begin function 14 read_canvas() -->\n\
8108 schaersvoo 4365
read_canvas = function(){\
8074 schaersvoo 4366
 set_reply_precision();\
7614 schaersvoo 4367
 var reply = new Array();\
4368
 var p = 0;var i = 0;\
4369
 while(userdraw_x[p]){\
4370
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
4371
  p = p+2;i++;\
4372
 };\
4373
 if(p == 0){alert(\"nothing drawn...\");return;};\
4374
 if( document.getElementById(\"canvas_input0\") ){\
4375
  var p = 0;var input_reply = new Array();\
4376
  if( document.getElementById(\"canvas_input0\")){\
4377
   var t = 0;\
4378
   while(document.getElementById(\"canvas_input\"+t)){\
4379
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4380
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4381
     p++;\
4382
    };\
4383
    t++;\
4384
   };\
4385
  };\
4386
  if( typeof userdraw_text != 'undefined' ){\
4387
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4388
  }\
4389
  else\
4390
  {\
4391
   return reply +\"\\n\"+input_reply;\
4392
  }\
4393
 }\
4394
 else\
4395
 {\
4396
  if( typeof userdraw_text != 'undefined' ){\
4397
   return reply +\"\\n\"+userdraw_text;\
4398
  }\
4399
  else\
4400
  {\
4401
   return reply;\
4402
  }\
4403
 };\
8108 schaersvoo 4404
};\n\
7653 schaersvoo 4405
<!-- end function 14 read_canvas() -->");
7614 schaersvoo 4406
    break;
4407
    case 15: fprintf(js_include_file,"\
7653 schaersvoo 4408
\n<!-- begin function 15  read_canvas() -->\n\
8108 schaersvoo 4409
read_canvas = function(){\
7614 schaersvoo 4410
 var input_reply = new Array();\
4411
 var p = 0;\
4412
 if( document.getElementById(\"canvas_input0\")){\
4413
  var t = 0;\
4414
  while(document.getElementById(\"canvas_input\"+t)){\
4415
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4416
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4417
    p++;\
4418
   };\
4419
   t++;\
4420
  };\
4421
 };\
4422
 if( typeof userdraw_text != 'undefined' ){\
4423
   return input_reply +\"\\n\"+userdraw_text;\
4424
 }\
4425
 else\
4426
 {\
4427
  return input_reply;\
4428
 };\
8108 schaersvoo 4429
};\n\
7653 schaersvoo 4430
<!-- end function 15 read_canvas() -->");
7614 schaersvoo 4431
    break;
4432
    case 16: fprintf(js_include_file,"\
7653 schaersvoo 4433
\n<!-- begin function 16 read_mathml() -->\n\
7614 schaersvoo 4434
function read_mathml(){\
4435
 var reply = new Array();\
4436
 var p = 0;\
4437
 if( document.getElementById(\"mathml0\")){\
4438
  while(document.getElementById(\"mathml\"+p)){\
4439
   reply[p] = document.getElementById(\"mathml\"+p).value;\
4440
   p++;\
4441
  };\
4442
 };\
4443
return reply;\
4444
};\
4445
this.read_mathml = read_mathml;\n\
7653 schaersvoo 4446
<!-- end function 16 read_mathml() -->");
7614 schaersvoo 4447
    break;
4448
    case 17:  fprintf(js_include_file,"\
7653 schaersvoo 4449
\n<!-- begin function 17 read_canvas() -->\n\
8108 schaersvoo 4450
read_canvas = function(){\
7614 schaersvoo 4451
 if( userdraw_text.length == 0){alert(\"no text typed...\");return;}\
4452
 return userdraw_text;\
8108 schaersvoo 4453
};\n\
7653 schaersvoo 4454
<!-- end function 17 read_canvas() -->");
7614 schaersvoo 4455
    break;
4456
    case 18: fprintf(js_include_file,"\
7653 schaersvoo 4457
\n<!-- begin function 18 read_canvas() -->\n\
8108 schaersvoo 4458
read_canvas = function(){\
7614 schaersvoo 4459
 var p = 0;\
4460
 var reply = new Array();\
4461
 var name;\
4462
 var t = true;\
8000 schaersvoo 4463
 var h;var m;var s;\
7614 schaersvoo 4464
 while(t){\
8000 schaersvoo 4465
  try{\
4466
   name = eval('clocks'+p);\
4467
   h = name.H;m = name.M;s = name.S;\
4468
   if(s < 0){s = 60 + s;m = m - 1;};\
4469
   if(m < 0){m = 60 + m;h = h - 1;};\
4470
   if(h < 0){h = 12 + h;};\
4471
   h = parseInt((h+m/60+s/3600)%%12);m = parseInt((m + s/60)%%60);s = parseInt(s%%60);\
4472
   reply[p] = h+\":\"+m+\":\"+s;\
4473
   p++;\
4474
  }catch(e){t=false;};\
7614 schaersvoo 4475
 };\
8000 schaersvoo 4476
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 4477
 return reply;\
8108 schaersvoo 4478
};\n\
7653 schaersvoo 4479
<!-- end function 18 read_canvas() -->");
7614 schaersvoo 4480
    break;
4481
    case 19: fprintf(js_include_file,"\
7653 schaersvoo 4482
\n<!-- begin function 19 read_canvas() -->\n\
8108 schaersvoo 4483
read_canvas = function(){\
7614 schaersvoo 4484
 return reply[0];\
8108 schaersvoo 4485
};\n\
7653 schaersvoo 4486
<!-- end function 19 read_canvas() -->");
8130 schaersvoo 4487
    break;
7614 schaersvoo 4488
    case 20: fprintf(js_include_file,"\
7653 schaersvoo 4489
\n<!-- begin function 20 read_canvas() -->\n\
8108 schaersvoo 4490
read_canvas = function(){\
8074 schaersvoo 4491
 var prec = %d;\
7614 schaersvoo 4492
 var len  = ext_drag_images.length;\
4493
 var reply = new Array(len);\
4494
 for(var p = 0 ; p < len ; p++){\
4495
    var img = ext_drag_images[p];\
8074 schaersvoo 4496
    reply[p] = (Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 4497
 };\
4498
 return reply;\
8108 schaersvoo 4499
};\n\
8074 schaersvoo 4500
<!-- end function 20 read_canvas() -->",reply_precision);
7614 schaersvoo 4501
    break;
4502
    case 21: fprintf(js_include_file,"\
7653 schaersvoo 4503
\n<!-- begin function 21 read_canvas() -->\n\
8108 schaersvoo 4504
read_canvas = function(){\
7614 schaersvoo 4505
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
4506
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 4507
 var prec = %d;\
7614 schaersvoo 4508
 while(userdraw_x[p]){\
8074 schaersvoo 4509
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 4510
  p++;\
4511
 };\
4512
 if(p == 0){alert(\"nothing drawn...\");return;};\
4513
 if( document.getElementById(\"canvas_input0\") ){\
4514
  var p = 0;var input_reply = new Array();\
4515
  if( document.getElementById(\"canvas_input0\")){\
4516
   var t = 0;\
4517
   while(document.getElementById(\"canvas_input\"+t)){\
4518
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4519
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4520
     p++;\
4521
    };\
4522
    t++;\
4523
   };\
4524
  };\
4525
  if( typeof userdraw_text != 'undefined' ){\
4526
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4527
  }\
4528
  else\
4529
  {\
4530
   return reply_coord+\"\\n\"+input_reply;\
4531
  }\
4532
 }\
4533
 else\
4534
 {\
4535
  if( typeof userdraw_text != 'undefined' ){\
4536
   return reply_coord+\"\\n\"+userdraw_text;\
4537
  }\
4538
  else\
4539
  {\
4540
   return reply_coord;\
4541
  };\
4542
 };\
8108 schaersvoo 4543
};\n\
8074 schaersvoo 4544
<!-- end function 21 read_canvas() -->",reply_precision);
7614 schaersvoo 4545
    break;
4546
    case 22: fprintf(js_include_file,"\
7653 schaersvoo 4547
\n<!-- begin function 22 read_canvas() -->\n\
8108 schaersvoo 4548
read_canvas = function(){\
7614 schaersvoo 4549
 var reply = new Array();\
7963 schaersvoo 4550
 var lu = userdraw_x.length;\
4551
 if(lu == 0){alert(\"nothing drawn...\");return;};\
7614 schaersvoo 4552
 var idx = 0;\
8074 schaersvoo 4553
 var prec = %d;\
7963 schaersvoo 4554
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 4555
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
4556
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 4557
 };\
4558
 if( document.getElementById(\"canvas_input0\") ){\
4559
  var p = 0;var input_reply = new Array();\
4560
  if( document.getElementById(\"canvas_input0\")){\
4561
   var t = 0;\
4562
   while(document.getElementById(\"canvas_input\"+t)){\
4563
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4564
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4565
     p++;\
4566
    };\
4567
    t++;\
4568
   };\
4569
  };\
4570
  if( typeof userdraw_text != 'undefined' ){\
4571
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4572
  }\
4573
  else\
4574
  {\
4575
   return reply +\"\\n\"+input_reply;\
4576
  }\
4577
 }\
4578
 else\
4579
 {\
4580
  if( typeof userdraw_text != 'undefined' ){\
4581
   return reply +\"\\n\"+userdraw_text;\
4582
  }\
4583
  else\
4584
  {\
4585
   return reply;\
4586
  }\
4587
 };\
8108 schaersvoo 4588
};\n\
8074 schaersvoo 4589
<!-- end function 22 read_canvas() -->",reply_precision);
7614 schaersvoo 4590
    break;
7782 schaersvoo 4591
    case 23: fprintf(js_include_file,"\
4592
\n<!-- begin function 23 read_canvas() default 5 px marge -->\n\
8108 schaersvoo 4593
read_canvas = function(){\
7782 schaersvoo 4594
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
4595
 var lu = userdraw_x.length;\
4596
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 4597
 var reply_x = new Array();var reply_y = new Array();\
4598
 var marge = 5;var p = 0;\
8074 schaersvoo 4599
 var prec = %d;\
7782 schaersvoo 4600
 for(var i = 0; i < lu - 1 ; i++ ){\
7962 schaersvoo 4601
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1])){\
8074 schaersvoo 4602
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 4603
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
4604
   p++;\
7782 schaersvoo 4605
  };\
8074 schaersvoo 4606
  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 4607
 };\
4608
 if( document.getElementById(\"canvas_input0\")){\
4609
  var p = 0;var input_reply = new Array();\
4610
  if( document.getElementById(\"canvas_input0\")){\
4611
   var t = 0;\
4612
   while(document.getElementById(\"canvas_input\"+t)){\
4613
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
4614
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
4615
     p++;\
4616
    };\
4617
    t++;\
4618
   };\
4619
  };\
4620
  if( typeof userdraw_text != 'undefined' ){\
4621
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
4622
  }\
4623
  else\
4624
  {\
4625
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
4626
  }\
4627
 }\
4628
 else\
4629
 {\
4630
  if( typeof userdraw_text != 'undefined' ){\
4631
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
4632
  }\
4633
  else\
4634
  {\
4635
   return reply_x+\"\\n\"+reply_y;\
4636
  };\
4637
 };\
8108 schaersvoo 4638
};\n\
8074 schaersvoo 4639
<!-- end function 23 read_canvas() -->",reply_precision);
7782 schaersvoo 4640
    break;
7984 schaersvoo 4641
    case 24: fprintf(js_include_file,"\n\
4642
<!-- begin function 24  read_canvas() -->\n\
8108 schaersvoo 4643
read_canvas = function(){\
7984 schaersvoo 4644
 var input_reply = new Array();\
4645
 var p = 0;\
4646
 if( document.getElementById(\"canvas_input0\")){\
4647
  while(document.getElementById(\"canvas_input\"+p)){\
4648
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
4649
    p++;\
4650
  };\
4651
  return input_reply;\
4652
 };\
8108 schaersvoo 4653
};\n\
7984 schaersvoo 4654
<!-- end function 24 read_canvas() -->");
4655
    break;
8083 schaersvoo 4656
    case 25:
4657
    fprintf(js_include_file,"\n<!-- begin function 25 read_canvas() : angle(s) in degrees-->\n\
8108 schaersvoo 4658
read_canvas = function(){\
8083 schaersvoo 4659
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
4660
 var lu = userdraw_radius.length;\
4661
 var prec = %d;\
4662
 var angle_reply = new Array(lu);\
4663
 for(var p = 0 ; p < lu ; p++){\
4664
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
4665
 };\
4666
 return angle_reply;\
8108 schaersvoo 4667
};\n\
8083 schaersvoo 4668
<!-- end function 25 read_canvas() -->",reply_precision);
4669
    break;
4670
    case 26:
8127 schaersvoo 4671
    fprintf(js_include_file,"\n<!-- begin function 26 read_canvas() : angle(s) in radians-->\n\
8108 schaersvoo 4672
read_canvas = function(){\
8083 schaersvoo 4673
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
4674
 var lu = userdraw_radius.length;\
4675
 var prec = %d;\
4676
 var angle_reply = new Array(lu);\
4677
 for(var p = 0 ; p < lu ; p++){\
4678
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
4679
 };\
4680
 return angle_reply;\
8108 schaersvoo 4681
};\n\
8127 schaersvoo 4682
<!-- end function 26 read_canvas() -->",reply_precision);
8083 schaersvoo 4683
    break;
8127 schaersvoo 4684
    case 27:
4685
    fprintf(js_include_file,"\n<!-- begin function 27 read_canvas()  : inputfield(s) location and their values : -->\n\
4686
read_canvas = function(){\
4687
 var lu = userdraw_x.length;\
4688
 if( lu < 1){alert(\"nothing drawn...\");return;}\
4689
 set_reply_precision();\
4690
 var prec = %d;\
4691
 for(var p = 0 ; p < lu ; p++){\
4692
   reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
4693
 };\
4694
 return reply;\
4695
};\n\
8224 bpr 4696
<!-- end function 27 read_canvas() -->",reply_precision);
8127 schaersvoo 4697
    break;
7614 schaersvoo 4698
    default: canvas_error("hmmm unknown replyformat...");break;
4699
}
4700
 return;
4701
}
4702
 
4703
 
8224 bpr 4704
/*
4705
 add drawfunction :
7614 schaersvoo 4706
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
4707
 - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
4708
 - grid / mathml
4709
 - will not scale or zoom in
4710
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
8224 bpr 4711
 - is printed directly into 'js_include_file'
7614 schaersvoo 4712
*/
4713
 
4714
void add_javascript_functions(int js_functions[],int canvas_root_id){
4715
int i;
4716
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
4717
 if( js_functions[i] == 1){
4718
    switch(i){
4719
    case DRAG_EXTERNAL_IMAGE:
4720
fprintf(js_include_file,"\n<!-- drag external images --->\n\
7653 schaersvoo 4721
var external_canvas = create_canvas%d(7,xsize,ysize);\
4722
var external_ctx = external_canvas.getContext(\"2d\");\
4723
var external_canvas_rect = external_canvas.getBoundingClientRect();\
4724
canvas_div.addEventListener(\"mousedown\",setxy,false);\
4725
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
4726
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
4727
var selected_image = null;\
4728
var ext_image_cnt = 0;\
4729
var ext_drag_images = new Array();\
4730
function drag_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,draggable){\
4731
 ext_image_cnt = idx;\
4732
 var image = new Image();\
4733
 image.src = URL;\
4734
 image.onload = function(){\
4735
  if( x0 < 1 ){ x0 = 0; };if( y0 < 1 ){ y0 = 0; };if( sx < 1 ){ sx = 0; };if( sy < 1 ){ sy = 0; };\
4736
  if( width < 1 ){ width = image.width; };if( height < 1 ){ height = image.height; };\
4737
  if( swidth < 1 ){ swidth = image.width; };if( sheight < 1 ){ sheight = image.height; };\
8112 schaersvoo 4738
  var img = new Array(10);\
7653 schaersvoo 4739
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
4740
  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;\
4741
  ext_drag_images[idx] = img;\
4742
  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
4743
 };\
4744
};\
4745
function dragstop(evt){\
4746
 selected_image = null;return;\
4747
};\
4748
function dragxy(evt){\
4749
 if( selected_image != null ){\
4750
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
4751
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
4752
  var s_img = ext_drag_images[selected_image];\
4753
  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
4754
  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
4755
  ext_drag_images[selected_image] = s_img;\
4756
  external_ctx.clearRect(0,0,xsize,ysize);\
4757
  for(var i = 0; i <= ext_image_cnt ; i++){\
4758
   var img = ext_drag_images[i];\
4759
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
4760
  };\
4761
 };\
4762
};\
4763
function setxy(evt){\
4764
 if( ! selected_image && evt.which == 1 ){\
4765
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
4766
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
4767
  var xm = evt.clientX - external_canvas_rect.left + xoff;\
4768
  var ym = evt.clientY - external_canvas_rect.top + yoff;\
4769
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
4770
   var img = ext_drag_images[p];\
4771
   if( img[0] == 1 ){\
4772
    var w = img.width;\
4773
    var h = img.height;\
4774
    if( xm > img[6] && xm < img[6] + img[4]){\
4775
     if( ym > img[7] && ym < img[7] + img[5]){\
4776
      img[6] = xm;\
4777
      img[7] = ym;\
4778
      ext_drag_images[p] = img;\
4779
      selected_image = p;\
4780
      dragxy(evt);\
4781
     };\
4782
    };\
4783
   };\
4784
  };\
4785
 }\
4786
 else\
4787
 {\
4788
  selected_image = null;\
4789
 };\
7614 schaersvoo 4790
};",canvas_root_id);
4791
    break;
4792
 
4793
    case DRAW_EXTERNAL_IMAGE:
4794
fprintf(js_include_file,"\n<!-- draw external images -->\n\
8105 schaersvoo 4795
var draw_external_image = function(URL,sx,sy,swidth,sheight,x0,y0,width,height,draggable){\
7614 schaersvoo 4796
 var image = new Image();\
4797
 image.src = URL;\
4798
 var canvas_bg_div = document.getElementById(\"canvas_div%d\");\
4799
 image.onload = function(){\
4800
  if( x0 < 1 ){ x0 = 0; };\
4801
  if( y0 < 1 ){ y0 = 0; };\
4802
  if( sx < 1 ){ sx = 0; };\
4803
  if( sy < 1 ){ sy = 0; };\
4804
  if( width < 1 ){ width = image.width;};\
4805
  if( height < 1 ){ height = image.height;};\
4806
  if( swidth < 1 ){ swidth = image.width;};\
4807
  if( sheight < 1 ){ sheight = image.height;};\
4808
  var ml = x0 - sx;\
4809
  var mh = y0 - sy;\
4810
  canvas_bg_div.style.backgroundPosition= \"left \"+ml+\"px top \"+mh+\"px\";\
4811
  canvas_bg_div.style.backgroundSize = width+\"px \"+height+\"px\";\
4812
  canvas_bg_div.style.backgroundRepeat = \"no-repeat\";\
4813
  canvas_bg_div.style.backgroundPosition= sx+\"px \"+sy+\"px\";\
4814
  canvas_bg_div.style.backgroundImage = \"url(\" + URL + \")\";\
4815
 };\
8224 bpr 4816
};",canvas_root_id);
7614 schaersvoo 4817
    break;
4818
    case DRAW_GRIDFILL:/* not used for userdraw */
4819
fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
8105 schaersvoo 4820
var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
7614 schaersvoo 4821
 var obj;\
4822
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4823
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4824
 }\
4825
 else\
4826
 {\
4827
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4828
 };\
4829
 var ctx = obj.getContext(\"2d\");\
4830
 var x,y;\
7883 schaersvoo 4831
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 4832
 ctx.save();\
4833
 ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
4834
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
4835
    ctx.moveTo(x,y0);\
4836
    ctx.lineTo(x,ysize);\
4837
 };\
7645 schaersvoo 4838
 for( y = y0 ; y < ysize+dy; y = y + dy ){\
7614 schaersvoo 4839
    ctx.moveTo(x0,y);\
4840
    ctx.lineTo(xsize,y);\
4841
 };\
4842
 ctx.stroke();\
4843
 ctx.restore();\
7653 schaersvoo 4844
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4845
    break;
8224 bpr 4846
 
7614 schaersvoo 4847
    case DRAW_IMAGEFILL:/* not  used for userdraw */
4848
fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
8105 schaersvoo 4849
var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
7614 schaersvoo 4850
 var obj;\
4851
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4852
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4853
 }\
4854
 else\
4855
 {\
4856
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4857
 };\
4858
 var ctx = obj.getContext(\"2d\");\
4859
 ctx.save();\
4860
 var img = new Image();\
4861
 img.src = URL;\
4862
 img.onload = function(){\
4863
  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
4864
    ctx.drawImage(img,x0,y0,xsize,ysize);\
4865
  }\
4866
  else\
4867
  {\
4868
    var repeat = \"repeat\";\
4869
    if(img.width > xsize - x0){\
4870
        repeat = \"repeat-y\";\
4871
    }\
4872
    else\
4873
    {\
4874
     if( img.height > ysize -x0 ){\
4875
      repeat = \"repeat-x\";\
4876
     }\
4877
    }\
4878
    var pattern = ctx.createPattern(img,repeat);\
4879
    ctx.rect(x0,y0,xsize,ysize);\
4880
    ctx.fillStyle = pattern;\
4881
  }\
4882
  ctx.fill();\
4883
 };\
4884
 ctx.restore();\
4885
 return;\
7653 schaersvoo 4886
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4887
    break;
8224 bpr 4888
 
7614 schaersvoo 4889
    case DRAW_DOTFILL:/* not  used for userdraw */
4890
fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
8105 schaersvoo 4891
var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\
7614 schaersvoo 4892
 var obj;\
4893
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4894
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4895
 }\
4896
 else\
4897
 {\
4898
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4899
 };\
4900
 var ctx = obj.getContext(\"2d\");\
4901
 var x,y;\
4902
 ctx.closePath();\
4903
 ctx.save();\
7645 schaersvoo 4904
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 4905
 ctx.fillStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
4906
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
4907
  for( y = y0 ; y < ysize+dy ; y = y + dy ){\
4908
   ctx.arc(x,y,radius,0,2*Math.PI,false);\
4909
   ctx.closePath();\
4910
  }\
4911
 }\
4912
 ctx.fill();\
4913
 ctx.restore();\
7653 schaersvoo 4914
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4915
    break;
7645 schaersvoo 4916
 
7647 schaersvoo 4917
    case DRAW_DIAMONDFILL:/* not used for userdraw */
7614 schaersvoo 4918
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
8105 schaersvoo 4919
var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7614 schaersvoo 4920
  var obj;\
4921
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4922
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4923
 }\
4924
 else\
4925
 {\
4926
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4927
 };\
4928
 var ctx = obj.getContext(\"2d\");\
4929
 var x;\
4930
 var y;\
4931
 ctx.save();\
4932
 ctx.lineWidth = linewidth;\
4933
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4934
 y = ysize;\
4935
 for( x = x0 ; x < xsize ; x = x + dx ){\
4936
  ctx.moveTo(x,y0);\
4937
  ctx.lineTo(xsize,y);\
4938
  y = y - dy;\
4939
 };\
4940
 y = y0;\
4941
 for( x = xsize ; x > 0 ; x = x - dx){\
4942
  ctx.moveTo(x,ysize);\
4943
  ctx.lineTo(x0,y);\
4944
  y = y + dy;\
4945
 };\
4946
 x = x0;\
4947
 for( y = y0 ; y < ysize ; y = y + dy ){\
4948
  ctx.moveTo(xsize,y);\
4949
  ctx.lineTo(x,ysize);\
4950
  x = x + dx;\
4951
 };\
4952
 x = xsize;\
4953
 for( y = ysize ; y > y0 ; y = y - dy ){\
4954
  ctx.moveTo(x,y0);\
4955
  ctx.lineTo(x0,y);\
4956
  x = x - dx;\
4957
 };\
4958
 ctx.stroke();\
4959
 ctx.restore();\
4960
 return;\
7653 schaersvoo 4961
 }",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 4962
    break;
8224 bpr 4963
 
7647 schaersvoo 4964
    case DRAW_HATCHFILL:/* not used for userdraw */
4965
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
8105 schaersvoo 4966
var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7647 schaersvoo 4967
  var obj;\
4968
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
4969
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
4970
 }\
4971
 else\
4972
 {\
4973
  obj = create_canvas%d(canvas_type,xsize,ysize);\
4974
 };\
4975
 var ctx = obj.getContext(\"2d\");\
4976
 var x;\
4977
 var y;\
4978
 ctx.save();\
4979
 ctx.lineWidth = linewidth;\
4980
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
4981
 y = ysize;\
4982
 for( x = x0 ; x < xsize ; x = x + dx ){\
4983
  ctx.moveTo(x,y0);\
4984
  ctx.lineTo(xsize,y);\
4985
  y = y - dy;\
4986
 };\
4987
 y = y0;\
4988
 for( x = xsize ; x >= dx ; x = x - dx){\
4989
  ctx.moveTo(x,ysize);\
4990
  ctx.lineTo(x0,y);\
4991
  y = y + dy;\
4992
 };\
4993
 ctx.stroke();\
4994
 ctx.restore();\
4995
 return;\
7653 schaersvoo 4996
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7647 schaersvoo 4997
    break;
7614 schaersvoo 4998
    case DRAW_CIRCLES:/*  used for userdraw */
4999
fprintf(js_include_file,"\n<!-- draw circles -->\n\
8105 schaersvoo 5000
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 5001
 ctx.save();\
8071 schaersvoo 5002
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5003
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5004
 ctx.lineWidth = line_width;\
5005
 for(var p = 0 ; p < x_points.length ; p++ ){\
5006
  ctx.beginPath();\
5007
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
5008
  ctx.closePath();\
5009
  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5010
  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5011
  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5012
  ctx.stroke();\
5013
 }\
5014
 ctx.restore();\
5015
 return;\
7653 schaersvoo 5016
};");
7614 schaersvoo 5017
    break;
7663 schaersvoo 5018
    case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
5019
fprintf(js_include_file,"\n<!-- draw polyline -->\n\
8105 schaersvoo 5020
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 5021
 ctx.save();\
8071 schaersvoo 5022
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 5023
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5024
 ctx.lineWidth = line_width;\
5025
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5026
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5027
 ctx.clearRect(0,0,xsize,ysize);\
5028
 ctx.beginPath();\
5029
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
5030
  ctx.moveTo(x_points[p],y_points[p]);\
5031
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
5032
 }\
5033
 ctx.closePath();\
5034
 ctx.stroke();\
5035
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5036
 for(var p = 0 ; p < x_points.length ; p++ ){\
5037
  ctx.beginPath();\
5038
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
5039
  ctx.closePath();ctx.fill();ctx.stroke();\
5040
 };\
5041
 ctx.restore();\
5042
 return;\
5043
};");
5044
    break;
8224 bpr 5045
 
7614 schaersvoo 5046
    case DRAW_SEGMENTS:/*  used for userdraw */
5047
fprintf(js_include_file,"\n<!-- draw segments -->\n\
8105 schaersvoo 5048
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 5049
 ctx.save();\
8071 schaersvoo 5050
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5051
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5052
 ctx.lineWidth = line_width;\
5053
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5054
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5055
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
5056
  ctx.beginPath();\
5057
  ctx.moveTo(x_points[p],y_points[p]);\
5058
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
5059
  ctx.closePath();\
5060
  ctx.stroke();\
5061
  }\
5062
  ctx.restore();\
5063
  return;\
5064
 };");
5065
    break;
8224 bpr 5066
 
7614 schaersvoo 5067
    case DRAW_LINES:/*  used for userdraw */
5068
fprintf(js_include_file,"\n<!-- draw lines -->\n\
5069
function calc_line(x1,x2,y1,y2){\
5070
 var marge = 2;\
5071
 if(x1 < x2+marge && x1>x2-marge){\
5072
  return [x1,0,x1,ysize];\
5073
 };\
5074
 if(y1 < y2+marge && y1>y2-marge){\
5075
  return [0,y1,xsize,y1];\
5076
 };\
5077
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
5078
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
5079
 return [0,Y1,xsize,Y2];\
5080
};\
8105 schaersvoo 5081
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 5082
 ctx.save();\
5083
 var line = new Array(4);\
8071 schaersvoo 5084
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5085
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5086
 ctx.lineWidth = line_width;\
5087
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5088
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5089
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
5090
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
5091
  ctx.beginPath();\
5092
  ctx.moveTo(line[0],line[1]);\
5093
  ctx.lineTo(line[2],line[3]);\
5094
  ctx.closePath();\
5095
  ctx.stroke();\
5096
  }\
5097
  ctx.restore();\
5098
  return;\
5099
 };");
5100
    break;
5101
 
8244 schaersvoo 5102
    case DRAW_DEMILINES:/*  used for userdraw */
5103
fprintf(js_include_file,"\n<!-- draw demilines -->\n\
5104
function find_inf_point(x1,y1,x2,y2){\
5105
 if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
5106
 var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
5107
 if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
5108
};\
5109
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){\
5110
 ctx.save();\
5111
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
5112
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5113
 ctx.lineWidth = line_width;\
5114
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5115
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5116
 var pair = new Array(4);\
5117
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
5118
  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
5119
  ctx.beginPath();\
5120
  ctx.moveTo(pair[0],pair[1]);\
5121
  ctx.lineTo(pair[2],pair[3]);\
5122
  ctx.closePath();\
5123
  ctx.stroke();\
5124
  }\
5125
  ctx.restore();\
5126
  return;\
5127
 };");
5128
    break;
5129
 
7614 schaersvoo 5130
    case DRAW_CROSSHAIRS:/*  used for userdraw */
5131
fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
8105 schaersvoo 5132
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 5133
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5134
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5135
 ctx.lineWidth = line_width;\
5136
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5137
 var x1,x2,y1,y2;\
5138
 for(var p = 0 ; p < x_points.length ; p++ ){\
5139
  x1 = x_points[p] - crosshair_size;\
5140
  x2 = x_points[p] + crosshair_size;\
5141
  y1 = y_points[p] - crosshair_size;\
5142
  y2 = y_points[p] + crosshair_size;\
5143
  ctx.beginPath();\
5144
  ctx.moveTo(x1,y1);\
5145
  ctx.lineTo(x2,y2);\
5146
  ctx.closePath();\
5147
  ctx.stroke();\
5148
  ctx.beginPath();\
5149
  ctx.moveTo(x2,y1);\
5150
  ctx.lineTo(x1,y2);\
5151
  ctx.closePath();\
5152
  ctx.stroke();\
5153
 }\
5154
 ctx.restore();\
5155
  return;\
7653 schaersvoo 5156
};");
7614 schaersvoo 5157
    break;
5158
 
5159
    case DRAW_RECTS:/*  used for userdraw */
5160
fprintf(js_include_file,"\n<!-- draw rects -->\n\
8105 schaersvoo 5161
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 5162
 ctx.save();\
8071 schaersvoo 5163
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5164
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5165
 ctx.lineWidth = line_width;\
5166
 ctx.strokeStyle = \"rgba('+stroke_color+','+stroke_opacity+')\";\
5167
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
5168
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
5169
  ctx.beginPath();\
5170
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
5171
  ctx.closePath();\
5172
  if(use_filled == 1 ){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5173
  ctx.stroke();\
5174
 };\
5175
 ctx.restore();\
5176
 return;\
7653 schaersvoo 5177
};");
7614 schaersvoo 5178
    break;
5179
 
5180
    case DRAW_ROUNDRECTS:/*  used for userdraw */
5181
fprintf(js_include_file,"\n<!-- draw round rects -->\n\
8105 schaersvoo 5182
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 5183
 ctx.save();\
8071 schaersvoo 5184
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5185
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5186
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5187
 var x,y,w,h,r;\
5188
 for(var p = 0; p < x_points.length; p = p+2){\
5189
  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);\
5190
  ctx.beginPath();ctx.moveTo(x + r, y);\
5191
  ctx.lineTo(x + w - r, y);\
5192
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
5193
  ctx.lineTo(x + w, y + h - r);\
5194
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
5195
  ctx.lineTo(x + r, y + h);\
5196
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
5197
  ctx.lineTo(x, y + r);\
5198
  ctx.quadraticCurveTo(x, y, x + r, y);\
5199
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
5200
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5201
  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
5202
  ctx.stroke();\
5203
 }\
5204
 ctx.restore();\
7653 schaersvoo 5205
};");
8224 bpr 5206
    break;
7614 schaersvoo 5207
 
5208
    case DRAW_ELLIPSES:/* not  used for userdraw */
5209
fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
8105 schaersvoo 5210
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 5211
 var obj;\
5212
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5213
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5214
 }\
5215
 else\
5216
 {\
5217
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5218
 };\
5219
 var ctx = obj.getContext(\"2d\");\
5220
 ctx.save();\
8071 schaersvoo 5221
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5222
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5223
 var cx,cy,ry,rx;\
5224
 ctx.lineWidth = line_width;\
5225
 if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
5226
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5227
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5228
 for(var p=0;p< x_points.length;p = p+2){\
5229
  ctx.beginPath();\
5230
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
5231
  ctx.translate(cx - rx, cy - ry);\
5232
  ctx.scale(rx, ry);\
5233
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
5234
  if( use_filled == 1 ){ctx.fill();}\
5235
  ctx.stroke();\
5236
 };\
5237
 ctx.restore();\
7653 schaersvoo 5238
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5239
    break;
5240
 
5241
    case DRAW_PATHS: /*  used for userdraw */
5242
fprintf(js_include_file,"\n<!-- draw paths -->\n\
8105 schaersvoo 5243
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 5244
 ctx.save();\
8071 schaersvoo 5245
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5246
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5247
 ctx.lineWidth = line_width;\
5248
 ctx.lineJoin = \"round\";\
5249
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5250
 ctx.beginPath();\
5251
 ctx.moveTo(x_points[0],y_points[0]);\
5252
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
5253
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
5254
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5255
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
5256
 ctx.stroke();\
5257
 ctx.restore();\
5258
 return;\
5259
};");
8224 bpr 5260
 
7614 schaersvoo 5261
    break;
5262
    case DRAW_ARROWS:/*  used for userdraw */
5263
fprintf(js_include_file,"\n<!-- draw arrows -->\n\
8105 schaersvoo 5264
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 5265
 ctx.save();\
8071 schaersvoo 5266
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 5267
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
5268
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5269
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5270
 ctx.lineWidth = line_width;\
5271
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5272
 ctx.lineCap = \"round\";\
5273
 var x1,y1,x2,y2,dx,dy,len;\
5274
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 5275
   ctx.save();\
7614 schaersvoo 5276
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
5277
   len = Math.sqrt(dx*dx+dy*dy);\
5278
   ctx.translate(x2,y2);\
5279
   ctx.rotate(Math.atan2(dy,dx));\
5280
   ctx.lineCap = \"round\";\
5281
   ctx.beginPath();\
5282
   ctx.moveTo(0,0);\
5283
   ctx.lineTo(-len,0);\
5284
   ctx.closePath();\
5285
   ctx.stroke();\
5286
   ctx.beginPath();\
5287
   ctx.moveTo(0,0);\
5288
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
5289
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
5290
   ctx.closePath();\
5291
   ctx.fill();\
7874 schaersvoo 5292
   ctx.restore();\
7614 schaersvoo 5293
   if( type == 2 ){\
5294
     ctx.save();\
5295
     ctx.translate(x1,y1);\
5296
     ctx.rotate(Math.atan2(-dy,-dx));\
5297
     ctx.beginPath();\
5298
     ctx.moveTo(0,0);\
5299
     ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
5300
     ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
5301
     ctx.closePath();\
5302
     ctx.stroke();\
5303
     ctx.fill();\
7874 schaersvoo 5304
     ctx.restore();\
7614 schaersvoo 5305
   }\
5306
  }\
5307
  ctx.restore();\
5308
  return;\
7653 schaersvoo 5309
};");
7614 schaersvoo 5310
    break;
5311
 
5312
    case DRAW_VIDEO:/* not  used for userdraw */
5313
fprintf(js_include_file,"\n<!-- draw video -->\n\
8105 schaersvoo 5314
var draw_video = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 5315
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5316
 var video_div = document.createElement(\"div\");\
5317
 canvas_div.appendChild(video_div);\
5318
 video_div.style.position = \"absolute\";\
5319
 video_div.style.left = x+\"px\";\
5320
 video_div.style.top = y+\"px\";\
5321
 video_div.style.width = w+\"px\";\
5322
 video_div.style.height = h+\"px\";\
5323
 var video = document.createElement(\"video\");\
5324
 video_div.appendChild(video);\
5325
 video.style.width = w+\"px\";\
5326
 video.style.height = h+\"px\";\
5327
 video.autobuffer = true;\
5328
 video.controls = true;video.autoplay = false;\
5329
 var src = document.createElement(\"source\");\
5330
 src.type = \"video/mp4\";\
5331
 src.src = URL;\
5332
 video.appendChild(src);\
5333
 video.load();\
5334
 return;\
8224 bpr 5335
};");
7614 schaersvoo 5336
    break;
8224 bpr 5337
 
7614 schaersvoo 5338
    case DRAW_AUDIO:/* not used for userdraw */
5339
fprintf(js_include_file,"\n<!-- draw audio -->\n\
8105 schaersvoo 5340
var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
7614 schaersvoo 5341
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5342
 var audio_div = document.createElement(\"div\");\
5343
 canvas_div.appendChild(audio_div);\
5344
 audio_div.style.position = \"absolute\";\
5345
 audio_div.style.left = x+\"px\";\
5346
 audio_div.style.top = y+\"px\";\
5347
 audio_div.style.width = w+\"px\";\
5348
 audio_div.style.height = h+\"px\";\
5349
 var audio = document.createElement(\"audio\");\
5350
 audio_div.appendChild(audio);\
5351
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
5352
 audio.autobuffer = true;\
5353
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;}\
5354
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;}\
5355
 var src1 = document.createElement(\"source\");\
5356
 src1.type = \"audio/ogg\";\
5357
 src1.src = URL1;\
5358
 audio.appendChild(src1);\
5359
 var src2 = document.createElement(\"source\");\
5360
 src2.type = \"audio/mpeg\";\
5361
 src2.src = URL2;\
5362
 audio.appendChild(src2);\
5363
 audio.load();\
5364
 return;\
7653 schaersvoo 5365
};");
7614 schaersvoo 5366
    break;
8224 bpr 5367
 
7614 schaersvoo 5368
    case DRAW_HTTP:/* not  used for userdraw */
5369
fprintf(js_include_file,"\n<!-- draw http -->\n\
8105 schaersvoo 5370
var draw_http = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 5371
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5372
 var http_div = document.createElement(\"div\");\
5373
 var iframe = document.createElement(\"iframe\");\
5374
 canvas_div.appendChild(http_div);\
5375
 http_div.appendChild(iframe);\
5376
 iframe.src = URL;\
5377
 iframe.setAttribute(\"width\",w);\
5378
 iframe.setAttribute(\"height\",h);\
5379
 return;\
7653 schaersvoo 5380
};");
7614 schaersvoo 5381
    break;
8224 bpr 5382
 
7614 schaersvoo 5383
    case DRAW_XML:
5384
fprintf(js_include_file,"\n<!-- draw xml -->\n\
8105 schaersvoo 5385
var draw_xml = function(canvas_root_id,x,y,w,h,mathml,onclick){\
7614 schaersvoo 5386
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
5387
 var xml_div = document.createElement(\"div\");\
5388
 canvas_div.appendChild(xml_div);\
5389
 xml_div.innerHTML = mathml;\
5390
 if(onclick != 0){\
5391
  xml_div.onclick = function(){\
5392
   reply[0] = onclick;\
5393
   alert(\"send \"+onclick+\" ?\");\
5394
  };\
5395
 };\
5396
 xml_div.style.position = \"absolute\";\
5397
 xml_div.style.left = x+\"px\";\
5398
 xml_div.style.top = y+\"px\";\
5399
 xml_div.style.width = w+\"px\";\
5400
 xml_div.style.height = h+\"px\";\
5401
 return;\
7653 schaersvoo 5402
};"
7614 schaersvoo 5403
);
5404
    break;
7654 schaersvoo 5405
    case DRAW_SGRAPH:
8224 bpr 5406
/*
7654 schaersvoo 5407
 xstart = given
5408
 ystart = given
5409
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
5410
*/
5411
fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
8105 schaersvoo 5412
var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
7658 schaersvoo 5413
 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);};\
5414
 var ctx = obj.getContext(\"2d\");\
5415
 ctx.font = fontfamily;\
5416
 var minor_opacity = 0.8*opacity;\
5417
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 5418
 var zero_x = 0.1*xsize;\
5419
 var zero_y = 0.9*ysize;\
8129 schaersvoo 5420
 var snor_x;var snor_y;\
7654 schaersvoo 5421
 if( xstart != xmin){\
7658 schaersvoo 5422
  snor_x = 0.1*xsize;\
5423
 }\
5424
 else\
5425
 {\
5426
  snor_x = 0;\
5427
  xstart = xmin;\
5428
 };\
5429
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5430
 ctx.lineWidth = 2;\
5431
 ctx.beginPath();\
5432
 ctx.moveTo(xsize,zero_y);\
5433
 ctx.lineTo(zero_x,zero_y);\
5434
 ctx.lineTo(zero_x,0);\
5435
 ctx.stroke();\
5436
 ctx.closePath();\
5437
 ctx.beginPath();\
5438
 ctx.moveTo(zero_x,zero_y);\
5439
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
5440
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
5441
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
5442
 ctx.lineTo(zero_x + snor_x,zero_y);\
5443
 ctx.stroke();\
5444
 ctx.closePath();\
5445
 ctx.beginPath();\
5446
 var num = xstart;\
7660 schaersvoo 5447
 var flipflop = 1;\
7658 schaersvoo 5448
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 5449
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 5450
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 5451
  txtsize = ctx.measureText(num).width;\
5452
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
5453
  if( flipflop == 1){\
5454
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
5455
  }\
5456
  else\
5457
  {\
5458
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
5459
  }\
5460
  num = num + xmajor;\
7658 schaersvoo 5461
 };\
5462
 ctx.stroke();\
5463
 ctx.closePath();\
5464
 ctx.lineWidth = 1;\
5465
 ctx.beginPath();\
5466
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
5467
   ctx.moveTo(x,zero_y);\
5468
   ctx.lineTo(x,0);\
5469
 };\
5470
 ctx.stroke();\
5471
 ctx.closePath();\
5472
 if( xminor > 1){\
5473
  ctx.lineWidth = 0.5;\
5474
  ctx.beginPath();\
5475
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
5476
  var minor_step_x = step_x / xminor;\
5477
  var nx;\
5478
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
5479
    num = 1;\
5480
    for(var p = 1 ; p < xminor ; p++){\
5481
     nx = x + num*minor_step_x;\
5482
     ctx.moveTo(nx,zero_y);\
5483
     ctx.lineTo(nx,0);\
5484
     num++;\
5485
    };\
5486
  };\
5487
  ctx.stroke();\
5488
  ctx.closePath();\
5489
  ctx.beginPath();\
5490
  ctx.lineWidth = 2;\
5491
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5492
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
5493
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
5494
  };\
5495
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
5496
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
5497
  };\
5498
  ctx.stroke();\
5499
  ctx.closePath();\
5500
  ctx.lineWidth = 0.5;\
5501
 };\
5502
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
5503
 if( ystart != ymin){\
5504
  snor_y = 0.1*ysize;\
5505
 }\
5506
 else\
5507
 {\
5508
  snor_y = 0;\
5509
  ystart = ymin;\
5510
 };\
5511
 ctx.lineWidth = 2;\
5512
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5513
 ctx.beginPath();\
5514
 ctx.moveTo(zero_x,zero_y);\
5515
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
5516
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
5517
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
5518
 ctx.lineTo(zero_x,zero_y - snor_y);\
5519
 ctx.stroke();\
5520
 ctx.closePath();\
5521
 ctx.beginPath();\
5522
 ctx.lineWidth = 1;\
5523
 num = ystart;\
5524
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
5525
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
5526
  ctx.moveTo(zero_x,y);\
5527
  ctx.lineTo(xsize,y);\
5528
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
5529
  num = num + ymajor;\
5530
 };\
5531
 ctx.stroke();\
5532
 ctx.closePath();\
5533
 if( yminor > 1){\
5534
  ctx.lineWidth = 0.5;\
5535
  ctx.beginPath();\
5536
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
5537
  var minor_step_y = step_y / yminor;\
5538
  var ny;\
5539
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
5540
   num = 1;\
5541
   for(var p = 1 ;p < yminor;p++){\
5542
     ny = y + num*minor_step_y;\
5543
     ctx.moveTo(zero_x,ny);\
5544
     ctx.lineTo(xsize,ny);\
5545
     num++;\
5546
    };\
5547
  };\
5548
  ctx.stroke();\
5549
  ctx.closePath();\
5550
  ctx.lineWidth = 2;\
5551
  ctx.beginPath();\
5552
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
5553
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
5554
   ctx.moveTo(zero_x,y);\
5555
   ctx.lineTo(zero_x+12,y);\
5556
  };\
5557
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
5558
   ctx.moveTo(zero_x,y);\
5559
   ctx.lineTo(zero_x+6,y);\
5560
  };\
5561
  ctx.stroke();\
5562
  ctx.closePath();\
5563
 };\
5564
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
7654 schaersvoo 5565
 if( typeof legend%d  !== 'undefined' ){\
5566
  ctx.globalAlpha = 1.0;\
5567
  var y_offset = 2*font_size;\
5568
  var txt;var txt_size;\
5569
  var x_offset = xsize - 2*font_size;\
5570
  var l_length = legend%d.length;var barcolor = new Array();\
5571
  if( typeof legendcolors%d !== 'undefined' ){\
5572
   for(var p = 0 ; p < l_length ; p++){\
5573
    barcolor[p] = legendcolors%d[p];\
5574
   };\
5575
  }else{\
5576
   if( barcolor.length == 0 ){\
5577
    for(var p = 0 ; p < l_length ; p++){\
5578
     barcolor[p] = stroke_color;\
5579
    };\
5580
   };\
5581
  };\
5582
  for(var p = 0; p < l_length; p++){\
5583
   ctx.fillStyle = barcolor[p];\
5584
   txt = legend%d[p];\
5585
   txt_size = ctx.measureText(txt).width;\
5586
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
5587
   y_offset = parseInt(y_offset + 1.5*font_size);\
5588
  };\
5589
 };\
7660 schaersvoo 5590
 if( typeof xaxislabel !== 'undefined' ){\
7658 schaersvoo 5591
   ctx.fillStyle = \'#000000\';\
5592
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
5593
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
5594
 };\
7660 schaersvoo 5595
 if( typeof yaxislabel !== 'undefined'){\
7658 schaersvoo 5596
   ctx.save();\
5597
   ctx.fillStyle = \'#000000\';\
5598
   var txt_size = ctx.measureText(yaxislabel).width;\
5599
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
5600
   ctx.rotate(-0.5*Math.PI);\
5601
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 5602
   ctx.restore();\
7658 schaersvoo 5603
 };\
7654 schaersvoo 5604
};\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);
5605
    break;
7614 schaersvoo 5606
 
5607
    case DRAW_GRID:/* not used for userdraw */
5608
fprintf(js_include_file,"\n<!-- draw grid -->\n\
8105 schaersvoo 5609
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 5610
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);};\
5611
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 5612
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
5613
ctx.save();\
8071 schaersvoo 5614
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 5615
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
5616
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
5617
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
5618
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
5619
ctx.font = font_family;\
7988 schaersvoo 5620
var barcolor = new Array();\
7614 schaersvoo 5621
var xstep = xsize*xmajor/(xmax - xmin);\
5622
var ystep = ysize*ymajor/(ymax - ymin);\
5623
var x2step = xstep / xminor;\
5624
var y2step = ystep / yminor;\
7996 schaersvoo 5625
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
5626
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
5627
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
7614 schaersvoo 5628
ctx.beginPath();\
5629
ctx.lineWidth = line_width;\
5630
ctx.strokeStyle = stroke_color;\
5631
for(var p = zero_x ; p < xsize; p = p + xstep){\
5632
 ctx.moveTo(p,0);\
5633
 ctx.lineTo(p,ysize);\
5634
};\
5635
for(var p = zero_x ; p > 0; p = p - xstep){\
5636
 ctx.moveTo(p,0);\
5637
 ctx.lineTo(p,ysize);\
5638
};\
5639
for(var p = zero_y ; p < ysize; p = p + ystep){\
5640
 ctx.moveTo(0,p);\
5641
 ctx.lineTo(xsize,p);\
5642
};\
5643
for(var p = zero_y ; p > 0; p = p - ystep){\
5644
 ctx.moveTo(0,p);\
5645
 ctx.lineTo(xsize,p);\
5646
};\
5647
if( typeof xaxislabel !== 'undefined' ){\
5648
 ctx.save();\
5649
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
5650
 var corr =  ctx.measureText(xaxislabel).width;\
5651
 ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
5652
 ctx.restore();\
5653
};\
5654
if( typeof yaxislabel !== 'undefined' ){\
5655
 ctx.save();\
5656
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7988 schaersvoo 5657
 var corr =  ctx.measureText(yaxislabel).width;\
7614 schaersvoo 5658
 ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
5659
 ctx.rotate(-0.5*Math.PI);\
5660
 ctx.fillText(yaxislabel,0,0);\
5661
 ctx.restore();\
5662
};\
5663
ctx.stroke();\
5664
ctx.closePath();\
5665
if( use_axis == 1 ){\
7988 schaersvoo 5666
 ctx.save();\
7614 schaersvoo 5667
 ctx.beginPath();\
5668
 ctx.strokeStyle = stroke_color;\
5669
 ctx.lineWidth = 0.6*line_width;\
5670
 for(var p = zero_x ; p < xsize; p = p + x2step){\
5671
  ctx.moveTo(p,0);\
5672
  ctx.lineTo(p,ysize);\
5673
 };\
5674
 for(var p = zero_x ; p > 0; p = p - x2step){\
5675
  ctx.moveTo(p,0);\
5676
  ctx.lineTo(p,ysize);\
5677
 };\
5678
 for(var p = zero_y ; p < ysize; p = p + y2step){\
5679
  ctx.moveTo(0,p);\
5680
  ctx.lineTo(xsize,p);\
5681
 };\
5682
 for(var p = zero_y ; p > 0; p = p - y2step){\
5683
  ctx.moveTo(0,p);\
5684
  ctx.lineTo(xsize,p);\
5685
 };\
5686
 ctx.stroke();\
5687
 ctx.closePath();\
5688
 ctx.beginPath();\
5689
 ctx.lineWidth = 2*line_width;\
5690
 ctx.strokeStyle = axis_color;\
5691
 ctx.moveTo(0,zero_y);\
5692
 ctx.lineTo(xsize,zero_y);\
5693
 ctx.moveTo(zero_x,0);\
5694
 ctx.lineTo(zero_x,ysize);\
5695
 ctx.stroke();\
5696
 ctx.closePath();\
5697
 ctx.lineWidth = line_width+0.5;\
5698
 ctx.beginPath();\
5699
 for(var p = zero_x ; p < xsize; p = p + xstep){\
5700
  ctx.moveTo(p,zero_y-tics_length);\
5701
  ctx.lineTo(p,zero_y+tics_length);\
5702
 };\
5703
 for(var p = zero_x ; p > 0; p = p - xstep){\
5704
  ctx.moveTo(p,zero_y-tics_length);\
5705
  ctx.lineTo(p,zero_y+tics_length);\
5706
 };\
5707
 for(var p = zero_y ; p < ysize; p = p + ystep){\
5708
  ctx.moveTo(zero_x-tics_length,p);\
5709
  ctx.lineTo(zero_x+tics_length,p);\
5710
 };\
5711
 for(var p = zero_y ; p > 0; p = p - ystep){\
5712
  ctx.moveTo(zero_x-tics_length,p);\
5713
  ctx.lineTo(zero_x+tics_length,p);\
5714
 };\
5715
 for(var p = zero_x ; p < xsize; p = p + x2step){\
5716
  ctx.moveTo(p,zero_y-0.5*tics_length);\
5717
  ctx.lineTo(p,zero_y+0.5*tics_length);\
5718
 };\
5719
 for(var p = zero_x ; p > 0; p = p - x2step){\
5720
  ctx.moveTo(p,zero_y-0.5*tics_length);\
5721
  ctx.lineTo(p,zero_y+0.5*tics_length);\
5722
 };\
5723
 for(var p = zero_y ; p < ysize; p = p + y2step){\
5724
  ctx.moveTo(zero_x-0.5*tics_length,p);\
5725
  ctx.lineTo(zero_x+0.5*tics_length,p);\
5726
 };\
5727
 for(var p = zero_y ; p > 0; p = p - y2step){\
5728
  ctx.moveTo(zero_x-0.5*tics_length,p);\
5729
  ctx.lineTo(zero_x+0.5*tics_length,p);\
5730
 };\
5731
 ctx.stroke();\
5732
 ctx.closePath();\
7988 schaersvoo 5733
 ctx.restore();\
5734
};\
5735
if( use_axis_numbering == 1 ){\
5736
 ctx.save();\
5737
 ctx.fillColor = axis_color;\
8110 schaersvoo 5738
 ctx.strokeStyle = axis_color;\
5739
 ctx.lineWidth = 2*line_width;\
7988 schaersvoo 5740
 ctx.font = font_family;\
5741
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
5742
 if( x_strings != null ){\
5743
  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 5744
  ctx.beginPath();\
7988 schaersvoo 5745
  for(var p = 0 ; p < len ; p = p+2){\
5746
   var x_nums = x2px(eval(x_strings[p]));\
5747
   var x_text = x_strings[p+1];\
5748
   corr = ctx.measureText(x_text).width;\
5749
   skip = 1.2*corr/xstep;\
5750
   if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
5751
   if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
5752
   ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
8110 schaersvoo 5753
   ctx.moveTo(x_nums,zero_y - tics_length);\
5754
   ctx.lineTo(x_nums,zero_y + tics_length);\
7988 schaersvoo 5755
  };\
8110 schaersvoo 5756
  ctx.closePath();\
7988 schaersvoo 5757
 }\
5758
 else\
5759
 {\
5760
  skip = 1;cnt = px2x(zero_x);\
5761
  prec = Math.log(precision)/(Math.log(10));\
5762
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
5763
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
5764
   if(skip == 0 ){\
7990 schaersvoo 5765
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5766
    corr = ctx.measureText(disp_cnt).width;\
5767
    skip = parseInt(1.2*corr/xstep);\
5768
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 5769
   }\
7988 schaersvoo 5770
   else\
5771
   {\
5772
    skip--;\
7614 schaersvoo 5773
   };\
7988 schaersvoo 5774
   cnt = cnt + xmajor;\
7614 schaersvoo 5775
  };\
7988 schaersvoo 5776
  cnt = px2x(zero_x);skip = 1;\
5777
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
5778
   if(skip == 0 ){\
7990 schaersvoo 5779
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5780
    corr = ctx.measureText(disp_cnt).width;\
5781
    skip = parseInt(1.2*corr/xstep);\
5782
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
5783
   }\
5784
   else\
5785
   {\
5786
    skip--;\
7614 schaersvoo 5787
   };\
7988 schaersvoo 5788
   cnt = cnt - xmajor;\
7614 schaersvoo 5789
  };\
5790
 };\
7988 schaersvoo 5791
 if( y_strings != null ){\
5792
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 5793
  ctx.beginPath();\
7988 schaersvoo 5794
  for(var p = 0 ; p < len ; p = p+2){\
5795
   var y_nums = y2px(eval(y_strings[p]));\
5796
   var y_text = y_strings[p+1];\
5797
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
5798
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
8110 schaersvoo 5799
   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
5800
   ctx.moveTo(zero_x - tics_length,y_nums);\
5801
   ctx.lineTo(zero_x + tics_length,y_nums);\
7614 schaersvoo 5802
  };\
8110 schaersvoo 5803
  ctx.closePath();\
7988 schaersvoo 5804
 }\
5805
 else\
5806
 {\
7991 schaersvoo 5807
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 5808
  cnt = px2y(zero_y);skip = 1;\
5809
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
5810
   if(skip == 0 ){\
5811
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 5812
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5813
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
5814
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
5815
   }\
5816
   else\
5817
   {\
5818
    skip--;\
5819
   };\
5820
   cnt = cnt - ymajor;\
7614 schaersvoo 5821
  };\
7988 schaersvoo 5822
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 5823
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 5824
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
5825
   if(skip == 0 ){\
5826
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 5827
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 5828
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
5829
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
5830
   }\
5831
   else\
5832
   {\
5833
    skip--;\
5834
   };\
5835
   cnt = cnt + ymajor;\
7614 schaersvoo 5836
  };\
5837
 };\
7988 schaersvoo 5838
 ctx.stroke();\
7614 schaersvoo 5839
 ctx.restore();\
5840
};\
7956 schaersvoo 5841
if( typeof legend0  !== 'undefined' ){\
7988 schaersvoo 5842
 ctx.save();\
7614 schaersvoo 5843
 ctx.globalAlpha = 1.0;\
5844
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
5845
 var y_offset = 2*font_size;\
5846
 var txt;var txt_size;\
5847
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 5848
 var l_length = legend0.length;\
5849
 if( typeof legendcolors0 !== 'undefined' ){\
7614 schaersvoo 5850
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 5851
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 5852
  };\
7988 schaersvoo 5853
 }\
5854
 else\
5855
 {\
7614 schaersvoo 5856
  if( barcolor.length == 0 ){\
5857
   for(var p = 0 ; p < l_length ; p++){\
5858
    barcolor[p] = stroke_color;\
5859
   };\
5860
  };\
5861
 };\
5862
 for(var p = 0; p < l_length; p++){\
5863
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 5864
  txt = legend0[p];\
7614 schaersvoo 5865
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 5866
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 5867
  y_offset = parseInt(y_offset + 1.5*font_size);\
5868
 };\
7988 schaersvoo 5869
 ctx.restore();\
7614 schaersvoo 5870
};\
7991 schaersvoo 5871
if( typeof barchart_0  !== 'undefined' ){\
5872
 ctx.save();\
5873
 var num_barcharts = 0;\
5874
 var bar_name = eval('barchart_0');\
5875
 while( typeof bar_name !== 'undefined' ){\
5876
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
5877
 };\
5878
 var bar_width = parseInt(0.8*xstep/(num_barcharts));\
5879
 for(var i=0 ; i< num_barcharts ; i++){\
5880
  bar_name = eval('barchart_'+i);\
5881
  var bar_x = new Array();\
5882
  var bar_y = new Array();\
5883
  var lb = bar_name.length;\
5884
  var idx = 0;\
5885
  var dx = parseInt(0.5*i*bar_width);\
5886
  for( var p = 0 ; p < lb ; p = p + 3 ){\
5887
   bar_x[idx] = x2px(bar_name[p]);\
5888
   bar_y[idx] = y2px(bar_name[p+1]);\
5889
   barcolor[idx] = bar_name[p+2];\
5890
   idx++;\
5891
  };\
5892
  ctx.globalAlpha = fill_opacity;\
5893
  ctx.beginPath();\
5894
  for( var p = 0; p < idx ; p++ ){\
5895
   ctx.strokeStyle = barcolor[p];\
5896
   ctx.fillStyle = barcolor[p];\
5897
   ctx.rect(bar_x[p]-0.4*xstep+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
5898
  };\
5899
  ctx.fill();\
5900
  ctx.stroke();\
5901
  ctx.closePath();\
5902
 };\
5903
 ctx.restore();\
5904
};\
7996 schaersvoo 5905
if( typeof linegraph_0 !== 'undefined' ){\
5906
 ctx.save();\
5907
 ctx.globalAlpha = 1.0;\
5908
 var i = 0;\
5909
 var line_name = eval('linegraph_'+i);\
5910
 while ( typeof line_name !== 'undefined' ){\
5911
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
5912
  ctx.lineWidth = parseInt(line_name[1]);\
5913
  if(line_name[2] == \"1\"){\
5914
   var d1 = parseInt(line_name[3]);\
5915
   var d2 = parseInt(line_name[4]);\
5916
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
5917
  }\
5918
  else\
5919
  {\
5920
  if(ctx.setLineDash){ctx.setLineDash = null;}\
5921
  if(ctx.mozDash){ctx.mozDash = null;}\
5922
  };\
5923
  var data_x = new Array();\
5924
  var data_y = new Array();\
5925
  var lb = line_name.length;\
5926
  var idx = 0;\
5927
  for( var p = 5 ; p < lb ; p = p + 2 ){\
5928
   data_x[idx] = x2px(line_name[p]);\
5929
   data_y[idx] = y2px(line_name[p+1]);\
5930
   idx++;\
5931
  };\
5932
  for( var p = 0; p < idx ; p++){\
5933
   ctx.beginPath();\
5934
   ctx.moveTo(data_x[p],data_y[p]);\
5935
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
5936
   ctx.stroke();\
5937
   ctx.closePath();\
5938
  };\
5939
  i++;\
5940
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
5941
 };\
5942
 ctx.restore();\
5943
};\
7614 schaersvoo 5944
return;\
7989 schaersvoo 5945
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5946
    break;
8224 bpr 5947
 
7614 schaersvoo 5948
    case DRAW_PIECHART:
7987 schaersvoo 5949
fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
7956 schaersvoo 5950
function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
7614 schaersvoo 5951
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
5952
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
5953
 }\
5954
 else\
5955
 {\
5956
  obj = create_canvas%d(canvas_type,xsize,ysize);\
5957
 };\
5958
 var ld = data_color_list.length;\
5959
 var sum = 0;\
5960
 var idx = 0;\
7956 schaersvoo 5961
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 5962
 var colors = new Array();\
5963
 var data = new Array();\
5964
 for(var p = 0;p < ld; p = p + 2){\
5965
  data[idx] = parseFloat(data_color_list[p]);\
5966
  sum = sum + data[idx];\
5967
  colors[idx] = data_color_list[p+1];\
5968
  idx++;\
5969
 };\
5970
 var ctx = obj.getContext(\"2d\");\
5971
 ctx.save();\
5972
 var angle;\
5973
 var angle_end = 0;\
5974
 var offset = Math.PI / 2;\
5975
 ctx.globalAlpha = fill_opacity;\
5976
 for(var p=0; p < idx; p++){\
5977
  ctx.beginPath();\
5978
  ctx.fillStyle = colors[p];\
5979
  ctx.moveTo(x_center,y_center);\
5980
  angle = Math.PI * (2 * data[p] / sum);\
5981
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
5982
  ctx.lineTo(x_center, y_center);\
5983
  ctx.fill();\
5984
  ctx.closePath();\
5985
  angle_end  = angle_end + angle;\
5986
 };\
7956 schaersvoo 5987
 if(typeof legend0 !== 'undefined'){\
5988
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 5989
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 5990
  ctx.font = font_family;\
7614 schaersvoo 5991
  var y_offset = font_size; \
5992
  var x_offset = 0;\
5993
  var txt;var txt_size;\
5994
  for(var p = 0; p < idx; p++){\
5995
   ctx.fillStyle = colors[p];\
7956 schaersvoo 5996
   txt = legenda[p];\
7614 schaersvoo 5997
   txt_size = ctx.measureText(txt).width;\
5998
   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
7956 schaersvoo 5999
   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
7614 schaersvoo 6000
   y_offset = parseInt(y_offset + 1.5*font_size);\
6001
  };\
6002
 };\
6003
 ctx.restore();\
7956 schaersvoo 6004
};",canvas_root_id,canvas_root_id,canvas_root_id);
8224 bpr 6005
 
7614 schaersvoo 6006
    break;
6007
    case DRAW_ARCS:
6008
fprintf(js_include_file,"\n<!-- draw arcs -->\n\
8105 schaersvoo 6009
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 6010
 ctx.save();\
6011
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 6012
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 6013
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
6014
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 6015
 start = 360 - start;\
6016
 end = 360 - end;\
7614 schaersvoo 6017
 ctx.lineWidth = line_width;\
6018
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8071 schaersvoo 6019
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
6020
 ctx.beginPath();\
6021
 ctx.moveTo(xc,yc);\
6022
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
6023
 ctx.lineTo(xc,yc);\
6024
 ctx.closePath();\
7614 schaersvoo 6025
 if( use_filled == 1 ){\
6026
  ctx.fill();\
8071 schaersvoo 6027
 };\
6028
 ctx.stroke();\
7614 schaersvoo 6029
 ctx.restore();\
8071 schaersvoo 6030
};");
8224 bpr 6031
 
7614 schaersvoo 6032
    break;
7983 schaersvoo 6033
    case DRAW_CENTERSTRING:
6034
fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
8105 schaersvoo 6035
var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
7983 schaersvoo 6036
 var obj;\
6037
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6038
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6039
 }\
6040
 else\
6041
 {\
6042
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6043
 };\
6044
 var ctx = obj.getContext(\"2d\");\
6045
 ctx.save();\
6046
 ctx.font = font_family;\
6047
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6048
 var stringwidth = ctx.measureText(text).width;\
6049
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
6050
 ctx.fillText(text,x,y2px(y));\
6051
return;\
6052
};",canvas_root_id,canvas_root_id,canvas_root_id);
6053
    break;
7614 schaersvoo 6054
    case DRAW_TEXTS:
6055
fprintf(js_include_file,"\n<!-- draw text -->\n\
8105 schaersvoo 6056
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 6057
  var obj;\
6058
  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6059
   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6060
  }\
6061
  else\
6062
  {\
6063
   obj = create_canvas%d(canvas_type,xsize,ysize);\
6064
  };\
6065
  var ctx = obj.getContext(\"2d\");\
6066
  if(angle2 == 0 && angle != 0){\
6067
   ctx.save();\
8071 schaersvoo 6068
   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6069
   if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6070
  };\
6071
  if( font_family.indexOf('px') != null ){\
6072
   ctx.font = font_family;\
6073
  }\
6074
  else\
6075
  {\
7956 schaersvoo 6076
   ctx.font = font_family;\
7614 schaersvoo 6077
  };\
6078
  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6079
  if(angle2 != 0){\
6080
   ctx.save();\
6081
   ctx.translate(x,y);\
6082
   ctx.rotate((360-angle2)*(Math.PI / 180));\
6083
   ctx.fillText(text,0,0);\
6084
   ctx.restore();\
6085
  }else{ctx.fillText(text,x,y);};\
6086
 ctx.restore();\
6087
 return;\
7653 schaersvoo 6088
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6089
    break;
6090
    case DRAW_CURVE:
6091
fprintf(js_include_file,"\n<!-- draw curve -->\n\
8105 schaersvoo 6092
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 6093
 var obj;\
6094
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6095
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6096
 }\
6097
 else\
6098
 {\
6099
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6100
 };\
6101
 var ctx = obj.getContext(\"2d\");\
6102
 ctx.save();\
8071 schaersvoo 6103
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6104
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6105
 ctx.beginPath();ctx.lineWidth = line_width;\
6106
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6107
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6108
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
6109
 for(var p = 1 ; p < x_points.length ; p++){\
6110
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
6111
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
6112
  }\
6113
  else\
6114
  {\
6115
   ctx.stroke();\
6116
   ctx.beginPath();\
6117
   p++;\
6118
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
6119
  };\
6120
 };\
6121
 ctx.stroke();\
6122
 ctx.restore();\
7653 schaersvoo 6123
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6124
    break;
8224 bpr 6125
 
7614 schaersvoo 6126
    case DRAW_INPUTS:
6127
fprintf(js_include_file,"\n<!-- draw input fields -->\n\
8105 schaersvoo 6128
var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value){\
7614 schaersvoo 6129
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
6130
var input = document.createElement(\"input\");\
6131
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
6132
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
6133
input.setAttribute(\"size\",size);\
6134
input.setAttribute(\"value\",value);\
7877 schaersvoo 6135
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
7653 schaersvoo 6136
canvas_div.appendChild(input);};");
7614 schaersvoo 6137
    break;
8224 bpr 6138
 
7614 schaersvoo 6139
    case DRAW_TEXTAREAS:
6140
fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
8105 schaersvoo 6141
var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
7614 schaersvoo 6142
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
6143
var textarea = document.createElement(\"textarea\");\
6144
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
6145
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
6146
textarea.setAttribute(\"cols\",cols);\
6147
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 6148
textarea.value = value;\
6149
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 6150
canvas_div.appendChild(textarea);};");
7614 schaersvoo 6151
    break;
8224 bpr 6152
 
7614 schaersvoo 6153
case DRAW_PIXELS:
6154
fprintf(js_include_file,"\n<!-- draw pixel -->\n\
8105 schaersvoo 6155
var draw_setpixel = function(x,y,color,opacity,pixelsize){\
7614 schaersvoo 6156
 var canvas = create_canvas%d(10,xsize,ysize);\
6157
 var d = 0.5*pixelsize;\
6158
 var ctx = canvas.getContext(\"2d\");\
6159
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
6160
 ctx.clearRect(0,0,xsize,ysize);\
6161
 for(var p=0; p<x.length;p++){\
6162
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
6163
 };\
6164
 ctx.fill();ctx.stroke();\
6165
};",canvas_root_id);
6166
break;
6167
 
6168
case DRAW_CLOCK:
6169
fprintf(js_include_file,"\n<!-- begin command clock -->\n\
6170
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
6171
var clock_ctx = clock_canvas.getContext(\"2d\");\
6172
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
8130 schaersvoo 6173
 clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
7614 schaersvoo 6174
 clock_ctx.save();\
7997 schaersvoo 6175
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 6176
 this.type = type || 0;\
6177
 this.interaction = interaction || 0;\
7862 schaersvoo 6178
 this.H = H;\
6179
 this.M = M;\
6180
 this.S = S;\
8000 schaersvoo 6181
 if(this.S == -1){this.S = 59;this.M = this.M - 1;};\
6182
 if(this.M == -1){this.M = 59;this.H = this.H - 1;};\
6183
 if(this.H == -1){this.H = 11;};\
7614 schaersvoo 6184
 this.xc = xc || xsize/2;\
6185
 this.yc = yc || ysize/2;\
6186
 this.radius = radius || xsize/4;\
6187
 var font_size = parseInt(0.2*this.radius);\
6188
 this.H_color = h_color || \"blue\";\
6189
 this.M_color = m_color || \"blue\";\
6190
 this.S_color = s_color || \"blue\";\
6191
 this.fg_color = fg_color || \"red\";\
6192
 this.bg_color = bg_color || \"white\";\
6193
 clock_ctx.translate(this.xc,this.yc);\
6194
 clock_ctx.beginPath();\
6195
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
6196
 clock_ctx.fillStyle = this.bg_color;\
6197
 clock_ctx.fill();\
6198
 clock_ctx.closePath();\
6199
 clock_ctx.beginPath();\
6200
 clock_ctx.font = font_size+\"px Arial\";\
6201
 clock_ctx.fillStyle = this.fg_color;\
6202
 clock_ctx.textAlign = \"center\";\
6203
 clock_ctx.textBaseline = 'middle';\
6204
 var angle;var x1,y1,x2,y2;\
6205
 var angle_cos;var angle_sin;\
7997 schaersvoo 6206
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 6207
 switch(type){\
6208
 case 0:clock_ctx.beginPath();\
6209
 for(var p = 1; p <= 12 ; p++){\
6210
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
6211
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
6212
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6213
  clock_ctx.moveTo(x1,y1);\
6214
  clock_ctx.lineTo(x2,y2);\
6215
 };\
6216
 for(var p = 1; p <= 60 ; p++){\
6217
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
6218
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
6219
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6220
  clock_ctx.moveTo(x1,y1);\
6221
  clock_ctx.lineTo(x2,y2);\
6222
 };\
6223
 clock_ctx.closePath();\
6224
 clock_ctx.stroke();\
6225
 break;\
6226
 case 1:\
6227
 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 6228
 case 2:\
6229
 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 6230
 clock_ctx.beginPath();\
6231
 for(var p = 1; p <= 12 ; p++){\
6232
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
6233
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
6234
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6235
  clock_ctx.moveTo(x1,y1);\
6236
  clock_ctx.lineTo(x2,y2);\
6237
 };\
6238
 for(var p = 1; p <= 60 ; p++){\
6239
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
6240
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
6241
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
6242
  clock_ctx.moveTo(x1,y1);\
6243
  clock_ctx.lineTo(x2,y2);\
6244
 };\
6245
 clock_ctx.closePath();\
6246
 clock_ctx.stroke();\
6247
 break;\
6248
 };\
6249
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
6250
 clock_ctx.rotate(angle);\
6251
 clock_ctx.beginPath();\
6252
 clock_ctx.moveTo(-3, -2);\
6253
 clock_ctx.lineTo(-3, 2);\
6254
 clock_ctx.lineTo(this.radius * 0.7, 1);\
6255
 clock_ctx.lineTo(this.radius  * 0.7, -1);\
6256
 clock_ctx.fillStyle = this.H_color;\
6257
 clock_ctx.fill();\
6258
 clock_ctx.rotate(-angle);\
6259
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
6260
 clock_ctx.rotate(angle);\
6261
 clock_ctx.beginPath();\
6262
 clock_ctx.moveTo(-3, -2);\
6263
 clock_ctx.lineTo(-3, 2);\
6264
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
6265
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
6266
 clock_ctx.fillStyle = this.M_color;\
6267
 clock_ctx.fill();\
6268
 clock_ctx.rotate(-angle);\
6269
 angle = (this.S - 15) * 2 * Math.PI / 60;\
6270
 clock_ctx.rotate(angle);\
6271
 clock_ctx.beginPath();\
6272
 clock_ctx.moveTo(0,0);\
6273
 clock_ctx.lineTo(this.radius  * 0.95, 0);\
6274
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
6275
 clock_ctx.strokeStyle = this.S_color;\
6276
 clock_ctx.stroke();\
6277
 clock_ctx.restore();\
7653 schaersvoo 6278
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 6279
break;
6280
 
6281
case DRAW_LATTICE:
6282
fprintf(js_include_file,"\n<!-- draw lattice -->\n\
8105 schaersvoo 6283
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 6284
 var obj;\
6285
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6286
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6287
 }\
6288
 else\
6289
 {\
6290
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6291
 };\
6292
 var ctx = obj.getContext(\"2d\");\
6293
 ctx.save();\
8071 schaersvoo 6294
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6295
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6296
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6297
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6298
 var radius = line_width;\
6299
 var x = 0;\
6300
 var y = 0;\
6301
 var x_step_px = xsize/(xmax-xmin);\
6302
 var y_step_px = ysize/(ymax-ymin);\
6303
 var xv1 = dx1*x_step_px;\
6304
 var yv1 = dy1*y_step_px;\
6305
 var xv2 = dx2*x_step_px;\
6306
 var yv2 = dy2*y_step_px;\
6307
 for(var p = 0; p < n1 ;p++){\
6308
  x = p*xv1 + x0;\
6309
  y = p*yv1 + y0;\
6310
  for(var c = 0; c < n2 ; c++){\
6311
   ctx.beginPath();\
6312
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
6313
   ctx.fill();\
6314
   ctx.stroke();\
6315
   ctx.closePath();\
6316
  };\
6317
 };\
6318
 ctx.restore();\
6319
 return;\
7653 schaersvoo 6320
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6321
    break;
7735 schaersvoo 6322
case DRAW_XYLOGSCALE:
6323
fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
8105 schaersvoo 6324
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 6325
 var obj;\
6326
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6327
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6328
 }\
6329
 else\
6330
 {\
6331
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6332
 };\
6333
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 6334
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6335
 ctx.save();\
7739 schaersvoo 6336
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 6337
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
6338
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
6339
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
6340
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
7739 schaersvoo 6341
 if(use_axis_numbering == 1){\
7956 schaersvoo 6342
  ctx.font = font_family;\
6343
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
6344
  ymarge = parseInt(1.5*font_size);\
6345
  ctx.save();\
6346
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6347
  ctx.rect(0,0,xmarge,ysize);\
6348
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6349
  ctx.fill();\
6350
  ctx.restore();\
6351
 }else{xmarge = 0;ymarge = 0;};\
7735 schaersvoo 6352
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6353
  ctx.save();\
6354
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6355
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6356
  corr =  ctx.measureText(xaxislabel).width;\
6357
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6358
  ctx.restore();\
6359
 };\
7735 schaersvoo 6360
 if( typeof yaxislabel !== '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(yaxislabel).width;\
6365
  ctx.translate(xmarge+font_size,corr+font_size);\
6366
  ctx.rotate(-0.5*Math.PI);\
6367
  ctx.fillText(yaxislabel,0,0);\
6368
  ctx.restore();\
6369
 };\
6370
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6371
 ctx.lineWidth = line_width;\
6372
 for(var p = x_min; p <= x_max ; p++){\
6373
  num = Math.pow(xlogbase,p);\
6374
  for(var i = 1 ; i < xlogbase ; i++){\
6375
   x_e = x2px(i*num);\
7735 schaersvoo 6376
   if( i == 1 ){\
7956 schaersvoo 6377
    ctx.lineWidth = line_width;\
6378
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7738 schaersvoo 6379
    if( use_axis_numbering == 1 && p > x_min){\
7956 schaersvoo 6380
      xtxt = xlogbase+'^'+p.toFixed(0);\
6381
      corr = 0.5*(ctx.measureText(xtxt).width);\
6382
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
6383
    };\
7735 schaersvoo 6384
   }else{\
7956 schaersvoo 6385
    ctx.lineWidth = 0.2*line_width;\
6386
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6387
   };\
7738 schaersvoo 6388
   if( x_e >= xmarge ){\
7956 schaersvoo 6389
    ctx.beginPath();\
6390
    ctx.moveTo(x_e,0);\
6391
    ctx.lineTo(x_e,ysize - ymarge);\
6392
    ctx.stroke();\
6393
    ctx.closePath();\
7738 schaersvoo 6394
   };\
7956 schaersvoo 6395
  };\
6396
 };\
6397
 for(var p = y_min; p <= y_max ; p++){\
6398
  num = Math.pow(ylogbase,p);\
6399
  for(var i = 1 ; i < ylogbase ; i++){\
6400
   y_e = y2px(i*num);\
6401
   if( i == 1 ){\
6402
    ctx.lineWidth = line_width;\
7735 schaersvoo 6403
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6404
    if( use_axis_numbering == 1 && p > y_min){\
6405
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
6406
    };\
6407
   }else{\
6408
    ctx.lineWidth = 0.2*line_width;\
6409
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6410
   };\
6411
   ctx.beginPath();\
6412
   ctx.moveTo(xmarge,y_e);\
6413
   ctx.lineTo(xsize,y_e);\
6414
   ctx.stroke();\
6415
   ctx.closePath();\
6416
  };\
6417
 };\
7735 schaersvoo 6418
 ctx.restore();\
6419
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
6420
    break;
7614 schaersvoo 6421
 
7735 schaersvoo 6422
case DRAW_XLOGSCALE:
6423
fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
8105 schaersvoo 6424
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 6425
 var obj;\
6426
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6427
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6428
 }\
6429
 else\
6430
 {\
6431
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6432
 };\
6433
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 6434
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6435
 ctx.save();\
6436
 ctx.lineWidth = line_width;\
7739 schaersvoo 6437
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 6438
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
6439
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
6440
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 6441
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
6442
 if(use_axis_numbering == 1){\
7956 schaersvoo 6443
  ctx.font = font_family;\
6444
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
6445
  ymarge = parseInt(1.5*font_size);\
6446
  ctx.save();\
6447
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6448
  ctx.rect(0,0,xmarge,ysize);\
6449
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6450
  ctx.fill();\
6451
  ctx.restore();\
6452
 }else{xmarge = 0;ymarge = 0;};\
7739 schaersvoo 6453
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6454
  ctx.save();\
6455
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6456
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6457
  corr =  ctx.measureText(xaxislabel).width;\
6458
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6459
  ctx.restore();\
6460
 };\
7739 schaersvoo 6461
 if( typeof yaxislabel !== '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(yaxislabel).width;\
6466
  ctx.translate(xmarge+font_size,corr+font_size);\
6467
  ctx.rotate(-0.5*Math.PI);\
6468
  ctx.fillText(yaxislabel,0,0);\
6469
  ctx.restore();\
6470
 };\
6471
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6472
 ctx.lineWidth = line_width;\
6473
 for(var p = x_min; p <= x_max ; p++){\
6474
  num = Math.pow(xlogbase,p);\
6475
  for(var i = 1 ; i < xlogbase ; i++){\
6476
   x_e = x2px(i*num);\
7735 schaersvoo 6477
   if( i == 1 ){\
7956 schaersvoo 6478
     ctx.lineWidth = line_width;\
7739 schaersvoo 6479
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
6480
    if( use_axis_numbering == 1 && p > x_min ){\
7735 schaersvoo 6481
      xtxt = xlogbase+'^'+p.toFixed(0);\
6482
      corr = 0.5*(ctx.measureText(xtxt).width);\
6483
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
6484
    };\
6485
   }else{\
7956 schaersvoo 6486
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 6487
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6488
   };\
7739 schaersvoo 6489
   if( x_e >= xmarge ){\
7956 schaersvoo 6490
    ctx.beginPath();\
6491
    ctx.moveTo(x_e,0);\
6492
    ctx.lineTo(x_e,ysize - ymarge);\
6493
    ctx.stroke();\
6494
    ctx.closePath();\
7739 schaersvoo 6495
   };\
6496
  };\
7956 schaersvoo 6497
 };\
7735 schaersvoo 6498
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
6499
 var minor_step = stepy / yminor;\
7749 schaersvoo 6500
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 6501
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6502
  ctx.lineWidth = line_width;\
6503
  ctx.beginPath();\
6504
  ctx.moveTo(xmarge,y);\
6505
  ctx.lineTo(xsize,y);\
6506
  ctx.stroke();\
6507
  ctx.closePath();\
7735 schaersvoo 6508
  if( use_axis_numbering == 1){\
6509
   ytxt = (px2y(y)).toFixed(prec);\
6510
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
6511
  };\
6512
  for(var dy = 1 ; dy < yminor ; dy++){\
6513
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 6514
   ctx.lineWidth = 0.2*line_width;\
6515
   ctx.beginPath();\
7739 schaersvoo 6516
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 6517
   ctx.lineTo(xsize,y+dy*minor_step);\
6518
   ctx.stroke();\
6519
   ctx.closePath();\
7735 schaersvoo 6520
  };\
6521
 };\
7956 schaersvoo 6522
 ctx.restore();\
6523
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 6524
    break;
7729 schaersvoo 6525
case DRAW_YLOGSCALE:
6526
fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
8105 schaersvoo 6527
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 6528
 var obj;\
6529
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6530
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6531
 }\
6532
 else\
6533
 {\
6534
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6535
 };\
6536
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 6537
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 6538
 ctx.save();\
6539
 ctx.lineWidth = line_width;\
7735 schaersvoo 6540
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
6541
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
8109 schaersvoo 6542
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
7739 schaersvoo 6543
 if(use_axis_numbering == 1){\
7956 schaersvoo 6544
  ctx.font = font_family;\
6545
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
6546
  ymarge = 2*font_size;\
6547
  ctx.save();\
6548
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
6549
  ctx.rect(0,0,xmarge,ysize);\
6550
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
6551
  ctx.fill();\
6552
  ctx.restore();\
6553
 }else{xmarge = 0;ymarge = 0;};\
7739 schaersvoo 6554
 if( typeof xaxislabel !== 'undefined' ){\
7956 schaersvoo 6555
  ctx.save();\
6556
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
6557
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6558
  corr =  ctx.measureText(xaxislabel).width;\
6559
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
6560
  ctx.restore();\
6561
 };\
7739 schaersvoo 6562
 if( typeof yaxislabel !== '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(yaxislabel).width;\
6567
  ctx.translate(xmarge+font_size,corr+font_size);\
6568
  ctx.rotate(-0.5*Math.PI);\
6569
  ctx.fillText(yaxislabel,0,0);\
6570
  ctx.restore();\
6571
 };\
6572
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
6573
 ctx.lineWidth = line_width;\
6574
 for(var p = y_min; p <= y_max ; p++){\
6575
  num = Math.pow(ylogbase,p);\
6576
  for(var i = 1 ; i < ylogbase ; i++){\
6577
   y_e = y2px(i*num);\
7729 schaersvoo 6578
   if( i == 1 ){\
7956 schaersvoo 6579
    ctx.lineWidth = line_width;\
7729 schaersvoo 6580
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7739 schaersvoo 6581
    if( use_axis_numbering == 1 && p > y_min){\
7735 schaersvoo 6582
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 6583
    };\
6584
   }else{\
7956 schaersvoo 6585
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 6586
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
6587
   };\
7956 schaersvoo 6588
   ctx.beginPath();\
6589
   ctx.moveTo(xmarge,y_e);\
6590
   ctx.lineTo(xsize,y_e);\
6591
   ctx.stroke();\
6592
   ctx.closePath();\
6593
  };\
6594
 };\
7729 schaersvoo 6595
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
6596
 var minor_step = stepx / xminor;\
6597
 var prec = Math.log(precision)/Math.log(10);\
6598
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 6599
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 6600
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 6601
  ctx.lineWidth = line_width;\
6602
  ctx.beginPath();\
6603
  ctx.moveTo(x,ysize-ymarge);\
6604
  ctx.lineTo(x,0);\
6605
  ctx.stroke();\
6606
  ctx.closePath();\
7729 schaersvoo 6607
  if( use_axis_numbering == 1){\
6608
   xtxt = (px2x(x)).toFixed(prec);\
6609
   corr = 0.5*(ctx.measureText(xtxt).width);\
6610
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
6611
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
6612
  };\
6613
  for(var dx = 1 ; dx < xminor ; dx++){\
6614
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 6615
   ctx.lineWidth = 0.2*line_width;\
6616
   ctx.beginPath();\
7739 schaersvoo 6617
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 6618
   ctx.lineTo(x+dx*minor_step,0);\
6619
   ctx.stroke();\
6620
   ctx.closePath();\
7735 schaersvoo 6621
  };\
6622
 };\
7956 schaersvoo 6623
 ctx.restore();\
6624
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 6625
    break;
7614 schaersvoo 6626
    default:break;
6627
   }
6628
  }
6629
 }
6630
  return;
6631
}
6632
 
6633
void check_string_length(int L){
6634
 if(L<1 || L > MAX_BUFFER-1){
6635
  canvas_error("problem with your arguments to command...");
6636
 }
6637
 return;
6638
}
6639
 
6640
 
6641
int get_token(FILE *infile){
6642
        int     c,i=0;
6643
        char    temp[MAX_INT], *input_type;
6644
        char    *line="line",
6645
        *audio="audio",
6646
        *blink="blink",
6647
        *arrowhead="arrowhead",
6648
        *crosshairsize="crosshairsize",
6649
        *crosshair="crosshair",
6650
        *crosshairs="crosshairs",
6651
        *audioobject="audioobject",
6652
        *style="style",
6653
        *mouse="mouse",
7991 schaersvoo 6654
        *mousex="mousex",
6655
        *mousey="mousey",
8071 schaersvoo 6656
        *mouse_display="display",
6657
        *mouse_degree="mouse_degree",
7614 schaersvoo 6658
        *userdraw="userdraw",
6659
        *highlight="highlight",
6660
        *http="http",
6661
        *rays="rays",
6662
        *dashtype="dashtype",
6663
        *dashed="dashed",
6664
        *filled="filled",
6665
        *lattice="lattice",
6666
        *parallel="parallel",
6667
        *segment="segment",
6668
        *dsegment="dsegment",
6669
        *seg="seg",
6670
        *bgimage="bgimage",
6671
        *bgcolor="bgcolor",
6672
        *strokecolor="strokecolor",
6673
        *backgroundimage="backgroundimage",
6674
        *text="text",
6675
        *textup="textup",
6676
        *mouseprecision="mouseprecision",
6677
        *precision="precision",
6678
        *plotsteps="plotsteps",
6679
        *plotstep="plotstep",
6680
        *tsteps="tsteps",
6681
        *curve="curve",
6682
        *dcurve="dcurve",
6683
        *plot="plot",
6684
        *dplot="dplot",
7788 schaersvoo 6685
        *levelcurve="levelcurve",
7614 schaersvoo 6686
        *fontsize="fontsize",
6687
        *fontcolor="fontcolor",
6688
        *axis="axis",
6689
        *axisnumbering="axisnumbering",
6690
        *axisnumbers="axisnumbers",
6691
        *arrow="arrow",
6692
        *darrow="darrow",
6693
        *arrow2="arrow2",
6694
        *darrow2="darrow2",
6695
        *zoom="zoom",
6696
        *grid="grid",
6697
        *hline="hline",
7786 schaersvoo 6698
        *dhline="dhline",
7614 schaersvoo 6699
        *drag="drag",
6700
        *horizontalline="horizontalline",
6701
        *vline="vline",
7786 schaersvoo 6702
        *dvline="dvline",
7614 schaersvoo 6703
        *verticalline="verticalline",
6704
        *triangle="triangle",
6705
        *ftriangle="ftriangle",
6706
        *mathml="mathml",
6707
        *html="html",
6708
        *input="input",
8146 schaersvoo 6709
        *clearbutton="clearbutton",
7614 schaersvoo 6710
        *inputstyle="inputstyle",
6711
        *textarea="textarea",
6712
        *trange="trange",
6713
        *ranget="ranget",
6714
        *xrange="xrange",
6715
        *yrange="yrange",
6716
        *rangex="rangex",
6717
        *rangey="rangey",
6718
        *polyline="polyline",
6719
        *lines="lines",
6720
        *poly="poly",
6721
        *polygon="polygon",
6722
        *fpolygon="fpolygon",
6723
        *fpoly="fpoly",
6724
        *filledpoly="filledpoly",
6725
        *filledpolygon="filledpolygon",
6726
        *rect="rect",
6727
        *frect="frect",
6728
        *rectangle="rectangle",
6729
        *frectangle="frectangle",
6730
        *square="square",
6731
        *fsquare="fsquare",
6732
        *dline="dline",
6733
        *arc="arc",
6734
        *filledarc="filledarc",
6735
        *size="size",
6736
        *string="string",
6737
        *stringup="stringup",
6738
        *copy="copy",
6739
        *copyresized="copyresized",
6740
        *opacity="opacity",
6741
        *transparent="transparent",
6742
        *fill="fill",
6743
        *point="point",
6744
        *points="points",
6745
        *linewidth="linewidth",
6746
        *circle="circle",
6747
        *fcircle="fcircle",
6748
        *disk="disk",
6749
        *comment="#",
6750
        *end="end",
6751
        *ellipse="ellipse",
6752
        *fellipse="fellipse",
6753
        *rotate="rotate",
7785 schaersvoo 6754
        *affine="affine",
6755
        *killaffine="killaffine",
7614 schaersvoo 6756
        *fontfamily="fontfamily",
6757
        *fillcolor="fillcolor",
6758
        *clicktile="clicktile",
6759
        *clicktile_colors="clicktile_colors",
6760
        *translation="translation",
6761
        *translate="translate",
6762
        *killtranslation="killtranslation",
6763
        *killtranslate="killtranslate",
6764
        *onclick="onclick",
6765
        *roundrect="roundrect",
6766
        *froundrect="froundrect",
6767
        *roundrectangle="roundrectangle",
6768
        *patternfill="patternfill",
6769
        *hatchfill="hatchfill",
6770
        *diafill="diafill",
7647 schaersvoo 6771
        *diamondfill="diamondfill",
7614 schaersvoo 6772
        *dotfill="dotfill",
6773
        *gridfill="gridfill",
6774
        *imagefill="imagefill",
7735 schaersvoo 6775
        *xlogbase="xlogbase",
6776
        *ylogbase="ylogbase",
7614 schaersvoo 6777
        *xlogscale="xlogscale",
6778
        *ylogscale="ylogscale",
6779
        *xylogscale="xylogscale",
6780
        *intooltip="intooltip",
6781
        *replyformat="replyformat",
6782
        *floodfill="floodfill",
6783
        *filltoborder="filltoborder",
6784
        *clickfill="clickfill",
6785
        *setpixel="setpixel",
6786
        *pixels="pixels",
6787
        *pixelsize="pixelsize",
6788
        *clickfillmarge="clickfillmarge",
6789
        *xaxis="xaxis",
6790
        *yaxis="yaxis",
6791
        *xaxistext="xaxistext",
6792
        *yaxistext="yaxistext",
6793
        *piechart="piechart",
6794
        *legend="legend",
6795
        *legendcolors="legendcolors",
6796
        *xlabel="xlabel",
6797
        *ylabel="ylabel",
6798
        *barchart="barchart",
6799
        *linegraph="linegraph",
6800
        *clock="clock",
6801
        *animate="animate",
6802
        *video="video",
6803
        *status="status",
7877 schaersvoo 6804
        *nostatus="nostatus",
7652 schaersvoo 6805
        *snaptogrid="snaptogrid",
7784 schaersvoo 6806
        *xsnaptogrid="xsnaptogrid",
6807
        *ysnaptogrid="ysnaptogrid",
7654 schaersvoo 6808
        *userinput_xy="userinput_xy",
8193 schaersvoo 6809
        *userinput_function="userinput_function",
7663 schaersvoo 6810
        *usertextarea_xy="usertextarea_xy",
8222 schaersvoo 6811
        *userinput="userinput",
7823 schaersvoo 6812
        *jsmath="jsmath",
7858 schaersvoo 6813
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 6814
        *setlimits="setlimits",
7858 schaersvoo 6815
        *jscurve="jscurve",
6816
        *jsplot="jsplot",
7983 schaersvoo 6817
        *sgraph="sgraph",
7984 schaersvoo 6818
        *title="title",
7996 schaersvoo 6819
        *centerstring="centerstring",
6820
        *xunit="xunit",
8071 schaersvoo 6821
        *yunit="yunit",
8101 schaersvoo 6822
        *slider="slider",
8105 schaersvoo 6823
        *killslider="killslider",
8244 schaersvoo 6824
        *angle="angle",
6825
        *halfline="halfline",
6826
        *demiline="demiline";
7614 schaersvoo 6827
 
6828
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')){
6829
            if( i == 0 && (c == ' ' || c == '\t') ){
6830
        continue; /* white spaces or tabs allowed before first command identifier */
6831
            }
6832
            else
6833
            {
6834
        if( c == ' ' || c == '\t' ){
6835
            break;
6836
        }
6837
        else
6838
        {
6839
            temp[i] = c;
6840
            if(i > MAX_INT - 2){canvas_error("command string too long !");}
6841
            i++;
6842
        }
6843
            }
6844
            if(temp[0] == '#') break;
6845
        }
6846
        if (c == EOF) finished = 1;
6847
 
6848
        if (c == '\n' || c == '\r') {
6849
        line_number++;
6850
        if (i == 0) { return EMPTY; }
6851
        } else if (c == EOF) {
6852
        return 0;
6853
        }
6854
 
6855
        temp[i]='\0';
6856
        input_type=(char*)my_newmem(strlen(temp));
6857
        snprintf(input_type,sizeof(temp),"%s",temp);
6858
 
6859
        if( strcmp(input_type, size) == 0 ){
6860
        free(input_type);
6861
        return SIZE;
6862
        }
6863
        if( strcmp(input_type, xrange) == 0 ){
6864
        free(input_type);
6865
        return XRANGE;
6866
        }
6867
        if( strcmp(input_type, rangex) == 0 ){
6868
        free(input_type);
6869
        return XRANGE;
6870
        }
6871
        if( strcmp(input_type, trange) == 0 ){
6872
        free(input_type);
6873
        return TRANGE;
6874
        }
6875
        if( strcmp(input_type, ranget) == 0 ){
6876
        free(input_type);
6877
        return TRANGE;
6878
        }
6879
        if( strcmp(input_type, yrange) == 0 ){
6880
        free(input_type);
6881
        return YRANGE;
6882
        }
6883
        if( strcmp(input_type, rangey) == 0 ){
6884
        free(input_type);
6885
        return YRANGE;
6886
        }
6887
        if( strcmp(input_type, linewidth) == 0 ){
6888
        free(input_type);
6889
        return LINEWIDTH;
6890
        }
6891
        if( strcmp(input_type, dashed) == 0 ){
6892
        free(input_type);
6893
        return DASHED;
6894
        }
6895
        if( strcmp(input_type, dashtype) == 0 ){
6896
        free(input_type);
6897
        return DASHTYPE;
6898
        }
6899
        if( strcmp(input_type, axisnumbering) == 0 ){
6900
        free(input_type);
6901
        return AXIS_NUMBERING;
6902
        }
6903
        if( strcmp(input_type, axisnumbers) == 0 ){
6904
        free(input_type);
6905
        return AXIS_NUMBERING;
6906
        }
6907
        if( strcmp(input_type, axis) == 0 ){
6908
        free(input_type);
6909
        return AXIS;
6910
        }
6911
        if( strcmp(input_type, grid) == 0 ){
6912
        free(input_type);
6913
        return GRID;
6914
        }
6915
        if( strcmp(input_type, parallel) == 0 ){
6916
        free(input_type);
6917
        return PARALLEL;
6918
        }
6919
        if( strcmp(input_type, hline) == 0 ||  strcmp(input_type, horizontalline) == 0 ){
6920
        free(input_type);
6921
        return HLINE;
6922
        }
6923
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
6924
        free(input_type);
6925
        return VLINE;
6926
        }
6927
        if( strcmp(input_type, line) == 0 ){
6928
        free(input_type);
6929
        return LINE;
6930
        }
6931
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
6932
        free(input_type);
6933
        return SEGMENT;
6934
        }
6935
        if( strcmp(input_type, dsegment) == 0 ){
6936
        free(input_type);
6937
        use_dashed = TRUE;
6938
        return SEGMENT;
6939
        }
6940
        if( strcmp(input_type, crosshairsize) == 0 ){
6941
        free(input_type);
6942
        return CROSSHAIRSIZE;
6943
        }
6944
        if( strcmp(input_type, arrowhead) == 0 ){
6945
        free(input_type);
6946
        return ARROWHEAD;
6947
        }
6948
        if( strcmp(input_type, crosshairs) == 0 ){
6949
        free(input_type);
6950
        return CROSSHAIRS;
6951
        }
6952
        if( strcmp(input_type, crosshair) == 0 ){
6953
        free(input_type);
6954
        return CROSSHAIR;
6955
        }
6956
        if( strcmp(input_type, onclick) == 0 ){
6957
        free(input_type);
6958
        return ONCLICK;
6959
        }
6960
        if( strcmp(input_type, drag) == 0 ){
6961
        free(input_type);
6962
        return DRAG;
6963
        }
6964
        if( strcmp(input_type, userdraw) == 0 ){
6965
        free(input_type);
6966
        return USERDRAW;
6967
        }
6968
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
6969
        free(input_type);
6970
        return STYLE;
6971
        }
6972
        if( strcmp(input_type, fillcolor) == 0 ){
6973
        free(input_type);
6974
        return FILLCOLOR;
6975
        }
6976
        if( strcmp(input_type, strokecolor) == 0 ){
6977
        free(input_type);
6978
        return STROKECOLOR;
6979
        }
6980
        if( strcmp(input_type, filled) == 0  ){
6981
        free(input_type);
6982
        return FILLED;
6983
        }
6984
        if( strcmp(input_type, http) == 0 ){
6985
        free(input_type);
6986
        return HTTP;
6987
        }
6988
        if( strcmp(input_type, rays) == 0 ){
6989
        free(input_type);
6990
        return RAYS;
6991
        }
6992
        if( strcmp(input_type, lattice) == 0 ){
6993
        free(input_type);
6994
        return LATTICE;
6995
        }
6996
        if( strcmp(input_type, bgimage) == 0 ){
6997
        free(input_type);
6998
        return BGIMAGE;
6999
        }
7000
        if( strcmp(input_type, bgcolor) == 0 ){
7001
        free(input_type);
7002
        return BGCOLOR;
7003
        }
7004
        if( strcmp(input_type, backgroundimage) == 0 ){
7005
        free(input_type);
7006
        return BGIMAGE;
7007
        }
7008
        if( strcmp(input_type, text) == 0 ){
7009
        free(input_type);
7010
        return FLY_TEXT;
7011
        }
7012
        if( strcmp(input_type, textup) == 0 ){
7013
        free(input_type);
7014
        return FLY_TEXTUP;
7015
        }
7016
        if( strcmp(input_type, mouse) == 0 ){
7017
        free(input_type);
7018
        return MOUSE;
7019
        }
7991 schaersvoo 7020
        if( strcmp(input_type, mousex) == 0 ){
7021
        free(input_type);
7022
        return MOUSEX;
7023
        }
7024
        if( strcmp(input_type, mousey) == 0 ){
7025
        free(input_type);
7026
        return MOUSEY;
7027
        }
8071 schaersvoo 7028
        if( strcmp(input_type, mouse_degree) == 0 ){
7029
        free(input_type);
7030
        return MOUSE_DEGREE;
7031
        }
7032
        if( strcmp(input_type, mouse_display) == 0 ){
7033
        free(input_type);
7034
        return MOUSE_DISPLAY;
7035
        }
7614 schaersvoo 7036
        if( strcmp(input_type, mouseprecision) == 0 ){
7037
        free(input_type);
7038
        return MOUSE_PRECISION;
7039
        }
7040
        if( strcmp(input_type, precision) == 0 ){
7041
        free(input_type);
7042
        return MOUSE_PRECISION;
7043
        }
7044
        if( strcmp(input_type, curve) == 0 ){
7045
        free(input_type);
7046
        return CURVE;
7047
        }
7048
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 7049
        use_dashed = TRUE;
7614 schaersvoo 7050
        free(input_type);
7051
        return CURVE;
7052
        }
7053
        if( strcmp(input_type, plot) == 0 ){
7054
        free(input_type);
7055
        return CURVE;
7056
        }
7057
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 7058
        use_dashed = TRUE;
7614 schaersvoo 7059
        free(input_type);
7060
        return CURVE;
7061
        }
7788 schaersvoo 7062
        if( strcmp(input_type, levelcurve) == 0 ){
7063
        free(input_type);
7064
        return LEVELCURVE;
7065
        }
7614 schaersvoo 7066
        if( strcmp(input_type, plotsteps) == 0 ){
7067
        free(input_type);
7068
        return PLOTSTEPS;
7069
        }
7070
        if( strcmp(input_type, plotstep) == 0 ){
7071
        free(input_type);
7072
        return PLOTSTEPS;
7073
        }
7074
        if( strcmp(input_type, tsteps) == 0 ){
7075
        free(input_type);
7076
        return PLOTSTEPS;
7077
        }
7078
        if( strcmp(input_type, fontsize) == 0 ){
7079
        free(input_type);
7080
        return FONTSIZE;
7081
        }
7082
        if( strcmp(input_type, fontcolor) == 0 ){
7083
        free(input_type);
7084
        return FONTCOLOR;
7085
        }
7086
        if( strcmp(input_type, arrow) == 0 ){
7087
        free(input_type);
7088
        return ARROW;
7089
        }
7090
        if( strcmp(input_type, arrow2) == 0 ){
7091
        free(input_type);
7092
        return ARROW2;
7093
        }
7094
        if( strcmp(input_type, darrow) == 0 ){
7095
        free(input_type);
8071 schaersvoo 7096
        use_dashed = TRUE;
7614 schaersvoo 7097
        return ARROW;
7098
        }
7099
        if( strcmp(input_type, darrow2) == 0 ){
7100
        free(input_type);
7101
        use_dashed = TRUE;
7102
        return ARROW2;
7103
        }
7104
        if( strcmp(input_type, zoom) == 0 ){
7105
        free(input_type);
7106
        return ZOOM;
7107
        }
7108
        if( strcmp(input_type, triangle) == 0 ){
7109
        free(input_type);
7110
        return TRIANGLE;
7111
        }
7112
        if( strcmp(input_type, ftriangle) == 0 ){
7113
        free(input_type);
7114
        use_filled = TRUE;
7115
        return TRIANGLE;
7116
        }
7117
        if( strcmp(input_type, input) == 0 ){
7118
        free(input_type);
7119
        return INPUT;
7120
        }
7121
        if( strcmp(input_type, inputstyle) == 0 ){
7122
        free(input_type);
7123
        return INPUTSTYLE;
7124
        }
7125
        if( strcmp(input_type, textarea) == 0 ){
7126
        free(input_type);
7127
        return TEXTAREA;
7128
        }
7129
        if( strcmp(input_type, mathml) == 0 ){
7130
        free(input_type);
7131
        return MATHML;
7132
        }
7133
        if( strcmp(input_type, html) == 0 ){
7134
        free(input_type);
7135
        return MATHML;
7136
        }
7137
        if( strcmp(input_type, fontfamily) == 0 ){
7138
        free(input_type);
7139
        return FONTFAMILY;
7140
        }
7141
        if( strcmp(input_type, lines) == 0  ||  strcmp(input_type, polyline) == 0 ){
7142
        free(input_type);
7143
        return POLYLINE;
7144
        }
7145
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
7146
        free(input_type);
7147
        return RECT;
7148
        }
7149
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
7150
        free(input_type);
7151
        return ROUNDRECT;
7152
        }
7153
        if( strcmp(input_type, froundrect) == 0 ){
7154
        free(input_type);
7155
        use_filled = TRUE;
7156
        return ROUNDRECT;
7157
        }
7158
        if( strcmp(input_type, square) == 0 ){
7159
        free(input_type);
7160
        return SQUARE;
7161
        }
7162
        if( strcmp(input_type, fsquare) == 0 ){
7163
        free(input_type);
7164
        use_filled = TRUE;
7165
        return SQUARE;
7166
        }
7167
        if( strcmp(input_type, dline) == 0 ){
7168
        use_dashed = TRUE;
7169
        free(input_type);
7170
        return LINE;
7171
        }
7786 schaersvoo 7172
        if( strcmp(input_type, dvline) == 0 ){
7173
        use_dashed = TRUE;
7174
        free(input_type);
7175
        return VLINE;
7176
        }
7177
        if( strcmp(input_type, dhline) == 0 ){
7178
        use_dashed = TRUE;
7179
        free(input_type);
7180
        return HLINE;
7181
        }
7614 schaersvoo 7182
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
7183
        use_filled = TRUE;
7184
        free(input_type);
7185
        return RECT;
7186
        }
7187
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
7188
        use_filled = TRUE;
7189
        free(input_type);
7190
        return CIRCLE;
7191
        }
7192
        if( strcmp(input_type, circle) == 0 ){
7193
        free(input_type);
7194
        return CIRCLE;
7195
        }
7196
        if( strcmp(input_type, point) == 0 ){
7197
        free(input_type);
7198
        return POINT;
7199
        }
7200
        if( strcmp(input_type, points) == 0 ){
7201
        free(input_type);
7202
        return POINTS;
7203
        }
7204
        if( strcmp(input_type, filledarc) == 0 ){
7205
        use_filled = TRUE;
7206
        free(input_type);
7207
        return ARC;
7208
        }
7209
        if( strcmp(input_type, arc) == 0 ){
7210
        free(input_type);
7211
        return ARC;
7212
        }
7213
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
7214
        free(input_type);
7215
        return POLY;
7216
        }
7217
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
7218
        use_filled = TRUE;
7219
        free(input_type);
7220
        return POLY;
7221
        }
7222
        if( strcmp(input_type, ellipse) == 0){
7223
        free(input_type);
7224
        return ELLIPSE;
7225
        }
7226
        if( strcmp(input_type, fill) == 0 ){
7227
        free(input_type);
7228
        return FLOODFILL;
7229
        }
7230
        if( strcmp(input_type, string) == 0 ){
7231
        free(input_type);
7232
        return STRING;
7233
        }
7234
        if( strcmp(input_type, stringup) == 0 ){
7235
        free(input_type);
7236
        return STRINGUP;
7237
        }
7238
        if( strcmp(input_type, opacity) == 0 ){
7239
        free(input_type);
7240
        return OPACITY;
7241
        }
7242
        if( strcmp(input_type, comment) == 0){
7243
        free(input_type);
7244
        return COMMENT;
7245
        }
7246
        if( strcmp(input_type, end) == 0){
7247
        free(input_type);
7248
        return END;
7249
        }
7250
        if( strcmp(input_type, fellipse) == 0){
7251
        free(input_type);
7252
        use_filled = TRUE;
7253
        return ELLIPSE;
8224 bpr 7254
        }
7614 schaersvoo 7255
        if( strcmp(input_type, blink) == 0 ){
7256
        free(input_type);
7257
        return BLINK;
7258
        }
8146 schaersvoo 7259
        if( strcmp(input_type, clearbutton) == 0){
7614 schaersvoo 7260
        free(input_type);
8146 schaersvoo 7261
        return CLEARBUTTON;
7614 schaersvoo 7262
        }
7263
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
7264
        free(input_type);
7265
        return TRANSLATION;
7266
        }
7267
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
7268
        free(input_type);
7269
        return KILLTRANSLATION;
7270
        }
7271
        if( strcmp(input_type, rotate) == 0){
7272
        free(input_type);
7273
        return ROTATE;
7274
        }
7785 schaersvoo 7275
        if( strcmp(input_type, affine) == 0){
7276
        free(input_type);
7277
        return AFFINE;
7278
        }
7279
        if( strcmp(input_type, killaffine) == 0){
7280
        free(input_type);
7281
        return KILLAFFINE;
7282
        }
7614 schaersvoo 7283
        if( strcmp(input_type, audio) == 0 ){
7284
        free(input_type);
7285
        return AUDIO;
7286
        }
7287
        if( strcmp(input_type, audioobject) == 0 ){
7288
        free(input_type);
7289
        return AUDIOOBJECT;
7290
        }
7291
        if( strcmp(input_type, slider) == 0 ){
7292
        free(input_type);
7293
        return SLIDER;
7294
        }
8101 schaersvoo 7295
        if( strcmp(input_type, killslider) == 0 ){
7296
        free(input_type);
7297
        return KILLSLIDER;
7298
        }
7614 schaersvoo 7299
        if( strcmp(input_type, copy) == 0 ){
7300
        free(input_type);
7301
        return COPY;
7302
        }
7303
        if( strcmp(input_type, copyresized) == 0 ){
7304
        free(input_type);
7305
        return COPYRESIZED;
7306
        }
7307
        if( strcmp(input_type, patternfill) == 0 ){
7308
        free(input_type);
7309
        return PATTERNFILL;
7310
        }
7311
        if( strcmp(input_type, hatchfill) == 0 ){
7312
        free(input_type);
7313
        return HATCHFILL;
7314
        }
7647 schaersvoo 7315
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
7614 schaersvoo 7316
        free(input_type);
7647 schaersvoo 7317
        return DIAMONDFILL;
7614 schaersvoo 7318
        }
7319
        if( strcmp(input_type, dotfill) == 0 ){
7320
        free(input_type);
7321
        return DOTFILL;
7322
        }
7323
        if( strcmp(input_type, gridfill) == 0 ){
7324
        free(input_type);
7325
        return GRIDFILL;
7326
        }
7327
        if( strcmp(input_type, imagefill) == 0 ){
7328
        free(input_type);
7329
        return IMAGEFILL;
7330
        }
7331
        if( strcmp(input_type, clicktile_colors) == 0 ){
7332
        free(input_type);
7333
        return CLICKTILE_COLORS;
7334
        }
7335
        if( strcmp(input_type, clicktile) == 0 ){
7336
        free(input_type);
7337
        return CLICKTILE;
7338
        }
7339
        if( strcmp(input_type, xlogscale) == 0 ){
7340
        free(input_type);
7341
        return XLOGSCALE;
7342
        }
7343
        if( strcmp(input_type, ylogscale) == 0 ){
7344
        free(input_type);
7345
        return YLOGSCALE;
7346
        }
7347
        if( strcmp(input_type, xylogscale) == 0 ){
7348
        free(input_type);
7349
        return XYLOGSCALE;
7350
        }
7351
        if( strcmp(input_type, ylogscale) == 0 ){
7352
        free(input_type);
7353
        return YLOGSCALE;
7354
        }
7735 schaersvoo 7355
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 7356
        free(input_type);
7735 schaersvoo 7357
        return XLOGBASE;
7614 schaersvoo 7358
        }
7735 schaersvoo 7359
        if( strcmp(input_type, ylogbase) == 0 ){
7360
        free(input_type);
7361
        return YLOGBASE;
7362
        }
7614 schaersvoo 7363
        if( strcmp(input_type, intooltip) == 0 ){
7364
        free(input_type);
7365
        return INTOOLTIP;
7366
        }
7367
        if( strcmp(input_type,video) == 0 ){
7368
        free(input_type);
7369
        return VIDEO;
7370
        }
7371
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
7372
        free(input_type);
7373
        return FLOODFILL;
8224 bpr 7374
        }
7614 schaersvoo 7375
        if( strcmp(input_type,filltoborder) == 0 ){
7376
        free(input_type);
7377
        return FILLTOBORDER;
8224 bpr 7378
        }
7614 schaersvoo 7379
        if( strcmp(input_type,clickfill) == 0 ){
7380
        free(input_type);
7381
        return CLICKFILL;
8224 bpr 7382
        }
7614 schaersvoo 7383
        if( strcmp(input_type, replyformat) == 0 ){
7384
        free(input_type);
7385
        return REPLYFORMAT;
7386
        }
7387
        if( strcmp(input_type, pixelsize) == 0 ){
7388
        free(input_type);
7389
        return PIXELSIZE;
7390
        }
7391
        if( strcmp(input_type, setpixel) == 0 ){
7392
        free(input_type);
7393
        return SETPIXEL;
7394
        }
7395
        if( strcmp(input_type, pixels) == 0 ){
7396
        free(input_type);
7397
        return PIXELS;
7398
        }
7399
        if( strcmp(input_type, clickfillmarge) == 0 ){
7400
        free(input_type);
7401
        return CLICKFILLMARGE;
7402
        }
7403
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
7404
        free(input_type);
7405
        return X_AXIS_STRINGS;
7406
        }
7407
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
7408
        free(input_type);
7409
        return Y_AXIS_STRINGS;
7410
        }
7411
        if( strcmp(input_type, piechart) == 0  ){
7412
        free(input_type);
7413
        return PIECHART;
7414
        }
7415
        if( strcmp(input_type, barchart) == 0  ){
7416
        free(input_type);
7417
        return BARCHART;
7418
        }
7419
        if( strcmp(input_type, linegraph) == 0  ){
7420
        free(input_type);
7421
        return LINEGRAPH;
7422
        }
7423
        if( strcmp(input_type, clock) == 0  ){
7424
        free(input_type);
7425
        return CLOCK;
7426
        }
7427
        if( strcmp(input_type, legend) == 0  ){
7428
        free(input_type);
7429
        return LEGEND;
7430
        }
7431
        if( strcmp(input_type, legendcolors) == 0  ){
7432
        free(input_type);
7433
        return LEGENDCOLORS;
7434
        }
7435
        if( strcmp(input_type, xlabel) == 0  ){
7436
        free(input_type);
7437
        return XLABEL;
7438
        }
7439
        if( strcmp(input_type, ylabel) == 0  ){
7440
        free(input_type);
7441
        return YLABEL;
7442
        }
7443
        if( strcmp(input_type, animate) == 0  ){
7444
        free(input_type);
7445
        return ANIMATE;
7446
        }
7447
        /* these are bitmap related flydraw commmands...must be removed. eventually */
7448
        if( strcmp(input_type, transparent) == 0 ){
7449
        free(input_type);
7450
        return TRANSPARENT;
7451
        }
7877 schaersvoo 7452
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 7453
        free(input_type);
7454
        return STATUS;
7455
        }
7456
        if( strcmp(input_type, snaptogrid) == 0 ){
7457
        free(input_type);
7458
        return SNAPTOGRID;
7459
        }
7784 schaersvoo 7460
        if( strcmp(input_type, xsnaptogrid) == 0 ){
7461
        free(input_type);
7462
        return XSNAPTOGRID;
7463
        }
7464
        if( strcmp(input_type, ysnaptogrid) == 0 ){
7465
        free(input_type);
7466
        return YSNAPTOGRID;
7467
        }
7652 schaersvoo 7468
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 7469
        free(input_type);
7652 schaersvoo 7470
        return USERINPUT_XY;
7471
        }
8193 schaersvoo 7472
        if( strcmp(input_type, userinput_function) == 0 ){
7473
        free(input_type);
7474
        return USERINPUT_FUNCTION;
7475
        }
7663 schaersvoo 7476
        if( strcmp(input_type, usertextarea_xy) == 0 ){
7477
        free(input_type);
7478
        return USERTEXTAREA_XY;
7479
        }
8222 schaersvoo 7480
        if( strcmp(input_type, userinput) == 0 ){
7481
        free(input_type);
7482
        return USERINPUT;
7483
        }
7654 schaersvoo 7484
        if( strcmp(input_type, sgraph) == 0 ){
7652 schaersvoo 7485
        free(input_type);
7654 schaersvoo 7486
        return SGRAPH;
7487
        }
7823 schaersvoo 7488
        if( strcmp(input_type, jsmath) == 0 ){
7654 schaersvoo 7489
        free(input_type);
7823 schaersvoo 7490
        return JSMATH;
7491
        }
7858 schaersvoo 7492
        if( strcmp(input_type, trace_jscurve) == 0 ){
7823 schaersvoo 7493
        free(input_type);
7858 schaersvoo 7494
        return TRACE_JSCURVE;
7823 schaersvoo 7495
        }
7858 schaersvoo 7496
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
7497
        free(input_type);
7498
        return JSCURVE;
7499
        }
7984 schaersvoo 7500
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
7983 schaersvoo 7501
        free(input_type);
7502
        return CENTERSTRING;
7503
        }
7838 schaersvoo 7504
        if( strcmp(input_type, setlimits) == 0 ){
7823 schaersvoo 7505
        free(input_type);
7838 schaersvoo 7506
        return SETLIMITS;
7507
        }
7996 schaersvoo 7508
        if( strcmp(input_type, xunit) == 0 ){
7838 schaersvoo 7509
        free(input_type);
7996 schaersvoo 7510
        return XUNIT;
7511
        }
7512
        if( strcmp(input_type, yunit) == 0 ){
7513
        free(input_type);
7514
        return YUNIT;
7515
        }
8105 schaersvoo 7516
        if( strcmp(input_type, angle) == 0 ){
7996 schaersvoo 7517
        free(input_type);
8105 schaersvoo 7518
        return ANGLE;
7519
        }
8244 schaersvoo 7520
        if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
8105 schaersvoo 7521
        free(input_type);
8244 schaersvoo 7522
        return HALFLINE;
7523
        }
7524
        free(input_type);
7614 schaersvoo 7525
        ungetc(c,infile);
7526
        return 0;
7527
}
7856 schaersvoo 7528