Subversion Repositories wimsdev

Rev

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

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