Subversion Repositories wimsdev

Rev

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

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