Subversion Repositories wimsdev

Rev

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