Subversion Repositories wimsdev

Rev

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