Subversion Repositories wimsdev

Rev

Rev 11817 | Rev 11820 | 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 */
11021 schaersvoo 18
void    add_javascript_function(int js_function[], int canvas_root_id);
7614 schaersvoo 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 */
9329 schaersvoo 64
char *getfile_cmd = "";
7614 schaersvoo 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 */
11802 schaersvoo 77
    int use_offset = FALSE;/* use_offset only for text shape objects... 0=none;1=xcentered;2=xyoffset*/
7614 schaersvoo 78
    int use_axis = FALSE;
79
    int use_axis_numbering = FALSE;
7797 schaersvoo 80
    int use_pan_and_zoom = FALSE;
7956 schaersvoo 81
    int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
7858 schaersvoo 82
    int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
83
    int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
11006 schaersvoo 84
    int jsplot_cnt = 0; /* keepint track on the curve identity */
8448 schaersvoo 85
    int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
7614 schaersvoo 86
    int line_width = 1;
87
    int decimals = 2;
8365 schaersvoo 88
    int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
89
    int use_userdraw = FALSE; /* flag to indicate user interaction */
7614 schaersvoo 90
    int drag_type = -1;/* 0,1,2 : xy,x,y */
9329 schaersvoo 91
    int use_tooltip = -1; /* 1= tooltip 2= popup window*/
7614 schaersvoo 92
    char *tooltip_text = "Click here";
93
    char *temp = ""; /* */
94
    char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
95
    char *stroke_color = "255,0,0";
96
    char *fill_color = "0,255,0";
97
    char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
98
    char *font_color = "#00000";
99
    char *draw_type = "points";
100
    char *fly_font = "normal";
8815 schaersvoo 101
    char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;";
7614 schaersvoo 102
    char *flytext = "";
7785 schaersvoo 103
    char *affine_matrix = "[1,0,0,1,0,0]";
8297 schaersvoo 104
    char *function_label = "f(x)=";
11006 schaersvoo 105
    int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
7614 schaersvoo 106
    int pixelsize = 1;
107
    int reply_format = 0;
108
    int input_cnt = 0;
109
    int ext_img_cnt = 0;
8071 schaersvoo 110
    int slider_cnt = 0;
11763 schaersvoo 111
    int fill_cnt = 0;
10953 bpr 112
    int font_size = 12;/* this may lead to problems when using something like "fontfamily Italic 24px Ariel" the "font_size" value is not substituted into fontfamily !! */
8388 schaersvoo 113
    int fly_font_size = 12; /*fly_font_size is relative to this... */
8365 schaersvoo 114
    int dashtype[2] = { 4 , 4 }; /* just line_px and space_px : may have more arguments...if needed in future*/
7614 schaersvoo 115
    int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
116
    for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
8365 schaersvoo 117
    int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
7833 schaersvoo 118
    int crosshair_size = 5; /* size in px*/
8365 schaersvoo 119
    int plot_steps = 250;/* the js-arrays with x_data_points and y_data_points will have size 250 each: use with care !!! use jscurve when precise plots are required  */
120
    int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange :just to flag an error message */
8448 schaersvoo 121
    int click_cnt = 0; /*counter to identify the "onclick" ojects ; 0 is first object set onclick: reply[click_cnt]=1 when clicked ; otherwise reply[click_cnt]=0 ; click_cnt is only increased when another object is set  again */
7614 schaersvoo 122
    int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
123
    int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
7989 schaersvoo 124
    int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
9433 schaersvoo 125
    int boxplot_cnt = 0;
7956 schaersvoo 126
    int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
8074 schaersvoo 127
    int reply_precision = 100; /* used for precision of student answers / drawings */
7614 schaersvoo 128
    double angle = 0.0;
10953 bpr 129
    char *rotation_center = "null";
8365 schaersvoo 130
    int clickfillmarge = 20; /* in pixels : if the 'remove click' is within this marge, the filling is removed */
131
    int animation_type = 9; /* REMOVED == object type curve in drag library */
7823 schaersvoo 132
    int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
10953 bpr 133
    int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
8365 schaersvoo 134
    size_t string_length = 0; /* measure the size of the user input fly-string */
135
    double stroke_opacity = 0.8; /* use some opacity as default */
136
    double fill_opacity = 0.8;/* use some opacity as default */
7614 schaersvoo 137
    char *URL = "http://localhost/images";
9213 schaersvoo 138
    char *slider_function_x = "x";
139
    char *slider_function_y = "y";
7614 schaersvoo 140
    memset(buffer,'\0',MAX_BUFFER);
141
    void *tmp_buffer = "";
8224 bpr 142
 
7614 schaersvoo 143
    /* default writing a unzipped js-include file into wims getfile directory */
144
    char *w_wims_session = getenv("w_wims_session");
8224 bpr 145
    if(  w_wims_session == NULL || *w_wims_session == 0 ){
7614 schaersvoo 146
        canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");
147
    }
148
    int L0=strlen(w_wims_session) + 21;
149
    char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
150
    snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
151
    mode_t process_mask = umask(0); /* check if file exists */
152
    int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
153
    if( result == 0 || errno == EEXIST ){
154
     umask(process_mask); /* be sure to set correct permission */
8224 bpr 155
     char *w_session = getenv("w_session");
7614 schaersvoo 156
     int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
9329 schaersvoo 157
    getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
8224 bpr 158
     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 159
    /* write the include tag to html page:<script type="text/javascript" src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
160
    /* now write file into getfile dir*/
161
    char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
162
    int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
163
    char *location = my_newmem(L2); /* create memory to fit string precisely */
164
    snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
165
    js_include_file = fopen(location,"w");/* open the file location for writing */
166
    /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
167
    if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
168
 
169
/* ----------------------------------------------------- */
170
/* while more lines to process */
171
 
172
    while(!finished){
9329 schaersvoo 173
        if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
7614 schaersvoo 174
        type = get_token(infile);
175
        done = FALSE;
176
        /*
9385 schaersvoo 177
        @ canvasdraw
178
        @ 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...)
9386 schaersvoo 179
        @ general syntax <ul><li>The transparency of all objects can be controlled by command <a href="#opacity">'opacity [0-255],[0,255]'</a></il><li>line width of any object can be controlled by command <a href="#linewidth">'linewidth int'</a></li><li>any may be dashed by using keyword <a href="#dashed">'dashed'</a> before the object command.<br />the dashing type can be controled by command <a href="#dashtype">'dashtype int,int'</a></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 <a href="#filled">'filled'</a> before the object command.<br />The fill colour of 'non_userdraw' objects will be the stroke colour...(flydraw harmonization 19/10/2013)</li><li>all draggable objects may have a <a href="#slider">slider</a> 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 <a href="#drag">'drag x/y/xy'</a><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 <a href="#zoom">zoom</a> and will be translated in case of panning</li><li> a 'onclick object' can be set 'clickable' by the preceding keyword <a href="#onclick">'onclick'</a><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 (instead 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><li>almost every <a href="#userdraw">"userdraw object,color"</a>  or <a href="#multidraw">"multidraw"</a> command 'family' may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..."  </li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command "snaptopoints x1,y1,x2,y2,..."  </li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntaxrule:<li><em>single_object</em> x1,y1,...,color</li><li><em>multi_object</em> color,x1,y1,...</li></ul><li>All inputfields or textareas generated, can be styled individually using command <a href="#inputstyle">'inputstyle some_css'</a><br/>the fontsize used for labeling these elements can be controlled by command <a href="fontsize">'fontsize int'</a> <br />command 'fontfamily' is <b>not</b> active for these elements </li></ul>
10953 bpr 180
        @ 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 />If the default reply formatting is not suitable, use command <a href='#replyformat'>'replyformat'</a> 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>
11006 schaersvoo 181
        @ you can check the javascript reply format in the wims tool <a href="http://localhost/wims/wims.cgi?lang=en&module=tool/directexec">direct exec</a>
10962 schaersvoo 182
        @ for usage within OEF (without anstype "draw"), something like this (a popup function plotter) will work:<br /><small>\\text{popup_grapher=wims(exec canvasdraw <br />popup<br />size 400,400<br />xrange -10,10<br />yrange -10,10<br />axis<br />axisnumbering<br />opacity 100,100<br />grid 2,2,grey,2,2,6,black<br />snaptogrid<br />linewidth 2<br />jsplot red,5*sin(1/x)<br />strokecolor green<br />functionlabel f(x)=<br />userinput function<br />mouse blue,22<br />)<br />}<br />\\statement{<br />\\popup_grapher<br />}</small>
9427 schaersvoo 183
        @ be aware that older browsers will probably not work correctly<br />no effort has been undertaken to add glue code for older browsers !! <br />in any case it's not wise to use older browsers...not just for canvasdraw
10827 schaersvoo 184
        @ if you find flaws, errors or other incompatibilities -not those mentioned in this document- send <a href='mailto:jm.evers-at-schaersvoorde.nl'>me</a> an email with screenshots and the generated javascript include file.
11002 schaersvoo 185
        @ there is limited support for touch devices : touchstart,touchmove and touchend in commands <a href="#userdraw">userdraw primitives </a>, <a href="#protractor">protractor</a> and <a href="#ruler">ruler</a><br />only single finger gestures are supported (for now)<br />for more accurate user-interaction with canvasdraw on touch devices: use the command family <a href="userinput_xy">userinput</a>
7614 schaersvoo 186
        */
187
        switch(type){
188
        case END:
189
        finished = 1;
190
        done = TRUE;
191
        break;
192
        case 0:
193
            sync_input(infile);
194
            break;
195
        case COMMENT:
196
            sync_input(infile);
197
            break;
11806 schaersvoo 198
        case AFFINE:
7614 schaersvoo 199
        /*
11806 schaersvoo 200
         @ affine a,b,c,d,tx,ty
201
         @ defines a transformation matrix for subsequent objects
202
         @ images drawn by setting skew params a &amp; d will be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !!
203
         @ use keyword 'killaffine' to end the transformation
204
         @ note 1: only 'draggable' / 'noclick' objects can be transformed.
205
         @ note 2: do not use 'onclick' or 'drag xy' with tranformation objects : the mouse coordinates do not get transformed (yet)
206
         @ note 3: no matrix operations on the transformation matrix implemented (yet)
207
         @ a : Scales the drawings horizontally
208
         @ b : Skews the drawings horizontally
209
         @ c : Skews the drawings vertically
210
         @ d : Scales the drawings vertically
211
         @ tx: Moves the drawings horizontally in xrange coordinate system
212
         @ ty: Moves the drawings vertically in yrange coordinate system
213
         @ the data precision may be set by preceding command "precision int"
7614 schaersvoo 214
        */
11806 schaersvoo 215
            for(i = 0 ; i<6;i++){
7614 schaersvoo 216
                switch(i){
11806 schaersvoo 217
                    case 0: double_data[0] = get_real(infile,0);break;
218
                    case 1: double_data[1] = get_real(infile,0);break;
219
                    case 2: double_data[2] = get_real(infile,0);break;
220
                    case 3: double_data[3] = get_real(infile,0);break;
221
                    case 4: double_data[4] = get_real(infile,0);break;
222
                    case 5: double_data[5] = get_real(infile,1);
223
                        use_affine = TRUE;
224
                        decimals = find_number_of_digits(precision);
225
                        string_length = snprintf(NULL,0,     "[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin));
226
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
227
                        snprintf(affine_matrix,string_length,"[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f] ",decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4]*xsize/(xmax - xmin),decimals,-1*double_data[5]*ysize/(ymax - ymin));
228
                        break;
7614 schaersvoo 229
                    default: break;
230
                }
231
            }
11806 schaersvoo 232
        break;
8386 schaersvoo 233
 
11806 schaersvoo 234
        case ANGLE:
7614 schaersvoo 235
        /*
11806 schaersvoo 236
         @ angle xc,yc,width,start_angle,end_angle,color
237
         @ width is in x-range
238
         @ will zoom in/out
239
         @ if size is controlled by command <a href='#slider'>'slider'</a> use radians to set limits of slider.
7614 schaersvoo 240
        */
11806 schaersvoo 241
            for(i=0;i<7;i++){
7614 schaersvoo 242
                switch(i){
11806 schaersvoo 243
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
244
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
245
                    case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
246
                    case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
247
                    case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
248
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
249
                        decimals = find_number_of_digits(precision);
250
                        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,%s,%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,rotation_center,use_offset);
251
                        reset();
252
                    break;
7614 schaersvoo 253
                }
254
            }
255
            break;
8386 schaersvoo 256
 
11806 schaersvoo 257
        case ANIMATE:
7614 schaersvoo 258
        /*
11806 schaersvoo 259
         @ animate type
260
         @ REMOVED : this should be done with a slider
261
         @ type may be "point" (nothing else , yet...)
262
         @ the point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
263
         @ will animate a point on the next plot/curve command
264
         @ the curve will not be draw
265
         @ moves repeatedly from xmin to xmax
7614 schaersvoo 266
        */
11806 schaersvoo 267
            if( strstr(get_string(infile,1),"point") != 0 ){animation_type = 15;}else{canvas_error("the only animation type (for now) is \"point\"...");}
7614 schaersvoo 268
            break;
8386 schaersvoo 269
 
270
 
11806 schaersvoo 271
        case ARC:
7614 schaersvoo 272
        /*
11806 schaersvoo 273
         @ arc xc,yc,width,height,start_angle,end_angle,color
274
         @ can <b>not</b> be set "onclick" or "drag xy"
275
         @ <b>attention</b>: width in height in x/y-range
276
         @ will not zoom in or zoom out (because radius is given in pixels an not in x/y-system !). Panning will work
277
         @ use command <a href='#angle'>'angle'</a> for scalable angle
7614 schaersvoo 278
        */
11806 schaersvoo 279
            for(i=0;i<7;i++){
280
                switch(i){
281
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
282
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
283
                    case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
284
                    case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
285
                    case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
286
                    case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
287
                    case 6:stroke_color = get_color(infile,1);/* name or hex color */
288
                    /* in Shape library:
289
                        x[0] = x[1] = xc = double_data[0]
290
                        y[0] = y[1] = yc = double_data[1]
291
                        w[0] = width = double_data[2]
292
                        w[1] = height = double_data[3]
293
                        h[0] = start_angle = double_data[4]
294
                        h[1] = end_angle = double_data[5]
295
                    */
296
                        decimals = find_number_of_digits(precision);
297
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,12,[%.*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,%s,%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[3],decimals,double_data[4],decimals,double_data[5],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,rotation_center,use_offset);
298
                        reset();
299
                    break;
300
                }
301
            }
7614 schaersvoo 302
            break;
11806 schaersvoo 303
        case ARROW:
7614 schaersvoo 304
        /*
11806 schaersvoo 305
        @ arrow x1,y1,x2,y2,h,color
306
        @ alternative : vector
307
        @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
308
        @ use command 'linewidth int' to adjust thickness of the arrow
9406 schaersvoo 309
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 310
        */
11806 schaersvoo 311
            for(i=0;i<6;i++){
7614 schaersvoo 312
                switch(i){
313
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
314
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
11806 schaersvoo 315
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
316
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
317
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
318
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
7614 schaersvoo 319
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 320
                        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,%s,%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,rotation_center,use_offset);
321
                        if(onclick > 0){click_cnt++;}
322
                        /* click_cnt++;*/
323
                        reset();
324
                        break;
325
                }
326
            }
327
            break;
8386 schaersvoo 328
 
11806 schaersvoo 329
        case ARROWS:
7614 schaersvoo 330
        /*
11806 schaersvoo 331
        @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
332
        @ alternative : vectors
333
        @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
334
        @ use command 'linewidth int' to adjust thickness of the arrow
335
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
7614 schaersvoo 336
        */
337
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
338
            fill_color = stroke_color;
11806 schaersvoo 339
            arrow_head = (int) get_real(infile,0);/* h */
7614 schaersvoo 340
            i=0;
341
            while( ! done ){     /* get next item until EOL*/
342
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
343
                if(i%2 == 0 ){
344
                    double_data[i] = get_real(infile,0); /* x */
345
                }
346
                else
347
                {
348
                    double_data[i] = get_real(infile,1); /* y */
349
                }
350
                i++;
351
            }
352
            decimals = find_number_of_digits(precision);
11806 schaersvoo 353
            for(c = 0 ; c < i-1 ; c = c+4){
354
                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,%s,%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,rotation_center,use_offset);
355
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 356
                /* click_cnt++; */
7614 schaersvoo 357
            }
358
            reset();
359
            break;
8386 schaersvoo 360
 
11806 schaersvoo 361
        case ARROW2:
7614 schaersvoo 362
        /*
11806 schaersvoo 363
        @ arrow2 x1,y1,x2,y2,h,color
364
        @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
365
        @ use command 'arrowhead int' to adjust the arrow head size
366
        @ use command 'linewidth int' to adjust thickness of the arrow
9406 schaersvoo 367
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 368
        */
11806 schaersvoo 369
            for(i=0;i<6;i++){
7614 schaersvoo 370
                switch(i){
371
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
372
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
11806 schaersvoo 373
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
374
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
375
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
376
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
377
                        decimals = find_number_of_digits(precision);
378
                        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,%s,%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,rotation_center,use_offset);
379
                        if(onclick > 0){click_cnt++;}
380
                        /* click_cnt++;*/
381
                        reset();
382
                        break;
383
                }
384
            }
385
            break;
8386 schaersvoo 386
 
11806 schaersvoo 387
        case ARROWS2:
7614 schaersvoo 388
        /*
11806 schaersvoo 389
        @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
390
        @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
391
        @ use command 'linewidth int' to adjust thickness of the arrows
392
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
7614 schaersvoo 393
        */
394
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
395
            fill_color = stroke_color;
11806 schaersvoo 396
            arrow_head = (int) get_real(infile,0);/* h */
7614 schaersvoo 397
            i=0;
398
            while( ! done ){     /* get next item until EOL*/
399
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
400
                if(i%2 == 0 ){
401
                    double_data[i] = get_real(infile,0); /* x */
402
                }
403
                else
404
                {
405
                    double_data[i] = get_real(infile,1); /* y */
406
                }
407
                i++;
408
            }
8224 bpr 409
            decimals = find_number_of_digits(precision);
11806 schaersvoo 410
            for(c = 0 ; c < i-1 ; c = c+4){
411
                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,%s,%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,rotation_center,use_offset);
412
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 413
                /* click_cnt++; */
11806 schaersvoo 414
 
7614 schaersvoo 415
            }
416
            reset();
417
            break;
11806 schaersvoo 418
        case ARROWHEAD:
9427 schaersvoo 419
        /*
11806 schaersvoo 420
        @ arrowhead int
421
        @ default 8 (pixels)
9427 schaersvoo 422
        */
11806 schaersvoo 423
            arrow_head = (int) (get_real(infile,1));
424
            break;
425
 
426
        case AUDIO:
427
        /*
428
        @ audio x,y,w,h,loop,visible,audiofile location
429
        @ x,y : left top corner of audio element (in xrange / yrange)
430
        @ w,y : width and height in pixels
431
        @ loop : 0 or 1 ( 1 = loop audio fragment)
432
        @ visible : 0 or 1 (1 = show controls)
433
        @ audio format may be in *.mp3 or *.ogg
434
        @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
435
        @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
436
        @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
437
        @ 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 />
438
        */
439
            if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
440
            for(i=0;i<7;i++){
441
                switch(i){
442
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
443
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
444
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
445
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
446
                    case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
447
                    case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
448
                    case 6:
449
                    temp = get_string(infile,1);
450
                    if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
451
                    if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
452
                    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);
453
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
454
                    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);
455
                    add_to_buffer(tmp_buffer);
456
                    break;
457
                    default:break;
9427 schaersvoo 458
                }
11806 schaersvoo 459
            }
460
            reset();
461
            break;
462
 
463
 
464
        case AXIS_NUMBERING:
465
        /*
466
            @ axisnumbering
467
            @ keyword (no arguments required)
468
            @ for special numbering of x-axis or y-axis see grid related commands <a href="#axis">axis</a>  <a href="#xaxis">xaxis</a> , <a href="#xaxisup">xaxisup</a>, <a href="#noxaxis">noxaxis</a> ,<a href="#yaxis">yaxis</a> , <a href="#yaxisup">yaxisup</a>, <a href="#noyaxis">noyaxis</a>
469
            @ to be used before command grid (see <a href="#grid">command grid</a>)
470
        */
471
            use_axis_numbering = 1;
472
            break;
473
        case AXIS:
474
        /*
475
            @ axis
476
            @ keyword (no arguments required)
477
            @ to be used before command grid (see <a href="#grid">command grid</a>)
478
 
479
        */
480
            use_axis = TRUE;
481
            break;
482
 
483
        case BARCHART:
484
        /*
485
        @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
486
        @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
487
        @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a>
488
        @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
489
        @ multiple barchart command may be used in a single script
490
        @ also see command <a href='#piechart'>'piechart'</a>
491
        @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
492
        */
493
            temp = get_string(infile,1);
494
            if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
495
            fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
496
            barchart_cnt++;
497
            reset();
498
            break;
499
 
500
        case BEZIER:
501
        /*
502
        @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
503
        @ draw a bezier curve between points, starting from (x_start:y_start)
504
        @ can <b>not</b> be dragged or set onclick
505
        */
506
            if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
507
            decimals = find_number_of_digits(precision);
508
            for(i = 0 ; i < 9; i++){
509
                switch(i){
510
                    case 0: stroke_color = get_color(infile,0);break;
511
                    case 1: double_data[0] = get_real(infile,0);break;/* start x */
512
                    case 2: double_data[1] = get_real(infile,0);break;/* start y */
513
                    case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
514
                    case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
515
                    case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
516
                    case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
517
                    case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
518
                    case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
519
                        string_length = snprintf(NULL,0,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix);
520
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
521
                        snprintf(tmp_buffer,string_length,"draw_bezier(%d,%d,[%f,%f,%f,%f,%f,%f,%f,%f],\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.2f,%d,%s);",STATIC_CANVAS,line_width,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],double_data[6],double_data[7],fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype[0],dashtype[1],use_rotate,angle,use_affine,affine_matrix);
522
                        add_to_buffer(tmp_buffer);
523
                        break;
524
                    default: break;
9427 schaersvoo 525
                }
526
            }
527
            reset();
528
            break;
11806 schaersvoo 529
 
530
 
531
        case BGCOLOR:
9427 schaersvoo 532
        /*
11806 schaersvoo 533
         @ bgcolor colorname or #hex
534
         @ use this color as background of the "div" containing the canvas(es)
9427 schaersvoo 535
        */
11806 schaersvoo 536
        /* [255,255,255]*/
537
            bgcolor = get_string(infile,1);
538
            if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
539
                int found = 0;
540
                for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
541
                    if( strcmp( colors[i].name , bgcolor ) == 0 ){
542
                        bgcolor = colors[i].hex;
543
                        found = 1;
544
                        break;
545
                    }
9427 schaersvoo 546
                }
11806 schaersvoo 547
                if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
548
            }
549
            fprintf(js_include_file,"<!-- set background color of canvas div -->\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
550
            break;
551
 
552
        case BGIMAGE:
553
        /*
554
         @ bgimage image_location
555
         @ use an image as background .<br />technical: we use the background of 'canvas_div'
556
         @ the background image will be resized to match "width = xsize" and "height = ysize"
557
        */
558
        URL = get_string(infile,1);
559
        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);
560
            break;
561
 
562
        case BLINK:
563
        /*
564
         @ blink time(seconds)
565
         @ NOT IMPLEMETED -YET
566
        */
567
            break;
568
 
569
        case BOXPLOT:
570
        /*
571
        @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
572
        @ example:<br />xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245<br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8
573
        @ example:<br />xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245<br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8
574
        @ use command <a href='filled'>'filled'</a> to fill the box<br /><b>note:</b> the strokecolor is used for filling Q1, the fillcolor is used for filling Q3
575
        @ use command <a href='#opacity'>'opacity'</a> to adjust fill_opacity of stroke and fill colours
576
        @ use command <a href='#legend'>'legend'</a> to automatically create a legend <br />unicode allowed in legend<br />use command 'fontfamily' to set the font of the legend.
577
        @ there is no limit to the number of boxplots used.
578
        @ can <b>not</b> be set draggable (<a href='#onclick'>'onclick'</a> is not ready ,yet)
579
        @ use keyword <a href="#userboxplot">'userboxplot'</a> before command boxplot, if a pupil must draw a boxplot (using his own min,Q1,median,Q3,max data)
580
        @ use keyword <a href="#userboxplotdata">'userboxplotdata'</a> before command boxplot, if a pupil must generate the data by some means.
581
        @ use command <a href="#boxplotdata">'boxplotdata'</a> when the boxplot should be drawn from wims-generated raw statistical date
582
        */
583
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
584
            for(i=0;i<8;i++){
585
                switch(i){
586
                    case 0: temp = get_string_argument(infile,0);
587
                            if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
588
                    case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
589
                    case 2:
590
                    if( js_function[DRAW_JSBOXPLOT] == 0 ){
591
                     double_data[1] = get_real(infile,0);
592
                     fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
593
                    }
594
                    else
595
                    {
596
                     double_data[1] = get_real(infile,1);
597
                     double_data[2] = 1;
598
                     double_data[3] = 1;
599
                     double_data[4] = 1;
600
                     double_data[5] = 1;
601
                     double_data[6] = 1;
602
                     double_data[7] = 1;
603
                     i=8;
604
                    }
605
                    break;/* center value x or y */
606
                    case 3: double_data[2] = get_real(infile,0); break;/* min */
607
                    case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
608
                    case 5: double_data[4] = get_real(infile,0); break;/* median */
609
                    case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
610
                    case 7: double_data[6] = get_real(infile,1); break;/* max */
611
                    default:break;
9427 schaersvoo 612
                }
613
            }
614
            decimals = find_number_of_digits(precision);
11806 schaersvoo 615
            /*function draw_boxplot(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)*/
616
            string_length = snprintf(NULL,0,  "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]);
617
            check_string_length(string_length);
618
            tmp_buffer = my_newmem(string_length+1);
619
            snprintf(tmp_buffer,string_length,  "draw_boxplot(%d,%d,%.*f,%.*f,[%.*f,%.*f,%.*f,%.*f,%.*f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d);\n",BOXPLOT_CANVAS+boxplot_cnt,int_data[0],decimals,double_data[0],decimals,double_data[1],decimals,double_data[2],decimals,double_data[3],decimals,double_data[4],decimals,double_data[5],decimals,double_data[6],line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype[0],dashtype[1]);
620
            add_to_buffer(tmp_buffer);
621
            boxplot_cnt++;
622
            reset();
623
        break;
624
        case BOXPLOTDATA:
625
        /*
626
        @ boxplotdata some_data
627
        @ 'some_data' are a list of numbers separated by a comma "," (items)
628
        @ only be used before command 'boxplot': the command <a href="#boxplot">'boxplot'</a> will provide the boxplot drawing of the data.
629
        @ xrange 0,100<br />yrange 0,10<br />boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23<br />boxplot x,4,5
630
        @ note: wims will not check your data input | format. use js-error console to debug any problems.
631
        @ a javascript function 'statistics()' will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function.
632
        */
633
            if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
634
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
635
            fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
636
 
637
        break;
638
 
639
        case CANVASTYPE:
640
         canvas_type = (int) (get_real(infile,1));
641
        /*
642
        @ canvastype TYPE
643
        @ for now only usefull before commands  filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled
644
        @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
645
        @ use another TYPE, if you know what you are doing...
646
        @ other possible canvasses (transparent PNG pictures xsize x ysize on top of each other)<ul><li> EXTERNAL_IMAGE_CANVAS  0</li><li> BG_CANVAS    1</li><li> STATIC_CANVAS        2</li><li> MOUSE_CANVAS 3</li><li> GRID_CANVAS  4</li><li> DRAG_CANVAS  5</li><li> DRAW_CANVAS  6</li><li> TEXT_CANVAS  7</li><li> CLOCK_CANVAS 8</li><li> ANIMATE_CANVAS       9</li><li> TRACE_CANVAS 10</li><li>BOXPLOT_CANVAS 11</li><li> JSPLOT_CANVAS     100  , will increase with every call</li><li> FILL_CANVAS       200  , will increase with every call </li><li> USERDRAW_JSPLOT 300  , will increase with every call </li><li>CLICKFILL_CANVAS 400  , will increase with every call/click</li><li>BOXPLOT_CANVAS 500  , will increase with every call</li></ul>
647
        */
648
        break;
649
 
650
        case CENTERSTRING:
651
        /*
652
         @ centerstring color,y-value,the text string
653
         @ title color,y-value,the text string
654
         @ draw a string centered on the canvas at y = y-value
655
         @ can not be set "onclick" or "drag xy" (...)
656
         @ unicode supported: centerstring red,5,\\u2232
657
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
658
        */
659
            if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
660
            for(i=0;i<3;i++){
661
                switch(i){
662
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
663
                    case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
664
                    case 2: temp = get_string_argument(infile,1);
665
                            /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
666
                            decimals = find_number_of_digits(precision);
667
                            string_length = snprintf(NULL,0,
668
                            "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
669
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
670
                            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);
671
                            add_to_buffer(tmp_buffer);
672
                            break;
673
                    default:break;
674
                }
9427 schaersvoo 675
            }
676
            break;
8386 schaersvoo 677
 
11806 schaersvoo 678
 
8386 schaersvoo 679
        case CIRCLE:
8299 schaersvoo 680
        /*
8386 schaersvoo 681
        @ circle xc,yc,width (2*r in pixels),color
9383 schaersvoo 682
        @ use command 'fcircle xc,yc,d,color'
683
        @ alternative: disk for a filled circle
8386 schaersvoo 684
        @ use command 'fillcolor color' to set the fillcolor
9406 schaersvoo 685
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8386 schaersvoo 686
        @ will shrink / expand on zoom out / zoom in
8299 schaersvoo 687
        */
8386 schaersvoo 688
            for(i=0;i<4;i++){
689
                switch(i){
690
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
691
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
692
                    case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
693
                    case 3: stroke_color = get_color(infile,1);/* name or hex color */
694
                        decimals = find_number_of_digits(precision);
11802 schaersvoo 695
                        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,%s,%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,rotation_center,use_offset);
8386 schaersvoo 696
                        if(onclick > 0){click_cnt++;}
697
                        /* click_cnt++;*/
698
                        reset();
699
                        break;
700
                    default : break;
701
                }
702
            }
703
            break;
704
 
705
        case CIRCLES:
706
        /*
707
        @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
9383 schaersvoo 708
        @ <b>attention</b> r = radius in x-range (!)
709
        @ use keyword 'filled' or command 'fcircles' to produce solid circles
710
        @ alternative : disks for filled circles
8386 schaersvoo 711
        @ use command 'fillcolor color' to set the fillcolor
9406 schaersvoo 712
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (individually)
8386 schaersvoo 713
        @ will shrink / expand on zoom out / zoom in
714
        */
8299 schaersvoo 715
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
716
            fill_color = stroke_color;
8386 schaersvoo 717
            i=1;
8299 schaersvoo 718
            while( ! done ){     /* get next item until EOL*/
719
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
8386 schaersvoo 720
                switch (i%3){
721
                 case 1:double_data[i-1] = get_real(infile,0);break; /* x */
722
                 case 2:double_data[i-1] = get_real(infile,0);break; /* y */
723
                 case 0:double_data[i-1] = get_real(infile,1);break; /* r */
8299 schaersvoo 724
                }
725
                i++;
726
            }
727
            decimals = find_number_of_digits(precision);
8386 schaersvoo 728
            for(c = 0 ; c < i-1 ; c = c+3){
11802 schaersvoo 729
                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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 730
                if(onclick > 0){click_cnt++;}
8386 schaersvoo 731
                /* click_cnt++; */
8299 schaersvoo 732
            }
733
            reset();
734
            break;
11806 schaersvoo 735
        case CLEARBUTTON:
736
        /*
737
         @ clearbutton value
738
         @ alternative : delete
739
         @ alternative : erase
740
         @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text 'value'
741
         @ <b>attention</b> command 'clearbutton' is incompatible with <a href="multidraw">multidraw</a> based drawings<br/>(in 'multidraw' there is always a remove_object_button for every drawprimitive)
742
         @ normally <a href="#userdraw">userdraw</a> 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
743
         @ uses the tooltip placeholder div element: may not be used with command 'intooltip'
744
         @ use command <a href="#inputstyle">'inputstyle'</a> to style the button...
745
         @ the clearbutton will have id="canvas_scripts[%d]" ; starting with %d=0 for the first script<br />to change the style of all "clearbutton" of all included canvasdraw scripts, use something like<br /><em>if(document.getElementById("clearbutton"+canvas_scripts[0])){<br />&nbsp;var p = 0;<br />&nbsp;while(document.getElementById("clearbutton"+canvas_scripts[p])){<br />&nbsp;&nbsp;document.getElementById("clearbutton"+canvas_scripts[p]).className="some_class_name";<br />&nbsp;&nbsp;&lt;!&minus;&minus; or document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); &minus;&minus;&gt;<br />&nbsp;&nbsp;p++;<br />&nbsp;};<br />};<br />
746
        */
747
        if(reply_format == 29){/* eg multidraw is selected */
748
         canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
749
        }
750
            add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
751
        break;
8386 schaersvoo 752
 
11806 schaersvoo 753
        case CLOCK:
7614 schaersvoo 754
        /*
11806 schaersvoo 755
        @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
756
        @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
757
        @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
758
        @ colors are optional: if not defined, default values will be used<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,green,blue,black,yellow
759
        @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
760
        @ 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><li>3: no prefab buttons...create your own buttons (or other means) to make the clock(s) adjustable by javascript function set_clock(num,type,diff)<br />wherein: num = clock id (starts with 0) ; type = 1 (hours) ; type = 2 (minutes) ; type = 3 (seconds) <br />and diff = the increment of 'type' (positive or negative) </li></ul>
761
        @ canvasdraw will not check validity of colornames...the javascript console is your best friend
762
        @ no combinations with other reply_types allowed, for now
763
        @ if interactive is set to '1', 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
764
        @ note: if you need multiple -interactive- clocks on a webpage, use multiple 'clock' commands in a single script !<br />and <i>not multiple canvas scripts</i> in a single page
765
        @ note: clocks will not zoom or pan, when using command <a href='#zoom'>'zoom'</a>
7614 schaersvoo 766
        */
11806 schaersvoo 767
            if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
768
 
769
        /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
770
            for(i=0;i<9;i++){
771
             switch(i){
772
              case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
773
              case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
774
              case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
775
              case 3: int_data[3] = get_real(infile,0);break;/* hours */
776
              case 4: int_data[4] = get_real(infile,0);break;/* minutes */
777
              case 5: int_data[5] = get_real(infile,0);break;/* seconds */
778
              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 */
779
              case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
780
                switch(int_data[7]){
781
                    case 0:break;
782
                    case 1:if(clock_cnt == 0){
783
                           if( reply_format == 0 ){
784
                            reply_format = 18; /* user sets clock */
785
                            /* 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");
786
                               check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
787
                               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");
788
                               add_to_buffer(tmp_buffer);
789
                           */
790
                            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");
791
                           }
792
                           else
793
                           {
794
                            canvas_error("interactive clock may not be used together with other reply_types...");
795
                           }
796
                          }
797
                          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);
798
                    break;
799
                    case 3:if(clock_cnt == 0){
800
                            if( reply_format == 0 ){
801
                             reply_format = 18; /* user sets clock */
802
                             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,1,name.H_color,name.M_color,name.S_color,name.bg_color,name.fg_color);};\n");
803
                            }
804
                            else
805
                            {
806
                             canvas_error("interactive clock may not be used together with other reply_types...");
807
                            }
808
                           }
809
                            /*
810
                            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);
811
                           */
812
                    break;
813
                    case 2:if( reply_format == 0 ){
814
                                reply_format = 19; /* "onclick */
815
                                fprintf(js_include_file,"\n<!-- begin onclick handler for clocks -->\nvar reply = new Array();canvas_div.addEventListener( 'mousedown', user_click,false);\n\nfunction user_click(evt){if(evt.which == 1){var canvas_rect = clock_canvas.getBoundingClientRect();var x = evt.clientX - canvas_rect.left;var y = evt.clientY - canvas_rect.top;var p = 0;var name;var t = true;while(t){try{name = eval('clocks'+p);if( x < name.xc + name.radius && x > name.xc - name.radius ){if( y < name.yc + name.radius && y > name.yc - name.radius ){reply[0] = p;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,\"lightblue\",name.fg_color);};}else{clock_ctx.clearRect(name.xc-name.radius,name.yc-name.radius,name.xc+name.radius,name.yc+name.radius);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);};p++;}catch(e){t=false;};};};};\n");
816
                            }
817
                            else
818
                            {
819
                                if( reply_format != 19){
820
                                   canvas_error("clickable clock(s) may not be used together with other reply_types...");
821
                                 }
822
                            }
823
                     break;
824
                     default: canvas_error("interactive must be set 0,1 or 2");break;
825
                }
826
                break;
827
                case 8:
828
                        if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
829
                            fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
830
                        }
831
                        temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
832
                        if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
833
                        else{
834
                        /* h_color,m_color,s_color,bg_color,fg_color */
835
                        temp = ",black\",\"black\",\"red\",\"white\",\"black";}
836
                        string_length = snprintf(NULL,0,"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);
837
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
838
                        snprintf(tmp_buffer,string_length,"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);
839
                        add_to_buffer(tmp_buffer);
840
                        fprintf(js_include_file,"var clocks%d;",clock_cnt);
841
                        clock_cnt++;
842
                        break;
843
                default:break;
844
             }
845
            }
846
            break;
847
 
848
 
849
        case COLORPALETTE:
850
        /*
851
         @ colorpalette color_name_1,color_name_2,...,color_name_8
852
         @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
853
         @ can be used with command <a href='#userdraw'>'userdraw clickfill,color'</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the pupil can choose from the given colors by clicking small coloured buttons.<br /> the click coordinates and corresponding fillcolor will be stored in read_canvas()...when using the appropriate replyformat.<br />the first color of the palette is color=0
854
         @ make sure to include the 'remove button' by using command <a href='#clearbutton'>clearbutton some_text</a>
855
        */
856
            if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
857
            fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
858
            while( ! done ){
859
                temp = get_color(infile,1);
860
                fprintf(js_include_file,"\"%s\",",temp);
861
            }
862
            fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
863
            add_color_palette(js_include_file,canvas_root_id,input_style);
864
            break;
865
 
866
        case COPY:
867
        /*
868
        @ copy x,y,x1,y1,x2,y2,[filename URL]
869
        @ The image may be "bitmap" or "SVG"
870
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
871
        @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
872
        @ [filename] is the URL of the image
873
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
874
        @ if command <a href="#drag">'drag x/y/xy'</a> 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 valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...'
875
        @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates
876
        @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
877
        @ you may draw / userdraw / drag other stuff on top of an "imported" image
878
        */
879
            for(i = 0 ; i<7;i++){
7614 schaersvoo 880
                switch(i){
11806 schaersvoo 881
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
882
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
883
                    case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
884
                    case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
885
                    case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
886
                    case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
887
                    case 6: URL = get_string(infile,1);
888
                            int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
889
                            int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
890
                            if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
891
                            int_data[9] = click_cnt;
892
                            if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
893
                                 if( reply_format == 0 ){ reply_format = 20; }
894
                                 int_data[8] = 2;/* drag & drop */
895
                            }
896
                            else
897
                            {
898
                                if( onclick == 1  ){
899
                                    reply_format = 20;
900
                                    int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
901
                                    click_cnt++; /* will also be used in dragstuff ! */
902
                                }
903
                                else
904
                                {
905
                                    int_data[8] = 0; /* just static image */
906
                                }
907
                            }
908
/*
909
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,ext_img_cnt,resizable,draggable,click_cnt)
910
*/
911
                            string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%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,int_data[8],int_data[9]);
912
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
913
                            snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%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,int_data[8],int_data[9]);
914
                            drag_type = -1; /* reset the drag_type indicator */
915
                            ext_img_cnt++;
916
                            onclick=0;
917
                            add_to_buffer(tmp_buffer);
918
                            break;
7614 schaersvoo 919
                    default: break;
920
                }
921
            }
922
            break;
11806 schaersvoo 923
/*
924
HTML5 specs:
925
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
926
img     Specifies the image, canvas, or video element to use
927
sx      The x coordinate where to start clipping : x1 = int_data[0]
928
sy      The y coordinate where to start clipping : x2 = int_data[1]
929
swidth  The width of the clipped image : int_data[2] - int_data[0]
930
sheight The height of the clipped image : int_data[3] - int_data[1]
931
x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
932
y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
933
width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
934
height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
935
*/
936
        case COPYRESIZED:
937
        /*
938
        @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
939
        @ The image may be any "bitmap" or "SVG"
940
        @ 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
941
        @ (dx1:dy1) must be left top corner; (dx2 :dy2) must be right bottom corner of inserted image
942
        @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
943
        @ URL is normal URL of network reachable image file location<br />(as seen from public_html-root or network reachable 'http://some_server/my_images/test.gif'<br />(eg no special wims paths are searched !!)
944
        @ if command <a href="#drag">'drag x/y/xy'</a> 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 valid for the next image<br />draggable / non-draggable images may be mixed<br />may be used together with preceding keywords 'snaptogrid','xsnaptogrid','ysnaptogrid' or 'snaptopoints x1,y1,x2,y2...'
945
        @ if keyword <a href="#onclick">'onclick'</a> is set before command 'copy' the image(s) is clickable (marked with a green rectangle around the image)<br />use 'read_dragdrop' to get the number of the clicked image(s)<br />use command 'clearbutton some_text' to reset the reply/click array.<br />example: 4 images; student clicked on image 2 and 3 : reply = 0,1,1,0<br />after clicking the clear button: reply = 0,0,0,0<br />May be mixed with commands 'drag x|y|xy' (use javascript read_canvas to get the new coordinates
946
        @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
947
        @ you may draw / userdraw / drag stuff on top of an "imported" image
948
        */
949
            for(i = 0 ; i<9;i++){
950
                switch(i){
951
                    case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
952
                    case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
953
                    case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
954
                    case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
955
                    case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
956
                    case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
957
                    case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
958
                    case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
959
                    case 8: URL = get_string(infile,1);
960
                            /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
961
                            if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
962
                                canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
963
                            }
964
                            int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
965
                            int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
966
                            int_data[6] = abs(int_data[6] - int_data[4]);/* width */
967
                            int_data[7] = abs(int_data[7] - int_data[5]);/* height */
968
                            if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
969
                            int_data[9] = click_cnt;
970
                            if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
971
                                 if( reply_format == 0 ){ reply_format = 20; }
972
                                 int_data[8] = 2;/* drag & drop */
973
                            }
974
                            else
975
                            {
976
                                if( onclick == 1  ){
977
                                    reply_format = 20;
978
                                    int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
979
                                    click_cnt++; /* will also be used in dragstuff ! */
980
                                }
981
                                else
982
                                {
983
                                    int_data[8] = 0; /* just static image */
984
                                }
985
                            }
986
/*
987
(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
988
URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
989
*/
990
                            string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%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,int_data[8],int_data[9]);
991
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
992
                            snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%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,int_data[8],int_data[9]);
993
                            drag_type = -1; /* reset the drag_type indicator */
994
                            ext_img_cnt++;
995
                            onclick=0;
996
                            add_to_buffer(tmp_buffer);
997
                            break;
998
                    default: break;
999
                }
1000
            }
1001
            break;
8386 schaersvoo 1002
 
11806 schaersvoo 1003
 
1004
        case CROSSHAIR:
8386 schaersvoo 1005
        /*
11806 schaersvoo 1006
        @ crosshair x,y,color
1007
        @ draw a single crosshair point at (x;y) in color 'color'
1008
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
1009
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1010
        */
1011
            for(i=0;i<3;i++){
1012
                switch(i){
1013
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
1014
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
1015
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
1016
                        decimals = find_number_of_digits(precision);
1017
                        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,%s,%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,rotation_center,use_offset);
1018
                        if(onclick > 0){click_cnt++;}
1019
                        /* click_cnt++ */
1020
                        reset();
1021
                        break;
1022
                    default:break;
1023
                }
1024
            }
1025
            break;
1026
 
1027
        case CROSSHAIRS:
1028
        /*
1029
        @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
1030
        @ draw multiple crosshair points at given coordinates in color 'color'
1031
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
9406 schaersvoo 1032
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
8386 schaersvoo 1033
        */
1034
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1035
            fill_color = stroke_color;
1036
            i=0;
1037
            while( ! done ){     /* get next item until EOL*/
1038
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1039
                if(i%2 == 0 ){
1040
                    double_data[i] = get_real(infile,0); /* x */
1041
                }
1042
                else
1043
                {
1044
                    double_data[i] = get_real(infile,1); /* y */
1045
                }
1046
                i++;
1047
            }
1048
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1049
            for(c=0 ; c < i-1 ; c = c+2){
1050
                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,%s,%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,rotation_center,use_offset);
8386 schaersvoo 1051
                if(onclick > 0){click_cnt++;}
11806 schaersvoo 1052
                /* click_cnt++; */
8386 schaersvoo 1053
            }
1054
            reset();
1055
            break;
1056
 
11806 schaersvoo 1057
        case CROSSHAIRSIZE:
7614 schaersvoo 1058
        /*
11806 schaersvoo 1059
        @ crosshairsize int
1060
        @ default 8 (px)
7614 schaersvoo 1061
        */
11806 schaersvoo 1062
            crosshair_size = (int) (get_real(infile,1));
1063
            break;
1064
 
1065
        case CURSOR:
1066
        /*
1067
        @ cursor 'some CSS cursor_style'
1068
        @ alternative : pointer
1069
        @ style can be any valid CSS property value, like crosshair,grabbing,move etc
1070
        @ wims will not check the validity of your cursor declaration
1071
        */
1072
            fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
1073
            break;
1074
 
1075
        case CURVE:
1076
        /*
1077
         @ curve color,formula(x)
1078
         @ alernative : plot color,formula(x)
1079
         @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
1080
         @ use command <a href="#precision">"precision" </a>to ncrease the number of digits of the plotted points
1081
         @ use command <a href="#plotsteps">"plotsteps"</a> to increase / decrease the amount of plotted points (default 150)
1082
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1083
         @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">"jsplot"'</a><br />(command "curve" will only calculate points within the xrange)
1084
        */
1085
            if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
1086
                use_parametric = FALSE;
1087
                stroke_color = get_color(infile,0);
1088
                char *fun1 = get_string_argument(infile,0);
1089
                char *fun2 = get_string_argument(infile,1);
1090
                if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
1091
                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,%s,%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,rotation_center,use_offset);
1092
            }
1093
            else
1094
            {
1095
                stroke_color = get_color(infile,0);
1096
                char *fun1 = get_string_argument(infile,1);
1097
                if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
1098
                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,%s,%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,rotation_center,use_offset);
1099
            }
1100
            if(onclick > 0){click_cnt++;}
1101
            /* click_cnt++; */
1102
            reset();
1103
            break;
1104
 
1105
        case DASHED:
1106
        /*
1107
        @ dashed
1108
        @ keyword (no arguments required)
1109
        @ next object will be drawn with a dashed line
1110
        @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
1111
        */
1112
            use_dashed = TRUE;
1113
            break;
1114
 
1115
        case DASHTYPE:
1116
        /*
1117
        @ dashtype line_width_px,space_width_px
1118
        @ every indiviual object may have its own dashtype, if needed...
1119
        @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
1120
        @ default value "dashtype 2,2" e.g. 2px line and 2px space
1121
        @ html5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
1122
        */
1123
            for(i=0;i<2;i++){
1124
                switch(i){
1125
                    case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
1126
                    case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
1127
                }
1128
            }
1129
        break;
1130
 
1131
        case DIAMONDFILL:
1132
        /*
1133
        @ diamondfill x0,y0,dx,dy,color
1134
        @ x0,y0 in xrange / yrange
1135
        @ distances dx,dy in pixels
1136
        @ ATTENTION: NOT TO BE USED AS ALTERNATIVE FOR FLYDRAW COMMAND
1137
        */
1138
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
7614 schaersvoo 1139
            for(i=0;i<5;i++){
1140
                switch(i){
11806 schaersvoo 1141
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
1142
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
1143
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
1144
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
1145
                    case 4: stroke_color = get_color(infile,1);
1146
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
1147
                    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);
1148
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1149
                    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);
1150
                    add_to_buffer(tmp_buffer);
1151
                    break;
1152
                    default:break;
1153
                }
1154
            }
1155
            reset();
1156
        break;
8224 bpr 1157
 
11806 schaersvoo 1158
        case DOTFILL:
1159
        /*
1160
        @ dotfill x0,y0,dx,dy,color
1161
        @ x0,y0 in xrange / yrange
1162
        @ distances dx,dy in pixels
1163
        @ radius of dots is linewidth
1164
        */
1165
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
11817 schaersvoo 1166
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1167
             js_function[DRAW_FILLTOBORDER] = 1;
1168
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1169
            }
1170
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1171
            for(i=0;i<5;i++){
1172
                switch(i){
11817 schaersvoo 1173
                    case 0: double_data[0] = get_real(infile,0); break; /* x in px */
1174
                    case 1: double_data[1] = get_real(infile,0); break; /* y in py */
1175
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1176
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1177
                    case 4: stroke_color = get_color(infile,1);
1178
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
11817 schaersvoo 1179
                    string_length = snprintf(NULL,0,  "draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
11806 schaersvoo 1180
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11817 schaersvoo 1181
                    snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],int_data[0],int_data[1],line_width,stroke_color,stroke_opacity,xsize,ysize);
11806 schaersvoo 1182
                    add_to_buffer(tmp_buffer);
11817 schaersvoo 1183
                    fill_cnt++;
7614 schaersvoo 1184
                    break;
11806 schaersvoo 1185
                    default:break;
7614 schaersvoo 1186
                }
1187
            }
11806 schaersvoo 1188
            reset();
1189
        break;
1190
 
1191
        case DRAG:
1192
        /*
1193
         @ drag [x][y][xy]
1194
         @ the next object will be draggable in x / y / xy direction
1195
         @ the displacement can be read by 'javascript:read_dragdrop();'
1196
         @ the precision (default 2 decimals) in the student reply may be set with command <a href="#precision">'precision'.</a><br />Use this 'precision' command before this command 'drag x|y|xy' !
1197
         @ 'onclick' and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both )
1198
         @ 'multi_objects' will be numbered in the given x/y-sequence (example: points red,0,0,1,1,2,2,3,3 : point (0:0) is object_number 1)
1199
         @ <b>attention</b>: static objects and 'onclick/drag' objects of the same type (like point,circle,etc) with the same coordinates (e.g. objects that overlap) will give problems in the 'recognition algorithm')<br />in this example<br /><em>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>the blue point will not be recognised as draggable !<br /><em>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue<br /></em>both points will be recognised
1200
         @ the answer is  : drag_or_onclick_object_number : Xorg : Yorg : Xnew : Ynew<br />wherein object_number is the sequence number of the draggable &amp; onclick objects in your script.<br />Only draggable & onclick objects will have an object_number (e.g things like point,crosshair,line,segment,circle,rect,triangle...etc)
1201
         @ use keyword 'snaptogrid' , 'xsnaptogrid' , 'ysnaptogrid' or command 'snaptopoints x1,y1,x2,y2,...' to switch from free to discrete movement
1202
         @ 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.
1203
         @ 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 !!
1204
        */
1205
            temp = get_string(infile,1);
1206
            if(strstr(temp,"xy") != NULL ){
1207
                drag_type = 0;
1208
            }
1209
            else
1210
            {
1211
                if(strstr(temp,"x") != NULL ){
1212
                    drag_type = 1;
1213
                }
1214
                else
1215
                {
1216
                    drag_type = 2;
1217
                }
1218
            }
1219
            /* assuming all drag&drop coordinates the same precision: so set only once */
1220
            if( print_drag_params_only_once == FALSE ){
1221
             fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
1222
             print_drag_params_only_once = TRUE;
1223
            }
1224
            onclick = 2;
1225
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
7614 schaersvoo 1226
            break;
8386 schaersvoo 1227
 
11806 schaersvoo 1228
        case ELLIPSE:
8351 schaersvoo 1229
        /*
11806 schaersvoo 1230
        @ ellipse xc,yc,radius_x,radius_y,color
1231
        @ a ellipse with center xc/yc in x/y-range
1232
        @ radius_x and radius_y are in pixels
9406 schaersvoo 1233
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
11806 schaersvoo 1234
        @ will shrink / expand on zoom out / zoom in
8351 schaersvoo 1235
        */
11806 schaersvoo 1236
            for(i=0;i<5;i++){
1237
                switch(i){
1238
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
1239
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
1240
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
1241
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
1242
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
1243
                        decimals = find_number_of_digits(precision);
1244
                        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,%s,%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,rotation_center,use_offset);
1245
                        if(onclick > 0){click_cnt++;}
1246
                        /* click_cnt++; */
1247
                        reset();
1248
                    break;
1249
                }
1250
            }
1251
            break;
1252
        case FILLALL:
1253
        /*
1254
        @ fillall color,x1,y1,x2,y2...x_n,y_n
1255
        @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
1256
        @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill
1257
        @ use this command  after all boundary objects are declared.
1258
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1259
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1260
        @ note: the fill-family of commands are very (client) cpu intensive operations!<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..
1261
        */
1262
            decimals = find_number_of_digits(precision);
1263
            fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
8351 schaersvoo 1264
            i=0;
11806 schaersvoo 1265
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1266
             js_function[DRAW_FILLTOBORDER] = 1;
1267
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1268
            }
8351 schaersvoo 1269
            while( ! done ){     /* get next item until EOL*/
1270
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1271
                if(i%2 == 0 ){
1272
                    double_data[i] = get_real(infile,0); /* x */
1273
                }
1274
                else
1275
                {
1276
                    double_data[i] = get_real(infile,1); /* y */
11818 schaersvoo 1277
                    string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
11806 schaersvoo 1278
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1279
                    snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[i-1],decimals,double_data[i],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
11806 schaersvoo 1280
                    add_to_buffer(tmp_buffer);
1281
                    fill_cnt++;
8351 schaersvoo 1282
                }
1283
                i++;
1284
            }
11806 schaersvoo 1285
        break;
1286
 
1287
        case FILLED:
1288
        /*
1289
        @ filled
1290
        @ keyword (no arguments required)
1291
        @ the next 'fillable' object (only) will be filled
1292
        @ use command "fillcolor color" to set fillcolor
1293
        @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
1294
        @ 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 !
1295
        */
1296
            use_filled = TRUE;
1297
            break;
1298
 
1299
        case FILLCOLOR:
1300
        /*
1301
        @ fillcolor colorname or #hex
1302
        @ set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
1303
        @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
1304
        */
1305
            fill_color = get_color(infile,1);
1306
            break;
1307
 
1308
        case FILLTOBORDER:
1309
        /*
1310
        @ filltoborder x,y,bordercolor,color
1311
        @ fill the region  of point (x:y)  with color 'color'
1312
        @ any other color will not act as border to the bucket fill
1313
        @ use this command  after all boundary objects are declared.
1314
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1315
        @ 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..
1316
        @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
1317
        */
1318
            for(i=0 ;i < 4 ; i++){
1319
                switch(i){
1320
                    case 0:double_data[0] = get_real(infile,0);break;
1321
                    case 1:double_data[1] = get_real(infile,0);break;
1322
                    case 2:bgcolor = get_color(infile,0);break;
1323
                    case 3:fill_color = get_color(infile,1);
1324
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1325
                                js_function[DRAW_FILLTOBORDER] = 1;
1326
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1327
                           }
1328
                           decimals = find_number_of_digits(precision);
1329
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
11818 schaersvoo 1330
                           string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
11806 schaersvoo 1331
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1332
                           snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],bgcolor,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
11806 schaersvoo 1333
                           add_to_buffer(tmp_buffer);
1334
                           fill_cnt++;
1335
                           break;
1336
                    default:break;
8351 schaersvoo 1337
                }
11806 schaersvoo 1338
            }
1339
            reset();
1340
        break;
1341
        case FLOODFILL:
1342
        /*
1343
        @ floodfill x,y,color
1344
        @ alternative : fill x,y,color
1345
        @ fill the region of point (x:y) with color 'color'
1346
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
1347
        @ use this command  after all boundary objects are declared.
1348
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1349
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1350
        @ 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..
1351
        */
1352
            for(i=0 ;i < 4 ; i++){
1353
                switch(i){
1354
                    case 0:double_data[0] = get_real(infile,0);break;
1355
                    case 1:double_data[1] = get_real(infile,0);break;
1356
                    case 2:fill_color = get_color(infile,1);
1357
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1358
                                js_function[DRAW_FILLTOBORDER] = 1;
1359
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1360
                           }
1361
                           decimals = find_number_of_digits(precision);
1362
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
11818 schaersvoo 1363
                           string_length = snprintf(NULL,0,  "setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
11806 schaersvoo 1364
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1365
                           snprintf(tmp_buffer,string_length,"setTimeout(function(){filltoborder(%.*f,%.*f,[%s,%d],[%s,%d],%d,false,null);},1000);\n",decimals,double_data[0],decimals,double_data[1],fill_color,(int) (fill_opacity/0.0039215),fill_color,(int) (fill_opacity/0.0039215),FILL_CANVAS+fill_cnt);
11806 schaersvoo 1366
                           add_to_buffer(tmp_buffer);
1367
                           fill_cnt++;
1368
                           break;
1369
                    default:break;
1370
                }
1371
            }
1372
            reset();
1373
        break;
1374
 
1375
        case FONTCOLOR:
1376
        /*
1377
         @ fontcolor color
1378
         @ color: hexcolor or colorname
1379
         @ default: black
1380
         @ example usage: x/y-axis text
1381
        */
1382
            font_color = get_color(infile,1);
1383
            break;
1384
 
1385
        case FONTFAMILY:
1386
        /*
1387
         @ fontfamily font_description
1388
         @ set the font family; for browsers that support it
1389
         @ font_description: Ariel ,Courier, Helvetica etc
1390
         @ 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
1391
         @ use correct syntax : 'font style' 'font size'px 'fontfamily'
1392
        */
1393
            font_family = get_string(infile,1);
1394
            break;
1395
 
1396
        case FONTSIZE:
1397
        /*
1398
         @ fontsize font_size
1399
         @ default value 12
1400
         @ note:for some macro's (like grid | legend | xaxistext | xlabel etc) sometimes command <a href="#fontfamily">"fontfamily"</a> can be used for some specific font-setting<br />this is however not always very straight forward...so just try and see what happens
1401
        */
1402
            font_size = (int) (get_real(infile,1));
1403
            break;
1404
 
1405
        case FUNCTION_LABEL:
1406
        /*
1407
         @ functionlabel 'some string'
1408
         @ default value "f(x)="
1409
         @ no mathml allowed (just ascii string)
1410
         @ use command 'fontsize int' to adjust the size
1411
         @ use command 'strokecolor colorname' to adjust the labels (individually, if needed)
1412
         @ if needed, use before every command 'userinput function | inputfield | textarea'
1413
        */
1414
            function_label = get_string_argument(infile,1);
1415
            break;
1416
 
1417
        case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/
1418
        /*
1419
         @ grid step_x,step_y,gridcolor
1420
         @ if keywords <a href="#axis">"axis"</a> or <a href="#axisnumbering">"axisnumbering"</a> 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
1421
         @ in that case, use command <a href="#fontcolor">"fontcolor"</a>, <a href="#fontsize">"fontsize"</a> and / or <a href="#fontfamily">"fontfamily"</a> to adjust font <br />defaults: black,12,Ariel
1422
         @ 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)
1423
         @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a>
1424
         @ use commands <a href="#xlabel">'xlabel some_string'</a> and/or <a href="#ylabel">'ylabel some_string'</a> to label axis;<br />use command "fontsize" to adjust size:the font family is non-configurable 'italic your_fontsize px Ariel' !
1425
         @ see commands (see <a href="#xaxis">"xaxis" or xaxistext"</a>, <a href="#yaxis">"yaxis" or "yaxistext"</a> to set tailormade values on axis (the used font is set by <a href="fontfamily">command fontfamily</a>; default '12px Ariel')
1426
         @ see command <a href="#legend">"legend"</a>to set a legend for the graph ;<br />use command <a href="#fontsize">"fontsize"</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
1427
        */
1428
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
1429
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
1430
            for(i=0;i<4;i++){
1431
                switch(i){
1432
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
1433
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
1434
                    case 2:
1435
                    if( use_axis == TRUE ){
1436
                        stroke_color = get_color(infile,0);
1437
                        done = FALSE;
1438
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
1439
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
1440
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
1441
                        fill_color = get_color(infile,1); /* used as axis_color*/
8351 schaersvoo 1442
                    }
1443
                    else
1444
                    {
11806 schaersvoo 1445
                        int_data[0] = 1;
1446
                        int_data[1] = 1;
1447
                        stroke_color = get_color(infile,1);
1448
                        fill_color = stroke_color;
8351 schaersvoo 1449
                    }
11806 schaersvoo 1450
                    if( double_data[0] <= 0 ||  double_data[1] <= 0 ||  int_data[0] <= 0 ||  int_data[1] <= 0 ){canvas_error("major or minor ticks must be positive !");}
1451
                    /* set snap_x snap_y values in pixels */
1452
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
1453
                    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);
1454
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1455
                    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);
1456
                    add_to_buffer(tmp_buffer);
1457
                    break;
8351 schaersvoo 1458
                }
1459
            }
1460
            reset();
1461
            break;
11806 schaersvoo 1462
        case GRIDFILL:
1463
        /*
1464
        @ gridfill x0,y0,dx,dy,color
1465
        @ x0,y0 in xrange / yrange
1466
        @ distances dx,dy in pixels
1467
        @ a draggable object may <a href="#snaptogrid">snap_to_grid</a> (using keywords snaptogrid,xsnaprogrid, ysnaptogrid or snaptopoints)
1468
        @ userdraw object may snap_to_grid
1469
        */
1470
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
1471
            for(i=0;i<5;i++){
1472
                switch(i){
1473
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
1474
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
1475
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
1476
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
1477
                    case 4: stroke_color = get_color(infile,1);
1478
                    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);
1479
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1480
                    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);
1481
                    add_to_buffer(tmp_buffer);
1482
                    break;
1483
                    default:break;
1484
                }
1485
            }
1486
            reset();
1487
        break;
8386 schaersvoo 1488
 
8244 schaersvoo 1489
        case HALFLINE:
1490
        /*
1491
        @ demiline x1,y1,x2,y2,color
1492
        @ alternative : halfline
1493
        @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
9406 schaersvoo 1494
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8244 schaersvoo 1495
        */
1496
            for(i=0;i<5;i++){
1497
                switch(i){
1498
                    case 0: double_data[0]= get_real(infile,0);break; /* x-values */
1499
                    case 1: double_data[1]= get_real(infile,0);break; /* y-values */
1500
                    case 2: double_data[10]= get_real(infile,0);break; /* x-values */
1501
                    case 3: double_data[11]= get_real(infile,0);break; /* y-values */
1502
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
1503
                    if(double_data[0] == double_data[10]){ /* vertical halfline */
1504
                        if(double_data[1] < double_data[11]){
1505
                         double_data[3] = ymax + 1000;
1506
                        }
1507
                        else
1508
                        {
1509
                         double_data[3] = ymin - 1000;
1510
                        }
10953 bpr 1511
                        double_data[2] = double_data[0];
8244 schaersvoo 1512
                    }
1513
                    else
1514
                    { /* horizontal halfline*/
1515
                     if( double_data[1] == double_data[11] ){
1516
                      if( double_data[0] < double_data[10] ){
1517
                        double_data[2] = xmax + 1000; /* halfline to the right */
1518
                      }
1519
                      else
1520
                      {
1521
                        double_data[2] = xmin - 1000; /* halfline to the left */
1522
                      }
1523
                      double_data[3] = double_data[1];
1524
                     }
1525
                     else
1526
                     {
1527
                      /* any other halfline */
1528
                      /* slope */
1529
                      double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
1530
                      /* const */
1531
                      double_data[13] = double_data[1] - double_data[12]*double_data[0];
1532
                      if( double_data[0] < double_data[10] ){
1533
                       double_data[2] = double_data[2] + 1000;
1534
                      }
1535
                      else
1536
                      {
1537
                       double_data[2] = double_data[2] - 1000;
1538
                      }
1539
                      double_data[3] = double_data[12]*double_data[2] + double_data[13];
1540
                     }
10953 bpr 1541
                    }
8244 schaersvoo 1542
                    decimals = find_number_of_digits(precision);
11802 schaersvoo 1543
                    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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 1544
                    if(onclick > 0){click_cnt++;}
1545
                    /* click_cnt++; */
1546
                    reset();
8244 schaersvoo 1547
                    break;
1548
                }
1549
            }
1550
            break;
8386 schaersvoo 1551
 
8365 schaersvoo 1552
        case HALFLINES:
1553
        /*
1554
        @ demilines color,x1,y1,x2,y2,....
1555
        @ alternative : halflines
1556
        @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc
9406 schaersvoo 1557
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
8365 schaersvoo 1558
        */
1559
            stroke_color=get_color(infile,0);
1560
            fill_color = stroke_color;
1561
            i=0;
1562
            while( ! done ){     /* get next item until EOL*/
1563
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1564
                if(i%2 == 0 ){
1565
                    double_data[i] = get_real(infile,0); /* x */
1566
                }
1567
                else
1568
                {
1569
                    double_data[i] = get_real(infile,1); /* y */
1570
                }
1571
                i++;
1572
            }
1573
            decimals = find_number_of_digits(precision);
1574
            for(c = 0 ; c < i-1 ; c = c+4){
1575
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
1576
                    if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
1577
                        double_data[c+3] = ymax + 1000;
1578
                    }
1579
                    else
1580
                    {
1581
                     double_data[c+3] = ymin - 1000;/* descending halfline */
1582
                    }
1583
                }
1584
                else
1585
                {
1586
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
1587
                        if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
1588
                            double_data[c+2] = xmax+100;
1589
                        }
1590
                        else
1591
                        {
1592
                            double_data[c+2] = xmin-1000; /* halfline to the right */
1593
                        }
1594
                    }
1595
                    else
1596
                    {
1597
                        /* m */
1598
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
1599
                        /* q */
1600
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
1601
                        if(double_data[c] < double_data[c+2]){ /* to the right */
1602
                            double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */
1603
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1604
                        }
1605
                        else
1606
                        { /* to the left */
1607
                            double_data[c+2] = xmin - 1000;
1608
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1609
                        }
1610
                    }
1611
                }
11802 schaersvoo 1612
                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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 1613
                if(onclick > 0){click_cnt++;}
1614
                /* click_cnt++; */
8365 schaersvoo 1615
            }
1616
            reset();
1617
            break;
11806 schaersvoo 1618
        case HATCHFILL:
1619
        /*
1620
        @ hatchfill x0,y0,dx,dy,color
1621
        @ x0,y0 in xrange / yrange
1622
        @ distances dx,dy in pixels
1623
        */
1624
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
1625
            for(i=0;i<5;i++){
1626
                switch(i){
1627
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
1628
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
1629
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* dx pixel */
1630
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* dy pixel*/
1631
                    case 4: stroke_color = get_color(infile,1);
1632
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
1633
                    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);
1634
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1635
                    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);
1636
                    add_to_buffer(tmp_buffer);
1637
                    break;
1638
                    default:break;
1639
                }
1640
            }
1641
            reset();
1642
        break;
8386 schaersvoo 1643
 
8224 bpr 1644
        case HLINE:
7614 schaersvoo 1645
        /*
1646
        @ hline x,y,color
9383 schaersvoo 1647
        @ alternative : horizontalline
7614 schaersvoo 1648
        @ draw a horizontal line through point (x:y) in color 'color'
9373 schaersvoo 1649
        @ or use command <a href='#curve'>'curve color,formula'</a> to draw the line <br />(uses more points to draw the line; is however better draggable)
9406 schaersvoo 1650
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 1651
        */
1652
            for(i=0;i<3;i++) {
1653
                switch(i){
1654
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
1655
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
1656
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
1657
                    double_data[3] = double_data[1];
1658
                    decimals = find_number_of_digits(precision);
11802 schaersvoo 1659
                    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,%s,%d));\n",click_cnt,onclick,drag_type,decimals,100*xmin,decimals,100*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,rotation_center,use_offset);
8379 schaersvoo 1660
                    if(onclick > 0){click_cnt++;}
1661
                    /* click_cnt++; */
1662
                    reset();
7614 schaersvoo 1663
                    break;
1664
                }
1665
            }
1666
            break;
8366 schaersvoo 1667
 
1668
        case HLINES:
1669
        /*
1670
        @ hlines color,x1,y1,x2,y2,...
9383 schaersvoo 1671
        @ alternative : horizontallines
8366 schaersvoo 1672
        @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
9406 schaersvoo 1673
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
8366 schaersvoo 1674
        */
1675
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1676
            fill_color = stroke_color;
1677
            i=0;
1678
            while( ! done ){     /* get next item until EOL*/
1679
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1680
                if(i%2 == 0 ){
1681
                    double_data[i] = get_real(infile,0); /* x */
1682
                }
1683
                else
1684
                {
1685
                    double_data[i] = get_real(infile,1); /* y */
1686
                }
1687
                i++;
1688
            }
1689
            decimals = find_number_of_digits(precision);
1690
            for(c = 0 ; c < i-1 ; c = c+2){
11802 schaersvoo 1691
                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,%s,%d));\n",click_cnt,onclick,drag_type,decimals,xmin,decimals,xmax,decimals,double_data[c+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,rotation_center,use_offset);
8379 schaersvoo 1692
                if(onclick > 0){click_cnt++;}
1693
                /* click_cnt++; */
8366 schaersvoo 1694
            }
1695
            reset();
1696
            break;
11806 schaersvoo 1697
        case HTTP:
7614 schaersvoo 1698
        /*
11806 schaersvoo 1699
         @ http x1,y1,x2,y2,http://some_adress.com
1700
         @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
1701
         @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
1702
         @ can <b>not</b> be 'set onclick' or 'drag xy'
7614 schaersvoo 1703
        */
11806 schaersvoo 1704
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
1705
            for(i=0;i<5;i++){
7614 schaersvoo 1706
                switch(i){
11806 schaersvoo 1707
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1708
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1709
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1710
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1711
                    case 4: decimals = find_number_of_digits(precision);
1712
                            temp = get_string(infile,1);
1713
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
1714
                            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);
1715
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
1716
                            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);
1717
                            add_to_buffer(tmp_buffer);
7614 schaersvoo 1718
                    break;
1719
                }
1720
            }
11806 schaersvoo 1721
            reset();
7614 schaersvoo 1722
            break;
11806 schaersvoo 1723
        case HTML:
8366 schaersvoo 1724
        /*
11806 schaersvoo 1725
         @ html x1,y1,x2,y2,html_string
1726
         @ all tags are allowed<br /> html-code using inputfields could be read using your own javascript-code. Do not use id's like 'canvas_input0' etc.
1727
         @ can be set onclick <br />(however dragging not supported)
8366 schaersvoo 1728
        */
11806 schaersvoo 1729
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
1730
            for(i=0;i<5;i++){
1731
                switch(i){
1732
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1733
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1734
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
1735
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
1736
                    case 4: decimals = find_number_of_digits(precision);
1737
                            temp = get_string(infile,1);
1738
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
1739
                            string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
1740
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1741
                            snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
1742
                            add_to_buffer(tmp_buffer);
1743
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
1744
                            break;
1745
                    default:break;
8366 schaersvoo 1746
                }
1747
            }
1748
            reset();
1749
            break;
8386 schaersvoo 1750
 
11806 schaersvoo 1751
        case IMAGEFILL:
7614 schaersvoo 1752
        /*
11806 schaersvoo 1753
        @ imagefill dx,dy,image_url
1754
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
1755
        @ After pattern filling ,the fill-color should be reset !
1756
        @ wims getins / image from class directory : imagefill 80,80,my_image.gif
1757
        @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
1758
        @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
1759
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
7614 schaersvoo 1760
        */
11806 schaersvoo 1761
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
1762
            for(i=0 ;i < 3 ; i++){
7614 schaersvoo 1763
                switch(i){
11806 schaersvoo 1764
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
1765
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
1766
                    case 2: URL = get_string_argument(infile,1);
1767
                            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);
1768
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1769
                            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);
1770
                            add_to_buffer(tmp_buffer);
1771
                    break;
7614 schaersvoo 1772
                }
1773
            }
11806 schaersvoo 1774
            reset();
1775
        break;
1776
 
1777
        case INPUTSTYLE:
1778
        /*
1779
        @ inputstyle style_description
1780
        @ may be used before any 'style-able' html object.(like inputfields or buttons)<br />or any html objects that are generated by some canvasdraw commands
1781
        @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
1782
        */
1783
            input_style = get_string(infile,1);
7614 schaersvoo 1784
            break;
11806 schaersvoo 1785
        case INPUT:
1786
        /*
1787
         @ input x,y,size,editable,value
1788
         @ to set inputfield "readonly", use editable = 0
1789
         @ only active inputfields (editable = 1) will be read with read_canvas();
1790
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'</a>
1791
         @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...)
1792
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
1793
         @ use keyword <a href='#xoffset'>xoffset | centered</a> if the inputfield should be centered on (x:y)<br /> default is the left top corner is (x:y)
1794
        */
1795
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
1796
            for(i = 0 ; i<5;i++){
1797
                switch(i){
1798
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
1799
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
1800
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
1801
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
1802
                    case 4:
1803
                            temp = get_string_argument(infile,1);
1804
                            string_length = snprintf(NULL,0,  "draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset);
1805
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1806
                            snprintf(tmp_buffer,string_length,"draw_inputs(%d,%d,%d,%d,%d,%d,\"%s\",\"%s\",%d);\n",canvas_root_id,input_cnt,int_data[0],int_data[1],int_data[2],int_data[3],input_style,temp,use_offset);
1807
                            add_to_buffer(tmp_buffer);
1808
                            input_cnt++;break;
1809
                    default: break;
1810
                }
1811
            }
1812
            if(reply_format == 0 ){reply_format = 15;}
1813
            reset();
1814
            break;
8386 schaersvoo 1815
 
11806 schaersvoo 1816
        case INTOOLTIP:
1817
            /*
1818
            @ intooltip link_text
1819
            @ link_text is a single line (span-element)
1820
            @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg'
1821
            @ link_text may contain HTML markup
1822
            @ the canvas will be displayed in a tooltip on 'link_text'
1823
            @ the canvas is default transparent: use command <a href="#bgcolor">'bgcolor color'</a> to adjust background-color<br />the link text will also be shown with this 'bgcolor'.
1824
            @ many 'userinput stuff' will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefor these commands are mutually exclusive.<br />keep this in mind...
1825
            */
1826
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
1827
            if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
1828
            tooltip_text = get_string(infile,1);
1829
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
1830
            use_tooltip = 1;
1831
            break;
1832
 
1833
        case JSCURVE:
7614 schaersvoo 1834
        /*
11806 schaersvoo 1835
         @ jscurve color,formula(x)
1836
         @ alternative : jsplot color,formula(x)
1837
         @ your function will be plotted by the javascript engine of the client browser.
1838
         @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
1839
         @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
1840
         @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
1841
         @ no validity check is done by wims.
1842
         @ 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
1843
         @ zooming & panning is better than for curves produced by command <a href="#curve">curve color,formula</a> because for avery change in x/y-range the curve is recalculated in javascript
1844
         @ use command 'trace_jscurve formula(x)` for tracing
1845
         @ use command 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
1846
         @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
1847
         @ commands plotjump / plotstep are not active for 'jscurve'
1848
         @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
1849
         @ plotting multiple js-curves on the same canvas <br/>(for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111 ,use :<br/> jscurve red,fun1(x),fun2(x)...fun_n(x)<br />  you want to specify individual colors | opacity | linewidth for these multiple js-curves.<br />use commands like: <a href="#multistrokecolors">multistrokecolors</a>,<a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a><br />, <a href="multistrokeopacity">multistroke</a><br />the <b>color</b> given for the command "jscurve <b>color</b>,formulas(x)" will not be used in that case...<br />but the color argument must still be given in any case (otherwise syntax error...)
1850
        */
1851
            stroke_color = get_color(infile,0);
1852
            if( use_js_math == FALSE){/* add this stuff only once...*/
1853
                add_to_js_math(js_include_file);
1854
                use_js_math = TRUE;
1855
            }
1856
            if( use_js_plot == FALSE){
1857
                use_js_plot = TRUE;
1858
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1859
            }
1860
            temp = get_string(infile,1);
1861
            temp = str_replace(temp,",","\",\"");
1862
            string_length = snprintf(NULL,0,  "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1863
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1864
            snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
1865
            add_to_buffer(tmp_buffer);
1866
            jsplot_cnt++;
1867
             /* we need to create multiple canvasses, so we may zoom and pan ?? */
1868
        break;
1869
 
1870
        case JSMATH:
1871
        /*
1872
            @ jsmath some_math_function
1873
            @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
1874
            @ 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
1875
            @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y'
1876
            @ example: jsmath sin(x^2)
1877
            @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead 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...
1878
            @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
1879
        */
1880
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
1881
            if( use_js_math == FALSE){
1882
                add_to_js_math(js_include_file);
1883
                use_js_math = TRUE;
1884
            }
1885
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
1886
            break;
1887
        case KILLAFFINE:
1888
        /*
1889
        @ killaffine
1890
        @ keyword : resets the transformation matrix to 1,0,0,1,0,0
1891
        */
1892
            use_affine = FALSE;
1893
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
1894
            break;
1895
 
1896
        case KILLROTATE:
1897
        /*
1898
         @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
1899
         @ a following rotate command will have the first object point as rotation center
1900
         @ if not set, the rotation center will remain unchanged
1901
        */
1902
            rotation_center= my_newmem(6);
1903
            snprintf(rotation_center,5,"null");
1904
         break;
1905
 
1906
        case KILLSLIDER:
1907
        /*
1908
         @ killslider
1909
         @ keyword (no arguments required)
1910
         @ ends grouping of object under a previously defined slider
1911
        */
1912
            slider = 0;
1913
            break;
1914
 
1915
        case KILLTRANSLATION:
1916
        /*
1917
         @ killtranslation
1918
         @ alternative : killtranslate
1919
         @ resets the translation matrix to 1,0,0,1,0,0
1920
        */
1921
            use_affine = FALSE;
1922
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
1923
            break;
1924
 
1925
        case LINE:
1926
        /*
1927
        @ line x1,y1,x2,y2,color
1928
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
1929
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
9406 schaersvoo 1930
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 1931
        */
8386 schaersvoo 1932
            for(i=0;i<5;i++){
7614 schaersvoo 1933
                switch(i){
11806 schaersvoo 1934
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
1935
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
1936
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
1937
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
1938
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
1939
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
1940
                        double_data[1] = xmin;
1941
                        double_data[3] = ymax;
1942
                        double_data[0] = double_data[10];
1943
                        double_data[2] = double_data[10];
1944
                    }
1945
                    else
1946
                    {
1947
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
1948
                            double_data[1] = double_data[11];
1949
                            double_data[3] = double_data[11];
1950
                            double_data[0] = ymin;
1951
                            double_data[2] = xmax;
1952
                        }
1953
                        else
1954
                        {
1955
                        /* m */
1956
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
1957
                        /* q */
1958
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
1959
 
1960
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
1961
 
1962
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
1963
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
1964
                            double_data[0] = xmin;
1965
                            double_data[2] = xmax;
1966
                        }
1967
                    }
1968
                    decimals = find_number_of_digits(precision);
1969
                    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,%s,%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,rotation_center,use_offset);
1970
                    if(onclick > 0){click_cnt++;}
1971
                    /* click_cnt++;*/
1972
                    reset();
1973
                    break;
7614 schaersvoo 1974
                }
1975
            }
1976
            break;
8386 schaersvoo 1977
 
11806 schaersvoo 1978
        case LINES:
8370 schaersvoo 1979
        /*
11806 schaersvoo 1980
        @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
1981
        @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
1982
        @ or use multiple commands 'curve color,formula' or "jscurve color,formule" to draw the line <br />(uses more points to draw the line; is however better draggable)
1983
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1984
        @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a>
8370 schaersvoo 1985
        */
1986
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1987
            fill_color = stroke_color;
1988
            i=0;
1989
            while( ! done ){     /* get next item until EOL*/
1990
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1991
                if(i%2 == 0 ){
1992
                    double_data[i] = get_real(infile,0); /* x */
1993
                }
1994
                else
1995
                {
1996
                    double_data[i] = get_real(infile,1); /* y */
1997
                }
1998
                i++;
1999
            }
2000
            decimals = find_number_of_digits(precision);
2001
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 2002
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
2003
                    double_data[c+1] = xmin;
2004
                    double_data[c+3] = ymax;
2005
                    double_data[c+2] = double_data[c];
2006
                }
2007
                else
2008
                {
2009
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
2010
                        double_data[c+3] = double_data[c+1];
2011
                        double_data[c] = ymin;
2012
                        double_data[c+2] = xmax;
2013
                    }
2014
                    else
2015
                    {
2016
                        /* m */
2017
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
2018
                        /* q */
2019
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
2020
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
2021
                        double_data[c+1] = (m)*(xmin)+(q);
2022
                        double_data[c+3] = (m)*(xmax)+(q);
2023
                        double_data[c] = xmin;
2024
                        double_data[c+2] = xmax;
2025
                    }
2026
                }
2027
                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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 2028
                if(onclick > 0){click_cnt++;}
2029
                /* click_cnt++; */
8370 schaersvoo 2030
            }
2031
            reset();
2032
            break;
8386 schaersvoo 2033
 
11806 schaersvoo 2034
 
2035
        case LINEWIDTH:
7614 schaersvoo 2036
        /*
11806 schaersvoo 2037
        @ linewidth int
2038
        @ default 1
7614 schaersvoo 2039
        */
11806 schaersvoo 2040
            line_width = (int) (get_real(infile,1));
2041
            break;
2042
 
2043
        case LATTICE:
2044
        /*
2045
         @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
2046
         @ can <b>not</b> be set "onclick" or "drag xy"
2047
        */
2048
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
2049
            for( i = 0; i<9; i++){
7614 schaersvoo 2050
                switch(i){
11806 schaersvoo 2051
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
2052
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
2053
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
2054
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
2055
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
2056
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
2057
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
2058
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
2059
                    case 8: stroke_color=get_color(infile,1);
7614 schaersvoo 2060
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 2061
                        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);
2062
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2063
                        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);
2064
                        add_to_buffer(tmp_buffer);break;
2065
                    default:break;
7614 schaersvoo 2066
                }
2067
            }
11806 schaersvoo 2068
            reset();
7614 schaersvoo 2069
            break;
8363 schaersvoo 2070
 
11806 schaersvoo 2071
        case LEVELCURVE:
8363 schaersvoo 2072
        /*
11806 schaersvoo 2073
        @ levelcurve color,expression in x/y,l1,l2,...
2074
        @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
2075
        @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
2076
        @ 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
2077
        @ note : the arrays for holding the javascript data are limited in size
2078
        @ note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
8363 schaersvoo 2079
        */
11806 schaersvoo 2080
            fill_color = get_color(infile,0);
2081
            char *fun1 = get_string_argument(infile,0);
2082
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
2083
            i = 0;
2084
            done = FALSE;
2085
            while( !done ){
2086
             double_data[i] = get_real(infile,1);
2087
             i++;
2088
            }
2089
            for(c = 0 ; c < i; c++){
2090
             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,%s,%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,rotation_center,use_offset);
2091
             if(onclick > 0){click_cnt++;}
2092
             /* click_cnt++; */
2093
            }
2094
            reset();
2095
            break;
8386 schaersvoo 2096
 
11806 schaersvoo 2097
        case LEGEND:
2098
        /*
2099
        @ legend string1:string2:string3....string_n
2100
        @ will be used to create a legend for a graph
2101
        @ also see command <a href='#piechart'>'piechart'</a>
2102
        @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default
2103
        @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend")
2104
        */
2105
            temp = get_string(infile,1);
2106
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2107
            legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
2108
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
2109
            break;
2110
 
2111
        case LEGENDCOLORS:
2112
        /*
2113
        @ legendcolors color1:color2:color3:...:color_n
2114
        @ 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
2115
        @ make sure the number of colours match the number of legend items
2116
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
2117
        */
2118
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
2119
            temp = get_string(infile,1);
2120
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2121
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
2122
            break;
2123
 
2124
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
2125
        /*
2126
        @ linegraph x1:y1:x2:y2...x_n:y_n
2127
        @ will plot your data in a graph
2128
        @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
2129
        @ can be used together with freestyle x-axis/y-axis texts : see commands <a href='#xaxis'>'xaxis'</a>,<a href='#xaxisup'>'xaxisup'</a> and <a href='#yaxis'>'yaxis'</a>
2130
        @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
2131
        @ also see command <a href='#piechart'>'piechart'</a>
2132
        @ multiple linegraphs may be used in a single plot
2133
        @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
2134
        @ <ul><li>use command <a href='#strokecolor'>'strokecolor'</a> before a command 'linegraph' to set the color of this graph</li><li>use command <a href='#linewidth'>'linewidth'</a> before command 'linegraph' to set linewidth of this graph</li><li>use keyword <a href='#dashed'>'dashed'</a> before command 'linegraph' to set dashing of the graph</li><li>if dashing is set, use command <a href='#dashtype'>'dashtype'</a> before command 'linegraph' to set the type of dashing of the (individual) graph</li></ul>
2135
        */
2136
            temp = get_string(infile,1);
2137
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2138
            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);
2139
            linegraph_cnt++;
2140
            reset();
2141
            break;
2142
 
2143
        case MATHML:
2144
        /*
2145
        @ mathml x1,y1,x2,y2,mathml_string
2146
        @ mathml will be displayed in a rectangle left top (x1:y1)...<br />x2 and y2 are still needed, but not used as the right bottom corner of the embedded div element.
2147
        @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor  of the mathml object
2148
        @ can be set onclick <br />javascript:read_dragdrop(); will return click numbers of mathml-objects<br />if 4 click_able object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
2149
        @ can be set draggable<br /> the javascript:read_dragdrop() will return all coordinates <br />in same order as the canvas script: unmoved object will have their original coordinates...
2150
        @ snaptogrid is supported...snaptopoints will work, but use with care...due to the primitive dragging<br />technically: the dragstuff library is not used...the mathml is embedded in a new div element and not in the html5-canvas
2151
        @ when clicked, the mathml object will be drawn in red color; the div background color will be determined by the <a href="#fillcolor">'fillcolor'</a> and <a href="#opacity">'opacity'</a> settings
2152
        @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
2153
        @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick  mathml
2154
        @ other drag objects (circles/rects etc) are supported , but read_dragdrop() will probably be difficult to interpret...
2155
        @ 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 /><b>attention</b>: if after this mathml-input object other user-interactions are included, these will read mathml too using "read_canvas();"
2156
        @ 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....
2157
        */
2158
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
2159
            for(i=0;i<5;i++){
2160
                switch(i){
2161
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
2162
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
2163
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
2164
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
2165
                    case 4: decimals = find_number_of_digits(precision);
2166
                            temp = get_string(infile,1);
2167
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
2168
                            string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
2169
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2170
                            snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity);
2171
                            add_to_buffer(tmp_buffer);
2172
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
2173
                            /*
2174
                             in case inputs are present , trigger adding the read_mathml()
2175
                             if no other reply_format is defined
2176
                             note: all other reply types will include a reading of elements with id='mathml'+p)
2177
                             */
2178
                            if(strstr(temp,"mathml0") != NULL){
2179
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
2180
                            }
2181
                            break;
2182
                    default:break;
2183
                }
2184
            }
2185
            reset();
2186
            break;
2187
 
2188
        case MOUSE:
2189
        /*
2190
         @ mouse color,fontsize
2191
         @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
2192
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2193
 
2194
        */
2195
            stroke_color = get_color(infile,0);
2196
            font_size = (int) (get_real(infile,1));
2197
            tmp_buffer = my_newmem(26);
2198
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2199
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
2200
            break;
2201
 
2202
 
2203
        case MOUSE_DEGREE:
2204
        /*
2205
         @ mouse_degree color,fontsize
2206
         @ will display the angle in degrees between x-axis, (0:0) and the cursor (x:y) in 'color' and 'font size'<br /> using a fontfamily Ariel
2207
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
2208
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2209
 
2210
        */
2211
            stroke_color = get_color(infile,0);
2212
            font_size = (int) (get_real(infile,1));
2213
            tmp_buffer = my_newmem(26);
2214
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2215
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2216
            js_function[JS_FIND_ANGLE] = 1;
2217
            break;
2218
        case MOUSE_DISPLAY:
2219
        /*
2220
         @ display TYPE,color,fontsize
2221
         @ TYPE may be x | y | xy | degree | radian | radius
2222
         @ 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 or radians for commands "userdraw arc,color" or protractor , ruler (if set dynamic)
2223
         @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol)
2224
         @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
2225
        */
2226
        temp = get_string_argument(infile,0);
2227
        if( strstr(temp,"xy") != NULL ){
2228
            int_data[0] = 2;
2229
        }else{
2230
            if( strstr(temp,"y") != NULL ){
2231
                int_data[0] = 1;
2232
            }else{
2233
                if( strstr(temp,"x") != NULL ){
2234
                    int_data[0] = 0;
2235
                }else{
2236
                    if(strstr(temp,"degree") != NULL){
2237
                        int_data[0] = 3;
2238
                        js_function[JS_FIND_ANGLE] = 1;
2239
                    }else{
2240
                        if(strstr(temp,"radian") != NULL){
2241
                            int_data[0] = 4;
2242
                            js_function[JS_FIND_ANGLE] = 1;
2243
                        }else{
2244
                            if(strstr(temp,"radius") != NULL){
2245
                                int_data[0] = 5;
2246
                            }else{
2247
                                int_data[0] = 2;
2248
                            }
2249
                        }
2250
                    }
2251
                }
2252
            }
2253
        }
2254
        stroke_color = get_color(infile,0);
2255
        font_size = (int) (get_real(infile,1));
2256
        tmp_buffer = my_newmem(26);
2257
        snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2258
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2259
        break;
2260
 
2261
        case MOUSE_PRECISION:
2262
        /*
2263
            @ precision int
2264
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
2265
            @ may be used / changed before every object
2266
            @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer
2267
        */
2268
            precision = (int) (get_real(infile,1));
2269
            if(precision < 1 ){precision = 1;};
2270
            break;
2271
 
2272
        case MOUSEX:
2273
        /*
2274
         @ mousex color,fontsize
2275
         @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel
2276
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2277
 
2278
        */
2279
            stroke_color = get_color(infile,0);
2280
            font_size = (int) (get_real(infile,1));
2281
            tmp_buffer = my_newmem(26);
2282
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2283
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2284
            break;
2285
        case MOUSEY:
2286
        /*
2287
         @ mousey color,fontsize
2288
         @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
2289
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2290
 
2291
        */
2292
            stroke_color = get_color(infile,0);
2293
            font_size = (int) (get_real(infile,1));
2294
            tmp_buffer = my_newmem(26);
2295
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2296
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2297
            break;
2298
 
2299
        case MULTIDASH:
2300
        /*
2301
         @ multidash 0,1,1
2302
         @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed
2303
         @ use before command <a href='#multidraw'>'multidraw'</a>
2304
         @ if not set all objects will be set 'not dashed'...<br />unless a generic keyword <em>'dashed'</em> was given before command <em>'multidraw'</em>
2305
         @ the dash-type is not -yet- adjustable <br />(e.g. command <em>dashtype line_px,space_px</em> will give no control over multidraw objects)
2306
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2307
         @ always use the same sequence as is used for 'multidraw'
2308
        */
2309
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2310
            temp = get_string(infile,1);
2311
            temp = str_replace(temp,",","\",\"");
2312
            fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
2313
            reset();/* if command 'dashed' was given...reset to not-dashed */
2314
            break;
2315
 
2316
        case MULTIDRAW:
2317
        /*
2318
         @ multidraw obj_type_1,obj_type_2...obj_type_11
2319
         @ for simple single object user drawings you could also use command <a href="#userdraw">'userdraw'</a>
2320
         @ implemented obj_types:<ul><li>point | points </li><li>circle | circles </li><li>line | lines </li><li>segment | segments </li><li>arrow | arrows <br />use command 'arrowhead int' for size (default value 8 pixels)</li><li>rect | rects </li><li>closedpoly<br /><b>only one</b> closedpolygon may be drawn.The number of 'corner points' is not preset (e.g. not limited,freestyle)<br />the polygone is closed when clicking on the first point again..(+/- 10px) </li><li>triangle | triangles</li><li>parallelogram | parallelograms</li><li>poly[3-9] | polys[3-9] draw 3...9 point polygone(s): polys3 is of course triangles </li></ul>
2321
         @ additionally objects may be user labelled, using obj_type 'text'...<br />in this case allways a text input field and if <a href="multiuserinput'> multiuserinput=1 </a>also (x:y) inputfields will be added to the page.<br />use commands 'fontfamily' and 'fontcolor' to adjust. (command 'multistrokeopacity' may be set to adjust text opacity)<br />note: text is always centered on the mouse-click or user-input coordinates !<br />note: no keyboard listeners are used
2322
         @ it makes no sense using something like "multidraw point,points" ... <br />something like "multidraw polys4,polys7" will only result in drawing a '4 point polygone' and not a '7 point polygone' : this is a design flaw and not a feature...
2323
         @ 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)
2324
         @ buttons for changing the obj_type (and incase of 'multiuserinput' , some inputfields and buttons) <br />will be present in the reserved div 'tooltip_div' and can be styled using command 'inputstyle some_css'
2325
         @ the button label will be default the 'object primitive name' (like 'point', 'circles').<br />If you want a different label (e.g. an other language) ,use command 'multilabel'<br />for example in dutch: <br /><em>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</em><br />(see command <a href='#multilabel'>'multilabel'</a> for more details)
2326
         @ multidraw is incompatible with command 'tooltip' (the reserved div_area is used for the multidraw control buttons)
2327
         @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>.
2328
         @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's )
2329
         @ a local function read_canvas%d will read all userbased drawings.<br />The output is always a 11 lines string with fixed sequence.<br/>line 1 = points_x+";"+points_y+"\\n"<br/>line 2 = circles_x+";"+circlespoint_y+";"+multi_radius+"\\n"<br/>line 3 = segments_x+";"+segments_y+"\\n"<br/>line 4 = arrows_x+";"+arrows_y+"\\n"<br/>line 5 = lines_x+";"+lines_y+"\\n"<br/>line 6 = triangles_x+";"+triangles_y+"\\n"<br/>line 7 = polys[3-9]_x+";"+polys[3-9]_y+"\\n"<br/>line 8 = rects_x +";"+rects_y+"\\n"<br />line 9 = closedpoly_x+";"+closedpoly_y+"\\n"<br/>line 10 = parallelogram_x+";"+parallelogram_y"\\n"<br/>line 11 = text_x+";"+text_y+";"+text"\\n"<br/>The x/y-data are in x/y-coordinate system and display precision may be set by a previous command 'precision 0 | 10 | 100 | 1000...'<br />In case of circles the radius is -for the time being- rounded to pixels<br /><b>use the wims "direct exec" tool to see the format of the reply</b>
2330
         @ It is best to prepare / format the student reply in clientside javascript.<br />However in wims language you could use something like this<br />for example you are interested in the polys5 drawings of a pupil (the pupil may draw multiple poly5 objects...)<br />note: the reply for 2 poly5's is:  x11,x12,x13,x14,x15,x21,x22,x23,x24,x25 ; y11,y12,y13,y14,y15,y21,y22,y23,y24,y25<br />rep = !line 7 of reply <br />rep = !translate ';' to '\\n' in $rep <br />pts = 5 # 5 points for polygon <br />x_rep = !line 1 of $rep <br />y_rep = !line 2 of $rep <br />tot = !itemcnt $x_rep <br />num_poly = $[$tot/$pts] <br />idx = 0 <br />!for p=1 to $num_poly <br />&nbsp;!for s=1 to $pts <br />&nbsp;&nbsp;!increase idx <br />&nbsp;&nbsp;X = !item $idx of $x_rep <br />&nbsp;&nbsp;Y = !item $idx of $y_rep <br />&nbsp;&nbsp;# do some checking <br />&nbsp;!next s <br />!next p <br />
2331
         @ <b>attention</b>: for command argument 'closedpoly' only one polygone can be drawn.<br />The last point (e.g. the point clicked near the first point) of the array is removed.
2332
         @ <em>technical: all 10 'draw primitives' + 'text' will have their own -transparent- PNG bitmap canvas. <br />So for example there can be a points_canvas entirely separated from a line_canvas.<br />This to avoid the need for a complete redraw when something is drawn to the canvas...(eg only the object_type_canvas is redrawn)<br />This in contrast to many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element.</em>
2333
        */
2334
        //    if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2335
            if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
2336
            use_userdraw = TRUE;
2337
            /* LET OP max 6 DRAW PRIMITIVES + TEXT */
2338
            temp = get_string(infile,1);
2339
            temp = str_replace(temp,",","\",\"");
2340
            /* if these are not set, set the default values for the 6 (!!!)  draw_primitives + draw_text */
2341
            fprintf(js_include_file,"\
2342
            if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null  ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
2343
            if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
2344
            if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
2345
            if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
2346
            if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2347
            if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2348
            if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2349
            if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
2350
            if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput= ['0','0','0','0','0','0','0','0'];};\
2351
            if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid;if( x_use_snap_to_grid == 1 && y_use_snap_to_grid == 1){ multisnaptogrid = [1,1,1,1,1,1,1];}else{if( x_use_snap_to_grid == 1 ){ multisnaptogrid = [2,2,2,2,2,2,2];}else{if( y_use_snap_to_grid == 1 ){ multisnaptogrid = [3,3,3,3,3,3,3];}else{ multisnaptogrid = [0,0,0,0,0,0,0];};};};};\
2352
            var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
2353
            stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,
2354
            fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,
2355
            stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,
2356
            fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,
2357
            line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,
2358
            use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,
2359
            use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,
2360
            temp,arrow_head,font_color,font_family);
2361
 
2362
            if(strstr(temp,"text") != NULL){
2363
             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2364
            }
2365
 
2366
            /* the canvasses range from 1000 ... 1008 */
2367
            add_js_multidraw(js_include_file,canvas_root_id,temp,input_style);
2368
            reply_precision = precision;
2369
            if( reply_format == 0){reply_format = 29;}
2370
            reset();/* if command 'filled' / 'dashed' was given...reset all */
2371
            break;
2372
        case MULTILABEL:
2373
        /*
2374
         @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
2375
         @ use before command <a href='#multidraw'>'multidraw'</a>
2376
         @ if not set all labels (e.g. the value='' of input type 'button') will be set by the english names for the draw_primitives (like 'point','circle'...)
2377
         @ the 'stop drawing' button text <b>must</b> be the last item on the 'multilabel' -list <br />for example:<br /><em>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</em>
2378
         @ all buttons can be 'styled' by using commant 'inputstyle'<br /><b>note:</b><em>If you want to add some CSS style to the buttons...<br />the id's of the 'draw buttons' are their english command argument<br />(e.g. id="canvasdraw_points" for the draw points button).<br />the id of the 'stop drawing' button is "canvasdraw_stop_drawing".<br />the id of the "OK" button is"canvasdraw_ok_button"</em>
2379
         @ wims will not check the amount or validity of your input
2380
         @ always use the same sequence as is used for 'multidraw'
2381
        */
2382
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2383
            temp = get_string(infile,1);
2384
            temp = str_replace(temp,",","\",\"");
2385
            fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
2386
            break;
2387
        case MULTILINEWIDTH:
2388
        /*
2389
         @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
2390
         @ use before command <a href='#multidraw'>'multidraw'</a>
2391
         @ if not set all line width will be set by a previous command <em>'linewidth int'</em>
2392
         @ use these up to 7 different line widths for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
2393
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2394
         @ always use the same sequence as is used for 'multidraw'
2395
        */
2396
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2397
            temp = get_string(infile,1);
2398
            temp = str_replace(temp,",","\",\"");
2399
            fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
2400
            break;
2401
        case MULTIFILL:
2402
        /*
2403
         @ multifill 0,0,1,0,1,0,0
2404
         @ meaning draw objects no. 3 and 5, in the list of command 'multifill', are filled<br />(if the object is fillable...and not a line,segment,arrow or point...)
2405
         @ use before command <a href='#multidraw'>'multidraw'</a>
2406
         @ if not set all objects -except point|points-  will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill'
2407
         @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon'
2408
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2409
         @ always use the same sequence as is used for 'multidraw'
2410
        */
2411
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2412
            temp = get_string(infile,1);
2413
            temp = str_replace(temp,",","\",\"");
2414
            fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
2415
            break;
2416
 
2417
        case MULTIFILLCOLORS:
2418
        /*
2419
         @ multifillcolors color_name_1,color_name_2,...,color_name_8
2420
         @ use before command <a href='#multidraw'>'multidraw'</a>
2421
         @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity'
2422
         @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n
2423
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
2424
         @ always use the same sequence as is used for 'multidraw'
2425
         @ can also be used with command <a href='#userdraw'>'userdraw clickfill,color'</a> when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors<br />if more control over the used colours is wanted , see command <a href='#colorpalette'>colorpalette color1,color2...</a>
2426
        */
2427
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2428
            fprintf(js_include_file,"var multifillcolors = [");
2429
            while( ! done ){
2430
                temp = get_color(infile,1);
2431
                fprintf(js_include_file,"\"%s\",",temp);
2432
            }
2433
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2434
            break;
2435
 
2436
        case MULTIFILLOPACITY:
2437
        /*
2438
         @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
2439
         @ float values 0 - 1 or integer values 0 - 255
2440
         @ use before command <a href='#multidraw'>'multidraw'</a>
2441
         @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em>
2442
         @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_y</em>
2443
         @ wims will not check the amount or validity of your input
2444
         @ always use the same sequence as is used for 'multidraw'
2445
        */
2446
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2447
            temp = get_string(infile,1);
2448
            temp = str_replace(temp,",","\",\"");
2449
            fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
2450
            break;
2451
        case MULTISNAPTOGRID:
2452
        /*
2453
         @ multisnaptogrid 0,1,1
2454
         @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>'snaptogrid'</a>)
2455
         @ only the x-values snap_to_grid: <em>multisnaptogrid 0,2,2</em>
2456
         @ only the y-values snap_to_grid: <em>multisnaptogrid 0,3,3</em>
2457
         @ mixing allowed: <em>multisnaptogrid 1,2,3,0</em> e.g. the first object will snap to the xy-grid, the second draw object will snap to the x-values, the third object will snap to the y-valeus of the grid, the last object may be placed anywhere on the canvas
2458
         @ use before command <a href='#multidraw'>'multidraw'</a>
2459
         @ if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw'
2460
         @ commands <a href='#xsnaptogrid'>'xsnaptogrid'</a>, <a href='#ysnaptogrid'>'ysnaptogrid'</a>, <a href='#snaptofunction'>'snaptofunction'</a> and <a href='#snaptopoints'>'snaptopoints</a> x1,y1,x2,y2...' are <b>not</b> supported at this time
2461
         @ always use the same sequence as is used for 'multidraw'
2462
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2463
        */
2464
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2465
            temp = get_string(infile,1);
2466
            temp = str_replace(temp,",","\",\"");
2467
            fprintf(js_include_file,"var multisnaptogrid = [\"%s\"];",temp);
2468
            reset();/* if command 'dashed' was given...reset to not-dashed */
2469
            break;
2470
        case MULTISTROKECOLORS:
2471
        /*
2472
         @ multistrokecolors color_name_1,color_name_2,...,color_name_8
2473
         @ use before command <a href='#multidraw'>'multidraw'</a>
2474
         @ if not set all colors will be 'stroke_color' , 'stroke_opacity'
2475
         @ use these up to 6 colors for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
2476
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
2477
         @ always use the same sequence as is used for 'multidraw'
2478
        */
2479
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2480
            fprintf(js_include_file,"var multistrokecolors = [");
2481
            while( ! done ){
2482
                temp = get_color(infile,1);
2483
                fprintf(js_include_file,"\"%s\",",temp);
2484
            }
2485
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2486
            break;
2487
        case MULTISTROKEOPACITY:
2488
        /*
2489
         @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
2490
         @ float values 0 - 1 or integer values 0 - 255
2491
         @ use before command <a href='#multidraw'>'multidraw'</a>
2492
         @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em>
2493
         @ use these up to 7 different stroke opacities for the draw primitives used by command <em>'multidraw obj_type_1,obj_type_2...obj_type_7</em>
2494
         @ wims will not check the amount or validity of your input
2495
         @ always use the same sequence as is used for 'multidraw'
2496
        */
2497
            if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2498
            temp = get_string(infile,1);
2499
            temp = str_replace(temp,",","\",\"");
2500
            fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
2501
            break;
2502
 
2503
        case MULTIUSERINPUT:
2504
        /*
2505
        @ multiuserinput 0,1,1,0
2506
        @ meaning, when the command 'multidraw' is used <br />multidraw circles,points,lines,triangles<br />objects 'points' and 'lines' may additionally be 'drawn' by direct input (inputfields)<br/>all other objects must be drawn with a mouse
2507
        @ in case of circle | circles a third inputfield for Radius (R) is added.<br />the radius must be in the x/y coordinate system (x-range) and <b>not</b> in pixels...students don't think in pixels.<br />note: R-values will not snap-to-grid
2508
        @ in case of line(s) | segment(s) | arrow(s) the user should write <b>x1:y1</b> in the first inputfield and <b/>x2:y2</b> in the second.<br />These 'hints' are pre-filled into the input field.<br />other coordinate delimiters are ";" and "," e.g. <b>x1;y1</b> or <b>x1,y1</b>.<br />An error message (alert box) will popup when things are not correctly...
2509
        @ in case of a triangle | poly3, three inputfields are provided.
2510
        @ in case of 'text' and multiuserinput=1 , 3 inputfields will be shown : x,y,text
2511
        @ in case of 'text' and multiuserinput=0 , 1 inputfield will be shown : text ... a mouse click will place the text on the canvas.
2512
        @ may be styled using command <a href="#inputstyle">"inputstyle"</a>
2513
        @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&amp;drop' or 'onclick' elements
2514
        @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status'
2515
        @ use before command <a href='#multidraw'>'multidraw'</a>
2516
        @ always use the same sequence as is used for 'multidraw'
2517
        */
2518
            /* simple rawmath and input check */
2519
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2520
            temp = get_string(infile,1);
2521
            temp = str_replace(temp,",","\",\"");
2522
            fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
2523
            break;
2524
 
2525
        case NOXAXIS:
2526
        /*
2527
        @ noaxis
2528
        @ keyword
2529
        @ if set, the automatic x-axis numbering will be ignored
2530
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
2531
        @ to be used before command grid (see <a href="#grid">command grid</a>)
2532
        */
2533
            fprintf(js_include_file,"x_strings = [0,\" \"];\n");
2534
            use_axis_numbering = 1;
2535
            break;
2536
        case NOYAXIS:
2537
        /*
2538
        @ noayis
2539
        @ keyword
2540
        @ if set, the automatic y-axis numbering will be ignored
2541
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
2542
        @ to be used before command grid (see <a href="#grid">command grid</a>)
2543
        */
2544
            fprintf(js_include_file,"y_strings = [0,\" \"];\n");
2545
            use_axis_numbering = 1;
2546
            break;
2547
        case OPACITY:
2548
        /*
2549
        @ opacity 0-255,0-255
2550
        @ opacity 0.0 - 1.0,0.0 - 1.0
2551
        @ alternative : transparent
2552
        @ first item is stroke opacity, second is fill opacity
2553
        */
2554
            for(i = 0 ; i<2;i++){
2555
                switch(i){
2556
                    case 0: double_data[0]= get_real(infile,0);break;
2557
                    case 1: double_data[1]= get_real(infile,1);break;
2558
                    default: break;
2559
                }
2560
            }
2561
            if( double_data[0] > 255 ||  double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */
2562
            if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = double_data[0];} /* 0.0 - 1.0 */
2563
            if( double_data[0] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = double_data[0];} /* 0.0 - 1.0 */
2564
            break;
2565
 
2566
        case ONCLICK:
2567
        /*
2568
         @ onclick
2569
         @ keyword (no arguments required)
2570
         @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas();
2571
         @ onclick seqeuence numbering starts at '0'.<br />e.g. if there are 6 objects set onclick, the first onclick object will have id-number '0', the last id-number '5'
2572
         @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked.
2573
         @ the click zone (accuracy) is determined by 2&times; the line width of the object
2574
         @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript <br />(although a single object can <b>not</b> be onclick and draggable at the same time...)
2575
         @ note: not all objects may be set onclick
2576
        */
2577
            fprintf(js_include_file,"use_dragdrop_reply = true;");
2578
            onclick = 1;
2579
 
2580
            break;
2581
 
2582
        case PARALLEL:
2583
        /*
2584
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
2585
         @ can <b>not</b> be set "onclick" or "drag xy"
2586
        */
2587
            for( i = 0;i < 8; i++ ){
2588
                switch(i){
2589
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
2590
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
2591
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
2592
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
2593
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
2594
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
2595
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
2596
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
2597
                    decimals = find_number_of_digits(precision);
2598
                    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,%s,%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,rotation_center,use_offset);
2599
                    if(onclick > 0){click_cnt++;}
2600
                    /* click_cnt++*/;
2601
                    reset();
2602
                    break;
2603
                    default: break;
2604
                }
2605
            }
2606
            break;
2607
 
2608
 
2609
        case PLOTSTEPS:
2610
            /*
2611
             @ plotsteps a_number
2612
             @ default 150
2613
             @ only used for commands <a href="#curve">"curve / plot"</a> and  <a href="#levelcurve">"levelcurve"</a>
2614
             @ use with care !
2615
            */
2616
            plot_steps = (int) (get_real(infile,1));
2617
            break;
2618
 
2619
        case POINT:
2620
        /*
2621
        @ point x,y,color
2622
        @ draw a single point at (x;y) in color 'color'
2623
        @ use command 'linewidth int'  to adust size
2624
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
2625
        @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
2626
        @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range
2627
        */
2628
            for(i=0;i<3;i++){
2629
                switch(i){
2630
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
2631
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
2632
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
2633
                    decimals = find_number_of_digits(precision);
2634
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[1],1.5*line_width,line_width,1.5*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,rotation_center,use_offset);
2635
                    /* click_cnt++; */
2636
                    if(onclick > 0){click_cnt++;}
2637
                    break;
2638
                    default: break;
2639
                }
2640
            }
2641
            reset();
2642
            break;
2643
 
2644
        case POINTS:
2645
        /*
2646
        @ points color,x1,y1,x2,y2,...,x_n,y_n
2647
        @ draw multiple points at given coordinates in color 'color'
2648
        @ use command 'linewidth int'  to adust size
2649
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
2650
        @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range
2651
        */
8363 schaersvoo 2652
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2653
            fill_color = stroke_color;
2654
            i=0;
2655
            while( ! done ){     /* get next item until EOL*/
2656
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2657
                if(i%2 == 0 ){
2658
                    double_data[i] = get_real(infile,0); /* x */
2659
                }
2660
                else
2661
                {
2662
                    double_data[i] = get_real(infile,1); /* y */
2663
                }
2664
                i++;
2665
            }
2666
            decimals = find_number_of_digits(precision);
11806 schaersvoo 2667
            for(c = 0 ; c < i-1 ; c = c+2){
2668
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,2,[%.*f],[%.*f],[%.2f],[%d],%.2f,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],1.5*line_width,line_width,1.5*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,rotation_center,use_offset);
8379 schaersvoo 2669
                /* click_cnt++; */
11806 schaersvoo 2670
                if(onclick > 0){click_cnt++;}
8363 schaersvoo 2671
            }
2672
            reset();
2673
            break;
11806 schaersvoo 2674
 
2675
        case POLY:
2676
        /*
2677
        @ poly color,x1,y1,x2,y2...x_n,y_n
2678
        @ polygon color,x1,y1,x2,y2...x_n,y_n
2679
        @ draw closed polygon
2680
        @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a>
2681
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
2682
        */
2683
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2684
            i=0;
2685
            c=0;
2686
            while( ! done ){     /* get next item until EOL*/
2687
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2688
                for( c = 0 ; c < 2; c++){
2689
                    if(c == 0 ){
2690
                        double_data[i] = get_real(infile,0);
2691
                        i++;
2692
                    }
2693
                    else
2694
                    {
2695
                        double_data[i] = get_real(infile,1);
2696
                        i++;
2697
                    }
2698
                }
2699
            }
2700
            /* draw path :  closed & optional filled */
2701
                decimals = find_number_of_digits(precision);
2702
                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,%s,%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,rotation_center,use_offset);
2703
                if(onclick > 0){click_cnt++;}
2704
                /* click_cnt++; */
2705
                reset();
2706
            break;
2707
 
7614 schaersvoo 2708
        case POLYLINE:
2709
        /*
2710
        @ polyline color,x1,y1,x2,y2...x_n,y_n
10975 schaersvoo 2711
        @ brokenline color,x1,y1,x2,y2...x_n,y_n
2712
        @ path color,x1,y1,x2,y2...x_n,y_n
2713
        @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n"
2714
        @ remark: there are commands "userdraw path(s),color" and "userdraw polyline,color"... these are two entirely different things !<br />the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command
2715
        @ the command interconnects the points in the given order with a line (canvasdraw will not close the drawing: use command <a href="#poly">polygon</a> for this)
2716
        @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually
9406 schaersvoo 2717
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 2718
        */
2719
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2720
            i=0;
2721
            c=0;
2722
            while( ! done ){     /* get next item until EOL*/
2723
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2724
                for( c = 0 ; c < 2; c++){
2725
                    if(c == 0 ){
2726
                        double_data[i] = get_real(infile,0);
2727
                        i++;
2728
                    }
2729
                    else
2730
                    {
2731
                        double_data[i] = get_real(infile,1);
2732
                        i++;
2733
                    }
2734
                }
2735
            }
2736
            /* draw path : not closed & not filled */
2737
            decimals = find_number_of_digits(precision);
11802 schaersvoo 2738
            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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 2739
            if(onclick > 0){click_cnt++;}
2740
            /* click_cnt++;*/
2741
            reset();
7614 schaersvoo 2742
            break;
11806 schaersvoo 2743
 
2744
        case POPUP:
2745
            /*
2746
            @ popup
2747
            @ keyword (no arguments)
2748
            @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
2749
            @ if keyword 'popup' is used after command 'size xsize,ysize' the canvas will also be displayed in a popup window with size 'xsize &times; ysize'
2750
            @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a>
2751
            @ to access the read_canvas and read_dragdrop functions in a popup window, use:<br /><em><br /> function read_all(){<br /> if( typeof popup !== 'undefined' ){<br />  var fun1 = popup['read_dragdrop'+canvas_scripts[0]];<br />  var fun2 = popup['read_canvas'+canvas_scripts[0]];<br />   popup.close();<br />  return "dragdrop="+fun1()+"\\ncanvas="+fun2();<br /> };<br /></em>
2752
            @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like:<br /><em>popup.set_clock(clock_id,type,diff);</em><br />as js-function for a button (or something else) in your document page.<br />wherein <b>clock_id</b> starts with 0 for the first clock<br /><b>type</b> is 1 for Hours,2 for Minutes and 3 for Seconds<br /><b>diff</b> is the increment (positive or negative) per click
2753
            */
2754
            use_tooltip = 2;
2755
            break;
2756
 
2757
        case PROTRACTOR:
7614 schaersvoo 2758
        /*
11806 schaersvoo 2759
         @ protractor x,y,x_width,type,mode,use_a_scale
2760
         @ x,y are the initial location
2761
         @ x_width : give the width in x-coordinate system (e.g. not in pixels !)
2762
         @ type = 1 : a triangle range  0 - 180<br />type = 2 : a circle shape 0 - 360
2763
         @ mode : use -1 to set the protractor interactive (mouse movement of protractor)<br />use mode = '0&deg; - 360&deg;' to set the protractor with a static angle of some value
2764
         @ if the value of the user_rotation angle is to be shown...use command <a href='#display'>display degree,color,fontsize</a><a href='#display'>display radian,color,fontsize</a>
2765
         @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable
2766
         @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
2767
         @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor.
2768
         @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision.
2769
         @ if combined with a ruler, use replyformat = 32
2770
         @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor
2771
         @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'protractor' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize &times; ysize e.g. the same size as the visual canvas... </em>
2772
         @ only one protractor allowed (for the time being)
2773
         @ usage: first left click on the protractor will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence...
7614 schaersvoo 2774
        */
11806 schaersvoo 2775
            for( i = 0;i < 6; i++ ){
2776
                switch(i){
2777
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
2778
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
2779
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
2780
                    case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
2781
                    case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
2782
                    case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
2783
                    decimals = find_number_of_digits(precision);
2784
                    if( int_data[2] < 0 ){
2785
                     if( js_function[JS_FIND_ANGLE] != 1 ){ /* add je function for calculating angle */
2786
                        js_function[JS_FIND_ANGLE] = 1;
2787
                     }
2788
                    }
2789
                    add_js_protractor(js_include_file,canvas_root_id,int_data[0],double_data[0],double_data[1],double_data[2],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[2],int_data[1]);
2790
 
2791
                    string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
2792
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2793
                    snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
2794
                    add_to_buffer(tmp_buffer);
2795
                    reply_precision = precision;
2796
                    /* no reply from protractor if non-interactive */
2797
                    if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
2798
                    break;
2799
                    default: break;
2800
                }
2801
            }
2802
            break;
2803
 
2804
        case PIXELS:
2805
        /*
2806
        @ pixels color,x1,y1,x2,y2,x3,y3...
2807
        @ draw rectangular "points" with diameter 1 pixel
2808
        @ pixels can <b>not</b> be dragged or clicked
2809
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2810
        */
2811
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2812
            stroke_color=get_color(infile,0);
7614 schaersvoo 2813
            i=0;
2814
            c=0;
2815
            while( ! done ){     /* get next item until EOL*/
2816
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2817
                for( c = 0 ; c < 2; c++){
2818
                    if(c == 0 ){
2819
                        double_data[i] = get_real(infile,0);
2820
                        i++;
2821
                    }
2822
                    else
2823
                    {
2824
                        double_data[i] = get_real(infile,1);
2825
                        i++;
2826
                    }
2827
                }
2828
            }
11806 schaersvoo 2829
            decimals = find_number_of_digits(precision);
2830
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
2831
            string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2832
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2833
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2834
            add_to_buffer(tmp_buffer);
2835
            reset();
7614 schaersvoo 2836
            break;
11806 schaersvoo 2837
 
2838
        case PIXELSIZE:
7614 schaersvoo 2839
        /*
11806 schaersvoo 2840
        @ pixelsize int
2841
        @ in case you want to deviate from default pixelsize = 1(...)
7614 schaersvoo 2842
        */
11806 schaersvoo 2843
            pixelsize = (int) get_real(infile,1);
2844
        break;
8105 schaersvoo 2845
 
11806 schaersvoo 2846
        case PIECHART:
7614 schaersvoo 2847
        /*
11806 schaersvoo 2848
        @ piechart xc,yc,radius,'data+colorlist'
2849
        @ (xc : yc) center of circle diagram in xrange/yrange
2850
        @ radius in pixels
2851
        @ 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
2852
        @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
2853
        @ the number of colors must match the number of data.
2854
        @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours
2855
        @ use command <a href='#legend'>'legend'</a> 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 2856
        */
11806 schaersvoo 2857
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
7614 schaersvoo 2858
            for(i=0;i<5;i++){
2859
                switch(i){
11806 schaersvoo 2860
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2861
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2862
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
2863
                    case 3: temp = get_string(infile,1);
2864
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
2865
                            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);
2866
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2867
                            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);
2868
                            add_to_buffer(tmp_buffer);
2869
                           break;
2870
                    default:break;
7614 schaersvoo 2871
                }
2872
            }
11806 schaersvoo 2873
            reset();
7614 schaersvoo 2874
        break;
8304 schaersvoo 2875
 
7614 schaersvoo 2876
        case RAYS:
2877
        /*
2878
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
2879
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 2880
         @ may be set draggable or onclick (every individual ray)
7614 schaersvoo 2881
        */
2882
            stroke_color=get_color(infile,0);
7786 schaersvoo 2883
            fill_color = stroke_color;
2884
            double_data[0] = get_real(infile,0);/* xc */
2885
            double_data[1] = get_real(infile,0);/* yc */
2886
            i=2;
2887
            while( ! done ){     /* get next item until EOL*/
2888
                if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
2889
                if(i%2 == 0 ){
2890
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 2891
                }
7786 schaersvoo 2892
                else
2893
                {
2894
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 2895
                }
7786 schaersvoo 2896
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
2897
                i++;
7614 schaersvoo 2898
            }
8224 bpr 2899
 
2900
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
2901
            decimals = find_number_of_digits(precision);
7786 schaersvoo 2902
            for(c=2; c<i;c = c+2){
11802 schaersvoo 2903
                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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 2904
                /* click_cnt++; */
2905
                if(onclick > 0){click_cnt++;}
7614 schaersvoo 2906
            }
2907
            reset();
2908
            break;
8304 schaersvoo 2909
 
11806 schaersvoo 2910
        case RECT:
8386 schaersvoo 2911
        /*
11806 schaersvoo 2912
        @ rect x1,y1,x2,y2,color
2913
        @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle
2914
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color'
9406 schaersvoo 2915
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8386 schaersvoo 2916
        */
11806 schaersvoo 2917
            for(i=0;i<5;i++){
2918
                switch(i){
2919
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
2920
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
2921
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
2922
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
2923
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
8386 schaersvoo 2924
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 2925
                        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,%s,%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,rotation_center,use_offset);
2926
                        if(onclick > 0){click_cnt++;}
2927
                        /* click_cnt++; */
8386 schaersvoo 2928
                        reset();
2929
                        break;
11806 schaersvoo 2930
                }
2931
            }
2932
            break;
8386 schaersvoo 2933
 
11806 schaersvoo 2934
        case RECTS:
8304 schaersvoo 2935
        /*
11806 schaersvoo 2936
        @ rects color,x1,y1,x2,y2,.....
2937
        @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle
2938
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....'
2939
        @ use command 'fillcolor color' before 'frects' to set the fill colour.
9406 schaersvoo 2940
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
8304 schaersvoo 2941
        */
2942
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2943
            fill_color = stroke_color;
2944
            i=0;
2945
            while( ! done ){     /* get next item until EOL*/
2946
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2947
                if(i%2 == 0 ){
2948
                    double_data[i] = get_real(infile,0); /* x */
2949
                }
2950
                else
2951
                {
2952
                    double_data[i] = get_real(infile,1); /* y */
2953
                }
2954
                i++;
2955
            }
2956
            decimals = find_number_of_digits(precision);
2957
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 2958
                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,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+2],decimals,double_data[c+2],decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+1],decimals,double_data[c+3],decimals,double_data[c+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,rotation_center,use_offset);
2959
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 2960
                /* click_cnt++; */
8304 schaersvoo 2961
            }
2962
            reset();
2963
            break;
8386 schaersvoo 2964
 
11806 schaersvoo 2965
        case REPLYFORMAT:
7614 schaersvoo 2966
        /*
11806 schaersvoo 2967
        @ replyformat number
2968
        @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
2969
        @ default values should be fine !
2970
        @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
2971
        @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
2972
        @ 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 \\n x2,y2,text2...\\n...x_n,y_n,text_n <br /> x/y-values are in xrang/yrange</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>20 = read_canvas() will reply "object_number:x:y" of external images : object_number of the first draggable external image in the fly-script starts with 0 <br />e.g. expect something like 0:-5:4,1:6:2,2:-2:-5 <br /> the first image position is (-5:4) , the second image position is (6:2) and the third image position is (-2:-5)        <li>21 = (x1:y1) (x2:y2) ... (x_n:y_n)<br />verbatim coordinate return</li><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>23 : can only be used for drawtype 'polyline'<br />a typical click sequence in drawtype polyline is x1,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>24 = read all inputfield values: even those set 'readonly'</li><li>25 = angle1,angle2...angle_n : will return the radius (one or many) of the user drawn circle segment in degrees </li><li>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  x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n</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>
2973
 
2974
        */
2975
         reply_format = (int) get_real(infile,1);
2976
         reply_precision = precision;
2977
        break;
2978
 
2979
        case ROUNDRECT:
2980
        /*
2981
        @ roundrect x1,y1,x2,y2,radius in px,color
2982
        @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
2983
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color'
2984
        @ fillcolor will be identical to 'color'
9406 schaersvoo 2985
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 2986
        */
11806 schaersvoo 2987
            for(i=0;i<6;i++){
2988
                switch(i){
2989
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
2990
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
2991
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
2992
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
2993
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
2994
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
2995
                        /* ensure no inverted roundrect is produced... */
2996
                        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];}
2997
                        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 2998
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 2999
                        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,%s,%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,rotation_center,use_offset);
8379 schaersvoo 3000
                        if(onclick > 0){click_cnt++;}
3001
                        /* click_cnt++;*/
3002
                        reset();
11806 schaersvoo 3003
                    break;
3004
                }
3005
            }
3006
            break;
8386 schaersvoo 3007
 
11806 schaersvoo 3008
        case ROUNDRECTS:
8347 schaersvoo 3009
        /*
11806 schaersvoo 3010
        @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
3011
        @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command
9406 schaersvoo 3012
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
8347 schaersvoo 3013
        */
11806 schaersvoo 3014
 
8347 schaersvoo 3015
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
11806 schaersvoo 3016
            int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
8347 schaersvoo 3017
            fill_color = stroke_color;
3018
            i=0;
3019
            while( ! done ){     /* get next item until EOL*/
3020
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3021
                if(i%2 == 0 ){
3022
                    double_data[i] = get_real(infile,0); /* x */
3023
                }
3024
                else
3025
                {
3026
                    double_data[i] = get_real(infile,1); /* y */
3027
                }
3028
                i++;
3029
            }
3030
            decimals = find_number_of_digits(precision);
3031
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 3032
                /* ensure no inverted roundrect is produced... */
3033
                if( double_data[c] > double_data[c+2] ){double_data[c+4] = double_data[c];double_data[c] = double_data[c+2];double_data[c+2] = double_data[c+4];}
3034
                if( double_data[c+3] > double_data[c+1] ){double_data[c+4] = double_data[c+1];double_data[c+1] = double_data[c+3];double_data[c+3] = double_data[c+4];}
3035
                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,%s,%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],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,rotation_center,use_offset);
3036
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 3037
                /* click_cnt++; */
8347 schaersvoo 3038
            }
3039
            reset();
3040
            break;
8386 schaersvoo 3041
 
11806 schaersvoo 3042
        case RULER:
7614 schaersvoo 3043
        /*
11806 schaersvoo 3044
        @ ruler x,y,x-width ,y-height,mode
3045
        @ x,y are the initial location
3046
        @ x-width , y-height are the ruler dimensions width &amp; height in xy-coordinate system
3047
        @ the ruler scale is by definition the x-scale, set by command 'xrange'<br />for example: a ruler x-width of 6 will have a scale ranging from 0 to 6
3048
        @ mode : use -1 to set the ruler interactive (eg mouse movement of ruler; drag &amp; rotate)<br />use mode = '0&deg; - 360&deg;' to set the ruler with a static angle of some value
3049
        @ if combined with a protractor, use replyformat = 32
3050
        @ only one ruler allowed (for the time being)
3051
        @ when using command 'zoom' , pay <b>attention</b> to the size and symmetry of your canvas<br />...to avoid a partial image, locate the start position near the center of the visual canvas<br /><em>technical:<br /> the actual 'ruler' is just a static generated image in a new canvas-memory<br />This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas.<br />That is the reason for the 'high-speed dragging and rotating'.<br />I've limited its size to xsize &times; ysize e.g. the same size as the visual canvas... </em>
3052
        @ usage: first left click on the ruler will activate dragging;<br />a second left click will activate rotating (just move mouse around)<br />a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3)<br />a next click will restart this sequence...
7614 schaersvoo 3053
        */
11806 schaersvoo 3054
            for( i = 0;i < 5; i++ ){
7614 schaersvoo 3055
                switch(i){
11806 schaersvoo 3056
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
3057
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
3058
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
3059
                    case 3: double_data[3] = get_real(infile,0);break; /* y-width */
3060
                    case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
3061
                    decimals = find_number_of_digits(precision);
3062
                    if( int_data[0] < 0 ){
3063
                      if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
3064
                    }
3065
                    add_js_ruler(js_include_file,canvas_root_id,double_data[0],double_data[1],double_data[2],double_data[3],font_family,stroke_color,stroke_opacity,fill_color,fill_opacity,line_width,int_data[0]);
3066
                    string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
3067
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3068
                    snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
3069
                    add_to_buffer(tmp_buffer);
3070
                    reply_precision = precision;
3071
                    /* no reply from ruler if non-interactive */
3072
                    if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
7614 schaersvoo 3073
                    break;
3074
                    default: break;
3075
                }
3076
            }
3077
            break;
8386 schaersvoo 3078
 
11806 schaersvoo 3079
        case RESETOFFSET:
7614 schaersvoo 3080
        /*
11806 schaersvoo 3081
         @ resetoffset
3082
         @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
3083
         @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
7614 schaersvoo 3084
        */
11806 schaersvoo 3085
         use_offset = 0;
3086
         break;
3087
 
3088
        case ROTATE:
3089
        /*
3090
         @ rotate rotation_angle
3091
         @ angle in degrees
3092
         @ (only) the next object will be rotated is given angle
3093
         @ positive values rotate counter clockwise
3094
         @ attention: all objects will be rotated around their first point...<br /><em>rotate 45</em><br /> <em>triangle 1,1,5,1,3,4,red</em><br />will rotate 45 degrees around point (1:1)
3095
         @ if another rotation center is needed, use command <a href="#rotationcenter">'rotationcenter xc,yc'</a>.<br />to reset this rotationcenter, use keyword <a href="killrotate">'killrotate'</a>
3096
         @ attention: rotate will mess up the interactivity of the rotated object <br />e.g. if combined with command <a href="#drag">"drag xy"</a> or keyword <a href="onclick">"onclick"</a> : the mouse recognises the original -unrotated- coordinates of the object
3097
        */
3098
            use_rotate = TRUE;
3099
            angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
7614 schaersvoo 3100
            break;
11806 schaersvoo 3101
        case ROTATION_CENTER:
9306 schaersvoo 3102
        /*
11806 schaersvoo 3103
        @ rotationcenter x_center,y_center
3104
        @ define an rotation center in your x/y-coordinate system
3105
        @ wims will not check the validity of your input; use javascript console to debug any erors
3106
        @ if not defined a rotation will be around the first point of an object
3107
        @ to be used before command <a href="#rotate">rotate</a>
3108
        @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
9306 schaersvoo 3109
        */
11806 schaersvoo 3110
            temp = get_string(infile,1);
3111
            string_length = snprintf(NULL,0,"[ %s ]",temp);
3112
            check_string_length(string_length);
3113
            rotation_center = my_newmem(string_length+1);
3114
            snprintf(rotation_center,string_length,"[%s]",temp);
9306 schaersvoo 3115
            break;
11806 schaersvoo 3116
 
3117
        case SIZE:
3118
            /*
3119
            @ size width,height
3120
            @ set canvas size in pixels
3121
            @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>)
3122
            @ 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
3123
            */
3124
            found_size_command = 1;
3125
            /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
3126
            xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
3127
            ysize = (int)(fabs(round(get_real(infile,1))));
3128
            /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
3129
            xmin = 0;xmax = xsize;
3130
            ymin = 0;ymax = ysize;
3131
 
3132
/*
3133
 The sequence in which stuff is finally printed is important !!
3134
*/
3135
fprintf(stdout,"\n\
3136
<script type=\"text/javascript\">\n\
3137
/*<![CDATA[*/\n\
3138
if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
3139
if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
3140
if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
3141
canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
3142
",canvas_root_id);
3143
 
3144
/* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
3145
if( use_tooltip != 2){
3146
 fprintf(stdout,"<!-- canvasdraw div  -->\n\
3147
<div tabindex=\"0\" id=\"canvas_div%d\" style=\"position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" oncontextmenu=\"return false;\"></div>\n\
3148
<!-- tooltip and input placeholder  -->\n\
3149
<div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
3150
<!-- include actual object code via include file -->\n\
3151
<script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
3152
}
3153
else
3154
{
3155
/*
3156
set canvas_div invisible and do not include placeholder in main html page :
3157
the js-include will also be in a popup window...to be shown when wims $status = done
3158
*/
3159
 fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
3160
<div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
3161
<div id=\"tooltip_placeholder_div%d\" style=\"display:none;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
3162
<!-- include actual object code via include file -->\n\
3163
<script id=\"canvas_script%d\" type=\"text/javascript\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
3164
}
3165
 
3166
/* these must be global...it's all really very poor javascript :( */
3167
fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
3168
\"use strict\";\n\
3169
<!-- these variables and functions must be global -->\n\
3170
var read_dragdrop%d;\
3171
var read_canvas%d;\
3172
var set_clock;\
3173
var clear_draw_area%d;\
3174
var update_draw_area%d;\
3175
var draw_boxplot;\
3176
var redraw_all%d;\
3177
var userdraw_primitive;\n\
3178
var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
3179
var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
3180
var xsize = %d;\
3181
var ysize = %d;\
3182
var precision = 100;\
3183
var canvas_div = document.getElementById(\"canvas_div%d\");\
3184
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;};\
3185
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;};\
3186
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);};};\
3187
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);};};\
3188
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);};};\
3189
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);};};\
3190
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
3191
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
3192
function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
3193
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) ));};\
3194
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;};\
3195
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;};\
3196
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));\
3197
var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
3198
var use_snap_to_points = 0;\
3199
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
3200
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n\
3201
var xlogbase = 10;\
3202
var ylogbase = 10;\
3203
var use_xlogscale = 0;\
3204
var use_ylogscale = 0;\
3205
var x_strings = null;var x_strings_up = null;\
3206
var y_strings = null;\
3207
var use_pan_and_zoom = 0;\
3208
var use_jsmath = 0;\
3209
var xstart = 0;\
3210
var ystart = 0;\
3211
var unit_x=\" \";\
3212
var unit_y=\" \";\
3213
var external_canvas = create_canvas%d(%d,xsize,ysize);\n",canvas_root_id,canvas_root_id,canvas_root_id,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,canvas_root_id,EXTERNAL_IMAGE_CANVAS);
3214
/* default add the drag code : nearly always used ...*/
3215
  add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
3216
 
3217
            break;
3218
 
3219
 
3220
        case SEGMENT:
7614 schaersvoo 3221
        /*
11806 schaersvoo 3222
        @ segment x1,y1,x2,y2,color
3223
        @ alternative : seg
3224
        @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
3225
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 3226
        */
11806 schaersvoo 3227
            for(i=0;i<5;i++) {
7614 schaersvoo 3228
                switch(i){
11806 schaersvoo 3229
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
3230
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
3231
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
3232
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
3233
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
3234
                        decimals = find_number_of_digits(precision);
3235
                        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,%s,%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,rotation_center,use_offset);
3236
                        if(onclick > 0){click_cnt++;}
3237
                        /* click_cnt++; */
3238
                        reset();
3239
                        break;
3240
                    default: break;
7614 schaersvoo 3241
                }
3242
            }
3243
            break;
10953 bpr 3244
 
11806 schaersvoo 3245
        case SEGMENTS:
9213 schaersvoo 3246
        /*
11806 schaersvoo 3247
        @ segments color,x1,y1,x2,y2,...,x_n,y_n
3248
        @ alternative : segs
3249
        @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color'
3250
        @ use command 'linewidth int'  to adust size
3251
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
9213 schaersvoo 3252
        */
11806 schaersvoo 3253
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3254
            fill_color = stroke_color;
3255
            i=0;
3256
            while( ! done ){     /* get next item until EOL*/
3257
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3258
                if(i%2 == 0 ){
3259
                    double_data[i] = get_real(infile,0); /* x */
3260
                }
3261
                else
3262
                {
3263
                    double_data[i] = get_real(infile,1); /* y */
3264
                }
3265
                i++;
3266
            }
3267
            decimals = find_number_of_digits(precision);
3268
            for(c = 0 ; c < i-1 ; c = c+4){
3269
                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,%s,%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,rotation_center,use_offset);
3270
                if(onclick > 0){click_cnt++;}
3271
                /* click_cnt++;*/
3272
            }
3273
            reset();
9213 schaersvoo 3274
            break;
11806 schaersvoo 3275
 
3276
        case SETLIMITS:
9213 schaersvoo 3277
        /*
11806 schaersvoo 3278
            @ setlimits
3279
            @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
3280
            @ may be used for inputfield based zooming / panning
3281
            @ may be styled using command <a href="#inputstyle">inputstyle</a>
3282
            @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc
3283
            @ note:the input value will not be checked on validity
9213 schaersvoo 3284
        */
11806 schaersvoo 3285
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
3286
            add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
3287
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
3288
            use_pan_and_zoom = TRUE;
3289
            done = TRUE;
9213 schaersvoo 3290
            break;
11806 schaersvoo 3291
 
3292
        case SETPIXEL:
9213 schaersvoo 3293
        /*
11806 schaersvoo 3294
        @ setpixel x,y,color
3295
        @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
3296
        @ pixels can <b>not</b> be dragged or clicked
3297
        @ "pixelsize = 1" may be changed by command "pixelsize int"
9213 schaersvoo 3298
        */
11806 schaersvoo 3299
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
3300
            for(i=0;i<3;i++){
3301
                switch(i){
3302
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
3303
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
3304
                    case 2: stroke_color = get_color(infile,1);
3305
                           string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3306
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3307
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3308
                           add_to_buffer(tmp_buffer);
3309
                           break;
3310
                    default:break;
3311
                }
3312
            }
3313
            reset();
3314
        break;
3315
 
3316
 
3317
        case SLIDER:
9213 schaersvoo 3318
        /*
11806 schaersvoo 3319
        @ slider start_value,end_value,width px,height px,<em>type</em>,label
3320
        @ <em>type</em> may be : xy,x,y,angle
3321
        @ if a slider value display is desired, use for argument <em>type</em>:<br />xy display<br />x display<br />y display<br />angle radian<br />angle degree
3322
        @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit'
3323
        @ if the translation should be performed using a function, use for type: xy function,x function,y function<br />use commands sliderfunction_x and/or sliderfunction_y before the slider command to define the functions<br />example:<br />sliderfunction_x x^2<br />sliderfunction_y y^2<br />slider -5,5,100,100,xy function,Some_Text<br />...some stuff to slide<br />killslider<br />sliderfunction_x x^2-2<br />slider -15,15,100,10,x function,Some_Other_Text<br />...more stuff to slide<br />killslider<br />... etc
3324
        @ use command 'slider' before draggable/clickable objects.
3325
        @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<em>size 300,300<br />xrange -5,5<br />yrange -5,5<br />grid 1,1,grey<br />linewidth 3<br />drag xy<br />fillcolor orange<br />strokecolor blue<br />slider 0,2*pi,250,30,angle degrees,Rotate arrow<br />arrow 2,2,5,5,8,red</em>
3326
        @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x'
3327
        @ 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'
3328
        @ amount of sliders is not limited.
3329
        @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
3330
        @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
3331
        @ every draggable object may have its own slider (no limit in amount of sliders)
3332
        @ label: some slider text
3333
        @ use fillcolor for slider ball
3334
        @ use strokecolor for slider bar
3335
        @ use fontfamily / fontcolor to set used fonts
3336
        @ use opacity (only fill opacity will be used) to set transparency
3337
        @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
9213 schaersvoo 3338
        */
11806 schaersvoo 3339
            slider_cnt++;/* slider starts at 1 */
3340
            for(i=0; i<6 ; i++){
3341
                switch(i){
3342
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
3343
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
3344
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
3345
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
3346
                    case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
3347
                            if(strstr(temp,"xy")!= 0){
3348
                                slider = 4;
3349
                            }
3350
                            else
3351
                            {
3352
                                if(strstr(temp,"x") != 0){
3353
                                    slider = 1;
3354
                                }
3355
                                else
3356
                                {
3357
                                    if(strstr(temp,"y") != 0){
3358
                                        slider = 2;
3359
                                    }
3360
                                    else
3361
                                    {
3362
                                        if(strstr(temp,"angle") != 0){ /* angle diplay radian */
3363
                                            slider = 3;
3364
                                        }
3365
                                        else
3366
                                        {
3367
                                            canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
3368
                                        }
3369
                                    }
3370
                                }
3371
                            }
3372
                            if(strstr(temp,"display")!=0){
3373
                                if( slider == 4 ){ /* show x:y */
3374
                                    use_slider_display = 1; /* show x xy values in canvas window */
3375
                                }
3376
                                else
3377
                                {
3378
                                    if( slider == 1 ){ /* show only x -values */
3379
                                     use_slider_display = 10;
3380
                                    }
3381
                                    else
3382
                                    {
3383
                                     use_slider_display = 11; /* show only y -values*/
3384
                                    }
3385
                                }
3386
                            }
3387
                            else
3388
                            {
3389
                                if(strstr(temp,"degree")!= 0){
3390
                                    use_slider_display = 2; /* show angle values in canvas window */
3391
                                }
3392
                                else
3393
                                {
3394
                                    if(strstr(temp,"radian")!=0){
3395
                                        use_slider_display = 3; /* show radian values in canvas window */
3396
                                    }
3397
                                }
3398
                            }
3399
                            if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */
3400
                                add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
3401
                            }
3402
                            if(strstr(temp,"fun")!= 0){
3403
                                if( use_js_math == FALSE){/* add this stuff only once...*/
3404
                                    add_to_js_math(js_include_file); use_js_math = TRUE;
3405
                                }
3406
                                fprintf(js_include_file,"var slider_function%d = {x:to_js_math('%s'),y:to_js_math('%s')};",slider_cnt,slider_function_x,slider_function_y);
3407
                                slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/
3408
                            }
3409
                            else
3410
                            {
3411
                                fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt);
3412
                                /* we must define these, otherwise 'use stict' will cause an error */
3413
                            }
3414
                    break;
3415
                    case 5: /* some string used for slider description  */
3416
                            if(slider == 4){
3417
                                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);
3418
                            }
3419
                            else
3420
                            {
3421
                                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);
3422
                            }
3423
                    break;
3424
                }
3425
             }
9213 schaersvoo 3426
            break;
11806 schaersvoo 3427
        case SLIDER_X:
9213 schaersvoo 3428
        /*
11806 schaersvoo 3429
         @ sliderfunction_x some_function_in_x
3430
         @ default value "x"
3431
         @ the x-value of the slider object(s) will be calculated with this function.
3432
         @ default is the x-slider value itself
3433
         @ only used by command 'slider'
3434
         @ define before a slider command !
9213 schaersvoo 3435
        */
11806 schaersvoo 3436
         slider_function_x = get_string(infile,1);
3437
        break;
3438
        case SLIDER_Y:
3439
         slider_function_y = get_string(infile,1);
3440
         /*
3441
         @ sliderfunction_y some_function_in_y
3442
         @ default value "y"
3443
         @ the y-value of the slider object(s) will be calculated with this function.
3444
         @ only used by command 'slider'
3445
         @ define before a slider command !
3446
         */
3447
        break;
3448
        case SGRAPH:
3449
        /*
3450
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
3451
         @ primitive implementation of a 'broken scale' graph...
3452
         @ 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 />
3453
         @ 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
3454
        */
3455
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
3456
            for(i = 0 ; i < 8 ;i++){
3457
                switch(i){
3458
                    case 0:double_data[0] = get_real(infile,0);break;
3459
                    case 1:double_data[1] = get_real(infile,0);break;
3460
                    case 2:double_data[2] = get_real(infile,0);break;
3461
                    case 3:double_data[3] = get_real(infile,0);break;
3462
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
3463
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
3464
                    case 6:stroke_color = get_color(infile,0);break;
3465
                    case 7:font_color = get_color(infile,1);
3466
                    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);
3467
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3468
                    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);
3469
                    add_to_buffer(tmp_buffer);
3470
                    break;
3471
                    default:break;
3472
                }
3473
            }
3474
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
9213 schaersvoo 3475
            break;
11806 schaersvoo 3476
 
3477
        case SNAPTOFUNCTION:
9213 schaersvoo 3478
        /*
11806 schaersvoo 3479
        @ snaptofunction some_function_in_x,some_funtion_in_y
3480
        @ alternative : snaptofun some_function_in_x,some_funtion_in_y
3481
        @ the next object will snap to the calculated values
3482
        @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y)
3483
        @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y
3484
        @ for now only one instance of 'snaptofunction' is allowed
3485
        @ use rawmath on your functions: no validity checking is done by wims !
3486
        @ example:<br />....<br />snaptofunction 5*(cos(x),4*sin(y)<br />linewidth 3<br />userdraw points,blue<br />....<br />
3487
        @ example : switching x and y coordinates?<br />snaptofunction y,x
9213 schaersvoo 3488
        */
11806 schaersvoo 3489
        temp = get_string_argument(infile,0);
3490
        fprintf(js_include_file,"\nuse_snap_to_points = 2;");
3491
        if( use_js_math == FALSE){/* add this stuff only once...*/
3492
            add_to_js_math(js_include_file); use_js_math = TRUE;
3493
        }
3494
        fprintf(js_include_file,"var snap_fun = {x:to_js_math('%s'),y:to_js_math('%s')};function snap_to_fun(px,py){ var x = px2x(px); var y = px2y(py); return [ x2px(eval(snap_fun.x)) , y2px(eval(snap_fun.y)) ];};",temp,get_string(infile,1));
3495
        break;
3496
        case SNAPTOPOINTS:
3497
        /*
3498
        @ snaptopoints x1,y1,x2,y2,x3,y3....
3499
        @ a userdraw object will snap to these points.
3500
        @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h)
3501
        @ a draggable object (use command "drag  x|y|xy") will snap to the clossed of these points when dragged (mouseup)
3502
        @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid"
3503
        */
3504
            i = 0;
3505
            while( ! done ){     /* get next item until EOL*/
3506
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3507
                if(i%2 == 0 ){
3508
                    double_data[i] = get_real(infile,0); /* x */
3509
                }
3510
                else
3511
                {
3512
                    double_data[i] = get_real(infile,1); /* y */
3513
                }
3514
                i++;
3515
            }
3516
            decimals = find_number_of_digits(precision);
3517
            fprintf(js_include_file,"\nuse_snap_to_points = 1;\nfunction find_min_diff(x,y,X,Y){var diff = 100000000;var chk;var idx = 0;for(var p = 0 ; p < %d ; p++){chk = distance(x,y,X[p],Y[p]);if( chk  < diff ){ diff = chk; idx = p;};};return idx;};\nfunction snap_to_points(x,y){x = px2x(x); y = px2y(y);var points = [%s];var xpoints = points[0];var ypoints = points[1];var idx = find_min_diff(x,y,xpoints,ypoints);x = xpoints[idx];y = ypoints[idx];return [x2px(x),y2px(y)];};\n",(int) (0.5*i),double_xy2js_array(double_data,i,decimals));
3518
        break;
3519
 
3520
        case SNAPTOGRID:
3521
        /*
3522
         @ snaptogrid
3523
         @ keyword (no arguments required)
3524
         @ a draggable object (use command "drag  x|y|xy") will snap to the given grid when dragged (mouseup)
3525
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
3526
         @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
3527
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
3528
         @ if xminor / yminor is defined,(use keyword 'axis' to activate the minor steps) 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 />
3529
        */
3530
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
3531
        break;
3532
 
3533
        case SQUARE:
3534
        /*
3535
        @ square x,y,side (px) ,color
3536
        @ draw a square with left top corner (x:y) with side 'side' in color 'color'
3537
        @ use command 'fsquare x,y,side,color' for a filled square
3538
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'square x,y,side,color'
3539
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
3540
        */
3541
            for(i=0;i<5;i++){
3542
                switch(i){
3543
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
3544
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
3545
                    case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
3546
                    case 3:
3547
                        stroke_color = get_color(infile,1);/* name or hex color */
3548
                        decimals = find_number_of_digits(precision);
3549
                        double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
3550
                        double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
3551
                        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,%s,%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,rotation_center,use_offset);
3552
                        if(onclick > 0){click_cnt++;}
3553
                        /* click_cnt++; */
3554
                        reset();
3555
                        break;
3556
                }
3557
            }
9213 schaersvoo 3558
            break;
11806 schaersvoo 3559
 
3560
        case STATUS:
9213 schaersvoo 3561
        /*
11806 schaersvoo 3562
        @ status
3563
        @ keyword
3564
        @ alernative : nostatus
3565
        @ used to override the effects of "status=done" in wims (answer.phtml)
3566
        @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands
3567
        @ 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'
9213 schaersvoo 3568
        */
11806 schaersvoo 3569
 
3570
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
9213 schaersvoo 3571
            break;
11806 schaersvoo 3572
 
3573
        case STRING:
9213 schaersvoo 3574
        /*
11806 schaersvoo 3575
         @ string color,x,y,the text string
3576
         @ may be set "onclick" or "drag xy"
3577
         @ unicode supported: string red,0,0,\\u2232
3578
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
9213 schaersvoo 3579
        */
11806 schaersvoo 3580
            for(i=0;i<5;i++){
3581
                switch(i){
3582
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
3583
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
3584
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
3585
                    case 3: decimals = find_number_of_digits(precision);
3586
                        temp = get_string_argument(infile,1);
3587
                        decimals = find_number_of_digits(precision);
3588
                        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,%s,%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,rotation_center,use_offset);
3589
                        if(onclick > 0){click_cnt++;}
3590
                        /* click_cnt++;*/
3591
                        reset();
3592
                        break;
3593
                    default:break;
3594
                }
9213 schaersvoo 3595
            }
3596
            break;
11806 schaersvoo 3597
 
3598
        case STRINGUP:
9213 schaersvoo 3599
        /*
11806 schaersvoo 3600
         @ stringup color,x,y,rotation_degrees,the text string
3601
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
3602
         @ unicode supported: stringup red,0,0,45,\\u2232
3603
         @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
3604
 
9213 schaersvoo 3605
        */
11806 schaersvoo 3606
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
3607
            for(i=0;i<6;i++){
3608
                switch(i){
3609
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
3610
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
3611
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
3612
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
3613
                    case 4: decimals = find_number_of_digits(precision);
3614
                            temp = get_string_argument(infile,1);
11811 schaersvoo 3615
                            string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s,%d);\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,use_offset);
11806 schaersvoo 3616
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11811 schaersvoo 3617
                            snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,%.2f,\"%s\",%d,%.2f,%d,%s,%d);\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,use_offset);
11806 schaersvoo 3618
                            add_to_buffer(tmp_buffer);
3619
                            break;
3620
                    default:break;
3621
                }
9213 schaersvoo 3622
            }
11806 schaersvoo 3623
            reset();
9213 schaersvoo 3624
            break;
11767 schaersvoo 3625
 
11806 schaersvoo 3626
        case STYLE:
11767 schaersvoo 3627
        /*
11806 schaersvoo 3628
         @ highlight color,opacity,linewidth
3629
         @ NOT IMPLEMENTED
3630
         @ use command "onclick" : when the object receives a userclick it will increase its linewidth
11767 schaersvoo 3631
        */
3632
            break;
11806 schaersvoo 3633
 
3634
 
3635
        case STROKECOLOR:
9213 schaersvoo 3636
        /*
11806 schaersvoo 3637
        @ strokecolor colorname or #hex
3638
        @ to be used for commands that do not supply a color argument (like command 'linegraph')
9213 schaersvoo 3639
        */
11806 schaersvoo 3640
            stroke_color = get_color(infile,1);
9213 schaersvoo 3641
            break;
11806 schaersvoo 3642
 
3643
        case FLY_TEXT:
9213 schaersvoo 3644
        /*
11806 schaersvoo 3645
        @ text fontcolor,x,y,font,text_string
3646
        @ font may be described by keywords : giant,huge,normal,small,tiny
3647
        @ use command 'fontsize' to increase base fontsize for these keywords
3648
        @ may be set "onclick" or "drag xy"
3649
        @ backwards compatible with flydraw
3650
        @ unicode supported: text red,0,0,huge,\\u2232
3651
        @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
3652
        @ 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.
9213 schaersvoo 3653
        */
11806 schaersvoo 3654
            for(i = 0; i < 5 ;i++){
3655
                switch(i){
3656
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
3657
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
3658
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
3659
                    case 3: fly_font = get_string_argument(infile,0);
3660
                            if(strcmp(fly_font,"giant") == 0){
3661
                                fly_font_size = (int)(font_size + 24);
3662
                            }
3663
                            else
3664
                            {
3665
                                if(strcmp(fly_font,"huge") == 0){
3666
                                    fly_font_size = (int)(font_size + 14);
3667
                                }
3668
                                else
3669
                                {
3670
                                    if(strcmp(fly_font,"large") == 0){
3671
                                        fly_font_size = (int)(font_size + 6);
3672
                                        }
3673
                                        else
3674
                                        {
3675
                                            if(strcmp(fly_font,"small") == 0){
3676
                                                fly_font_size = (int)(font_size - 4);
3677
                                                if(fly_font_size<0){fly_font_size = 8;}
3678
                                        }
3679
                                    }
3680
                                }
3681
                            }
3682
                            break;
3683
                    case 4:
3684
                        temp = get_string_argument(infile,1);
3685
                        decimals = find_number_of_digits(precision);
3686
                        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,%s,%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,fly_font_size,"null",use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset);
3687
                        if(onclick > 0){click_cnt++;}
3688
                        /* click_cnt++;*/
3689
                        reset();
3690
                        break;
3691
                    default:break;
3692
                }
10953 bpr 3693
            }
9213 schaersvoo 3694
            break;
11806 schaersvoo 3695
        case TEXTAREA:
9289 schaersvoo 3696
        /*
11806 schaersvoo 3697
         @ textarea x,y,cols,rows,readonly,value
3698
         @ may be further controlled by <a href="#inputstyle">"inputstyle"</a>
3699
         @ if "$status=done"  (e.g. in answer.phtml) the inputfield will be cleared and set readonly<br />override this by keyword <a href="#status">'status'.</a>
3700
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
3701
         @ keyword 'xoffset | centered' is not active for commande 'textarea'
9289 schaersvoo 3702
        */
11806 schaersvoo 3703
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
3704
            for(i = 0 ; i<6;i++){
9289 schaersvoo 3705
                switch(i){
11806 schaersvoo 3706
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
3707
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
3708
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
3709
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
3710
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
3711
                    case 5: temp = get_string_argument(infile,1);
3712
                            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);
3713
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3714
                            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);
3715
                            add_to_buffer(tmp_buffer);
3716
                            input_cnt++;break;
9289 schaersvoo 3717
                    default: break;
3718
                }
3719
            }
11806 schaersvoo 3720
            if(reply_format == 0 ){reply_format = 15;}
3721
            reset();
9289 schaersvoo 3722
            break;
11806 schaersvoo 3723
 
3724
        case FLY_TEXTUP:
9289 schaersvoo 3725
        /*
11806 schaersvoo 3726
         @ textup fontcolor,x,y,font,text_string
3727
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
3728
         @ font may be described by keywords : giant,huge,normal,small,tiny
3729
         @ use command 'fontsize' to increase base fontsize for the keywords
3730
         @ backwards compatible with flydraw
3731
         @ unicode supported: textup red,0,0,huge,\\u2232
3732
         @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
3733
         @ 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.
9289 schaersvoo 3734
        */
11806 schaersvoo 3735
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
3736
            for(i = 0; i<5 ;i++){
9289 schaersvoo 3737
                switch(i){
11806 schaersvoo 3738
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
3739
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
3740
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
3741
                    case 3: fly_font = get_string_argument(infile,0);
3742
                            if(strcmp(fly_font,"giant") == 0){
3743
                                fly_font_size = (int)(font_size + 24);
3744
                            }
3745
                            else
3746
                            {
3747
                                if(strcmp(fly_font,"huge") == 0){
3748
                                    fly_font_size = (int)(font_size + 14);
3749
                                }
3750
                                else
3751
                                {
3752
                                    if(strcmp(fly_font,"large") == 0){
3753
                                        fly_font_size = (int)(font_size + 6);
3754
                                        }
3755
                                        else
3756
                                        {
3757
                                            if(strcmp(fly_font,"small") == 0){
3758
                                                fly_font_size = (int)(font_size - 4);
3759
                                                if(fly_font_size<0){fly_font_size = 8;}
3760
                                        }
3761
                                    }
3762
                                }
3763
                            }
3764
                            break;
3765
                    case 4:
9289 schaersvoo 3766
                    decimals = find_number_of_digits(precision);
11806 schaersvoo 3767
                    temp = get_string_argument(infile,1);
11811 schaersvoo 3768
                    string_length = snprintf(NULL,0,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix,use_offset);
9289 schaersvoo 3769
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11811 schaersvoo 3770
                    snprintf(tmp_buffer,string_length,"draw_text(%d,%d,%d,%d,\"%s\",\"%s\",%.2f,90,\"%s\",%d,%.2f,%d,%s,%d);\n",STATIC_CANVAS,int_data[0],int_data[1],fly_font_size,"null",font_color,stroke_opacity,temp,use_rotate,angle,use_affine,affine_matrix,use_offset);
9289 schaersvoo 3771
                    add_to_buffer(tmp_buffer);
3772
                    break;
11806 schaersvoo 3773
                    default:break;
3774
                }
3775
            }
3776
            reset();
3777
            break;
3778
 
3779
 
3780
        case TRACE_JSCURVE:
3781
        /*
3782
         @ trace_jscurve some_math_function
3783
         @ will use a crosshair to trace the jsmath curve
3784
         @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
3785
         @ default labels 'x' and 'y'<br />use commands 'xlabel some_x_axis_name' and 'ylabel some_y_axis_name' to customize the labels for the input fields
3786
         @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
3787
         @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair.
3788
         @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath : use 2*x instead 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...
3789
        @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
3790
        */
3791
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
3792
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
3793
            if( use_js_math == FALSE){
3794
                add_to_js_math(js_include_file);
3795
                use_js_math = TRUE;
3796
            }
3797
            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,input_style);
3798
            break;
3799
 
3800
 
3801
        case TRANGE:
3802
        /*
3803
        @ trange tmin,tmax
3804
        @ alternative : ranget
3805
        @ default -2,2
3806
        */
3807
            use_parametric = TRUE;
3808
            for(i = 0 ; i<2; i++){
3809
                switch(i){
3810
                    case 0: tmin = get_real(infile,0);break;
3811
                    case 1: tmax = get_real(infile,1);break;
9289 schaersvoo 3812
                    default: break;
3813
                }
3814
            }
11806 schaersvoo 3815
            if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
9289 schaersvoo 3816
            break;
11806 schaersvoo 3817
        case TRANSLATION:
3818
        /*
3819
         @ translation tx,ty
3820
         @ alternative : translate
3821
         @ will translate the next objects tx in xrange and ty in yrange
3822
         @ use command 'killtranstation' to end the command
3823
        */
3824
            for(i = 0 ; i<2;i++){
3825
                switch(i){
3826
                    case 0: double_data[0] = get_real(infile,0);break;
3827
                    case 1: double_data[1] = get_real(infile,1);
3828
                        use_affine = TRUE;
3829
                        decimals = find_number_of_digits(precision);
3830
                        string_length = snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
3831
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
3832
                        snprintf(affine_matrix,string_length,"[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
3833
                        break;
3834
                    default: break;
3835
                }
3836
            }
3837
        break;
3838
 
3839
        case TRIANGLE:
3840
        /*
3841
         @ triangle x1,y1,x2,y2,x3,y3,color
3842
         @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle
3843
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
3844
        */
3845
            for(i=0;i<7;i++){
3846
                switch(i){
3847
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
3848
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
3849
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
3850
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
3851
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
3852
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
3853
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
3854
                        decimals = find_number_of_digits(precision);
3855
                        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,%s,%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,rotation_center,use_offset);
3856
                        if(onclick > 0){click_cnt++;}
3857
                        /* click_cnt++;*/
3858
                        reset();
3859
                        break;
3860
                    default: break;
3861
                }
3862
            }
3863
            break;
3864
        case TRIANGLES:
3865
        /*
3866
         @ triangles color,x1,y1,x2,y2,x3,y3,...
3867
         @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles
3868
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
3869
        */
3870
            stroke_color = get_color(infile,0);/* name or hex color */
3871
            i = 0;
3872
            decimals = find_number_of_digits(precision);
3873
            while( ! done ){
3874
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3875
                double_data[0] = get_real(infile,0); /* x1 */
3876
                double_data[1] = get_real(infile,0); /* y1 */
3877
                double_data[2] = get_real(infile,0); /* x2 */
3878
                double_data[3] = get_real(infile,0); /* y2 */
3879
                double_data[4] = get_real(infile,0); /* x3 */
3880
                double_data[5] = get_real(infile,1); /* y3 */
3881
                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,%s,%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,rotation_center,use_offset);
3882
                if(onclick > 0){click_cnt++;}
3883
                i = i + 6;
3884
            }
3885
            reset();
3886
            break;
3887
        case USERBOXPLOT:
3888
        /*
3889
         @ userboxplot
3890
         @ keyword, no arguments
3891
         @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
3892
         @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function
3893
         @ for example:<br />put the canvas-script into a html element with id='boxplot'and set style='display:none'<br />define a variable called 'student_boxplot' and fill it with the 5 student-data (from inputfields or something)<br />var student_boxplot = new Array(5)<br />function show_boxplot(){<br />student_boxplot[0] = min;<br />student_boxplot[1] = Q1;<br />student_boxplot[2] = median;<br />student_boxplot[3] = Q3;<br />student_boxplot[4] = max;<br />document.getElementById('boxplot').style.display = "block";<br />draw_boxplot(12345,1,2.00,5.00,[0,0,0,0,0],4,"0,0,255",0.78,"255,165,0",0.60,1,0,1,1);<br />};<br />In the canvas-script the function draw_boxplot has the following arguments:<br />draw_boxplot=function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1)
3894
        */
3895
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
3896
            fprintf(js_include_file,"var boxplot_source = 3;\n");
3897
            js_function[DRAW_JSBOXPLOT] = 2;
3898
        break;
3899
 
3900
        case USERBOXPLOTDATA:
3901
        /*
3902
         @ userboxplotdata
3903
         @ keyword, no arguments
3904
         @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
3905
         @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data"
3906
         @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
3907
         @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()'
3908
        */
3909
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
3910
            fprintf(js_include_file,"var boxplot_source = 2;\n");
3911
            js_function[DRAW_JSBOXPLOT] = 1;
3912
 
3913
        break;
3914
 
7614 schaersvoo 3915
        case USERDRAW:
3916
        /*
3917
        @ userdraw object_type,color
9213 schaersvoo 3918
        @ only a single object_type is allowed.
9385 schaersvoo 3919
        @ for multiple object user drawings use command <a href="#multidraw">'multidraw'</a>
11764 schaersvoo 3920
        @ 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 | brokenline </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] (e.g poly3 ... poly7...poly9 </li><li>rect</li><li>roundrect</li><li>rects</li><li>roundrects</li><li>freehandline | path</li><li>freehandlines | paths</li><li>clickfill : fill the clicked area with a color<br />the click may be set <a href="#snaptogrid">'snaptogrid'</a><br />may be used together with command <a href="#floodfill">'floodfill'</a><br />multiple areas may be selected <br /><b>always</b> use together with command <a href="clearbutton">'clearbutton some_text'</a> for removal of all click_colored areas<br />the function read_cancas() will return the click coordinates in the sequence of the user clicks<br />use command <a href="#canvastype">'canvastype'</a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)<br />command <a href='#multifillcolors'>multifillcolors color1,color2...color_n</a> can also be used when more than one fillcolor is wanted.<br />in that case use for example <a href='#replyformat'>replyformat 10</a> ... reply=x1:y1:color1,x2:y2:color2...<br />the colors will restart at the first color, when there are more fill-clicks than multi-fill-colors</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>
11088 schaersvoo 3921
        @ 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)
3922
        @ note: object_type text: Any string or multiple strings may be placed anywhere on the canvas.<br />"backspace / delete / esc" will remove typed text if the mouse is clicked non the text.<br />You will need to hit "enter" to add the text to the array "userdraw_txt"<br />Placing the cursor somewhere on a typed text and hitting "delete/backspace/esc" ,
11080 schaersvoo 3923
        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
11088 schaersvoo 3924
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
3925
        @ note: all objects will be removed -after a javascript confirm box- when clicked on an object point with middle or right mouse button (e.g. event.which != 1 : all buttons but left)
7614 schaersvoo 3926
        @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
8224 bpr 3927
        @ use command "dashed" and/or "dashtype int,int" to trigger dashing
7614 schaersvoo 3928
        @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
3929
        @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
10953 bpr 3930
        @ may be combined with keyword 'userinput_xy'
11088 schaersvoo 3931
        @ 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.!<br />use command <a href="#multidraw">multidraw</a> is this is a problem for you...
7614 schaersvoo 3932
        */
3933
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
9213 schaersvoo 3934
                canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
7614 schaersvoo 3935
            }
8074 schaersvoo 3936
            reply_precision = precision;
7614 schaersvoo 3937
            use_userdraw = TRUE;
11041 schaersvoo 3938
            fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();\
3939
            userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
11001 schaersvoo 3940
            var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
3941
            if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
3942
            if(wims_status != \"done\"){\
11006 schaersvoo 3943
            canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
3944
            canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
3945
            canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
3946
            canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
3947
            canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
11001 schaersvoo 3948
            }\n<!-- end userdraw mouse & touch events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
7614 schaersvoo 3949
            draw_type = get_string_argument(infile,0);
3950
            stroke_color = get_color(infile,1);
3951
            if( strcmp(draw_type,"point") == 0 ){
3952
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 3953
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 3954
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 3955
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 3956
                if(use_input_xy == 1){
7652 schaersvoo 3957
                    add_input_circle(js_include_file,1,1);
8815 schaersvoo 3958
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 3959
                }
7614 schaersvoo 3960
                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);
3961
            }
3962
            else
3963
            if( strcmp(draw_type,"points") == 0 ){
3964
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 3965
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 3966
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 3967
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 3968
                if(use_input_xy == 1){
7652 schaersvoo 3969
                    add_input_circle(js_include_file,1,2);
8815 schaersvoo 3970
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 3971
                }
7614 schaersvoo 3972
                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);
3973
            }
3974
            else
3975
            if( strcmp(draw_type,"segment") == 0 ){
3976
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
3977
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 3978
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 3979
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 3980
                if(use_input_xy == 1){
7652 schaersvoo 3981
                    add_input_segment(js_include_file,1);
8815 schaersvoo 3982
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 3983
                }
7614 schaersvoo 3984
                add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
3985
            }
3986
            else
10975 schaersvoo 3987
            if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
7663 schaersvoo 3988
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 3989
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 3990
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 3991
                if( use_input_xy == 1 ){
3992
                    add_input_polyline(js_include_file);
8815 schaersvoo 3993
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7663 schaersvoo 3994
                }
3995
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
3996
            }
3997
            else
7614 schaersvoo 3998
            if( strcmp(draw_type,"segments") == 0 ){
3999
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4000
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 4001
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 4002
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4003
                if(use_input_xy == 1){
7652 schaersvoo 4004
                    add_input_segment(js_include_file,2);
8815 schaersvoo 4005
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4006
                }
7614 schaersvoo 4007
                add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4008
            }
4009
            else
4010
            if( strcmp(draw_type,"circle") == 0 ){
4011
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4012
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 4013
                /* 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 4014
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4015
                if(use_input_xy == 1){
7652 schaersvoo 4016
                    add_input_circle(js_include_file,2,1);
8815 schaersvoo 4017
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4018
                }
7614 schaersvoo 4019
                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]);
4020
            }
4021
            else
4022
            if( strcmp(draw_type,"circles") == 0 ){
4023
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4024
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 4025
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
4026
                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 4027
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4028
                if(use_input_xy == 1){
7652 schaersvoo 4029
                    add_input_circle(js_include_file,2,2);
8815 schaersvoo 4030
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4031
                }
7614 schaersvoo 4032
            }
4033
            else
4034
            if(strcmp(draw_type,"crosshair") == 0 ){
4035
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4036
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4037
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
4038
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 4039
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4040
                if(use_input_xy == 1){
7654 schaersvoo 4041
                    add_input_crosshair(js_include_file,1);
8815 schaersvoo 4042
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4043
                }
7614 schaersvoo 4044
            }
4045
            else
4046
            if(strcmp(draw_type,"crosshairs") == 0 ){
4047
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4048
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4049
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
4050
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 4051
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4052
                if(use_input_xy == 1){
7654 schaersvoo 4053
                    add_input_crosshair(js_include_file,2);
8815 schaersvoo 4054
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4055
                }
7614 schaersvoo 4056
            }
4057
            else
4058
            if(strcmp(draw_type,"freehandline") == 0 ){
4059
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4060
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4061
                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 4062
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4063
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4064
            }
4065
            else
4066
            if(strcmp(draw_type,"freehandlines") == 0 ){
4067
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4068
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4069
                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 4070
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4071
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4072
            }
4073
            else
4074
            if(strcmp(draw_type,"path") == 0 ){
4075
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4076
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4077
                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 4078
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4079
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4080
            }
4081
            else
4082
            if(strcmp(draw_type,"paths") == 0 ){
4083
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4084
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4085
                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 4086
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4087
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4088
            }
4089
            else
4090
            if(strcmp(draw_type,"arrows") == 0 ){
4091
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4092
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4093
                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 4094
                if(use_input_xy == 1){
7654 schaersvoo 4095
                    add_input_arrow(js_include_file,2);
8815 schaersvoo 4096
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4097
                }
8071 schaersvoo 4098
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4099
            }
4100
            else
7874 schaersvoo 4101
            if(strcmp(draw_type,"arrows2") == 0 ){
4102
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4103
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4104
                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 4105
                if(use_input_xy == 1){
7874 schaersvoo 4106
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4107
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4108
                }
8071 schaersvoo 4109
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4110
            }
4111
            else
4112
            if(strcmp(draw_type,"arrow2") == 0 ){
4113
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4114
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4115
                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 4116
                if(use_input_xy == 1){
7874 schaersvoo 4117
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4118
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4119
                }
8071 schaersvoo 4120
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4121
            }
4122
            else
7614 schaersvoo 4123
            if(strcmp(draw_type,"arrow") == 0 ){
4124
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4125
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4126
                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 4127
                if(use_input_xy == 1){
7654 schaersvoo 4128
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4129
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4130
                }
8071 schaersvoo 4131
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4132
            }
4133
            else
4134
            if(strcmp(draw_type,"polygon") == 0){
4135
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4136
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4137
                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 4138
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4139
                if(use_input_xy == 2){
7780 schaersvoo 4140
                  add_textarea_polygon(js_include_file);
8815 schaersvoo 4141
                  add_textarea_xy(js_include_file,canvas_root_id,input_style);
7746 schaersvoo 4142
                }
7614 schaersvoo 4143
            }
8224 bpr 4144
            else
7614 schaersvoo 4145
            if(strncmp(draw_type,"poly",4) == 0){
4146
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
4147
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4148
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4149
                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 4150
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4151
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4152
            }
8224 bpr 4153
            else
7614 schaersvoo 4154
            if(strcmp(draw_type,"triangle") == 0){
4155
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4156
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4157
                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 4158
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4159
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4160
            }
8224 bpr 4161
            else
7989 schaersvoo 4162
            if( strcmp(draw_type,"hline") == 0 ){
4163
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4164
                if(reply_format == 0){reply_format = 11;}
4165
                add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4166
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4167
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4168
            }
4169
            else
4170
            if( strcmp(draw_type,"hlines") == 0 ){
4171
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4172
                if(reply_format == 0){reply_format = 11;}
4173
                add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4174
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4175
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4176
            }
4177
            else
4178
            if( strcmp(draw_type,"vline") == 0 ){
4179
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4180
                if(reply_format == 0){reply_format = 11;}
4181
                add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4182
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4183
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4184
            }
4185
            else
4186
            if( strcmp(draw_type,"vlines") == 0 ){
4187
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4188
                if(reply_format == 0){reply_format = 11;}
4189
                add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4190
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4191
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4192
            }
4193
            else
7614 schaersvoo 4194
            if( strcmp(draw_type,"line") == 0 ){
4195
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4196
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4197
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 4198
                add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 4199
                if( use_input_xy == 1 ){
7780 schaersvoo 4200
                    add_input_line(js_include_file,1);
8815 schaersvoo 4201
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7747 schaersvoo 4202
                }
8071 schaersvoo 4203
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4204
            }
4205
            else
4206
            if( strcmp(draw_type,"lines") == 0 ){
4207
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4208
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4209
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 4210
                add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 4211
                if( use_input_xy == 1 ){
7780 schaersvoo 4212
                    add_input_line(js_include_file,2);
8815 schaersvoo 4213
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7746 schaersvoo 4214
                }
8071 schaersvoo 4215
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4216
            }
4217
            else
8362 schaersvoo 4218
            if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
8244 schaersvoo 4219
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4220
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4221
                if(reply_format == 0){reply_format = 11;}
4222
                add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4223
                if( use_input_xy == 1 ){
4224
                    add_input_demiline(js_include_file,2);
8815 schaersvoo 4225
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4226
                }
4227
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4228
            }
4229
            else
8362 schaersvoo 4230
            if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
8244 schaersvoo 4231
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4232
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4233
                if(reply_format == 0){reply_format = 11;}
4234
                add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4235
                if( use_input_xy == 1 ){
4236
                    add_input_demiline(js_include_file,1);
8815 schaersvoo 4237
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4238
                }
4239
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4240
            }
4241
            else
7614 schaersvoo 4242
            if( strcmp(draw_type,"rects") == 0){
4243
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 4244
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4245
                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 4246
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4247
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4248
            }
8224 bpr 4249
            else
7614 schaersvoo 4250
            if( strcmp(draw_type,"roundrects") == 0){
4251
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 4252
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4253
                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 4254
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4255
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4256
            }
8224 bpr 4257
            else
7614 schaersvoo 4258
            if( strcmp(draw_type,"rect") == 0){
4259
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 4260
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4261
                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 4262
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4263
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4264
            }
8224 bpr 4265
            else
7614 schaersvoo 4266
            if( strcmp(draw_type,"roundrect") == 0){
4267
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 4268
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4269
                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 4270
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4271
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4272
            }
4273
            else
8083 schaersvoo 4274
            if( strcmp(draw_type,"arcs") == 0){
4275
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
4276
                if(reply_format == 0){reply_format = 25;}
4277
                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]);
4278
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4279
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4280
            }
4281
            else
8071 schaersvoo 4282
            if( strcmp(draw_type,"arc") == 0){
4283
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
11017 schaersvoo 4284
                if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
8083 schaersvoo 4285
                if(reply_format == 0){reply_format = 25;}
4286
                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 4287
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4288
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4289
            }
4290
            else
7614 schaersvoo 4291
            if( strcmp(draw_type,"text") == 0){
7876 schaersvoo 4292
                if(reply_format == 0){reply_format = 17;}
11084 schaersvoo 4293
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity);
7652 schaersvoo 4294
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4295
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4296
            }
8116 schaersvoo 4297
            else
4298
            if( strcmp(draw_type,"inputs") == 0){
8224 bpr 4299
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 4300
                if(reply_format == 0){reply_format = 27;}
11803 schaersvoo 4301
                add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset);
8116 schaersvoo 4302
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4303
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4304
            }
4305
            else
4306
            if( strcmp(draw_type,"input") == 0){
8224 bpr 4307
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 4308
                if(reply_format == 0){reply_format = 27;}
11803 schaersvoo 4309
                add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset);
8116 schaersvoo 4310
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4311
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4312
            }
8193 schaersvoo 4313
            else
11005 schaersvoo 4314
            if( strcmp(draw_type,"clickfill") == 0){
4315
                decimals = find_number_of_digits(precision);
4316
                if(reply_format == 0){reply_format = 22;}
4317
                add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215));
4318
                if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
4319
                 js_function[DRAW_FILLTOBORDER] = 1;
11006 schaersvoo 4320
                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
11005 schaersvoo 4321
                }
4322
            }
4323
            else
7614 schaersvoo 4324
            {
4325
                canvas_error("unknown drawtype or typo? ");
4326
            }
4327
            reset();
4328
        break;
8386 schaersvoo 4329
 
4330
        case USERINPUT:
4331
        /*
4332
         @ userinput function | textarea | inputfield
9382 schaersvoo 4333
         @ alternative : userinput_function
4334
         @ alternative : userinput_textarea
4335
         @ alternative : userinput_xy
8386 schaersvoo 4336
         @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
4337
         @ function may be used any time (e.g. without userdraw)
8815 schaersvoo 4338
         @ multiple 'userinput function' commands may be used.
8386 schaersvoo 4339
         @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)="
4340
         @ use command 'strokecolor some_color' to adjust the plot / functionlabel color
8815 schaersvoo 4341
         @ use command 'inputstyle some_css' to adjust the inputfields
4342
         @ use command 'fontsize int' to adjust the label fonts. (default 12px)
4343
         @ the user input for the function will be corrected by a simple 'rawmath' implementation...<br />an error message will be shown if javascript can not interpret the user input
8386 schaersvoo 4344
        */
4345
            temp = get_string_argument(infile,1);
4346
            if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
4347
             if( js_function[DRAW_JSFUNCTION] != 1 ){
4348
              add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
4349
              js_function[DRAW_JSFUNCTION] = 1;
4350
              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 4351
              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],font_size);
8386 schaersvoo 4352
              input_cnt++;
4353
             }
10953 bpr 4354
             else
8386 schaersvoo 4355
             {
4356
              /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
8815 schaersvoo 4357
              fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
8386 schaersvoo 4358
              input_cnt++;
4359
             }
4360
             if( use_js_math == FALSE){/* add this stuff only once...*/
4361
              add_to_js_math(js_include_file);
4362
              use_js_math = TRUE;
4363
             }
4364
             if( use_js_plot == FALSE){
4365
              use_js_plot = TRUE;
4366
              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
4367
             }
4368
            }
4369
            else
4370
            {
4371
             if(strstr(temp,"inputfield") != 0 ){
4372
              if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
4373
              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4374
              use_input_xy = 1;
4375
             }
4376
             else
4377
             {
4378
              if(strstr(temp,"textarea") != 0 ){
4379
               if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
4380
               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4381
               use_input_xy = 2;
4382
              }
4383
              else
4384
              {
4385
                canvas_error("userinput argument may be \"function,inputfield,textarea\"");
4386
              }
4387
             }
4388
            }
4389
            break;
4390
        case USERINPUT_XY:
4391
        /*
4392
        @ userinput_xy
9372 schaersvoo 4393
        @ keyword (no arguments required)
8386 schaersvoo 4394
        @ to be used in combination with command "userdraw object_type,color"
4395
        @ 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)
4396
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
4397
        @ 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.
11088 schaersvoo 4398
        @ can <b>not</b> be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
8386 schaersvoo 4399
        @ user drawings will not zoom on zooming (or pan on panning)
8815 schaersvoo 4400
        @ use command 'inputstyle some_css' to adjust the inputarea.
4401
        @ use command 'fontsize int' to adjust the text labels (if needed)
8386 schaersvoo 4402
        */
4403
            /* add simple eval check to avoid code injection with unprotected eval(string) */
4404
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
4405
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4406
            use_input_xy = 1;
4407
            break;
4408
 
4409
        case USERINPUT_FUNCTION:
4410
        /*
4411
        @ userinput_function
9372 schaersvoo 4412
        @ keyword (no arguments required)
8386 schaersvoo 4413
        @ if set , a inputfield will be added to the page
4414
        @ repeat keyword for more function input fields
4415
        @ the userinput value will be plotted in the canvas
10953 bpr 4416
        @ this value may be read with 'read_canvas()'. <br />for do it yourself js-scripters : If this is the first inputfield in the script, its id is canvas_input0
8386 schaersvoo 4417
        @ 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
8815 schaersvoo 4418
        @ fontsize can be set using command 'fontsize int'
8386 schaersvoo 4419
        @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
4420
        */
4421
            if( js_function[DRAW_JSFUNCTION] != 1 ){
4422
             js_function[DRAW_JSFUNCTION] = 1;
4423
             add_rawmath(js_include_file);
4424
             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 4425
             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],font_size);
8386 schaersvoo 4426
             input_cnt++;
4427
            }
10953 bpr 4428
            else
8386 schaersvoo 4429
            {
4430
              /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
8815 schaersvoo 4431
             fprintf(js_include_file,"add_input_jsfunction(%d,\"%s\",\"%s\",%d,\"%s\",\"%.2f\",%d,%d,%d,%d);\n",input_cnt,input_style,function_label,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],font_size);
8386 schaersvoo 4432
             input_cnt++;
4433
            }
4434
            if( use_js_math == FALSE){/* add this stuff only once...*/
4435
             add_to_js_math(js_include_file);
4436
             use_js_math = TRUE;
4437
            }
4438
            if( use_js_plot == FALSE){
4439
             use_js_plot = TRUE;
4440
             add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
4441
            }
4442
            break;
4443
 
4444
 
4445
 
11806 schaersvoo 4446
        case USERTEXTAREA_XY:
7788 schaersvoo 4447
        /*
11806 schaersvoo 4448
        @ usertextarea_xy
4449
        @ keyword (no arguments required)
4450
        @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
4451
        @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
4452
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
4453
        @ user drawings will not zoom on zooming (or pan on panning)
4454
        @ use command 'inputstyle some_css' to adjust the inputarea.
4455
        @ use command 'fontsize int' to adjust the text labels (if needed)
7788 schaersvoo 4456
        */
11806 schaersvoo 4457
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
4458
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4459
            use_input_xy = 2;
7788 schaersvoo 4460
            break;
8386 schaersvoo 4461
 
11806 schaersvoo 4462
        case VLINE:
8386 schaersvoo 4463
        /*
11806 schaersvoo 4464
        @ vline x,y,color
4465
        @ alternative : verticalline
4466
        @ draw a vertical line through point (x:y) in color 'color'
4467
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8386 schaersvoo 4468
        */
11806 schaersvoo 4469
            for(i=0;i<3;i++) {
7614 schaersvoo 4470
                switch(i){
11806 schaersvoo 4471
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
4472
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
4473
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
4474
                        double_data[2] = double_data[0];
7614 schaersvoo 4475
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 4476
                        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,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[0],decimals,double_data[2],decimals,100*ymin,decimals,100*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,rotation_center,use_offset);
4477
                        if(onclick > 0){click_cnt++;}
4478
                        /* click_cnt++; */
8379 schaersvoo 4479
                        reset();
7614 schaersvoo 4480
                    break;
4481
                }
4482
            }
4483
            break;
4484
 
11806 schaersvoo 4485
        case VLINES:
11802 schaersvoo 4486
        /*
11806 schaersvoo 4487
        @ vlines color,x1,y1,x2,y2....
4488
        @ alternative : verticallines
4489
        @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
4490
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
11802 schaersvoo 4491
        */
11806 schaersvoo 4492
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
4493
            fill_color = stroke_color;
4494
            i=0;
4495
            while( ! done ){     /* get next item until EOL*/
4496
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
4497
                if(i%2 == 0 ){
4498
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 4499
                }
11806 schaersvoo 4500
                else
4501
                {
4502
                    double_data[i] = get_real(infile,1); /* y */
7983 schaersvoo 4503
                }
11806 schaersvoo 4504
                i++;
7983 schaersvoo 4505
            }
11806 schaersvoo 4506
            decimals = find_number_of_digits(precision);
4507
            for(c = 0 ; c < i-1 ; c = c+2){
4508
                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,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c],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,rotation_center,use_offset);
4509
                if(onclick > 0){click_cnt++;}
4510
                /* click_cnt++; */
4511
            }
4512
            reset();
7983 schaersvoo 4513
            break;
11806 schaersvoo 4514
 
4515
 
4516
        case VIDEO:
7614 schaersvoo 4517
        /*
11806 schaersvoo 4518
        @ video x,y,w,h,videofile location
4519
        @ x,y : left top corner of audio element (in xrange / yrange)
4520
        @ w,y : width and height in pixels
4521
        @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
4522
        @ video format may be in *.mp4 (todo:other formats)
7614 schaersvoo 4523
        */
11806 schaersvoo 4524
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
7614 schaersvoo 4525
            for(i=0;i<5;i++){
4526
                switch(i){
11806 schaersvoo 4527
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
4528
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
4529
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
4530
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
4531
                    case 4: temp = get_string(infile,1);
4532
                            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);
7614 schaersvoo 4533
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11806 schaersvoo 4534
                            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);
7614 schaersvoo 4535
                            add_to_buffer(tmp_buffer);
4536
                            break;
4537
                    default:break;
4538
                }
4539
            }
4540
            reset();
4541
            break;
11806 schaersvoo 4542
 
7614 schaersvoo 4543
        case X_AXIS_STRINGS:
4544
        /*
4545
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9385 schaersvoo 4546
         @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9346 schaersvoo 4547
         @ use these x-axis num1...num_n values instead of default xmin...xmax
11044 schaersvoo 4548
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
4549
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
11088 schaersvoo 4550
         @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br />note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
9346 schaersvoo 4551
         @ a javascript error message will flag non-matching value:name pairs
9341 schaersvoo 4552
         @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied
11044 schaersvoo 4553
         @ to be used before command grid (see <a href="#grid">command grid</a>)
7614 schaersvoo 4554
         @ 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
4555
        */
4556
            temp = get_string(infile,1);
4557
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
4558
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
4559
            fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
4560
            use_axis_numbering = 1;
4561
            break;
9341 schaersvoo 4562
        case X_AXIS_STRINGS_UP:
4563
        /*
4564
         @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9385 schaersvoo 4565
         @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9341 schaersvoo 4566
         @ the text will be rotated 90&deg; up
11044 schaersvoo 4567
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
4568
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
9346 schaersvoo 4569
         @ use these x-axis num1...num_n values instead of default xmin...xmax
11088 schaersvoo 4570
         @ use command "fontcolor","fontfamily" to adjust font <br />defaults: black,12,Ariel<br />note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
9346 schaersvoo 4571
         @ a javascript error message will flag non-matching value:name pairs
9341 schaersvoo 4572
         @ if the 'x-axis words' are too big, they will overlap the graph<br /> (in this case the text will start from ysize upwards)
11044 schaersvoo 4573
         @ to be used before command grid (see <a href="#grid">command grid</a>)
9341 schaersvoo 4574
         @ example:<br />size 400,400<br />xrange 0,13<br />yrange -100,500<br />axis<br />xaxisup 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
4575
        */
4576
            temp = get_string(infile,1);
4577
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
4578
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
4579
            fprintf(js_include_file,"x_strings_up = 1;x_strings = [\"%s\"];\n ",temp);
4580
            use_axis_numbering = 1;
4581
            break;
8224 bpr 4582
 
11806 schaersvoo 4583
        case XERRORBARS:
7614 schaersvoo 4584
        /*
11806 schaersvoo 4585
        @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
4586
        @ draw multiple points with x-errorbars E1 (error value left from point) and E2 (error value right from point) at given coordinates in color 'color'
4587
        @ the errors E1 and E2 values are in xrange.
4588
        @ use command 'linewidth int' to adust size
4589
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
7614 schaersvoo 4590
        */
11806 schaersvoo 4591
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
4592
            fill_color = stroke_color;
4593
            i=0;
4594
            while( ! done ){     /* get next item until EOL*/
4595
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
4596
                if(i%2 == 0 ){
4597
                    double_data[i] = get_real(infile,0); /* x */
8071 schaersvoo 4598
                }
11806 schaersvoo 4599
                else
4600
                {
4601
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 4602
                }
11806 schaersvoo 4603
                i++;
7614 schaersvoo 4604
            }
11806 schaersvoo 4605
            decimals = find_number_of_digits(precision);
4606
            for(c = 2 ; c < i-1 ; c = c+2){
4607
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,20,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],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,rotation_center,use_offset);
4608
                /* click_cnt++; */
4609
                if(onclick > 0){click_cnt++;}
4610
            }
7614 schaersvoo 4611
            reset();
4612
            break;
11806 schaersvoo 4613
 
4614
        case XRANGE:
7614 schaersvoo 4615
        /*
11806 schaersvoo 4616
        @ xrange xmin,xmax
4617
        @ alternative : rangex
4618
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 4619
        */
11806 schaersvoo 4620
            for(i = 0 ; i<2; i++){
7614 schaersvoo 4621
                switch(i){
11806 schaersvoo 4622
                    case 0: xmin = get_real(infile,0);break;
4623
                    case 1: xmax = get_real(infile,1);break;
7614 schaersvoo 4624
                    default: break;
4625
                }
4626
            }
11806 schaersvoo 4627
            if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
4628
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
4629
            found_size_command++;
7614 schaersvoo 4630
            break;
8386 schaersvoo 4631
 
4632
 
4633
 
11806 schaersvoo 4634
        case XSNAPTOGRID:
7614 schaersvoo 4635
        /*
11806 schaersvoo 4636
         @ xsnaptogrid
4637
         @ keyword (no arguments required)
4638
         @ a draggable object (use command "drag  x|y|xy") will snap to the given x-grid values when dragged (mouseup)
4639
         @ in case of userdraw the drawn points will snap to xmajor grid
4640
         @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1)
4641
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
4642
         @ if xminor is defined (use keyword 'axis' to activate xminor), 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 />
7614 schaersvoo 4643
        */
11806 schaersvoo 4644
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
4645
        break;
8386 schaersvoo 4646
 
11806 schaersvoo 4647
        case XOFFSET:
7614 schaersvoo 4648
        /*
11806 schaersvoo 4649
         @ xoffset | centered
4650
         @ keyword ; to place the text centered above the text coordinates(x:y) ...
4651
         @ may be used for points or other things requirering centered labels
11811 schaersvoo 4652
         @ may be active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-library)
7614 schaersvoo 4653
        */
11806 schaersvoo 4654
         use_offset = 1;
4655
         break;
8386 schaersvoo 4656
 
11806 schaersvoo 4657
        case XYOFFSET:
7614 schaersvoo 4658
        /*
11806 schaersvoo 4659
         @ xyoffset
4660
         @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
4661
         @ may be used for points or other things requirering labels
4662
         @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
4663
         @ in case of inputfields the inputfield will be centered x and y on it's coordinates.<br />for example:<br />inputs 1,1,10,? <br />point 1,1,red <br /> the point will be completely invisible<br />note: keyword 'xyoffset' will also provide centering if used with <a href='#@userdraw'>input(s),color</a>  
7614 schaersvoo 4664
        */
11806 schaersvoo 4665
         use_offset = 2;
4666
         break;
8386 schaersvoo 4667
 
7996 schaersvoo 4668
        case XUNIT:
4669
        /*
4670
         @ xunit some_unit_for_x-values
4671
         @ unicode allowed (no html code)
4672
         @ use together with command mousex
9372 schaersvoo 4673
         @ will display the cursor x-coordinate in 'unit'
7996 schaersvoo 4674
        */
4675
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
4676
            break;
11806 schaersvoo 4677
 
4678
        case XLABEL:
7996 schaersvoo 4679
        /*
11806 schaersvoo 4680
        @ xlabel some_string
4681
        @ will be used to create a label for the x-axis (label is in quadrant I)
4682
        @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
4683
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command)
7996 schaersvoo 4684
        */
11806 schaersvoo 4685
            temp = get_string(infile,1);
4686
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7996 schaersvoo 4687
            break;
8071 schaersvoo 4688
 
11806 schaersvoo 4689
        case XLOGBASE:
7991 schaersvoo 4690
        /*
11806 schaersvoo 4691
        @ xlogbase number
4692
        @ sets the logbase number for the x-axis
4693
        @ default value 10
4694
        @ use together with commands xlogscale / xylogscale
7991 schaersvoo 4695
        */
11806 schaersvoo 4696
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7991 schaersvoo 4697
            break;
4698
 
11806 schaersvoo 4699
        case XLOGSCALE:
7614 schaersvoo 4700
        /*
11806 schaersvoo 4701
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
4702
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
4703
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
4704
         @ the linewidth is set using command 'linewidth int'
4705
         @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>'
4706
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
4707
         @ 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>
4708
         @ note: the complete canvas will be used for the 'log paper'
4709
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
4710
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
4711
         @ note: when using something like 'xrange 0.0001,0.01'...combined with commands <a href='#mouse'>'mouse'</a> and/or <a href='#userdraw'>'userdraw</a>...<br /> make sure the <a href='#precision'>precision</a> is set accordingly
4712
         @ note: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy !
4713
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 4714
        */
11806 schaersvoo 4715
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
4716
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
4717
            for(i=0;i<4;i++){
7614 schaersvoo 4718
                switch(i){
11806 schaersvoo 4719
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
4720
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
4721
                    case 2: stroke_color = get_color(infile,0); break;
4722
                    case 3: fill_color = get_color(infile,1);
4723
                        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);
4724
                        tmp_buffer = my_newmem(string_length+1);
4725
                        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);
4726
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
4727
                        add_to_buffer(tmp_buffer);
4728
                        break;
7614 schaersvoo 4729
                    default:break;
4730
                }
4731
            }
4732
            break;
11806 schaersvoo 4733
 
4734
        case XYLOGSCALE:
7614 schaersvoo 4735
        /*
11806 schaersvoo 4736
         @ xylogscale majorcolor,minorcolor
4737
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
4738
         @ the linewidth is set using command 'linewidth int'
4739
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
4740
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
4741
         @ 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>
4742
         @ note: the complete canvas will be used for the 'log paper'
4743
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
4744
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
4745
         @ 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')
4746
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
4747
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 4748
        */
11806 schaersvoo 4749
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
4750
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
4751
            for(i=0;i<2;i++){
7614 schaersvoo 4752
                switch(i){
11806 schaersvoo 4753
                    case 0: stroke_color = get_color(infile,0); break;
4754
                    case 1: fill_color = get_color(infile,1);
4755
                        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);
4756
                        tmp_buffer = my_newmem(string_length+1);
4757
                        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);
4758
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
4759
                        add_to_buffer(tmp_buffer);
4760
                        break;
7614 schaersvoo 4761
                    default:break;
4762
                }
4763
            }
4764
        break;
11806 schaersvoo 4765
 
4766
 
4767
        case Y_AXIS_STRINGS:
7647 schaersvoo 4768
        /*
11806 schaersvoo 4769
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
4770
         @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
4771
         @ use command "fontcolor", "fontfamily" to adjust font <br />defaults: black,12,Ariel<br /> note: command "fontsize" is not active for this command.("fontsize" can be used for the <a href="#legend">"legend"</a> in a <a href="#grid">grid</a>)
4772
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
4773
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
4774
         @ use these y-axis num1...num_n  values instead of default ymin...ymax
4775
         @ a javascript error message will flag non-matching value:name pairs
4776
         @ to be used before command grid (see <a href="#grid">command grid</a>)
4777
         @ 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
7647 schaersvoo 4778
        */
11806 schaersvoo 4779
            temp = get_string(infile,1);
4780
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
4781
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
4782
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
4783
            use_axis_numbering = 1;
4784
            break;
4785
 
4786
 
4787
        case YERRORBARS:
7614 schaersvoo 4788
        /*
11806 schaersvoo 4789
        @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
4790
        @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
4791
        @ the errors E1 and E2 values are in yrange.
4792
        @ use command 'linewidth int' to adust size
4793
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
7614 schaersvoo 4794
        */
11806 schaersvoo 4795
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
4796
            fill_color = stroke_color;
11772 schaersvoo 4797
            i=0;
4798
            while( ! done ){     /* get next item until EOL*/
4799
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
4800
                if(i%2 == 0 ){
4801
                    double_data[i] = get_real(infile,0); /* x */
4802
                }
4803
                else
4804
                {
4805
                    double_data[i] = get_real(infile,1); /* y */
4806
                }
4807
                i++;
4808
            }
11806 schaersvoo 4809
            for(c = 2 ; c < i-1 ; c = c+2){
4810
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,19,[%.*f],[%.*f],[%.2f],[%.2f],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d));\n",click_cnt,onclick,drag_type,decimals,double_data[c],decimals,double_data[c+1],double_data[0],double_data[1],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,rotation_center,use_offset);
4811
                /* click_cnt++; */
4812
                if(onclick > 0){click_cnt++;}
8083 schaersvoo 4813
            }
11806 schaersvoo 4814
            decimals = find_number_of_digits(precision);
8083 schaersvoo 4815
            reset();
11806 schaersvoo 4816
            break;
4817
 
11811 schaersvoo 4818
        case YOFFSET:
4819
        /*
4820
         @ yoffset
4821
         @ keyword, only active for commands <a href="#textup">textup</a> and <a href="#stringup">stringup</a>
4822
         @ places the text <b>under</b> the (x:y) coordinates(x:y)<br/ >eg the string 'hello' will end at char 'o' on (x:y) <br />normal behaviour : string starts at (x:y)
4823
         @ string ending on (x:y) is valid for all rotation angles
4824
         @ may be used for points or other things requirering labels in y-direction
4825
         @ other text position manipulations: see <a href="#xoffset">xoffset</a>  for centering on x-coordinate or <a href="#xyoffset">xyoffset</a> label placement for points etc.
4826
        */
4827
        use_offset = 3;
4828
         break;
4829
 
11806 schaersvoo 4830
        case YRANGE:
7614 schaersvoo 4831
        /*
11806 schaersvoo 4832
        @ yrange ymin,ymax
4833
        @ alternative : rangey
4834
        @ if not given 0,ysize (eg in pixels)
7614 schaersvoo 4835
        */
11806 schaersvoo 4836
            for(i = 0 ; i<2; i++){
7614 schaersvoo 4837
                switch(i){
11806 schaersvoo 4838
                    case 0: ymin = get_real(infile,0);break;
4839
                    case 1: ymax = get_real(infile,1);break;
4840
                    default: break;
7614 schaersvoo 4841
                }
4842
            }
11806 schaersvoo 4843
            if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
4844
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
4845
            found_size_command++;
4846
            break;
4847
 
4848
        case YSNAPTOGRID:
7614 schaersvoo 4849
        /*
11806 schaersvoo 4850
         @ ysnaptogrid
4851
         @ keyword (no arguments required)
4852
         @ a draggable object (use command "drag  x|y|xy") will snap to the given y-grid values when dragged (mouseup)
4853
         @ in case of userdraw the drawn points will snap to ymajor grid
4854
         @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1)
4855
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
4856
         @ if yminor is defined (use keyword 'axis' to activate yminor), 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 />
7614 schaersvoo 4857
        */
11806 schaersvoo 4858
        fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
7614 schaersvoo 4859
        break;
11080 schaersvoo 4860
 
7614 schaersvoo 4861
        case YLABEL:
4862
        /*
4863
        @ ylabel some_string
8224 bpr 4864
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
9379 schaersvoo 4865
        @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
10953 bpr 4866
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command "fontsize" to adjust.<br />(command "fontfamily" is not active for this command)
7614 schaersvoo 4867
        */
4868
            temp = get_string(infile,1);
7653 schaersvoo 4869
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 4870
            break;
7735 schaersvoo 4871
        case YLOGBASE:
4872
        /*
4873
        @ ylogbase number
4874
        @ sets the logbase number for the y-axis
4875
        @ default value 10
4876
        @ use together with commands ylogscale / xylogscale
4877
        */
4878
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
4879
            break;
7614 schaersvoo 4880
        case YLOGSCALE:
7729 schaersvoo 4881
        /*
4882
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
4883
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
4884
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
4885
         @ the linewidth is set using command 'linewidth int'
4886
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
7735 schaersvoo 4887
         @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
8224 bpr 4888
         @ 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>
11088 schaersvoo 4889
         @ note: the complete canvas will be used for the 'log paper'
4890
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
4891
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
4892
         @ 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')
4893
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
9383 schaersvoo 4894
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7729 schaersvoo 4895
        */
4896
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
4897
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
4898
            for(i=0;i<4;i++){
4899
                switch(i){
4900
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
4901
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
4902
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 4903
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 4904
                        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 4905
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 4906
                        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 4907
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 4908
                        add_to_buffer(tmp_buffer);
4909
                        break;
4910
                    default:break;
4911
                }
4912
            }
7614 schaersvoo 4913
            break;
11806 schaersvoo 4914
 
4915
        case YUNIT:
7735 schaersvoo 4916
        /*
11806 schaersvoo 4917
         @ yunit some_unit_for_y-values
4918
         @ unicode allowed (no html code)
4919
         @ use together with command mousey
4920
         @ will display the cursor y-coordinate in 'unit'
7735 schaersvoo 4921
        */
11806 schaersvoo 4922
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
4923
            break;
4924
 
4925
        case ZOOM:
4926
        /*
4927
         @ zoom button_color
4928
         @ introduce a very small 'controlpanel' at the lower right corner
4929
         @ giving six 15&times;15px 'active' rectangle areas<br />(for &times;,leftarrow,rightarrow,uparrow,downarrow and a '-' and a '+' sign ) for zooming and/or panning of the image
4930
         @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
4931
         @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
4932
         @ command 'opacity' may be used to set stroke_opacity of 'buttons
4933
         @ note: use command 'zoom' at the end of your script code (the same is true for command 'mouse')
4934
         @ note: only objects that may be set draggable / clickable will be zoomed / panned
4935
         @ 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 !!
4936
        */
4937
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
4938
            use_pan_and_zoom = TRUE;
4939
            stroke_color = get_color(infile,1);
4940
            /* we use BG_CANVAS (0) */
4941
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
4942
            done = TRUE;
4943
            break;
4944
 
4945
/* ready */
7614 schaersvoo 4946
        default:sync_input(infile);
4947
        break;
4948
    }
8224 bpr 4949
  }
7614 schaersvoo 4950
  /* we are done parsing script file */
7983 schaersvoo 4951
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
4952
  if( found_size_command == 1 ){
4953
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
4954
  }
4955
  else
4956
  {
4957
    if( found_size_command != 3 ){
8222 schaersvoo 4958
     canvas_error("Please specify both xrange and yrange ...");
7983 schaersvoo 4959
    }
4960
  }
8257 schaersvoo 4961
 
8222 schaersvoo 4962
  /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
11021 schaersvoo 4963
  add_javascript_function(js_function,canvas_root_id);
7614 schaersvoo 4964
   /* add read_canvas() etc functions if needed */
8257 schaersvoo 4965
  if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
7797 schaersvoo 4966
  if( use_pan_and_zoom == TRUE ){
4967
  /* in case of zooming ... */
7729 schaersvoo 4968
  fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
7797 schaersvoo 4969
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 4970
  var ymin_start=ymin;var ymax_start=xmax;\
4971
  var zoom_x_increment=0;var zoom_y_increment=0;\
4972
  var pan_x_increment=0;var pan_y_increment=0;\
4973
  if(use_ylogscale == 0 ){\
7956 schaersvoo 4974
   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 4975
  }else{\
4976
   zoom_x_increment = (xmax - xmin)/20;\
4977
   pan_x_increment = (xmax - xmin)/20;\
4978
  };\
9406 schaersvoo 4979
  var zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 4980
  function start_canvas%d(type){\
9406 schaersvoo 4981
   zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 4982
   switch(type){\
7729 schaersvoo 4983
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
4984
    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 4985
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
4986
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
4987
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
4988
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
11004 schaersvoo 4989
    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
7653 schaersvoo 4990
    default:break;\
4991
   };\
4992
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
4993
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
9406 schaersvoo 4994
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
11088 schaersvoo 4995
   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
9406 schaersvoo 4996
   %s ;\
7653 schaersvoo 4997
  };\
7797 schaersvoo 4998
  start_canvas%d(333);\
9438 schaersvoo 4999
 };\
5000
\n<!-- end wims_canvas_function -->\n\
9406 schaersvoo 5001
wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
7797 schaersvoo 5002
  }
5003
  else
5004
  {
5005
  /* no zoom, just add buffer */
5006
  fprintf(js_include_file,"\n<!-- add buffer -->\n\
5007
  %s\
5008
 };\n\
5009
<!-- end wims_canvas_function -->\n\
5010
wims_canvas_function%d();\n",buffer,canvas_root_id);
5011
  }
7614 schaersvoo 5012
/* done writing the javascript include file */
5013
fclose(js_include_file);
5014
 
5015
}
5016
 
5017
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
9329 schaersvoo 5018
 if( use_tooltip > 0 ){
5019
  if( use_tooltip == 1 ){
5020
   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
5021
  }
5022
  else
5023
  {
5024
   if( use_tooltip == 2 ){
5025
    add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
5026
   }
5027
  }
5028
 }
7614 schaersvoo 5029
exit(EXIT_SUCCESS);
5030
}
5031
/* end main() */
5032
 
5033
/******************************************************************************
5034
**
5035
**  sync_input
5036
**
5037
**  synchronises input line - reads to end of line, leaving file pointer
5038
**  at first character of next line.
5039
**
5040
**  Used by:
5041
**  main program - error handling.
5042
**
5043
******************************************************************************/
5044
void sync_input(FILE *infile)
5045
{
5046
        int c = 0;
5047
 
7658 schaersvoo 5048
        if( c == '\n' || c == ';' ) return;
5049
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 5050
        if( c == EOF ) finished = 1;
7658 schaersvoo 5051
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 5052
        return;
5053
}
5054
 
5055
/******************************************************************************/
5056
 
5057
char *str_replace(const char *str, const char *old, const char *new){
5058
/* http://creativeandcritical.net/str-replace-c/ */
5059
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
5060
    char *ret, *r;
5061
    const char *p, *q;
5062
    size_t oldlen = strlen(old);
5063
    size_t count = 0;
5064
    size_t retlen = 0;
5065
    size_t newlen = strlen(new);
5066
    if (oldlen != newlen){
5067
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
5068
            count++;
5069
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
5070
        }
8224 bpr 5071
    }
7614 schaersvoo 5072
    else
5073
    {
5074
        retlen = strlen(str);
5075
    }
8224 bpr 5076
 
7614 schaersvoo 5077
    if ((ret = malloc(retlen + 1)) == NULL){
5078
        ret = NULL;
5079
        canvas_error("string argument is NULL");
5080
    }
5081
    else
5082
    {
5083
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
5084
            size_t l = q - p;
5085
            memcpy(r, p, l);
5086
            r += l;
5087
            memcpy(r, new, newlen);
5088
            r += newlen;
5089
        }
5090
        strcpy(r, p);
5091
    }
5092
    return ret;
5093
}
5094
 
5095
/******************************************************************************/
7848 bpr 5096
 
7614 schaersvoo 5097
char *get_color(FILE *infile , int last){
5098
    int c,i = 0,is_hex = 0;
5099
    char temp[MAX_COLOR_STRING], *string;
8305 schaersvoo 5100
    const char *not_allowed = "0123456789";
10891 schaersvoo 5101
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
7614 schaersvoo 5102
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
5103
        if( c == '#' ){
5104
            is_hex = 1;
5105
        }
5106
        if( c != ' '){
8304 schaersvoo 5107
            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 5108
            temp[i]=tolower(c);
5109
            i++;
5110
        }
5111
    }
10891 schaersvoo 5112
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5113
    if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5114
    if( c == EOF ){finished = 1;}
5115
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
5116
    temp[i]='\0';
5117
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
5118
    if( is_hex == 1 ){
5119
        char red[3], green[3], blue[3];
5120
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
5121
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
5122
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
5123
        int r = (int) strtol(red,   NULL, 16);
5124
        int g = (int) strtol(green, NULL, 16);
5125
        int b = (int) strtol(blue,  NULL, 16);
5126
        string = (char *)my_newmem(12);
5127
        snprintf(string,11,"%d,%d,%d",r,g,b);
5128
        return string;
5129
    }
5130
    else
5131
    {
5132
        string = (char *)my_newmem(sizeof(temp));
5133
        snprintf(string,sizeof(temp),"%s",temp);
8304 schaersvoo 5134
        for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
7614 schaersvoo 5135
            if( strcmp( colors[i].name , string ) == 0 ){
5136
                return colors[i].rgb;
5137
            }
5138
        }
8304 schaersvoo 5139
        canvas_error("I was expecting a color name or hexnumber...but found nothing.");
7614 schaersvoo 5140
    }
8304 schaersvoo 5141
    return "0,0,255";
7614 schaersvoo 5142
}
5143
 
5144
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
5145
    int c,i=0;
5146
    char  temp[MAX_BUFFER], *string;
10891 schaersvoo 5147
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
7614 schaersvoo 5148
        temp[i]=c;
5149
        i++;
5150
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
5151
    }
10891 schaersvoo 5152
    if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
5153
    if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
11022 schaersvoo 5154
    if( c == EOF ) {finished = 1;}
7614 schaersvoo 5155
    temp[i]='\0';
11022 schaersvoo 5156
    if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
7614 schaersvoo 5157
    string=(char *)my_newmem(strlen(temp));
5158
    snprintf(string,sizeof(temp),"%s",temp);
5159
    return string;
5160
}
5161
 
5162
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
5163
    int c,i=0;
5164
    char temp[MAX_BUFFER], *string;
10891 schaersvoo 5165
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
7614 schaersvoo 5166
        temp[i]=c;
5167
        i++;
5168
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
5169
    }
8224 bpr 5170
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
10891 schaersvoo 5171
    if( c == '\n' || c == '\t' ) { line_number++; }
7614 schaersvoo 5172
    if( c == EOF ) {finished = 1;}
9478 schaersvoo 5173
    if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
7614 schaersvoo 5174
    temp[i]='\0';
10953 bpr 5175
/*
8322 schaersvoo 5176
    17.10.2014 removed (question Perrin)
5177
    may cause some unwanted effects...
7614 schaersvoo 5178
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
8322 schaersvoo 5179
*/
7614 schaersvoo 5180
    string=(char *)my_newmem(sizeof(temp));
5181
    snprintf(string,sizeof(temp),"%s",temp);
5182
    done = TRUE;
5183
    return string;
5184
}
5185
 
5186
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
5187
    int c,i=0,found_calc = 0;
5188
    double y;
5189
    char tmp[MAX_INT];
10953 bpr 5190
    /*
5191
     these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
8383 schaersvoo 5192
     but there should be a better way to avoid segfaults !
8348 schaersvoo 5193
    */
5194
    const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
5195
    const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
10891 schaersvoo 5196
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
7614 schaersvoo 5197
     if( c != ' ' ){
8224 bpr 5198
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 5199
       continue;
8224 bpr 5200
      }
7614 schaersvoo 5201
      else
5202
      {
8304 schaersvoo 5203
       c = tolower(c);
5204
       if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
5205
       if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
7614 schaersvoo 5206
       tmp[i] = c;
5207
       i++;
5208
      }
5209
     }
5210
     if( i > MAX_INT - 1){canvas_error("number too large");}
5211
    }
10891 schaersvoo 5212
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5213
    if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5214
    if( c == EOF ){done = TRUE ; finished = 1;}
5215
    tmp[i]='\0';
5216
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
8304 schaersvoo 5217
    if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
7848 bpr 5218
     void *f = eval_create(tmp);
7614 schaersvoo 5219
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 5220
     y = eval_x(f, 1);
7614 schaersvoo 5221
     /* if function is bogus; y = 1 : so no core dumps */
7848 bpr 5222
     eval_destroy(f);
7614 schaersvoo 5223
    }
5224
    else
5225
    {
5226
     y = atof(tmp);
5227
    }
5228
    return y;
5229
}
8304 schaersvoo 5230
 
5231
 
7614 schaersvoo 5232
void canvas_error(char *msg){
8383 schaersvoo 5233
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
7614 schaersvoo 5234
    finished = 1;
5235
    exit(EXIT_SUCCESS);
5236
}
5237
 
5238
 
5239
/* convert x/y coordinates to pixel */
5240
int x2px(double x){
5241
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
5242
}
5243
 
5244
int y2px(double y){
5245
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
5246
}
5247
 
5248
double px2x(int x){
5249
 return (x*(xmax - xmin)/xsize + xmin);
5250
}
5251
double px2y(int y){
5252
 return (y*(ymax - ymin)/ysize + ymin);
5253
}
5254
 
5255
void add_to_buffer(char *tmp){
5256
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
5257
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
5258
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
5259
 if( space_left > strlen(tmp)){
5260
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
5261
 }
5262
 else
5263
 {
5264
  canvas_error("buffer is too big\n");
5265
 }
5266
 tmp = NULL;free(tmp);
5267
 return;
5268
}
5269
 
5270
void reset(){
5271
 if(use_filled == TRUE){use_filled = FALSE;}
5272
 if(use_dashed == TRUE){use_dashed = FALSE;}
5273
 if(use_rotate == TRUE){use_rotate = FALSE;}
8379 schaersvoo 5274
 onclick = 0;
7614 schaersvoo 5275
}
5276
 
5277
 
5278
 
5279
/* What reply format in read_canvas();
5280
 
5281
note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
5282
1 = x1,x2,x3,x4....x_n
5283
    y1,y2,y3,y4....y_n
5284
 
5285
    x/y in pixels
5286
 
5287
2 = x1,x2,x3,x4....x_n
5288
    y1,y2,y3,y4....y_n
5289
    x/y in  xrange / yrange coordinate system
5290
 
5291
3 = x1,x2,x3,x4....x_n
5292
    y1,y2,y3,y4....y_n
5293
    r1,r2,r3,r4....r_n
5294
 
8224 bpr 5295
    x/y in pixels
7614 schaersvoo 5296
    r in pixels
5297
 
5298
4 = x1,x2,x3,x4....x_n
5299
    y1,y2,y3,y4....y_n
5300
    r1,r2,r3,r4....r_n
5301
 
5302
    x/y in  xrange / yrange coordinate system
5303
    r in pixels
5304
 
5305
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
5306
    Ay1,Ay2,Ay3,Ay4....Ay_n
5307
    Bx1,Bx2,Bx3,Bx4....Bx_n
5308
    By1,By2,By3,By4....By_n
5309
    Cx1,Cx2,Cx3,Cx4....Cx_n
5310
    Cy1,Cy2,Cy3,Cy4....Cy_n
5311
    ....
5312
    Zx1,Zx2,Zx3,Zx4....Zx_n
5313
    Zy1,Zy2,Zy3,Zy4....Zy_n
8224 bpr 5314
 
7614 schaersvoo 5315
    x/y in pixels
5316
 
5317
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
5318
    Ay1,Ay2,Ay3,Ay4....Ay_n
5319
    Bx1,Bx2,Bx3,Bx4....Bx_n
5320
    By1,By2,By3,By4....By_n
5321
    Cx1,Cx2,Cx3,Cx4....Cx_n
5322
    Cy1,Cy2,Cy3,Cy4....Cy_n
5323
    ....
5324
    Zx1,Zx2,Zx3,Zx4....Zx_n
5325
    Zy1,Zy2,Zy3,Zy4....Zy_n
5326
 
5327
    x/y in  xrange / yrange coordinate system
8224 bpr 5328
 
7614 schaersvoo 5329
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 5330
 
7614 schaersvoo 5331
    x/y in pixels
5332
 
5333
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 5334
 
7614 schaersvoo 5335
    x/y in  xrange / yrange coordinate system
5336
 
8224 bpr 5337
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 5338
 
5339
    x/y in pixels
5340
 
8224 bpr 5341
10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 5342
 
5343
    x/y in  xrange / yrange coordinate system
5344
 
5345
11 = Ax1,Ay1,Ax2,Ay2
5346
     Bx1,By1,Bx2,By2
5347
     Cx1,Cy1,Cx2,Cy2
5348
     Dx1,Dy1,Dx2,Dy2
5349
     ......
5350
     Zx1,Zy1,Zx2,Zy2
8224 bpr 5351
 
7614 schaersvoo 5352
    x/y in  xrange / yrange coordinate system
5353
 
5354
12 = Ax1,Ay1,Ax2,Ay2
5355
     Bx1,By1,Bx2,By2
5356
     Cx1,Cy1,Cx2,Cy2
5357
     Dx1,Dy1,Dx2,Dy2
5358
     ......
5359
     Zx1,Zy1,Zx2,Zy2
8224 bpr 5360
 
7614 schaersvoo 5361
    x/y in pixels
5362
 
5363
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
5364
 
5365
    x/y in  xrange / yrange coordinate system
5366
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
5367
    x/y in pixels
5368
15 = reply from inputfields,textareas
5369
    reply1,reply2,reply3,...,reply_n
7984 schaersvoo 5370
    only fields set write (a.g. will not read 'readonly' inputfield values'
7614 schaersvoo 5371
 
5372
16 = read mathml inputfields only
5373
 
11080 schaersvoo 5374
17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
7614 schaersvoo 5375
 when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
5376
 
5377
18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
5378
19 = return clicked object number (analogue to shape-library onclick)
5379
20 = return x/y-data in x-range/y-range of all 'draggable' images
5380
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
5381
22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
5382
    x/y in  xrange / yrange coordinate system
8224 bpr 5383
23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
7984 schaersvoo 5384
24 = read all inputfield values: even those set 'readonly'
8224 bpr 5385
25 = return all userdrawn arcs in degrees:
5386
26 = return all userdrawn arcs in radians:
11080 schaersvoo 5387
27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
8322 schaersvoo 5388
28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
10953 bpr 5389
    x/y/r in  xrange / yrange coordinate system: may be used to reinput into command
8322 schaersvoo 5390
    'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'
5391
    will not return anything else (e.g. no inputfields , text etc)
10953 bpr 5392
29 = mulidraw read :
5393
 
7614 schaersvoo 5394
*/
5395
 
5396
 
8257 schaersvoo 5397
void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
7614 schaersvoo 5398
/* just 1 reply type allowed */
8074 schaersvoo 5399
fprintf(js_include_file,"\
5400
\n<!-- begin set_reply_precision() -->\n\
5401
function set_reply_precision(){\
5402
 var len = userdraw_x.length;\
5403
 var prec = %d;\
5404
 for(var p = 0 ; p < len ; p++ ){\
5405
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
5406
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
5407
 };\
5408
 len = userdraw_radius.length;\
5409
 if( len > 0 ){\
5410
  for(var p = 0 ; p < len ; p++ ){\
5411
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
5412
  };\
5413
 };\
5414
};",reply_precision);
7963 schaersvoo 5415
 
7614 schaersvoo 5416
switch(type_reply){
8224 bpr 5417
/*
7614 schaersvoo 5418
answers may have:
5419
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
5420
*/
5421
    case 1: fprintf(js_include_file,"\
8257 schaersvoo 5422
\n<!-- begin function 1 read_canvas%d() -->\n\
5423
read_canvas%d = function(){\
7614 schaersvoo 5424
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 5425
 set_reply_precision();\
7614 schaersvoo 5426
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5427
  var p = 0;var input_reply = new Array();\
5428
  if( document.getElementById(\"canvas_input0\")){\
5429
   var t = 0;\
5430
   while(document.getElementById(\"canvas_input\"+t)){\
5431
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5432
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5433
     p++;\
5434
    };\
5435
    t++;\
5436
   };\
5437
  };\
11088 schaersvoo 5438
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5439
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
5440
  }\
5441
  else\
5442
  {\
5443
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
5444
  }\
5445
 }\
5446
 else\
5447
 {\
11088 schaersvoo 5448
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5449
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
5450
  }\
5451
  else\
5452
  {\
5453
   return userdraw_x+\"\\n\"+userdraw_y;\
5454
  }\
5455
 };\
8108 schaersvoo 5456
};\n\
8257 schaersvoo 5457
<!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5458
    break;
5459
    case 2: fprintf(js_include_file,"\
8257 schaersvoo 5460
\n<!-- begin function 2 read_canvas%d() -->\n\
5461
read_canvas%d = function(){\
7614 schaersvoo 5462
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 5463
 set_reply_precision();\
7614 schaersvoo 5464
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 5465
 var prec = %d;\
7614 schaersvoo 5466
 while(userdraw_x[p]){\
8074 schaersvoo 5467
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
5468
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 5469
  p++;\
5470
 };\
11806 schaersvoo 5471
 if(p == 0){return;};\
7614 schaersvoo 5472
 if( document.getElementById(\"canvas_input0\")){\
5473
  var p = 0;var input_reply = new Array();\
5474
  if( document.getElementById(\"canvas_input0\")){\
5475
   var t = 0;\
5476
   while(document.getElementById(\"canvas_input\"+t)){\
5477
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5478
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5479
     p++;\
5480
    };\
5481
    t++;\
5482
   };\
5483
  };\
11088 schaersvoo 5484
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5485
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5486
  }\
5487
  else\
5488
  {\
5489
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
5490
  }\
5491
 }\
5492
 else\
5493
 {\
11088 schaersvoo 5494
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5495
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
5496
  }\
5497
  else\
5498
  {\
5499
   return reply_x+\"\\n\"+reply_y;\
5500
  };\
5501
 };\
8108 schaersvoo 5502
};\n\
8257 schaersvoo 5503
<!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5504
    break;
5505
    case 3: fprintf(js_include_file,"\
8257 schaersvoo 5506
\n<!-- begin function 3 read_canvas%d() -->\n\
5507
read_canvas%d = function(){\
7614 schaersvoo 5508
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 5509
 set_reply_precision();\
7614 schaersvoo 5510
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5511
  var p = 0;var input_reply = new Array();\
5512
  if( document.getElementById(\"canvas_input0\")){\
5513
   var t = 0;\
5514
   while(document.getElementById(\"canvas_input\"+t)){\
5515
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5516
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5517
     p++;\
5518
    };\
5519
    t++;\
5520
   };\
5521
  };\
11088 schaersvoo 5522
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5523
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5524
  }\
5525
  else\
5526
  {\
5527
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
5528
  }\
5529
 }\
5530
 else\
5531
 {\
11088 schaersvoo 5532
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5533
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
5534
  }\
5535
  else\
5536
  {\
5537
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
5538
  }\
5539
 }\
8108 schaersvoo 5540
};\n\
8257 schaersvoo 5541
<!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5542
    break;
5543
    case 4: fprintf(js_include_file,"\
8257 schaersvoo 5544
\n<!-- begin function 4 read_canvas%d() -->\n\
5545
read_canvas%d = function(){\
8074 schaersvoo 5546
 var prec = %d;\
7614 schaersvoo 5547
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
5548
 while(userdraw_x[p]){\
8074 schaersvoo 5549
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
5550
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 5551
  p++;\
5552
 };\
11806 schaersvoo 5553
 if(p == 0){return;};\
7614 schaersvoo 5554
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5555
  var p = 0;var input_reply = new Array();\
5556
  if( document.getElementById(\"canvas_input0\")){\
5557
   var t = 0;\
5558
   while(document.getElementById(\"canvas_input\"+t)){\
5559
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5560
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5561
     p++;\
5562
    };\
5563
    t++;\
5564
   };\
5565
  };\
11088 schaersvoo 5566
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5567
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5568
  }\
5569
  else\
5570
  {\
5571
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
5572
  }\
5573
 }\
5574
 else\
5575
 {\
11088 schaersvoo 5576
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5577
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
5578
  }\
5579
  else\
5580
  {\
5581
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
5582
  }\
5583
 };\
8108 schaersvoo 5584
};\n\
8257 schaersvoo 5585
<!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5586
    break;
8224 bpr 5587
    /*
5588
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
5589
        used for userdraw multiple paths
7614 schaersvoo 5590
    */
5591
    case 5: fprintf(js_include_file,"\
8257 schaersvoo 5592
\n<!-- begin function 5 read_canvas%d() -->\n\
5593
read_canvas%d = function(){\
8074 schaersvoo 5594
 set_reply_precision();\
7614 schaersvoo 5595
 var p = 0;\
5596
 var reply = \"\";\
5597
 for(p = 0; p < userdraw_x.length;p++){\
5598
  if(userdraw_x[p] != null ){\
5599
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
5600
  };\
5601
 };\
11806 schaersvoo 5602
 if(p == 0){return;};\
7614 schaersvoo 5603
 userdraw_x = [];userdraw_y = [];\
5604
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5605
  var p = 0;var input_reply = new Array();\
5606
  if( document.getElementById(\"canvas_input0\")){\
5607
   var t = 0;\
5608
   while(document.getElementById(\"canvas_input\"+t)){\
5609
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5610
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5611
     p++;\
5612
    };\
5613
    t++;\
5614
   };\
5615
  };\
11088 schaersvoo 5616
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5617
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5618
  }\
5619
  else\
5620
  {\
5621
   return reply +\"\\n\"+input_reply;\
5622
  }\
5623
 }\
5624
 else\
5625
 {\
11088 schaersvoo 5626
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5627
   return reply+\"\\n\"+userdraw_text;\
5628
  }\
5629
  else\
5630
  {\
5631
   return reply;\
5632
  }\
5633
 };\
8108 schaersvoo 5634
};\n\
8257 schaersvoo 5635
<!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5636
    break;
8224 bpr 5637
    /*
5638
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
5639
        used for userdraw multiple paths
7614 schaersvoo 5640
    */
5641
    case 6: fprintf(js_include_file,"\
8257 schaersvoo 5642
\n<!-- begin function 6 read_canvas%d() -->\n\
5643
read_canvas%d = function(){\
7614 schaersvoo 5644
 var p = 0;\
5645
 var reply = \"\";\
5646
 var tmp_x = new Array();\
5647
 var tmp_y = new Array();\
8074 schaersvoo 5648
 var prec = %d;\
7614 schaersvoo 5649
 for(p = 0 ; p < userdraw_x.length; p++){\
5650
  tmp_x = userdraw_x[p];\
5651
  tmp_y = userdraw_y[p];\
5652
  if(tmp_x != null){\
5653
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 5654
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
5655
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 5656
   };\
5657
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
5658
  };\
5659
 };\
11806 schaersvoo 5660
 if(p == 0){return;};\
7614 schaersvoo 5661
 userdraw_x = [];userdraw_y = [];\
5662
 if( document.getElementById(\"canvas_input0\") ){\
5663
  var p = 0;var input_reply = new Array();\
5664
  if( document.getElementById(\"canvas_input0\")){\
5665
   var t = 0;\
5666
   while(document.getElementById(\"canvas_input\"+t)){\
5667
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5668
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5669
     p++;\
5670
    };\
5671
    t++;\
5672
   };\
5673
  };\
11088 schaersvoo 5674
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5675
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5676
  }\
5677
  else\
5678
  {\
5679
   return reply +\"\\n\"+input_reply;\
5680
  }\
5681
 }\
5682
 else\
5683
 {\
11088 schaersvoo 5684
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5685
   return reply +\"\\n\"+userdraw_text;\
5686
  }\
5687
  else\
5688
  {\
5689
   return reply;\
5690
  }\
5691
 };\
8108 schaersvoo 5692
};\n\
8257 schaersvoo 5693
<!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5694
    break;
5695
    case 7: fprintf(js_include_file,"\
8257 schaersvoo 5696
\n<!-- begin function 7 read_canvas%d() -->\n\
5697
read_canvas%d = function(){\
8074 schaersvoo 5698
 set_reply_precision();\
7614 schaersvoo 5699
 var reply = new Array();\
5700
 var p = 0;\
5701
 while(userdraw_x[p]){\
5702
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
5703
  p++;\
5704
 };\
11806 schaersvoo 5705
 if(p == 0){return;};\
7614 schaersvoo 5706
 if( document.getElementById(\"canvas_input0\") ){\
5707
  var p = 0;var input_reply = new Array();\
5708
  if( document.getElementById(\"canvas_input0\")){\
5709
   var t = 0;\
5710
   while(document.getElementById(\"canvas_input\"+t)){\
5711
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5712
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5713
     p++;\
5714
    };\
5715
    t++;\
5716
   };\
5717
  };\
11088 schaersvoo 5718
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5719
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5720
  }\
5721
  else\
5722
  {\
5723
   return reply+\"\\n\"+input_reply;\
5724
  }\
7862 schaersvoo 5725
 }\
7614 schaersvoo 5726
 else\
5727
 {\
11088 schaersvoo 5728
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5729
   return reply+\"\\n\"+userdraw_text;\
5730
  }\
5731
  else\
5732
  {\
5733
   return reply;\
5734
  }\
5735
 };\
8108 schaersvoo 5736
};\n\
8257 schaersvoo 5737
<!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5738
    break;
5739
    case 8: fprintf(js_include_file,"\
8257 schaersvoo 5740
\n<!-- begin function 8 read_canvas%d() -->\n\
5741
read_canvas%d = function(){\
7614 schaersvoo 5742
 var reply = new Array();\
5743
 var p = 0;\
8074 schaersvoo 5744
 var prec = %d;\
7614 schaersvoo 5745
 while(userdraw_x[p]){\
8074 schaersvoo 5746
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 5747
  p++;\
5748
 };\
11806 schaersvoo 5749
 if(p == 0){return;};\
7614 schaersvoo 5750
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5751
  var p = 0;var input_reply = new Array();\
5752
  if( document.getElementById(\"canvas_input0\")){\
5753
   var t = 0;\
5754
   while(document.getElementById(\"canvas_input\"+t)){\
5755
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5756
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5757
     p++;\
5758
    };\
5759
    t++;\
5760
   };\
5761
  };\
11088 schaersvoo 5762
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5763
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5764
  }\
5765
  else\
5766
  {\
5767
   return reply +\"\\n\"+input_reply;\
5768
  }\
5769
 }\
5770
 else\
5771
 {\
11088 schaersvoo 5772
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5773
   return reply +\"\\n\"+userdraw_text;\
5774
  }\
5775
  else\
5776
  {\
5777
   return reply;\
5778
  }\
5779
 };\
8108 schaersvoo 5780
};\n\
8257 schaersvoo 5781
<!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5782
    break;
5783
    case 9: fprintf(js_include_file,"\
8257 schaersvoo 5784
\n<!-- begin function 9 read_canvas%d() -->\n\
5785
read_canvas%d = function(){\
8074 schaersvoo 5786
 set_reply_precision();\
7614 schaersvoo 5787
 var reply = new Array();\
5788
 var p = 0;\
5789
 while(userdraw_x[p]){\
5790
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
5791
  p++;\
5792
 };\
11806 schaersvoo 5793
 if(p == 0){return;};\
7614 schaersvoo 5794
 if( document.getElementById(\"canvas_input0\") ){\
5795
  var p = 0;var input_reply = new Array();\
5796
  if( document.getElementById(\"canvas_input0\")){\
5797
   var t = 0;\
5798
   while(document.getElementById(\"canvas_input\"+t)){\
5799
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5800
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5801
     p++;\
5802
    };\
5803
    t++;\
5804
   };\
5805
  };\
11088 schaersvoo 5806
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5807
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5808
  }\
5809
  else\
5810
  {\
5811
   return reply +\"\\n\"+input_reply;\
5812
  }\
5813
 }\
5814
 else\
5815
 {\
11088 schaersvoo 5816
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5817
   return reply +\"\\n\"+userdraw_text;\
5818
  }\
5819
  else\
5820
  {\
5821
   return reply;\
5822
  }\
5823
 };\
8108 schaersvoo 5824
};\n\
8257 schaersvoo 5825
<!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5826
    break;
5827
    case 10: fprintf(js_include_file,"\
8257 schaersvoo 5828
\n<!-- begin function 10 read_canvas%d() -->\n\
5829
read_canvas%d = function(){\
7614 schaersvoo 5830
 var reply = new Array();\
5831
 var p = 0;\
8074 schaersvoo 5832
 var prec = %d;\
7614 schaersvoo 5833
 while(userdraw_x[p]){\
8074 schaersvoo 5834
  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 5835
  p++;\
5836
 };\
11806 schaersvoo 5837
 if(p == 0){return;};\
7614 schaersvoo 5838
 if( document.getElementById(\"canvas_input0\") ){\
5839
  var p = 0;var input_reply = new Array();\
5840
  if( document.getElementById(\"canvas_input0\")){\
5841
   var t = 0;\
5842
   while(document.getElementById(\"canvas_input\"+t)){\
5843
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5844
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5845
     p++;\
5846
    };\
5847
    t++;\
5848
   };\
5849
  };\
11088 schaersvoo 5850
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5851
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5852
  }\
5853
  else\
5854
  {\
5855
   return reply +\"\\n\"+input_reply;\
5856
  }\
5857
 }\
5858
 else\
5859
 {\
11088 schaersvoo 5860
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5861
   return reply +\"\\n\"+userdraw_text;\
5862
  }\
5863
  else\
5864
  {\
5865
   return reply;\
5866
  }\
5867
 };\
8108 schaersvoo 5868
};\n\
8257 schaersvoo 5869
<!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5870
    break;
5871
    case 11: fprintf(js_include_file,"\
8257 schaersvoo 5872
\n<!-- begin function 11 read_canvas%d() -->\n\
5873
read_canvas%d = function(){\
7614 schaersvoo 5874
 var reply = \"\";\
5875
 var p = 0;\
8074 schaersvoo 5876
 var prec = %d;\
7614 schaersvoo 5877
 while(userdraw_x[p]){\
8074 schaersvoo 5878
  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 5879
  p = p+2;\
5880
 };\
11806 schaersvoo 5881
 if(p == 0){return;};\
7614 schaersvoo 5882
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5883
  var p = 0;var input_reply = new Array();\
5884
  if( document.getElementById(\"canvas_input0\")){\
5885
   var t = 0;\
5886
   while(document.getElementById(\"canvas_input\"+t)){\
5887
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5888
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5889
     p++;\
5890
    };\
5891
    t++;\
5892
   };\
5893
  };\
11088 schaersvoo 5894
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5895
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5896
  }\
5897
  else\
5898
  {\
5899
   return reply +\"\\n\"+input_reply;\
5900
  }\
5901
 }\
5902
 else\
5903
 {\
11088 schaersvoo 5904
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5905
   return reply +\"\\n\"+userdraw_text;\
5906
  }\
5907
  else\
5908
  {\
5909
   return reply;\
5910
  }\
5911
 };\
8108 schaersvoo 5912
};\n\
8257 schaersvoo 5913
<!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5914
    break;
5915
    case 12: fprintf(js_include_file,"\
8257 schaersvoo 5916
\n<!-- begin function 12 read_canvas%d() -->\n\
5917
read_canvas%d = function(){\
8074 schaersvoo 5918
 set_reply_precision();\
7614 schaersvoo 5919
 var reply = \"\";\
5920
 var p = 0;\
5921
 for(p = 0; p< userdraw_x.lenght;p = p+2){\
5922
  if(userdraw_x[p] != null){\
5923
    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
5924
  };\
5925
 };\
11806 schaersvoo 5926
 if(p == 0){return;};\
7614 schaersvoo 5927
 if( document.getElementById(\"canvas_input0\") ){\
5928
  var p = 0;var input_reply = new Array();\
5929
  if( document.getElementById(\"canvas_input0\")){\
5930
   var t = 0;\
5931
   while(document.getElementById(\"canvas_input\"+t)){\
5932
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5933
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5934
     p++;\
5935
    };\
5936
    t++;\
5937
   };\
5938
  };\
11088 schaersvoo 5939
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5940
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5941
  }\
5942
  else\
5943
  {\
5944
   return reply +\"\\n\"+input_reply;\
5945
  }\
5946
 }\
5947
 else\
5948
 {\
11088 schaersvoo 5949
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5950
   return reply +\"\\n\"+userdraw_text\
5951
  }\
5952
  else\
5953
  {\
5954
   return reply;\
5955
  }\
5956
 };\
8108 schaersvoo 5957
};\n\
8257 schaersvoo 5958
<!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5959
    break;
5960
    case 13: fprintf(js_include_file,"\
8257 schaersvoo 5961
\n<!-- begin function 13 read_canvas%d() -->\n\
5962
read_canvas%d = function(){\
7614 schaersvoo 5963
 var reply = new Array();\
5964
 var p = 0;var i = 0;\
8074 schaersvoo 5965
 var prec = %d;\
7614 schaersvoo 5966
 while(userdraw_x[p]){\
8074 schaersvoo 5967
  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 5968
  p = p+2;i++;\
5969
 };\
11806 schaersvoo 5970
 if(p == 0){return;};\
7614 schaersvoo 5971
 if( document.getElementById(\"canvas_input0\") ){\
5972
  var p = 0;var input_reply = new Array();\
5973
  if( document.getElementById(\"canvas_input0\")){\
5974
   var t = 0;\
5975
   while(document.getElementById(\"canvas_input\"+t)){\
5976
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5977
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5978
     p++;\
5979
    };\
5980
    t++;\
5981
   };\
5982
  };\
11088 schaersvoo 5983
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5984
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5985
  }\
5986
  else\
5987
  {\
5988
   return reply +\"\\n\"+input_reply;\
5989
  }\
5990
 }\
5991
 else\
5992
 {\
11088 schaersvoo 5993
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5994
   return reply +\"\\n\"+userdraw_text\
5995
  }\
5996
  else\
5997
  {\
5998
   return reply;\
5999
  }\
6000
 };\
8108 schaersvoo 6001
};\n\
8257 schaersvoo 6002
<!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6003
    break;
6004
    case 14: fprintf(js_include_file,"\
8257 schaersvoo 6005
\n<!-- begin function 14 read_canvas%d() -->\n\
6006
read_canvas%d = function(){\
8074 schaersvoo 6007
 set_reply_precision();\
7614 schaersvoo 6008
 var reply = new Array();\
6009
 var p = 0;var i = 0;\
6010
 while(userdraw_x[p]){\
6011
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
6012
  p = p+2;i++;\
6013
 };\
11806 schaersvoo 6014
 if(p == 0){return;};\
7614 schaersvoo 6015
 if( document.getElementById(\"canvas_input0\") ){\
6016
  var p = 0;var input_reply = new Array();\
6017
  if( document.getElementById(\"canvas_input0\")){\
6018
   var t = 0;\
6019
   while(document.getElementById(\"canvas_input\"+t)){\
6020
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6021
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6022
     p++;\
6023
    };\
6024
    t++;\
6025
   };\
6026
  };\
11088 schaersvoo 6027
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6028
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6029
  }\
6030
  else\
6031
  {\
6032
   return reply +\"\\n\"+input_reply;\
6033
  }\
6034
 }\
6035
 else\
6036
 {\
11088 schaersvoo 6037
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6038
   return reply +\"\\n\"+userdraw_text;\
6039
  }\
6040
  else\
6041
  {\
6042
   return reply;\
6043
  }\
6044
 };\
8108 schaersvoo 6045
};\n\
8257 schaersvoo 6046
<!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6047
    break;
6048
    case 15: fprintf(js_include_file,"\
8257 schaersvoo 6049
\n<!-- begin function 15  read_canvas%d() -->\n\
6050
read_canvas%d = function(){\
7614 schaersvoo 6051
 var input_reply = new Array();\
6052
 var p = 0;\
6053
 if( document.getElementById(\"canvas_input0\")){\
6054
  var t = 0;\
6055
  while(document.getElementById(\"canvas_input\"+t)){\
6056
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6057
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6058
    p++;\
6059
   };\
6060
   t++;\
6061
  };\
6062
 };\
11088 schaersvoo 6063
 if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6064
   return input_reply +\"\\n\"+userdraw_text;\
6065
 }\
6066
 else\
6067
 {\
6068
  return input_reply;\
6069
 };\
8108 schaersvoo 6070
};\n\
8257 schaersvoo 6071
<!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6072
    break;
6073
    case 16: fprintf(js_include_file,"\
7653 schaersvoo 6074
\n<!-- begin function 16 read_mathml() -->\n\
7614 schaersvoo 6075
function read_mathml(){\
6076
 var reply = new Array();\
6077
 var p = 0;\
6078
 if( document.getElementById(\"mathml0\")){\
6079
  while(document.getElementById(\"mathml\"+p)){\
6080
   reply[p] = document.getElementById(\"mathml\"+p).value;\
6081
   p++;\
6082
  };\
6083
 };\
6084
return reply;\
6085
};\
6086
this.read_mathml = read_mathml;\n\
7653 schaersvoo 6087
<!-- end function 16 read_mathml() -->");
7614 schaersvoo 6088
    break;
6089
    case 17:  fprintf(js_include_file,"\
8257 schaersvoo 6090
\n<!-- begin function 17 read_canvas%d() -->\n\
6091
read_canvas%d = function(){\
11080 schaersvoo 6092
 var len = userdraw_x.length;\
6093
 if( len == 0){alert(\"no text typed...\");return;}\
6094
 var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
6095
 for(var p = 1 ; p < len ; p++){\
6096
  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
6097
 };\
6098
 return rep;\
8108 schaersvoo 6099
};\n\
8257 schaersvoo 6100
<!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6101
    break;
6102
    case 18: fprintf(js_include_file,"\
10956 schaersvoo 6103
\n<!-- javascript has no real modulo function -->\n\
6104
function mod(n, m){\
6105
 var m = parseInt(((n %% m) + m) %% m);\
6106
 return m;\
6107
};\
8257 schaersvoo 6108
\n<!-- begin function 18 read_canvas%d() -->\n\
6109
read_canvas%d = function(){\
7614 schaersvoo 6110
 var p = 0;\
6111
 var reply = new Array();\
6112
 var name;\
6113
 var t = true;\
8000 schaersvoo 6114
 var h;var m;var s;\
7614 schaersvoo 6115
 while(t){\
8000 schaersvoo 6116
  try{\
6117
   name = eval('clocks'+p);\
6118
   h = name.H;m = name.M;s = name.S;\
10956 schaersvoo 6119
   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
8000 schaersvoo 6120
   reply[p] = h+\":\"+m+\":\"+s;\
6121
   p++;\
6122
  }catch(e){t=false;};\
7614 schaersvoo 6123
 };\
8000 schaersvoo 6124
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 6125
 return reply;\
8108 schaersvoo 6126
};\n\
8257 schaersvoo 6127
<!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6128
    break;
6129
    case 19: fprintf(js_include_file,"\
8257 schaersvoo 6130
\n<!-- begin function 19 read_canvas%d() -->\n\
6131
read_canvas%d = function(){\
7614 schaersvoo 6132
 return reply[0];\
8108 schaersvoo 6133
};\n\
8257 schaersvoo 6134
<!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
8130 schaersvoo 6135
    break;
7614 schaersvoo 6136
    case 20: fprintf(js_include_file,"\
8257 schaersvoo 6137
\n<!-- begin function 20 read_canvas%d() -->\n\
6138
read_canvas%d = function(){\
8074 schaersvoo 6139
 var prec = %d;\
7614 schaersvoo 6140
 var len  = ext_drag_images.length;\
6141
 var reply = new Array(len);\
6142
 for(var p = 0 ; p < len ; p++){\
6143
    var img = ext_drag_images[p];\
8556 schaersvoo 6144
    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 6145
 };\
6146
 return reply;\
8108 schaersvoo 6147
};\n\
8257 schaersvoo 6148
<!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6149
    break;
6150
    case 21: fprintf(js_include_file,"\
8257 schaersvoo 6151
\n<!-- begin function 21 read_canvas%d() -->\n\
6152
read_canvas%d = function(){\
7614 schaersvoo 6153
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
6154
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 6155
 var prec = %d;\
7614 schaersvoo 6156
 while(userdraw_x[p]){\
8074 schaersvoo 6157
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 6158
  p++;\
6159
 };\
11806 schaersvoo 6160
 if(p == 0){return;};\
7614 schaersvoo 6161
 if( document.getElementById(\"canvas_input0\") ){\
6162
  var p = 0;var input_reply = new Array();\
6163
  if( document.getElementById(\"canvas_input0\")){\
6164
   var t = 0;\
6165
   while(document.getElementById(\"canvas_input\"+t)){\
6166
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6167
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6168
     p++;\
6169
    };\
6170
    t++;\
6171
   };\
6172
  };\
11088 schaersvoo 6173
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6174
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6175
  }\
6176
  else\
6177
  {\
6178
   return reply_coord+\"\\n\"+input_reply;\
6179
  }\
6180
 }\
6181
 else\
6182
 {\
11088 schaersvoo 6183
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6184
   return reply_coord+\"\\n\"+userdraw_text;\
6185
  }\
6186
  else\
6187
  {\
6188
   return reply_coord;\
6189
  };\
6190
 };\
8108 schaersvoo 6191
};\n\
8257 schaersvoo 6192
<!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6193
    break;
6194
    case 22: fprintf(js_include_file,"\
8257 schaersvoo 6195
\n<!-- begin function 22 read_canvas%d() -->\n\
6196
read_canvas%d = function(){\
7614 schaersvoo 6197
 var reply = new Array();\
7963 schaersvoo 6198
 var lu = userdraw_x.length;\
11806 schaersvoo 6199
 if(lu == 0){return;};\
7614 schaersvoo 6200
 var idx = 0;\
8074 schaersvoo 6201
 var prec = %d;\
7963 schaersvoo 6202
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 6203
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
6204
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 6205
 };\
6206
 if( document.getElementById(\"canvas_input0\") ){\
6207
  var p = 0;var input_reply = new Array();\
6208
  if( document.getElementById(\"canvas_input0\")){\
6209
   var t = 0;\
6210
   while(document.getElementById(\"canvas_input\"+t)){\
6211
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6212
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6213
     p++;\
6214
    };\
6215
    t++;\
6216
   };\
6217
  };\
11088 schaersvoo 6218
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6219
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6220
  }\
6221
  else\
6222
  {\
6223
   return reply +\"\\n\"+input_reply;\
6224
  }\
6225
 }\
6226
 else\
6227
 {\
11088 schaersvoo 6228
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6229
   return reply +\"\\n\"+userdraw_text;\
6230
  }\
6231
  else\
6232
  {\
6233
   return reply;\
6234
  }\
6235
 };\
8108 schaersvoo 6236
};\n\
8257 schaersvoo 6237
<!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6238
    break;
7782 schaersvoo 6239
    case 23: fprintf(js_include_file,"\
8257 schaersvoo 6240
\n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\
6241
read_canvas%d = function(){\
7782 schaersvoo 6242
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
6243
 var lu = userdraw_x.length;\
6244
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 6245
 var reply_x = new Array();var reply_y = new Array();\
6246
 var marge = 5;var p = 0;\
8074 schaersvoo 6247
 var prec = %d;\
7782 schaersvoo 6248
 for(var i = 0; i < lu - 1 ; i++ ){\
10987 schaersvoo 6249
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
8074 schaersvoo 6250
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 6251
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
6252
   p++;\
7782 schaersvoo 6253
  };\
8074 schaersvoo 6254
  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 6255
 };\
6256
 if( document.getElementById(\"canvas_input0\")){\
6257
  var p = 0;var input_reply = new Array();\
6258
  if( document.getElementById(\"canvas_input0\")){\
6259
   var t = 0;\
6260
   while(document.getElementById(\"canvas_input\"+t)){\
6261
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6262
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6263
     p++;\
6264
    };\
6265
    t++;\
6266
   };\
6267
  };\
11088 schaersvoo 6268
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6269
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6270
  }\
6271
  else\
6272
  {\
6273
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
6274
  }\
6275
 }\
6276
 else\
6277
 {\
11088 schaersvoo 6278
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6279
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
6280
  }\
6281
  else\
6282
  {\
6283
   return reply_x+\"\\n\"+reply_y;\
6284
  };\
6285
 };\
8108 schaersvoo 6286
};\n\
8257 schaersvoo 6287
<!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7782 schaersvoo 6288
    break;
7984 schaersvoo 6289
    case 24: fprintf(js_include_file,"\n\
8257 schaersvoo 6290
<!-- begin function 24  read_canvas%d() -->\n\
6291
read_canvas%d = function(){\
7984 schaersvoo 6292
 var input_reply = new Array();\
6293
 var p = 0;\
6294
 if( document.getElementById(\"canvas_input0\")){\
6295
  while(document.getElementById(\"canvas_input\"+p)){\
6296
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
6297
    p++;\
6298
  };\
6299
  return input_reply;\
6300
 };\
8108 schaersvoo 6301
};\n\
8257 schaersvoo 6302
<!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7984 schaersvoo 6303
    break;
8083 schaersvoo 6304
    case 25:
8257 schaersvoo 6305
    fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\
6306
read_canvas%d = function(){\
8083 schaersvoo 6307
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
6308
 var lu = userdraw_radius.length;\
6309
 var prec = %d;\
6310
 var angle_reply = new Array(lu);\
6311
 for(var p = 0 ; p < lu ; p++){\
6312
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
6313
 };\
6314
 return angle_reply;\
8108 schaersvoo 6315
};\n\
8257 schaersvoo 6316
<!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 6317
    break;
6318
    case 26:
8257 schaersvoo 6319
    fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\
6320
read_canvas%d = function(){\
8083 schaersvoo 6321
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
6322
 var lu = userdraw_radius.length;\
6323
 var prec = %d;\
6324
 var angle_reply = new Array(lu);\
6325
 for(var p = 0 ; p < lu ; p++){\
6326
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
6327
 };\
6328
 return angle_reply;\
8108 schaersvoo 6329
};\n\
8257 schaersvoo 6330
<!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 6331
    break;
8127 schaersvoo 6332
    case 27:
8257 schaersvoo 6333
    fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d()  : inputfield(s) location and their values : -->\n\
6334
read_canvas%d = function(){\
8127 schaersvoo 6335
 var lu = userdraw_x.length;\
6336
 if( lu < 1){alert(\"nothing drawn...\");return;}\
6337
 set_reply_precision();\
6338
 var prec = %d;\
11080 schaersvoo 6339
 var rep = (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\",\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\",\"+ document.getElementById(\"canvas_input\"+p).value;\
8127 schaersvoo 6340
 for(var p = 0 ; p < lu ; p++){\
11080 schaersvoo 6341
   rep = rep = \"\\n\" + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\":\"+ document.getElementById(\"canvas_input\"+p).value;\
8127 schaersvoo 6342
 };\
11080 schaersvoo 6343
 return rep;\
8127 schaersvoo 6344
};\n\
8257 schaersvoo 6345
<!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8127 schaersvoo 6346
    break;
8322 schaersvoo 6347
    case 28:
6348
    fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\
6349
read_canvas%d = function(){\
6350
 var prec = %d;\
6351
 var reply = new Array();var p = 0;\
6352
 var idx = 0;\
6353
 while(userdraw_x[p]){\
6354
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
6355
  idx++;\
6356
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
6357
  idx++;\
6358
  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
6359
  idx++;\
6360
  p++;\
6361
 };\
6362
 if( p == 0){alert(\"nothing drawn...\");return;}\
6363
 return reply;\
6364
};\n\
9213 schaersvoo 6365
<!-- end function 28 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8322 schaersvoo 6366
    break;
9213 schaersvoo 6367
    case 29:
6368
    fprintf(js_include_file,"\n<!-- begin function 29 read_canvas%d() -->\n\
6369
function xy_precision(array_x,array_y){\
6370
 var len = array_x.length;\
6371
 var x_array = new Array(len);\
6372
 var y_array = new Array(len);\
6373
 var prec = %d;\
6374
 for(var p = 0 ; p < len ; p++ ){\
6375
  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
6376
  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
6377
 };\
9230 schaersvoo 6378
 return x_array+\";\"+y_array;\
9213 schaersvoo 6379
};\n\
6380
function round_to_pixel(array_r){\
6381
var len = array_r.length;\
6382
 for(var p = 0 ; p < len ; p++ ){\
6383
  array_r[p] = Math.round(array_r[p]);\
6384
 };\
6385
 return array_r;\
6386
};\
6387
read_canvas%d = function(){\
9300 schaersvoo 6388
 var reply=\" \";\
6389
 if( points_x && points_x.length > 0 ){reply = reply + xy_precision(points_x,points_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6390
 if( circles_x && circles_x.length > 0 ){ reply = reply + xy_precision(circles_x,circles_y)+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6391
 if( segments_x && segments_x.length > 0 ){ reply = reply +  xy_precision(segments_x,segments_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6392
 if( arrows_x && arrows_x.length > 0 ){ reply = reply +  xy_precision(arrows_x,arrows_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6393
 if( lines_x && lines_x.length > 0 ){ reply = reply + xy_precision(lines_x,lines_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6394
 if( triangles_x && triangles_x.length > 0){ reply = reply + xy_precision(triangles_x,triangles_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
11226 schaersvoo 6395
 if( polys_x && polys_x.length > 0){ reply = reply + xy_precision(polys_x,polys_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9372 schaersvoo 6396
 if( rects_x && rects_x.length > 0 ){ reply = reply + xy_precision(rects_x,rects_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9300 schaersvoo 6397
 if( closedpoly_x && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();reply = reply + xy_precision(closedpoly_x,closedpoly_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
11230 schaersvoo 6398
 if( parallelogram_x && parallelogram_x.length > 0){ reply = reply + xy_precision(parallelogram_x,parallelogram_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9338 schaersvoo 6399
 if( text_x && text_x.length > 0){ reply = reply + xy_precision(text_x,text_y)+\";\"+text_abc+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9213 schaersvoo 6400
 return reply;\
6401
};\n\
6402
<!-- end function 29 read_canvas%d() -->",canvas_root_id,reply_precision,canvas_root_id,canvas_root_id);
6403
    break;
9289 schaersvoo 6404
    case 30:
6405
    fprintf(js_include_file,"\n<!-- begin function 30 read_canvas%d() -->\n\
6406
read_canvas%d = function(){\
6407
 var reply = new Array(3);\
6408
 var prec = %d;\
6409
 reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
6410
 reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
6411
 reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
6412
 return reply;\
6413
};\n\
6414
<!-- end function 30 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
6415
    break;
6416
    case 31:
6417
    fprintf(js_include_file,"\n<!-- begin function 31 read_canvas%d() -->\n\
6418
read_canvas%d = function(){\
6419
 var reply = new Array(3);\
6420
 var prec = %d;\
6421
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
6422
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
6423
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
6424
 return reply;\
6425
};\n\
6426
<!-- end function 31 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
6427
    break;
6428
    case 32:
6429
    fprintf(js_include_file,"\n<!-- begin function 32 read_canvas%d() -->\n\
6430
read_canvas%d = function(){\
6431
 var reply = new Array(6);\
6432
 var prec = %d;\
6433
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
6434
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
6435
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
6436
 reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
6437
 reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
6438
 reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
6439
 return reply;\
6440
};\n\
6441
<!-- end function 32 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
6442
    break;
7614 schaersvoo 6443
    default: canvas_error("hmmm unknown replyformat...");break;
6444
}
6445
 return;
6446
}
6447
 
6448
 
8224 bpr 6449
/*
6450
 add drawfunction :
7614 schaersvoo 6451
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
6452
 - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
6453
 - grid / mathml
6454
 - will not scale or zoom in
6455
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
8224 bpr 6456
 - is printed directly into 'js_include_file'
7614 schaersvoo 6457
*/
6458
 
11021 schaersvoo 6459
void add_javascript_function(int js_function[],int canvas_root_id){
7614 schaersvoo 6460
int i;
6461
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
11017 schaersvoo 6462
 if( js_function[i] == 1){
7614 schaersvoo 6463
    switch(i){
11026 bpr 6464
    case JS_FIND_ANGLE:
11025 schaersvoo 6465
    fprintf(js_include_file,"\n\
6466
<!-- function find_angle() -->\n\
6467
 function find_angle(xc,yc,x1,y1){\
11019 schaersvoo 6468
 var dx = x1 - xc;\
6469
 var dy = yc - y1;\
6470
 if( dx > 0 && dy < 0){ return Math.atan(-1*dy/dx);};\
6471
 if( dx < 0 && dy < 0){ return Math.PI + Math.atan(-1*dy/dx);};\
6472
 if( dx < 0 && dy > 0){ return Math.PI + Math.atan(-1*dy/dx);};\
6473
 if( dx > 0 && dy > 0){ return 2*Math.PI + Math.atan(-1*dy/dx);};};");
11017 schaersvoo 6474
    break;
8448 schaersvoo 6475
    case DRAW_EXTERNAL_IMAGE:
10953 bpr 6476
/* the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
8448 schaersvoo 6477
 draw_external_image(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,int_data[8],int_data[9]);
6478
*/
7614 schaersvoo 6479
fprintf(js_include_file,"\n<!-- drag external images --->\n\
7653 schaersvoo 6480
var external_ctx = external_canvas.getContext(\"2d\");\
6481
var external_canvas_rect = external_canvas.getBoundingClientRect();\
6482
canvas_div.addEventListener(\"mousedown\",setxy,false);\
6483
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
6484
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
6485
var selected_image = null;\
6486
var ext_image_cnt = 0;\
6487
var ext_drag_images = new Array();\
8448 schaersvoo 6488
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt){\
7653 schaersvoo 6489
 ext_image_cnt = idx;\
8448 schaersvoo 6490
 if(draggable == 1 ){\
6491
  reply[click_cnt] = 0;\
6492
 };\
7653 schaersvoo 6493
 var image = new Image();\
6494
 image.src = URL;\
6495
 image.onload = function(){\
8448 schaersvoo 6496
  if( sx < 1 ){ sx = 0; };\
6497
  if( sy < 1 ){ sy = 0; };\
6498
  if( swidth < 1 ){swidth = image.width;};\
6499
  if( sheight < 1 ){sheight = image.height;};\
6500
  if( width < 1 ){width = image.width;};\
6501
  if( height < 1 ){height = image.height;};\
6502
  if( resizable == 0 ){\
6503
   if( swidth > image.width ){ swidth = image.width; };\
6504
   if( sheight > image.height){ sheight = image.height;};\
6505
   if( width > image.width ){ width = image.width; };\
6506
   if( height > image.height){ height = image.height;};\
6507
  };\
6508
  var img = new Array(11);\
7653 schaersvoo 6509
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
8448 schaersvoo 6510
  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;img[10] = click_cnt;\
7653 schaersvoo 6511
  ext_drag_images[idx] = img;\
6512
  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
6513
 };\
6514
};\
6515
function dragstop(evt){\
6516
 selected_image = null;return;\
6517
};\
6518
function dragxy(evt){\
6519
 if( selected_image != null ){\
6520
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
6521
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
6522
  var s_img = ext_drag_images[selected_image];\
6523
  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
6524
  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
8386 schaersvoo 6525
  if( use_snap_to_points == 1){\
6526
   var img_xy = snap_to_points(s_img[6],s_img[7]);\
6527
   s_img[6] = img_xy[0];s_img[7] = img_xy[1];\
6528
  }\
6529
  else\
6530
  {\
6531
   if( x_use_snap_to_grid == 1 ){\
6532
    s_img[6] = snap_to_x(s_img[6]);\
6533
   };\
6534
   if( y_use_snap_to_grid == 1 ){\
6535
    s_img[7] = snap_to_x(s_img[7]);\
6536
   };\
6537
  };\
7653 schaersvoo 6538
  ext_drag_images[selected_image] = s_img;\
6539
  external_ctx.clearRect(0,0,xsize,ysize);\
6540
  for(var i = 0; i <= ext_image_cnt ; i++){\
6541
   var img = ext_drag_images[i];\
6542
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
6543
  };\
6544
 };\
6545
};\
6546
function setxy(evt){\
6547
 if( ! selected_image && evt.which == 1 ){\
6548
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
6549
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
6550
  var xm = evt.clientX - external_canvas_rect.left + xoff;\
6551
  var ym = evt.clientY - external_canvas_rect.top + yoff;\
8448 schaersvoo 6552
  var img;\
7653 schaersvoo 6553
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
8448 schaersvoo 6554
   if( ext_drag_images[p] ){\
6555
    img = ext_drag_images[p];\
6556
    if( img[0] != 0 ){\
6557
     if( xm > img[6] && xm < img[6] + img[8]){\
6558
      if( ym > img[7] && ym < img[7] + img[9]){\
6559
       if( img[0] == 1){\
6560
        if( reply[img[10]] == 1 ){\
6561
         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
6562
        }\
6563
        else\
6564
        {\
6565
         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
6566
        };\
6567
        external_ctx.lineWidth = 6;\
6568
        external_ctx.beginPath();\
6569
        external_ctx.rect(img[6],img[7],img[8],img[9]);\
6570
        external_ctx.closePath();\
6571
        external_ctx.stroke();\
6572
        return;\
6573
       }\
6574
       else\
6575
       {\
6576
        img[6] = xm;\
6577
        img[7] = ym;\
6578
        ext_drag_images[p] = img;\
6579
        selected_image = p;\
6580
        dragxy(evt);\
6581
       };\
6582
      };\
7653 schaersvoo 6583
     };\
6584
    };\
6585
   };\
6586
  };\
6587
 }\
6588
 else\
6589
 {\
6590
  selected_image = null;\
6591
 };\
8448 schaersvoo 6592
};");
7614 schaersvoo 6593
    break;
8370 schaersvoo 6594
    case DRAW_BEZIER:
6595
fprintf(js_include_file,"\n<!-- draw bezier curve -->\n\
6596
var draw_bezier = function(canvas_type,linewidth,xy_points,fill_color,fill_opacity,stroke_color,stroke_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,use_affine,affine_matrix){\
6597
 var obj;\
6598
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6599
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6600
 }\
6601
 else\
6602
 {\
6603
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6604
 };\
6605
 var ctx = obj.getContext(\"2d\");\
6606
 ctx.save();\
6607
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6608
 ctx.lineWidth = linewidth;\
11088 schaersvoo 6609
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8370 schaersvoo 6610
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
6611
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
6612
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6613
 ctx.beginPath();\
6614
 ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
6615
 ctx.bezierCurveTo(x2px(xy_points[2]),y2px(xy_points[3]),x2px(xy_points[4]),y2px(xy_points[5]),x2px(xy_points[6]),y2px(xy_points[7]));\
6616
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
6617
 ctx.stroke();\
6618
 ctx.restore();\
6619
};\n",canvas_root_id,canvas_root_id,canvas_root_id);
6620
    break;
7614 schaersvoo 6621
    case DRAW_GRIDFILL:/* not used for userdraw */
6622
fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
8105 schaersvoo 6623
var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
7614 schaersvoo 6624
 var obj;\
6625
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6626
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6627
 }\
6628
 else\
6629
 {\
6630
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6631
 };\
6632
 var ctx = obj.getContext(\"2d\");\
6633
 var x,y;\
7883 schaersvoo 6634
 snap_x = dx;snap_y = dy;\
7614 schaersvoo 6635
 ctx.save();\
9462 schaersvoo 6636
 ctx.lineWidth = line_width;\
11088 schaersvoo 6637
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6638
 ctx.strokeStyle=\"rgba(\"+color+\",\"+opacity+\")\";\
6639
 for( x = x0 ; x < xsize+dx ; x = x + dx ){\
6640
    ctx.moveTo(x,y0);\
6641
    ctx.lineTo(x,ysize);\
6642
 };\
7645 schaersvoo 6643
 for( y = y0 ; y < ysize+dy; y = y + dy ){\
7614 schaersvoo 6644
    ctx.moveTo(x0,y);\
6645
    ctx.lineTo(xsize,y);\
6646
 };\
6647
 ctx.stroke();\
6648
 ctx.restore();\
7653 schaersvoo 6649
 return;};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6650
    break;
8224 bpr 6651
 
7614 schaersvoo 6652
    case DRAW_IMAGEFILL:/* not  used for userdraw */
6653
fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
8105 schaersvoo 6654
var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
7614 schaersvoo 6655
 var obj;\
6656
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6657
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6658
 }\
6659
 else\
6660
 {\
6661
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6662
 };\
6663
 var ctx = obj.getContext(\"2d\");\
6664
 ctx.save();\
6665
 var img = new Image();\
6666
 img.src = URL;\
6667
 img.onload = function(){\
6668
  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
6669
    ctx.drawImage(img,x0,y0,xsize,ysize);\
6670
  }\
6671
  else\
6672
  {\
6673
    var repeat = \"repeat\";\
6674
    if(img.width > xsize - x0){\
6675
        repeat = \"repeat-y\";\
6676
    }\
6677
    else\
6678
    {\
6679
     if( img.height > ysize -x0 ){\
6680
      repeat = \"repeat-x\";\
6681
     }\
6682
    }\
6683
    var pattern = ctx.createPattern(img,repeat);\
6684
    ctx.rect(x0,y0,xsize,ysize);\
6685
    ctx.fillStyle = pattern;\
6686
  }\
6687
  ctx.fill();\
6688
 };\
6689
 ctx.restore();\
6690
 return;\
7653 schaersvoo 6691
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6692
    break;
8224 bpr 6693
 
7614 schaersvoo 6694
    case DRAW_DOTFILL:/* not  used for userdraw */
6695
fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
11818 schaersvoo 6696
var click_fill_pattern;\
11817 schaersvoo 6697
var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\n\
11818 schaersvoo 6698
if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
6699
var fc = %d+canvas_type;\n\
6700
fill_canvas_no.push(fc);\
6701
 var obj = create_canvas%d(fc,xsize,ysize);\n\
11817 schaersvoo 6702
 var ctx = obj.getContext('2d');\n\
6703
 var x,y;\n\
6704
 ctx.fillStyle='rgba(255,255,255,0.01)';\n\
6705
 ctx.rect(0,0,xsize,ysize);\n\
6706
 ctx.fill();\n\
6707
 ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\n\
6708
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\n\
6709
 for( x = 0 ; x < xsize ; x = x + dx ){\n\
6710
  for( y = 0 ; y < ysize ; y = y + dy ){\n\
6711
   ctx.beginPath();\n\
6712
   ctx.arc(x,y,radius,0,2*Math.PI,false);\n\
6713
   ctx.closePath();\n\
6714
   ctx.fill();\n\
6715
  };\n\
6716
 };\n\
11818 schaersvoo 6717
 click_fill_pattern = ctx;\n\
6718
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\n\
6719
 return;};",canvas_root_id,canvas_root_id);
7614 schaersvoo 6720
    break;
7645 schaersvoo 6721
 
7647 schaersvoo 6722
    case DRAW_DIAMONDFILL:/* not used for userdraw */
7614 schaersvoo 6723
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
8105 schaersvoo 6724
var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7614 schaersvoo 6725
  var obj;\
6726
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6727
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6728
 }\
6729
 else\
6730
 {\
6731
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6732
 };\
6733
 var ctx = obj.getContext(\"2d\");\
6734
 var x;\
6735
 var y;\
6736
 ctx.save();\
6737
 ctx.lineWidth = linewidth;\
11088 schaersvoo 6738
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6739
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6740
 y = ysize;\
6741
 for( x = x0 ; x < xsize ; x = x + dx ){\
6742
  ctx.moveTo(x,y0);\
6743
  ctx.lineTo(xsize,y);\
6744
  y = y - dy;\
6745
 };\
6746
 y = y0;\
6747
 for( x = xsize ; x > 0 ; x = x - dx){\
6748
  ctx.moveTo(x,ysize);\
6749
  ctx.lineTo(x0,y);\
6750
  y = y + dy;\
6751
 };\
6752
 x = x0;\
6753
 for( y = y0 ; y < ysize ; y = y + dy ){\
6754
  ctx.moveTo(xsize,y);\
6755
  ctx.lineTo(x,ysize);\
6756
  x = x + dx;\
6757
 };\
6758
 x = xsize;\
6759
 for( y = ysize ; y > y0 ; y = y - dy ){\
6760
  ctx.moveTo(x,y0);\
6761
  ctx.lineTo(x0,y);\
6762
  x = x - dx;\
6763
 };\
6764
 ctx.stroke();\
6765
 ctx.restore();\
6766
 return;\
7653 schaersvoo 6767
 }",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6768
    break;
8224 bpr 6769
 
7647 schaersvoo 6770
    case DRAW_HATCHFILL:/* not used for userdraw */
6771
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
8105 schaersvoo 6772
var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,stroke_color,stroke_opacity,xsize,ysize){\
7647 schaersvoo 6773
  var obj;\
6774
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6775
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6776
 }\
6777
 else\
6778
 {\
6779
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6780
 };\
6781
 var ctx = obj.getContext(\"2d\");\
6782
 var x;\
6783
 var y;\
6784
 ctx.save();\
6785
 ctx.lineWidth = linewidth;\
11088 schaersvoo 6786
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7647 schaersvoo 6787
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6788
 y = ysize;\
6789
 for( x = x0 ; x < xsize ; x = x + dx ){\
6790
  ctx.moveTo(x,y0);\
6791
  ctx.lineTo(xsize,y);\
6792
  y = y - dy;\
6793
 };\
6794
 y = y0;\
6795
 for( x = xsize ; x >= dx ; x = x - dx){\
6796
  ctx.moveTo(x,ysize);\
6797
  ctx.lineTo(x0,y);\
6798
  y = y + dy;\
6799
 };\
6800
 ctx.stroke();\
6801
 ctx.restore();\
6802
 return;\
7653 schaersvoo 6803
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7647 schaersvoo 6804
    break;
7614 schaersvoo 6805
    case DRAW_CIRCLES:/*  used for userdraw */
6806
fprintf(js_include_file,"\n<!-- draw circles -->\n\
8105 schaersvoo 6807
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 6808
 ctx.save();\
8071 schaersvoo 6809
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6810
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6811
 ctx.lineWidth = line_width;\
11088 schaersvoo 6812
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6813
 for(var p = 0 ; p < x_points.length ; p++ ){\
6814
  ctx.beginPath();\
6815
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
6816
  ctx.closePath();\
6817
  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6818
  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
6819
  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6820
  ctx.stroke();\
6821
 }\
6822
 ctx.restore();\
6823
 return;\
7653 schaersvoo 6824
};");
7614 schaersvoo 6825
    break;
7663 schaersvoo 6826
    case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
6827
fprintf(js_include_file,"\n<!-- draw polyline -->\n\
8105 schaersvoo 6828
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 6829
 ctx.save();\
8071 schaersvoo 6830
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 6831
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6832
 ctx.lineWidth = line_width;\
11088 schaersvoo 6833
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7663 schaersvoo 6834
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6835
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6836
 ctx.clearRect(0,0,xsize,ysize);\
6837
 ctx.beginPath();\
6838
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
6839
  ctx.moveTo(x_points[p],y_points[p]);\
6840
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
6841
 }\
6842
 ctx.closePath();\
6843
 ctx.stroke();\
6844
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6845
 for(var p = 0 ; p < x_points.length ; p++ ){\
6846
  ctx.beginPath();\
6847
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
6848
  ctx.closePath();ctx.fill();ctx.stroke();\
6849
 };\
6850
 ctx.restore();\
6851
 return;\
6852
};");
6853
    break;
8224 bpr 6854
 
7614 schaersvoo 6855
    case DRAW_SEGMENTS:/*  used for userdraw */
6856
fprintf(js_include_file,"\n<!-- draw segments -->\n\
8105 schaersvoo 6857
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 6858
 ctx.save();\
8071 schaersvoo 6859
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6860
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6861
 ctx.lineWidth = line_width;\
11088 schaersvoo 6862
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6863
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6864
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6865
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
6866
  ctx.beginPath();\
6867
  ctx.moveTo(x_points[p],y_points[p]);\
6868
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
6869
  ctx.closePath();\
6870
  ctx.stroke();\
6871
  }\
6872
  ctx.restore();\
6873
  return;\
6874
 };");
6875
    break;
8224 bpr 6876
 
7614 schaersvoo 6877
    case DRAW_LINES:/*  used for userdraw */
6878
fprintf(js_include_file,"\n<!-- draw lines -->\n\
6879
function calc_line(x1,x2,y1,y2){\
6880
 var marge = 2;\
6881
 if(x1 < x2+marge && x1>x2-marge){\
6882
  return [x1,0,x1,ysize];\
6883
 };\
6884
 if(y1 < y2+marge && y1>y2-marge){\
6885
  return [0,y1,xsize,y1];\
6886
 };\
6887
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
6888
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
6889
 return [0,Y1,xsize,Y2];\
6890
};\
8105 schaersvoo 6891
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 6892
 ctx.save();\
6893
 var line = new Array(4);\
8071 schaersvoo 6894
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6895
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6896
 ctx.lineWidth = line_width;\
11088 schaersvoo 6897
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6898
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6899
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6900
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
6901
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
6902
  ctx.beginPath();\
6903
  ctx.moveTo(line[0],line[1]);\
6904
  ctx.lineTo(line[2],line[3]);\
6905
  ctx.closePath();\
6906
  ctx.stroke();\
6907
  }\
6908
  ctx.restore();\
6909
  return;\
6910
 };");
6911
    break;
6912
 
8244 schaersvoo 6913
    case DRAW_DEMILINES:/*  used for userdraw */
6914
fprintf(js_include_file,"\n<!-- draw demilines -->\n\
6915
function find_inf_point(x1,y1,x2,y2){\
6916
 if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
6917
 var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
6918
 if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
6919
};\
6920
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){\
6921
 ctx.save();\
6922
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
6923
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6924
 ctx.lineWidth = line_width;\
11088 schaersvoo 6925
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8244 schaersvoo 6926
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6927
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6928
 var pair = new Array(4);\
6929
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
6930
  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
6931
  ctx.beginPath();\
6932
  ctx.moveTo(pair[0],pair[1]);\
6933
  ctx.lineTo(pair[2],pair[3]);\
6934
  ctx.closePath();\
6935
  ctx.stroke();\
6936
  }\
6937
  ctx.restore();\
6938
  return;\
6939
 };");
6940
    break;
6941
 
7614 schaersvoo 6942
    case DRAW_CROSSHAIRS:/*  used for userdraw */
6943
fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
8105 schaersvoo 6944
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 6945
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6946
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6947
 ctx.lineWidth = line_width;\
11088 schaersvoo 6948
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6949
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6950
 var x1,x2,y1,y2;\
6951
 for(var p = 0 ; p < x_points.length ; p++ ){\
6952
  x1 = x_points[p] - crosshair_size;\
6953
  x2 = x_points[p] + crosshair_size;\
6954
  y1 = y_points[p] - crosshair_size;\
6955
  y2 = y_points[p] + crosshair_size;\
6956
  ctx.beginPath();\
6957
  ctx.moveTo(x1,y1);\
6958
  ctx.lineTo(x2,y2);\
6959
  ctx.closePath();\
6960
  ctx.stroke();\
6961
  ctx.beginPath();\
6962
  ctx.moveTo(x2,y1);\
6963
  ctx.lineTo(x1,y2);\
6964
  ctx.closePath();\
6965
  ctx.stroke();\
6966
 }\
6967
 ctx.restore();\
6968
  return;\
7653 schaersvoo 6969
};");
7614 schaersvoo 6970
    break;
6971
 
6972
    case DRAW_RECTS:/*  used for userdraw */
6973
fprintf(js_include_file,"\n<!-- draw rects -->\n\
8105 schaersvoo 6974
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 6975
 ctx.save();\
8071 schaersvoo 6976
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6977
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6978
 ctx.lineWidth = line_width;\
11088 schaersvoo 6979
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8448 schaersvoo 6980
 ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
7614 schaersvoo 6981
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
6982
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
6983
  ctx.beginPath();\
6984
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
6985
  ctx.closePath();\
8448 schaersvoo 6986
  if(use_filled == 1 ){ctx.fillStyle = 'rgba('+fill_color+','+fill_opacity+')';ctx.fill();}\
7614 schaersvoo 6987
  ctx.stroke();\
6988
 };\
6989
 ctx.restore();\
6990
 return;\
7653 schaersvoo 6991
};");
7614 schaersvoo 6992
    break;
6993
 
6994
    case DRAW_ROUNDRECTS:/*  used for userdraw */
6995
fprintf(js_include_file,"\n<!-- draw round rects -->\n\
8105 schaersvoo 6996
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 6997
 ctx.save();\
8071 schaersvoo 6998
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6999
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7000
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
9462 schaersvoo 7001
 ctx.lineWidth = line_width;\
11088 schaersvoo 7002
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7003
 var x,y,w,h,r;\
7004
 for(var p = 0; p < x_points.length; p = p+2){\
7005
  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);\
7006
  ctx.beginPath();ctx.moveTo(x + r, y);\
7007
  ctx.lineTo(x + w - r, y);\
7008
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
7009
  ctx.lineTo(x + w, y + h - r);\
7010
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
7011
  ctx.lineTo(x + r, y + h);\
7012
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
7013
  ctx.lineTo(x, y + r);\
7014
  ctx.quadraticCurveTo(x, y, x + r, y);\
7015
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
7016
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7017
  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
7018
  ctx.stroke();\
7019
 }\
7020
 ctx.restore();\
7653 schaersvoo 7021
};");
8224 bpr 7022
    break;
7614 schaersvoo 7023
 
7024
    case DRAW_ELLIPSES:/* not  used for userdraw */
7025
fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
8105 schaersvoo 7026
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 7027
 var obj;\
7028
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7029
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7030
 }\
7031
 else\
7032
 {\
7033
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7034
 };\
7035
 var ctx = obj.getContext(\"2d\");\
7036
 ctx.save();\
8071 schaersvoo 7037
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7038
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7039
 var cx,cy,ry,rx;\
7040
 ctx.lineWidth = line_width;\
11088 schaersvoo 7041
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7042
 if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
7043
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7044
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7045
 for(var p=0;p< x_points.length;p = p+2){\
7046
  ctx.beginPath();\
7047
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
7048
  ctx.translate(cx - rx, cy - ry);\
7049
  ctx.scale(rx, ry);\
7050
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
7051
  if( use_filled == 1 ){ctx.fill();}\
7052
  ctx.stroke();\
7053
 };\
7054
 ctx.restore();\
7653 schaersvoo 7055
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 7056
    break;
7057
 
7058
    case DRAW_PATHS: /*  used for userdraw */
7059
fprintf(js_include_file,"\n<!-- draw paths -->\n\
8105 schaersvoo 7060
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 7061
 ctx.save();\
8071 schaersvoo 7062
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7063
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7064
 ctx.lineWidth = line_width;\
11088 schaersvoo 7065
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7066
 ctx.lineJoin = \"round\";\
7067
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7068
 ctx.beginPath();\
7069
 ctx.moveTo(x_points[0],y_points[0]);\
7070
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
7071
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
7072
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7073
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
7074
 ctx.stroke();\
7075
 ctx.restore();\
7076
 return;\
7077
};");
8224 bpr 7078
 
7614 schaersvoo 7079
    break;
7080
    case DRAW_ARROWS:/*  used for userdraw */
7081
fprintf(js_include_file,"\n<!-- draw arrows -->\n\
8105 schaersvoo 7082
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 7083
 ctx.save();\
8071 schaersvoo 7084
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7085
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7086
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7087
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7088
 ctx.lineWidth = line_width;\
11088 schaersvoo 7089
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7090
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7091
 ctx.lineCap = \"round\";\
7092
 var x1,y1,x2,y2,dx,dy,len;\
7093
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 7094
   ctx.save();\
7614 schaersvoo 7095
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
7096
   len = Math.sqrt(dx*dx+dy*dy);\
7097
   ctx.translate(x2,y2);\
7098
   ctx.rotate(Math.atan2(dy,dx));\
7099
   ctx.lineCap = \"round\";\
7100
   ctx.beginPath();\
7101
   ctx.moveTo(0,0);\
7102
   ctx.lineTo(-len,0);\
7103
   ctx.closePath();\
7104
   ctx.stroke();\
7105
   ctx.beginPath();\
7106
   ctx.moveTo(0,0);\
7107
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
7108
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
7109
   ctx.closePath();\
7110
   ctx.fill();\
7874 schaersvoo 7111
   ctx.restore();\
7614 schaersvoo 7112
   if( type == 2 ){\
7113
     ctx.save();\
7114
     ctx.translate(x1,y1);\
7115
     ctx.rotate(Math.atan2(-dy,-dx));\
7116
     ctx.beginPath();\
7117
     ctx.moveTo(0,0);\
8347 schaersvoo 7118
     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
7119
     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
7614 schaersvoo 7120
     ctx.closePath();\
7121
     ctx.stroke();\
7122
     ctx.fill();\
7874 schaersvoo 7123
     ctx.restore();\
8379 schaersvoo 7124
   };\
7125
  };\
7614 schaersvoo 7126
  ctx.restore();\
7127
  return;\
7653 schaersvoo 7128
};");
7614 schaersvoo 7129
    break;
7130
 
7131
    case DRAW_VIDEO:/* not  used for userdraw */
7132
fprintf(js_include_file,"\n<!-- draw video -->\n\
8105 schaersvoo 7133
var draw_video = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 7134
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7135
 var video_div = document.createElement(\"div\");\
7136
 canvas_div.appendChild(video_div);\
7137
 video_div.style.position = \"absolute\";\
7138
 video_div.style.left = x+\"px\";\
7139
 video_div.style.top = y+\"px\";\
7140
 video_div.style.width = w+\"px\";\
7141
 video_div.style.height = h+\"px\";\
7142
 var video = document.createElement(\"video\");\
7143
 video_div.appendChild(video);\
7144
 video.style.width = w+\"px\";\
7145
 video.style.height = h+\"px\";\
7146
 video.autobuffer = true;\
7147
 video.controls = true;video.autoplay = false;\
7148
 var src = document.createElement(\"source\");\
7149
 src.type = \"video/mp4\";\
7150
 src.src = URL;\
7151
 video.appendChild(src);\
7152
 video.load();\
7153
 return;\
8224 bpr 7154
};");
7614 schaersvoo 7155
    break;
8224 bpr 7156
 
7614 schaersvoo 7157
    case DRAW_AUDIO:/* not used for userdraw */
7158
fprintf(js_include_file,"\n<!-- draw audio -->\n\
8105 schaersvoo 7159
var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
7614 schaersvoo 7160
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7161
 var audio_div = document.createElement(\"div\");\
7162
 canvas_div.appendChild(audio_div);\
7163
 audio_div.style.position = \"absolute\";\
7164
 audio_div.style.left = x+\"px\";\
7165
 audio_div.style.top = y+\"px\";\
7166
 audio_div.style.width = w+\"px\";\
7167
 audio_div.style.height = h+\"px\";\
7168
 var audio = document.createElement(\"audio\");\
7169
 audio_div.appendChild(audio);\
7170
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
7171
 audio.autobuffer = true;\
8379 schaersvoo 7172
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
7173
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
7614 schaersvoo 7174
 var src1 = document.createElement(\"source\");\
7175
 src1.type = \"audio/ogg\";\
7176
 src1.src = URL1;\
7177
 audio.appendChild(src1);\
7178
 var src2 = document.createElement(\"source\");\
7179
 src2.type = \"audio/mpeg\";\
7180
 src2.src = URL2;\
7181
 audio.appendChild(src2);\
7182
 audio.load();\
7183
 return;\
7653 schaersvoo 7184
};");
7614 schaersvoo 7185
    break;
8224 bpr 7186
 
7614 schaersvoo 7187
    case DRAW_HTTP:/* not  used for userdraw */
7188
fprintf(js_include_file,"\n<!-- draw http -->\n\
8105 schaersvoo 7189
var draw_http = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 7190
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7191
 var http_div = document.createElement(\"div\");\
7192
 var iframe = document.createElement(\"iframe\");\
7193
 canvas_div.appendChild(http_div);\
7194
 http_div.appendChild(iframe);\
7195
 iframe.src = URL;\
7196
 iframe.setAttribute(\"width\",w);\
7197
 iframe.setAttribute(\"height\",h);\
7198
 return;\
7653 schaersvoo 7199
};");
7614 schaersvoo 7200
    break;
8224 bpr 7201
 
11238 schaersvoo 7202
    case DRAW_XML: /*
7203
    onclick=1 : click
7204
    onclick=2 drag
7205
    xy:drag_type = 0;
7206
    x:    drag_type = 1;
7207
    y:    drag_type = 2;
7208
    */
7209
 
7614 schaersvoo 7210
fprintf(js_include_file,"\n<!-- draw xml -->\n\
11756 schaersvoo 7211
var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity){\
7614 schaersvoo 7212
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7213
 var xml_div = document.createElement(\"div\");\
7214
 canvas_div.appendChild(xml_div);\
7215
 xml_div.innerHTML = mathml;\
8379 schaersvoo 7216
 xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11745 schaersvoo 7217
 var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11756 schaersvoo 7218
 var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7219
 var no_color = \"rgba(255,255,255,0)\";\
7220
 xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
11745 schaersvoo 7221
 var dragging = false;\
11747 schaersvoo 7222
 if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
7223
 if( onclick == 1 ){reply[click_cnt] = 0;};\
7224
 if( onclick == 2 ){\
7225
  xml_div.onclick = function(){\
11756 schaersvoo 7226
   canvas_div.onclick = function(evt){if(dragging){dragging = false;xml_div.style.color = color_org; xml_div.style.backgroundColor = no_color;}else{dragging = true;xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;};};\
11747 schaersvoo 7227
   canvas_div.onmousemove = function(evt){\
7228
    if(!dragging){return;};\
7229
    var x1;var y1;\
7230
    var mouse = dragstuff.getMouse(evt,xml_div);\
7231
    switch(drag_type){\
7232
     case 0: x1 = mouse.x;y1 = mouse.y;break;\
7233
     case 1: x1 = mouse.x;y1 = y;break;\
7234
     case 2: x1 = x;y1 = mouse.y;break;\
7235
     default:x1 = x;y1 = y; break;\
7236
    };\
7237
    if( x_use_snap_to_grid == 1 ){ x1 = snap_to_x(x1);};\
7238
    if( y_use_snap_to_grid == 1 ){ y1 = snap_to_y(y1);};\
7239
    if( use_snap_to_points != 0 ){ var xy = new Array(2);if( use_snap_to_points == 1 ){xy = snap_to_points(x1,y1);}else{xy = snap_to_fun(x1,y1);};x1 = xy[0];y1 = xy[1];};\
7240
    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
7241
    reply[click_cnt] = px2x(x1)+','+px2y(y1);\
11238 schaersvoo 7242
   };\
7614 schaersvoo 7243
  };\
11238 schaersvoo 7244
 };\
7245
 if(onclick == 1){\
11747 schaersvoo 7246
  xml_div.onclick = function(){\
11756 schaersvoo 7247
  if(reply[click_cnt] == 0){ reply[click_cnt] = 1; xml_div.style.color = 'red';xml_div.style.backgroundColor = back_color;}else{reply[click_cnt] = 0;xml_div.style.color = color_org;xml_div.style.backgroundColor = no_color;};};\
7614 schaersvoo 7248
 };\
7249
 return;\
11745 schaersvoo 7250
};");
7614 schaersvoo 7251
    break;
7654 schaersvoo 7252
    case DRAW_SGRAPH:
8224 bpr 7253
/*
7654 schaersvoo 7254
 xstart = given
7255
 ystart = given
7256
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
7257
*/
7258
fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
8105 schaersvoo 7259
var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
7658 schaersvoo 7260
 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);};\
7261
 var ctx = obj.getContext(\"2d\");\
7262
 ctx.font = fontfamily;\
7263
 var minor_opacity = 0.8*opacity;\
7264
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 7265
 var zero_x = 0.1*xsize;\
7266
 var zero_y = 0.9*ysize;\
8129 schaersvoo 7267
 var snor_x;var snor_y;\
7654 schaersvoo 7268
 if( xstart != xmin){\
7658 schaersvoo 7269
  snor_x = 0.1*xsize;\
7270
 }\
7271
 else\
7272
 {\
7273
  snor_x = 0;\
7274
  xstart = xmin;\
7275
 };\
7276
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7277
 ctx.lineWidth = 2;\
7278
 ctx.beginPath();\
7279
 ctx.moveTo(xsize,zero_y);\
7280
 ctx.lineTo(zero_x,zero_y);\
7281
 ctx.lineTo(zero_x,0);\
7282
 ctx.stroke();\
7283
 ctx.closePath();\
7284
 ctx.beginPath();\
7285
 ctx.moveTo(zero_x,zero_y);\
7286
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
7287
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
7288
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
7289
 ctx.lineTo(zero_x + snor_x,zero_y);\
7290
 ctx.stroke();\
7291
 ctx.closePath();\
7292
 ctx.beginPath();\
7293
 var num = xstart;\
7660 schaersvoo 7294
 var flipflop = 1;\
7658 schaersvoo 7295
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 7296
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 7297
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 7298
  txtsize = ctx.measureText(num).width;\
7299
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
7300
  if( flipflop == 1){\
7301
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
7302
  }\
7303
  else\
7304
  {\
7305
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
8379 schaersvoo 7306
  };\
7976 schaersvoo 7307
  num = num + xmajor;\
7658 schaersvoo 7308
 };\
7309
 ctx.stroke();\
7310
 ctx.closePath();\
7311
 ctx.lineWidth = 1;\
7312
 ctx.beginPath();\
7313
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7314
   ctx.moveTo(x,zero_y);\
7315
   ctx.lineTo(x,0);\
7316
 };\
7317
 ctx.stroke();\
7318
 ctx.closePath();\
7319
 if( xminor > 1){\
7320
  ctx.lineWidth = 0.5;\
7321
  ctx.beginPath();\
7322
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
7323
  var minor_step_x = step_x / xminor;\
7324
  var nx;\
7325
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
7326
    num = 1;\
7327
    for(var p = 1 ; p < xminor ; p++){\
7328
     nx = x + num*minor_step_x;\
7329
     ctx.moveTo(nx,zero_y);\
7330
     ctx.lineTo(nx,0);\
7331
     num++;\
7332
    };\
7333
  };\
7334
  ctx.stroke();\
7335
  ctx.closePath();\
7336
  ctx.beginPath();\
7337
  ctx.lineWidth = 2;\
7338
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7339
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7340
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
7341
  };\
7342
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
7343
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
7344
  };\
7345
  ctx.stroke();\
7346
  ctx.closePath();\
7347
  ctx.lineWidth = 0.5;\
7348
 };\
7349
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
7350
 if( ystart != ymin){\
7351
  snor_y = 0.1*ysize;\
7352
 }\
7353
 else\
7354
 {\
7355
  snor_y = 0;\
7356
  ystart = ymin;\
7357
 };\
7358
 ctx.lineWidth = 2;\
7359
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7360
 ctx.beginPath();\
7361
 ctx.moveTo(zero_x,zero_y);\
7362
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
7363
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
7364
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
7365
 ctx.lineTo(zero_x,zero_y - snor_y);\
7366
 ctx.stroke();\
7367
 ctx.closePath();\
7368
 ctx.beginPath();\
7369
 ctx.lineWidth = 1;\
7370
 num = ystart;\
7371
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
7372
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
7373
  ctx.moveTo(zero_x,y);\
7374
  ctx.lineTo(xsize,y);\
7375
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
7376
  num = num + ymajor;\
7377
 };\
7378
 ctx.stroke();\
7379
 ctx.closePath();\
7380
 if( yminor > 1){\
7381
  ctx.lineWidth = 0.5;\
7382
  ctx.beginPath();\
7383
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
7384
  var minor_step_y = step_y / yminor;\
7385
  var ny;\
7386
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
7387
   num = 1;\
7388
   for(var p = 1 ;p < yminor;p++){\
7389
     ny = y + num*minor_step_y;\
7390
     ctx.moveTo(zero_x,ny);\
7391
     ctx.lineTo(xsize,ny);\
7392
     num++;\
7393
    };\
7394
  };\
7395
  ctx.stroke();\
7396
  ctx.closePath();\
7397
  ctx.lineWidth = 2;\
7398
  ctx.beginPath();\
7399
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7400
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
7401
   ctx.moveTo(zero_x,y);\
7402
   ctx.lineTo(zero_x+12,y);\
7403
  };\
7404
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
7405
   ctx.moveTo(zero_x,y);\
7406
   ctx.lineTo(zero_x+6,y);\
7407
  };\
7408
  ctx.stroke();\
7409
  ctx.closePath();\
7410
 };\
7411
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
11088 schaersvoo 7412
 if( typeof(legend%d)  !== 'undefined' ){\
7654 schaersvoo 7413
  ctx.globalAlpha = 1.0;\
7414
  var y_offset = 2*font_size;\
7415
  var txt;var txt_size;\
7416
  var x_offset = xsize - 2*font_size;\
7417
  var l_length = legend%d.length;var barcolor = new Array();\
11088 schaersvoo 7418
  if( typeof(legendcolors%d) !== 'undefined' ){\
7654 schaersvoo 7419
   for(var p = 0 ; p < l_length ; p++){\
7420
    barcolor[p] = legendcolors%d[p];\
7421
   };\
7422
  }else{\
7423
   if( barcolor.length == 0 ){\
7424
    for(var p = 0 ; p < l_length ; p++){\
7425
     barcolor[p] = stroke_color;\
7426
    };\
7427
   };\
7428
  };\
7429
  for(var p = 0; p < l_length; p++){\
7430
   ctx.fillStyle = barcolor[p];\
7431
   txt = legend%d[p];\
7432
   txt_size = ctx.measureText(txt).width;\
7433
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
7434
   y_offset = parseInt(y_offset + 1.5*font_size);\
7435
  };\
7436
 };\
11088 schaersvoo 7437
 if( typeof(xaxislabel) !== 'undefined' ){\
7658 schaersvoo 7438
   ctx.fillStyle = \'#000000\';\
7439
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
7440
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
7441
 };\
11088 schaersvoo 7442
 if( typeof(yaxislabel) !== 'undefined'){\
7658 schaersvoo 7443
   ctx.save();\
7444
   ctx.fillStyle = \'#000000\';\
7445
   var txt_size = ctx.measureText(yaxislabel).width;\
7446
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
7447
   ctx.rotate(-0.5*Math.PI);\
7448
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 7449
   ctx.restore();\
7658 schaersvoo 7450
 };\
7654 schaersvoo 7451
};\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);
7452
    break;
7614 schaersvoo 7453
 
7454
    case DRAW_GRID:/* not used for userdraw */
7455
fprintf(js_include_file,"\n<!-- draw grid -->\n\
8105 schaersvoo 7456
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 7457
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);};\
7458
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 7459
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7460
ctx.save();\
8071 schaersvoo 7461
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 7462
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
7463
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7464
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
7465
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
7466
ctx.font = font_family;\
7988 schaersvoo 7467
var barcolor = new Array();\
7614 schaersvoo 7468
var xstep = xsize*xmajor/(xmax - xmin);\
7469
var ystep = ysize*ymajor/(ymax - ymin);\
7470
var x2step = xstep / xminor;\
7471
var y2step = ystep / yminor;\
7996 schaersvoo 7472
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
7473
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
7474
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
11088 schaersvoo 7475
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7476
ctx.beginPath();\
7477
ctx.lineWidth = line_width;\
7478
ctx.strokeStyle = stroke_color;\
7479
for(var p = zero_x ; p < xsize; p = p + xstep){\
7480
 ctx.moveTo(p,0);\
7481
 ctx.lineTo(p,ysize);\
7482
};\
7483
for(var p = zero_x ; p > 0; p = p - xstep){\
7484
 ctx.moveTo(p,0);\
7485
 ctx.lineTo(p,ysize);\
7486
};\
7487
for(var p = zero_y ; p < ysize; p = p + ystep){\
7488
 ctx.moveTo(0,p);\
7489
 ctx.lineTo(xsize,p);\
7490
};\
7491
for(var p = zero_y ; p > 0; p = p - ystep){\
7492
 ctx.moveTo(0,p);\
7493
 ctx.lineTo(xsize,p);\
7494
};\
11088 schaersvoo 7495
if( typeof(xaxislabel) !== 'undefined' ){\
7614 schaersvoo 7496
 ctx.save();\
7497
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7498
 var corr =  ctx.measureText(xaxislabel).width;\
7499
 ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
7500
 ctx.restore();\
7501
};\
11088 schaersvoo 7502
if( typeof(yaxislabel) !== 'undefined' ){\
7614 schaersvoo 7503
 ctx.save();\
7504
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7988 schaersvoo 7505
 var corr =  ctx.measureText(yaxislabel).width;\
7614 schaersvoo 7506
 ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
7507
 ctx.rotate(-0.5*Math.PI);\
7508
 ctx.fillText(yaxislabel,0,0);\
7509
 ctx.restore();\
7510
};\
7511
ctx.stroke();\
7512
ctx.closePath();\
7513
if( use_axis == 1 ){\
7988 schaersvoo 7514
 ctx.save();\
7614 schaersvoo 7515
 ctx.beginPath();\
7516
 ctx.strokeStyle = stroke_color;\
7517
 ctx.lineWidth = 0.6*line_width;\
7518
 for(var p = zero_x ; p < xsize; p = p + x2step){\
7519
  ctx.moveTo(p,0);\
7520
  ctx.lineTo(p,ysize);\
7521
 };\
7522
 for(var p = zero_x ; p > 0; p = p - x2step){\
7523
  ctx.moveTo(p,0);\
7524
  ctx.lineTo(p,ysize);\
7525
 };\
7526
 for(var p = zero_y ; p < ysize; p = p + y2step){\
7527
  ctx.moveTo(0,p);\
7528
  ctx.lineTo(xsize,p);\
7529
 };\
7530
 for(var p = zero_y ; p > 0; p = p - y2step){\
7531
  ctx.moveTo(0,p);\
7532
  ctx.lineTo(xsize,p);\
7533
 };\
7534
 ctx.stroke();\
7535
 ctx.closePath();\
7536
 ctx.beginPath();\
7537
 ctx.lineWidth = 2*line_width;\
7538
 ctx.strokeStyle = axis_color;\
7539
 ctx.moveTo(0,zero_y);\
7540
 ctx.lineTo(xsize,zero_y);\
7541
 ctx.moveTo(zero_x,0);\
7542
 ctx.lineTo(zero_x,ysize);\
7543
 ctx.stroke();\
7544
 ctx.closePath();\
7545
 ctx.lineWidth = line_width+0.5;\
7546
 ctx.beginPath();\
7547
 for(var p = zero_x ; p < xsize; p = p + xstep){\
7548
  ctx.moveTo(p,zero_y-tics_length);\
7549
  ctx.lineTo(p,zero_y+tics_length);\
7550
 };\
7551
 for(var p = zero_x ; p > 0; p = p - xstep){\
7552
  ctx.moveTo(p,zero_y-tics_length);\
7553
  ctx.lineTo(p,zero_y+tics_length);\
7554
 };\
7555
 for(var p = zero_y ; p < ysize; p = p + ystep){\
7556
  ctx.moveTo(zero_x-tics_length,p);\
7557
  ctx.lineTo(zero_x+tics_length,p);\
7558
 };\
7559
 for(var p = zero_y ; p > 0; p = p - ystep){\
7560
  ctx.moveTo(zero_x-tics_length,p);\
7561
  ctx.lineTo(zero_x+tics_length,p);\
7562
 };\
7563
 for(var p = zero_x ; p < xsize; p = p + x2step){\
7564
  ctx.moveTo(p,zero_y-0.5*tics_length);\
7565
  ctx.lineTo(p,zero_y+0.5*tics_length);\
7566
 };\
7567
 for(var p = zero_x ; p > 0; p = p - x2step){\
7568
  ctx.moveTo(p,zero_y-0.5*tics_length);\
7569
  ctx.lineTo(p,zero_y+0.5*tics_length);\
7570
 };\
7571
 for(var p = zero_y ; p < ysize; p = p + y2step){\
7572
  ctx.moveTo(zero_x-0.5*tics_length,p);\
7573
  ctx.lineTo(zero_x+0.5*tics_length,p);\
7574
 };\
7575
 for(var p = zero_y ; p > 0; p = p - y2step){\
7576
  ctx.moveTo(zero_x-0.5*tics_length,p);\
7577
  ctx.lineTo(zero_x+0.5*tics_length,p);\
7578
 };\
7579
 ctx.stroke();\
7580
 ctx.closePath();\
7988 schaersvoo 7581
 ctx.restore();\
7582
};\
7583
if( use_axis_numbering == 1 ){\
7584
 ctx.save();\
7585
 ctx.fillColor = axis_color;\
8110 schaersvoo 7586
 ctx.strokeStyle = axis_color;\
7587
 ctx.lineWidth = 2*line_width;\
7988 schaersvoo 7588
 ctx.font = font_family;\
7589
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
7590
 if( x_strings != null ){\
7591
  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 7592
  ctx.beginPath();\
9341 schaersvoo 7593
  if( x_strings_up == null){\
7594
   for(var p = 0 ; p < len ; p = p+2){\
7595
    var x_nums = x2px(eval(x_strings[p]));\
7596
    var x_text = x_strings[p+1];\
7597
    corr = ctx.measureText(x_text).width;\
7598
    skip = 1.2*corr/xstep;\
7599
    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
7600
    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
7601
    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
7602
    ctx.moveTo(x_nums,zero_y - tics_length);\
7603
    ctx.lineTo(x_nums,zero_y + tics_length);\
7604
   };\
7605
  }\
7606
  else\
7607
  {\
7608
   for(var p = 0 ; p < len ; p = p+2){\
7609
    var x_nums = x2px(eval(x_strings[p]));\
7610
    var x_text = x_strings[p+1];\
7611
    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
7612
    if( corr > ysize ){corr = ysize;};\
7613
    ctx.save();\
9346 schaersvoo 7614
    ctx.translate(x_nums+0.25*font_size, corr);\
9341 schaersvoo 7615
    ctx.rotate(-1.5708);\
7616
    ctx.fillText(x_text,0,0);\
7617
    ctx.restore();\
7618
    ctx.moveTo(x_nums,zero_y - tics_length);\
7619
    ctx.lineTo(x_nums,zero_y + tics_length);\
7620
   };\
7988 schaersvoo 7621
  };\
8110 schaersvoo 7622
  ctx.closePath();\
7988 schaersvoo 7623
 }\
7624
 else\
7625
 {\
7626
  skip = 1;cnt = px2x(zero_x);\
7627
  prec = Math.log(precision)/(Math.log(10));\
7628
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
7629
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
7630
   if(skip == 0 ){\
7990 schaersvoo 7631
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7632
    corr = ctx.measureText(disp_cnt).width;\
7633
    skip = parseInt(1.2*corr/xstep);\
7634
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 7635
   }\
7988 schaersvoo 7636
   else\
7637
   {\
7638
    skip--;\
7614 schaersvoo 7639
   };\
7988 schaersvoo 7640
   cnt = cnt + xmajor;\
7614 schaersvoo 7641
  };\
7988 schaersvoo 7642
  cnt = px2x(zero_x);skip = 1;\
7643
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
7644
   if(skip == 0 ){\
7990 schaersvoo 7645
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7646
    corr = ctx.measureText(disp_cnt).width;\
7647
    skip = parseInt(1.2*corr/xstep);\
7648
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7649
   }\
7650
   else\
7651
   {\
7652
    skip--;\
7614 schaersvoo 7653
   };\
7988 schaersvoo 7654
   cnt = cnt - xmajor;\
7614 schaersvoo 7655
  };\
7656
 };\
7988 schaersvoo 7657
 if( y_strings != null ){\
7658
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 7659
  ctx.beginPath();\
7988 schaersvoo 7660
  for(var p = 0 ; p < len ; p = p+2){\
7661
   var y_nums = y2px(eval(y_strings[p]));\
7662
   var y_text = y_strings[p+1];\
7663
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
7664
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
8110 schaersvoo 7665
   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
7666
   ctx.moveTo(zero_x - tics_length,y_nums);\
7667
   ctx.lineTo(zero_x + tics_length,y_nums);\
7614 schaersvoo 7668
  };\
8110 schaersvoo 7669
  ctx.closePath();\
7988 schaersvoo 7670
 }\
7671
 else\
7672
 {\
7991 schaersvoo 7673
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 7674
  cnt = px2y(zero_y);skip = 1;\
7675
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
7676
   if(skip == 0 ){\
7677
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 7678
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7679
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
7680
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
7681
   }\
7682
   else\
7683
   {\
7684
    skip--;\
7685
   };\
7686
   cnt = cnt - ymajor;\
7614 schaersvoo 7687
  };\
7988 schaersvoo 7688
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 7689
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 7690
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
7691
   if(skip == 0 ){\
7692
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 7693
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7694
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
7695
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
7696
   }\
7697
   else\
7698
   {\
7699
    skip--;\
7700
   };\
7701
   cnt = cnt + ymajor;\
7614 schaersvoo 7702
  };\
7703
 };\
7988 schaersvoo 7704
 ctx.stroke();\
7614 schaersvoo 7705
 ctx.restore();\
7706
};\
11088 schaersvoo 7707
if( typeof(legend0)  !== 'undefined' ){\
7988 schaersvoo 7708
 ctx.save();\
7614 schaersvoo 7709
 ctx.globalAlpha = 1.0;\
7710
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
7711
 var y_offset = 2*font_size;\
7712
 var txt;var txt_size;\
7713
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 7714
 var l_length = legend0.length;\
11088 schaersvoo 7715
 if( typeof(legendcolors0) !== 'undefined' ){\
7614 schaersvoo 7716
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 7717
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 7718
  };\
7988 schaersvoo 7719
 }\
7720
 else\
7721
 {\
7614 schaersvoo 7722
  if( barcolor.length == 0 ){\
7723
   for(var p = 0 ; p < l_length ; p++){\
7724
    barcolor[p] = stroke_color;\
7725
   };\
7726
  };\
7727
 };\
7728
 for(var p = 0; p < l_length; p++){\
7729
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 7730
  txt = legend0[p];\
7614 schaersvoo 7731
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 7732
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 7733
  y_offset = parseInt(y_offset + 1.5*font_size);\
7734
 };\
7988 schaersvoo 7735
 ctx.restore();\
7614 schaersvoo 7736
};\
11088 schaersvoo 7737
if( typeof(barchart_0)  !== 'undefined' ){\
7991 schaersvoo 7738
 ctx.save();\
7739
 var num_barcharts = 0;\
7740
 var bar_name = eval('barchart_0');\
11088 schaersvoo 7741
 while( typeof(bar_name) !== 'undefined' ){\
7991 schaersvoo 7742
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
7743
 };\
9346 schaersvoo 7744
 var bar_width = parseInt(0.8*x2step/(num_barcharts));\
7991 schaersvoo 7745
 for(var i=0 ; i< num_barcharts ; i++){\
7746
  bar_name = eval('barchart_'+i);\
7747
  var bar_x = new Array();\
7748
  var bar_y = new Array();\
7749
  var lb = bar_name.length;\
7750
  var idx = 0;\
7751
  var dx = parseInt(0.5*i*bar_width);\
7752
  for( var p = 0 ; p < lb ; p = p + 3 ){\
7753
   bar_x[idx] = x2px(bar_name[p]);\
7754
   bar_y[idx] = y2px(bar_name[p+1]);\
7755
   barcolor[idx] = bar_name[p+2];\
7756
   idx++;\
7757
  };\
7758
  ctx.globalAlpha = fill_opacity;\
7759
  for( var p = 0; p < idx ; p++ ){\
11739 schaersvoo 7760
   ctx.beginPath();\
7991 schaersvoo 7761
   ctx.strokeStyle = barcolor[p];\
7762
   ctx.fillStyle = barcolor[p];\
9346 schaersvoo 7763
   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
11739 schaersvoo 7764
   ctx.fill();\
7765
   ctx.stroke();\
7766
   ctx.closePath();\
7991 schaersvoo 7767
  };\
7768
 };\
7769
 ctx.restore();\
7770
};\
11088 schaersvoo 7771
if( typeof(linegraph_0) !== 'undefined' ){\
7996 schaersvoo 7772
 ctx.save();\
7773
 ctx.globalAlpha = 1.0;\
7774
 var i = 0;\
7775
 var line_name = eval('linegraph_'+i);\
11088 schaersvoo 7776
 while ( typeof(line_name) !== 'undefined' ){\
7996 schaersvoo 7777
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
7778
  ctx.lineWidth = parseInt(line_name[1]);\
7779
  if(line_name[2] == \"1\"){\
7780
   var d1 = parseInt(line_name[3]);\
7781
   var d2 = parseInt(line_name[4]);\
7782
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
7783
  }\
7784
  else\
7785
  {\
7786
  if(ctx.setLineDash){ctx.setLineDash = null;}\
7787
  if(ctx.mozDash){ctx.mozDash = null;}\
7788
  };\
7789
  var data_x = new Array();\
7790
  var data_y = new Array();\
7791
  var lb = line_name.length;\
7792
  var idx = 0;\
7793
  for( var p = 5 ; p < lb ; p = p + 2 ){\
7794
   data_x[idx] = x2px(line_name[p]);\
7795
   data_y[idx] = y2px(line_name[p+1]);\
7796
   idx++;\
7797
  };\
7798
  for( var p = 0; p < idx ; p++){\
7799
   ctx.beginPath();\
7800
   ctx.moveTo(data_x[p],data_y[p]);\
7801
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
7802
   ctx.stroke();\
7803
   ctx.closePath();\
7804
  };\
7805
  i++;\
7806
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
7807
 };\
7808
 ctx.restore();\
7809
};\
7614 schaersvoo 7810
return;\
7989 schaersvoo 7811
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 7812
    break;
8224 bpr 7813
 
7614 schaersvoo 7814
    case DRAW_PIECHART:
7987 schaersvoo 7815
fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
7956 schaersvoo 7816
function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
7614 schaersvoo 7817
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7818
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7819
 }\
7820
 else\
7821
 {\
7822
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7823
 };\
7824
 var ld = data_color_list.length;\
7825
 var sum = 0;\
7826
 var idx = 0;\
7956 schaersvoo 7827
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 7828
 var colors = new Array();\
7829
 var data = new Array();\
7830
 for(var p = 0;p < ld; p = p + 2){\
7831
  data[idx] = parseFloat(data_color_list[p]);\
7832
  sum = sum + data[idx];\
7833
  colors[idx] = data_color_list[p+1];\
7834
  idx++;\
7835
 };\
7836
 var ctx = obj.getContext(\"2d\");\
7837
 ctx.save();\
7838
 var angle;\
7839
 var angle_end = 0;\
7840
 var offset = Math.PI / 2;\
7841
 ctx.globalAlpha = fill_opacity;\
7842
 for(var p=0; p < idx; p++){\
7843
  ctx.beginPath();\
7844
  ctx.fillStyle = colors[p];\
7845
  ctx.moveTo(x_center,y_center);\
7846
  angle = Math.PI * (2 * data[p] / sum);\
7847
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
7848
  ctx.lineTo(x_center, y_center);\
7849
  ctx.fill();\
7850
  ctx.closePath();\
7851
  angle_end  = angle_end + angle;\
7852
 };\
11088 schaersvoo 7853
 if(typeof(legend0) !== 'undefined'){\
7956 schaersvoo 7854
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 7855
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 7856
  ctx.font = font_family;\
7614 schaersvoo 7857
  var y_offset = font_size; \
7858
  var x_offset = 0;\
7859
  var txt;var txt_size;\
7860
  for(var p = 0; p < idx; p++){\
7861
   ctx.fillStyle = colors[p];\
7956 schaersvoo 7862
   txt = legenda[p];\
7614 schaersvoo 7863
   txt_size = ctx.measureText(txt).width;\
7864
   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
7956 schaersvoo 7865
   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
7614 schaersvoo 7866
   y_offset = parseInt(y_offset + 1.5*font_size);\
7867
  };\
7868
 };\
7869
 ctx.restore();\
7956 schaersvoo 7870
};",canvas_root_id,canvas_root_id,canvas_root_id);
8224 bpr 7871
 
7614 schaersvoo 7872
    break;
9433 schaersvoo 7873
    case DRAW_JSBOXPLOT:
7874
fprintf(js_include_file,"\n<!-- draw jsboxplots -->\n\
7875
function statistics(data){\
7876
 var len = data.length;\
7877
 var min = 10000000;\
7878
 var max = -10000000;\
7879
 var sum = 0;var d;\
7880
 for(var i=0;i<len;i++){\
7881
  d = data[i];\
7882
  if(d < min){min = d;}else{if(d > max){max = d;};};\
7883
  sum+= parseFloat(data[i]);\
7884
 };\
7885
 var mean = parseFloat(sum/len);\
7886
 var variance = 0;\
7887
 for(var i=0;i<len;i++){\
7888
  d = data[i];\
7889
  variance += (d - mean)*(d - mean);\
7890
 };\
7891
 variance = parseFloat(variance / len);\
7892
 var std = Math.sqrt(variance);\
7893
 data.sort(function(a,b){return a - b;});\
7894
 var median;var Q1;var Q3;\
7895
 var half = Math.floor(0.5*len);\
7896
 var q1 = Math.floor(0.25*len);\
7897
 var q3 = Math.floor(0.75*len);\
7898
 var half = Math.floor(0.5*len);\
7899
 if(len %%2 == 1){\
7900
  median = data[half];\
7901
  Q1 = data[q1];\
7902
  Q3 = data[q3];\
7903
 }\
7904
 else\
7905
 {\
7906
  median = (data[half - 1] + data[half] )/2;\
7907
  Q1 = (data[q1 - 1] + data[q1] )/2;\
7908
  Q3 = (data[q3 - 1] + data[q3] )/2;\
7909
 };\
7910
 return [min,Q1,median,Q3,max];\
7911
};");
7912
    break;
7913
    case DRAW_BOXPLOT:
7914
fprintf(js_include_file,"\n<!-- draw boxplots -->\n\
9465 schaersvoo 7915
draw_boxplot = function(canvas_type,xy,hw,cxy,data,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1){\
9433 schaersvoo 7916
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7917
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7918
 }\
7919
 else\
7920
 {\
7921
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7922
 };\
7923
 var ctx = obj.getContext(\"2d\");\
7924
 ctx.clearRect(0,0,xsize,ysize);\
7925
 ctx.save();\
7926
 ctx.lineWidth = line_width;\
11088 schaersvoo 7927
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
9433 schaersvoo 7928
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7929
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7930
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
7931
 var hh = 0.25*hw;\
9465 schaersvoo 7932
 switch(boxplot_source){\
11088 schaersvoo 7933
  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
7934
  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
7935
  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
9465 schaersvoo 7936
  default: break;\
9433 schaersvoo 7937
 };\
7938
 var min,Q1,median,Q3,max;\
7939
 if(xy == 1 ){\
7940
  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
7941
  hh = Math.abs(y2px(hh) - y2px(ystart));\
7942
  hw = Math.abs(y2px(hw) - y2px(ystart));\
7943
  cxy = y2px(cxy);\
9465 schaersvoo 7944
  ctx.beginPath();\
9433 schaersvoo 7945
  ctx.moveTo(min,cxy);\
7946
  ctx.lineTo(Q1,cxy);\
7947
  ctx.moveTo(Q3,cxy);\
7948
  ctx.lineTo(max,cxy);\
7949
  ctx.moveTo(min,cxy+hh);\
7950
  ctx.lineTo(min,cxy-hh);\
7951
  ctx.moveTo(max,cxy+hh);\
7952
  ctx.lineTo(max,cxy-hh);\
9465 schaersvoo 7953
  ctx.closePath();\
7954
  ctx.stroke();\
7955
  ctx.beginPath();\
9433 schaersvoo 7956
  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
9465 schaersvoo 7957
  ctx.closePath();\
7958
  if( use_filled == 1 ){\
7959
   ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\
7960
   ctx.fill();\
7961
  };\
7962
  ctx.stroke();\
7963
  ctx.beginPath();\
9433 schaersvoo 7964
  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
9465 schaersvoo 7965
  ctx.closePath();\
7966
  if( use_filled == 1 ){\
7967
   ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7968
   ctx.fill();\
7969
  };\
7970
  ctx.stroke();\
9433 schaersvoo 7971
 }else{\
7972
  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
7973
  hh = Math.abs(x2px(hh) - x2px(xstart));\
7974
  hw = Math.abs(x2px(hw) - x2px(xstart));\
7975
  cxy = x2px(cxy);\
9465 schaersvoo 7976
  ctx.beginPath();\
9433 schaersvoo 7977
  ctx.moveTo(cxy,min);\
7978
  ctx.lineTo(cxy,Q1);\
7979
  ctx.moveTo(cxy,Q3);\
7980
  ctx.lineTo(cxy,max);\
7981
  ctx.moveTo(cxy + hh,min);\
7982
  ctx.lineTo(cxy - hh,min);\
7983
  ctx.moveTo(cxy + hh,max);\
7984
  ctx.lineTo(cxy - hh,max);\
9465 schaersvoo 7985
  ctx.closePath;\
7986
  ctx.stroke();\
7987
  ctx.beginPath();\
9433 schaersvoo 7988
  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
9465 schaersvoo 7989
  ctx.closePath();\
7990
  if( use_filled == 1 ){\
7991
   ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\
7992
   ctx.fill();\
7993
  };\
7994
  ctx.stroke();\
7995
  ctx.beginPath();\
9433 schaersvoo 7996
  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
9465 schaersvoo 7997
  ctx.closePath();\
7998
  if( use_filled == 1 ){\
7999
   ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8000
   ctx.fill();\
8001
  };\
8002
  ctx.stroke();\
9433 schaersvoo 8003
 };\
8004
 ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
8005
    break;
7614 schaersvoo 8006
    case DRAW_ARCS:
8007
fprintf(js_include_file,"\n<!-- draw arcs -->\n\
8105 schaersvoo 8008
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 8009
 ctx.save();\
8010
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 8011
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 8012
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
8013
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 8014
 start = 360 - start;\
8015
 end = 360 - end;\
7614 schaersvoo 8016
 ctx.lineWidth = line_width;\
11088 schaersvoo 8017
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8018
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8071 schaersvoo 8019
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8020
 ctx.beginPath();\
8021
 ctx.moveTo(xc,yc);\
8022
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
8023
 ctx.lineTo(xc,yc);\
8024
 ctx.closePath();\
7614 schaersvoo 8025
 if( use_filled == 1 ){\
8026
  ctx.fill();\
8071 schaersvoo 8027
 };\
8028
 ctx.stroke();\
7614 schaersvoo 8029
 ctx.restore();\
8071 schaersvoo 8030
};");
8224 bpr 8031
 
7614 schaersvoo 8032
    break;
7983 schaersvoo 8033
    case DRAW_CENTERSTRING:
8034
fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
8105 schaersvoo 8035
var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
7983 schaersvoo 8036
 var obj;\
8037
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8038
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8039
 }\
8040
 else\
8041
 {\
8042
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8043
 };\
8044
 var ctx = obj.getContext(\"2d\");\
8045
 ctx.save();\
9481 schaersvoo 8046
 ctx.clearRect(0,0,xsize,ysize);\
7983 schaersvoo 8047
 ctx.font = font_family;\
8048
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8049
 var stringwidth = ctx.measureText(text).width;\
8050
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
8051
 ctx.fillText(text,x,y2px(y));\
9481 schaersvoo 8052
 ctx.restore();\
7983 schaersvoo 8053
return;\
8054
};",canvas_root_id,canvas_root_id,canvas_root_id);
8055
    break;
7614 schaersvoo 8056
    case DRAW_TEXTS:
8057
fprintf(js_include_file,"\n<!-- draw text -->\n\
11811 schaersvoo 8058
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,use_offset){\
7614 schaersvoo 8059
  var obj;\
8060
  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8061
   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8062
  }\
8063
  else\
8064
  {\
8065
   obj = create_canvas%d(canvas_type,xsize,ysize);\
8066
  };\
8067
  var ctx = obj.getContext(\"2d\");\
9868 schaersvoo 8068
  if( font_family != 'null' ){\
8069
   ctx.font = font_family;\
8070
  }\
8071
  else\
8072
  {\
8073
   ctx.font = font_size+'px Ariel';\
8074
  };\
11811 schaersvoo 8075
  if( use_offset == 3 ){\
8076
   y = y + (Math.sin(angle2))*(ctx.measureText(text).width);\
8077
   x = x - (Math.cos(angle2))*(ctx.measureText(text).width);\
8078
  };\
7614 schaersvoo 8079
  if(angle2 == 0 && angle != 0){\
8080
   ctx.save();\
8071 schaersvoo 8081
   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
11811 schaersvoo 8082
   if(use_rotate == 1 ){\
8083
   ctx.rotate(angle*Math.PI/180);};\
7614 schaersvoo 8084
  };\
8085
  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8086
  if(angle2 != 0){\
8087
   ctx.save();\
8088
   ctx.translate(x,y);\
8089
   ctx.rotate((360-angle2)*(Math.PI / 180));\
8090
   ctx.fillText(text,0,0);\
8091
   ctx.restore();\
8092
  }else{ctx.fillText(text,x,y);};\
8093
 ctx.restore();\
8094
 return;\
7653 schaersvoo 8095
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8096
    break;
8097
    case DRAW_CURVE:
8098
fprintf(js_include_file,"\n<!-- draw curve -->\n\
8105 schaersvoo 8099
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 8100
 var obj;\
8101
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8102
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8103
 }\
8104
 else\
8105
 {\
8106
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8107
 };\
8108
 var ctx = obj.getContext(\"2d\");\
8109
 ctx.save();\
8071 schaersvoo 8110
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 8111
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
8112
 ctx.beginPath();ctx.lineWidth = line_width;\
11088 schaersvoo 8113
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8114
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
8115
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8116
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
8117
 for(var p = 1 ; p < x_points.length ; p++){\
8118
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
8119
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
8120
  }\
8121
  else\
8122
  {\
8123
   ctx.stroke();\
8124
   ctx.beginPath();\
8125
   p++;\
8126
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
8127
  };\
8128
 };\
8129
 ctx.stroke();\
8130
 ctx.restore();\
7653 schaersvoo 8131
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8132
    break;
8224 bpr 8133
 
7614 schaersvoo 8134
    case DRAW_INPUTS:
8135
fprintf(js_include_file,"\n<!-- draw input fields -->\n\
11803 schaersvoo 8136
var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
7614 schaersvoo 8137
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
8138
var input = document.createElement(\"input\");\
8139
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
8140
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
8141
input.setAttribute(\"size\",size);\
8142
input.setAttribute(\"value\",value);\
7877 schaersvoo 8143
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
11803 schaersvoo 8144
canvas_div.appendChild(input);\
8145
if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
8146
};\
8147
function center_input(id,x,y,style){\
8148
 var inp = document.getElementById(id);\
8149
 var pos = inp.getBoundingClientRect();\
8150
 var center_x = parseInt(x - 0.5*(pos.width));\
8151
 var center_y = parseInt(y - 0.5*(pos.height));\
8152
 try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
8153
 catch(e){return;};\
8154
};");
7614 schaersvoo 8155
    break;
8224 bpr 8156
 
7614 schaersvoo 8157
    case DRAW_TEXTAREAS:
8158
fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
8105 schaersvoo 8159
var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
7614 schaersvoo 8160
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
8161
var textarea = document.createElement(\"textarea\");\
8162
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
8163
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
8164
textarea.setAttribute(\"cols\",cols);\
8165
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 8166
textarea.value = value;\
8167
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 8168
canvas_div.appendChild(textarea);};");
7614 schaersvoo 8169
    break;
8224 bpr 8170
 
7614 schaersvoo 8171
case DRAW_PIXELS:
8172
fprintf(js_include_file,"\n<!-- draw pixel -->\n\
8105 schaersvoo 8173
var draw_setpixel = function(x,y,color,opacity,pixelsize){\
7614 schaersvoo 8174
 var canvas = create_canvas%d(10,xsize,ysize);\
8175
 var d = 0.5*pixelsize;\
8176
 var ctx = canvas.getContext(\"2d\");\
9462 schaersvoo 8177
 if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
7614 schaersvoo 8178
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
8179
 ctx.clearRect(0,0,xsize,ysize);\
8180
 for(var p=0; p<x.length;p++){\
8181
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
8182
 };\
8183
 ctx.fill();ctx.stroke();\
8184
};",canvas_root_id);
8185
break;
8186
 
8187
case DRAW_CLOCK:
8188
fprintf(js_include_file,"\n<!-- begin command clock -->\n\
8189
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
8190
var clock_ctx = clock_canvas.getContext(\"2d\");\
8191
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
8130 schaersvoo 8192
 clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
7614 schaersvoo 8193
 clock_ctx.save();\
7997 schaersvoo 8194
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 8195
 this.type = type || 0;\
8196
 this.interaction = interaction || 0;\
7862 schaersvoo 8197
 this.H = H;\
8198
 this.M = M;\
8199
 this.S = S;\
7614 schaersvoo 8200
 this.xc = xc || xsize/2;\
8201
 this.yc = yc || ysize/2;\
8202
 this.radius = radius || xsize/4;\
8203
 var font_size = parseInt(0.2*this.radius);\
8204
 this.H_color = h_color || \"blue\";\
8205
 this.M_color = m_color || \"blue\";\
8206
 this.S_color = s_color || \"blue\";\
8207
 this.fg_color = fg_color || \"red\";\
8208
 this.bg_color = bg_color || \"white\";\
8209
 clock_ctx.translate(this.xc,this.yc);\
8210
 clock_ctx.beginPath();\
8211
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
8212
 clock_ctx.fillStyle = this.bg_color;\
8213
 clock_ctx.fill();\
8214
 clock_ctx.closePath();\
8215
 clock_ctx.beginPath();\
8216
 clock_ctx.font = font_size+\"px Arial\";\
8217
 clock_ctx.fillStyle = this.fg_color;\
8218
 clock_ctx.textAlign = \"center\";\
8219
 clock_ctx.textBaseline = 'middle';\
8220
 var angle;var x1,y1,x2,y2;\
8221
 var angle_cos;var angle_sin;\
7997 schaersvoo 8222
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 8223
 switch(type){\
8224
 case 0:clock_ctx.beginPath();\
8225
 for(var p = 1; p <= 12 ; p++){\
8226
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
8227
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
8228
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8229
  clock_ctx.moveTo(x1,y1);\
8230
  clock_ctx.lineTo(x2,y2);\
8231
 };\
8232
 for(var p = 1; p <= 60 ; p++){\
8233
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
8234
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
8235
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8236
  clock_ctx.moveTo(x1,y1);\
8237
  clock_ctx.lineTo(x2,y2);\
8238
 };\
8239
 clock_ctx.closePath();\
8240
 clock_ctx.stroke();\
8241
 break;\
8242
 case 1:\
8243
 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 8244
 case 2:\
8245
 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 8246
 clock_ctx.beginPath();\
8247
 for(var p = 1; p <= 12 ; p++){\
8248
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
8249
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
8250
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8251
  clock_ctx.moveTo(x1,y1);\
8252
  clock_ctx.lineTo(x2,y2);\
8253
 };\
8254
 for(var p = 1; p <= 60 ; p++){\
8255
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
8256
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
8257
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8258
  clock_ctx.moveTo(x1,y1);\
8259
  clock_ctx.lineTo(x2,y2);\
8260
 };\
8261
 clock_ctx.closePath();\
8262
 clock_ctx.stroke();\
8263
 break;\
8264
 };\
8265
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
8266
 clock_ctx.rotate(angle);\
8267
 clock_ctx.beginPath();\
8268
 clock_ctx.moveTo(-3, -2);\
8269
 clock_ctx.lineTo(-3, 2);\
11026 bpr 8270
 clock_ctx.lineTo(this.radius * 0.6, 1);\
8271
 clock_ctx.lineTo(this.radius  * 0.6, -1);\
7614 schaersvoo 8272
 clock_ctx.fillStyle = this.H_color;\
8273
 clock_ctx.fill();\
8274
 clock_ctx.rotate(-angle);\
8275
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
8276
 clock_ctx.rotate(angle);\
8277
 clock_ctx.beginPath();\
8278
 clock_ctx.moveTo(-3, -2);\
8279
 clock_ctx.lineTo(-3, 2);\
8280
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
8281
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
8282
 clock_ctx.fillStyle = this.M_color;\
8283
 clock_ctx.fill();\
8284
 clock_ctx.rotate(-angle);\
8285
 angle = (this.S - 15) * 2 * Math.PI / 60;\
8286
 clock_ctx.rotate(angle);\
8287
 clock_ctx.beginPath();\
8288
 clock_ctx.moveTo(0,0);\
11026 bpr 8289
 clock_ctx.lineTo(this.radius  * 0.9, 1);\
8290
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
7614 schaersvoo 8291
 clock_ctx.strokeStyle = this.S_color;\
8292
 clock_ctx.stroke();\
8293
 clock_ctx.restore();\
7653 schaersvoo 8294
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 8295
break;
8296
 
8297
case DRAW_LATTICE:
8298
fprintf(js_include_file,"\n<!-- draw lattice -->\n\
8105 schaersvoo 8299
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 8300
 var obj;\
8301
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8302
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8303
 }\
8304
 else\
8305
 {\
8306
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8307
 };\
8308
 var ctx = obj.getContext(\"2d\");\
8309
 ctx.save();\
8071 schaersvoo 8310
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 8311
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
8312
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8313
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8314
 var radius = line_width;\
8315
 var x = 0;\
8316
 var y = 0;\
8317
 var x_step_px = xsize/(xmax-xmin);\
8318
 var y_step_px = ysize/(ymax-ymin);\
8319
 var xv1 = dx1*x_step_px;\
8320
 var yv1 = dy1*y_step_px;\
8321
 var xv2 = dx2*x_step_px;\
8322
 var yv2 = dy2*y_step_px;\
8323
 for(var p = 0; p < n1 ;p++){\
8324
  x = p*xv1 + x0;\
8325
  y = p*yv1 + y0;\
8326
  for(var c = 0; c < n2 ; c++){\
8327
   ctx.beginPath();\
8328
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
8329
   ctx.fill();\
8330
   ctx.stroke();\
8331
   ctx.closePath();\
8332
  };\
8333
 };\
8334
 ctx.restore();\
8335
 return;\
7653 schaersvoo 8336
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8337
    break;
7735 schaersvoo 8338
case DRAW_XYLOGSCALE:
8339
fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
8105 schaersvoo 8340
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 8341
 var obj;\
8342
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8343
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8344
 }\
8345
 else\
8346
 {\
8347
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8348
 };\
8349
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 8350
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 8351
 ctx.save();\
7739 schaersvoo 8352
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 8353
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
8354
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
8355
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
8356
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
7739 schaersvoo 8357
 if(use_axis_numbering == 1){\
7956 schaersvoo 8358
  ctx.font = font_family;\
8359
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
8360
  ymarge = parseInt(1.5*font_size);\
8361
  ctx.save();\
8362
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
8363
  ctx.rect(0,0,xmarge,ysize);\
8364
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
8365
  ctx.fill();\
8366
  ctx.restore();\
8367
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 8368
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 8369
  ctx.save();\
8370
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8371
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8372
  corr =  ctx.measureText(xaxislabel).width;\
8373
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
8374
  ctx.restore();\
8375
 };\
11088 schaersvoo 8376
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 8377
  ctx.save();\
8378
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8379
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8380
  corr = ctx.measureText(yaxislabel).width;\
8381
  ctx.translate(xmarge+font_size,corr+font_size);\
8382
  ctx.rotate(-0.5*Math.PI);\
8383
  ctx.fillText(yaxislabel,0,0);\
8384
  ctx.restore();\
8385
 };\
8386
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8387
 ctx.lineWidth = line_width;\
8388
 for(var p = x_min; p <= x_max ; p++){\
8389
  num = Math.pow(xlogbase,p);\
8390
  for(var i = 1 ; i < xlogbase ; i++){\
8391
   x_e = x2px(i*num);\
7735 schaersvoo 8392
   if( i == 1 ){\
7956 schaersvoo 8393
    ctx.lineWidth = line_width;\
8394
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7738 schaersvoo 8395
    if( use_axis_numbering == 1 && p > x_min){\
7956 schaersvoo 8396
      xtxt = xlogbase+'^'+p.toFixed(0);\
8397
      corr = 0.5*(ctx.measureText(xtxt).width);\
8398
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
8399
    };\
7735 schaersvoo 8400
   }else{\
7956 schaersvoo 8401
    ctx.lineWidth = 0.2*line_width;\
8402
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8403
   };\
7738 schaersvoo 8404
   if( x_e >= xmarge ){\
7956 schaersvoo 8405
    ctx.beginPath();\
8406
    ctx.moveTo(x_e,0);\
8407
    ctx.lineTo(x_e,ysize - ymarge);\
8408
    ctx.stroke();\
8409
    ctx.closePath();\
7738 schaersvoo 8410
   };\
7956 schaersvoo 8411
  };\
8412
 };\
8413
 for(var p = y_min; p <= y_max ; p++){\
8414
  num = Math.pow(ylogbase,p);\
8415
  for(var i = 1 ; i < ylogbase ; i++){\
8416
   y_e = y2px(i*num);\
8417
   if( i == 1 ){\
8418
    ctx.lineWidth = line_width;\
7735 schaersvoo 8419
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 8420
    if( use_axis_numbering == 1 && p > y_min){\
8421
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
8422
    };\
8423
   }else{\
8424
    ctx.lineWidth = 0.2*line_width;\
8425
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8426
   };\
8427
   ctx.beginPath();\
8428
   ctx.moveTo(xmarge,y_e);\
8429
   ctx.lineTo(xsize,y_e);\
8430
   ctx.stroke();\
8431
   ctx.closePath();\
8432
  };\
8433
 };\
7735 schaersvoo 8434
 ctx.restore();\
8435
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
8436
    break;
7614 schaersvoo 8437
 
7735 schaersvoo 8438
case DRAW_XLOGSCALE:
8439
fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
8105 schaersvoo 8440
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 8441
 var obj;\
8442
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8443
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8444
 }\
8445
 else\
8446
 {\
8447
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8448
 };\
8449
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 8450
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 8451
 ctx.save();\
8452
 ctx.lineWidth = line_width;\
7739 schaersvoo 8453
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 8454
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
8455
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
8456
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 8457
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
8458
 if(use_axis_numbering == 1){\
7956 schaersvoo 8459
  ctx.font = font_family;\
8460
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
8461
  ymarge = parseInt(1.5*font_size);\
8462
  ctx.save();\
8463
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
8464
  ctx.rect(0,0,xmarge,ysize);\
8465
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
8466
  ctx.fill();\
8467
  ctx.restore();\
8468
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 8469
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 8470
  ctx.save();\
8471
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8472
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8473
  corr =  ctx.measureText(xaxislabel).width;\
8474
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
8475
  ctx.restore();\
8476
 };\
11088 schaersvoo 8477
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 8478
  ctx.save();\
8479
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8480
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8481
  corr = ctx.measureText(yaxislabel).width;\
8482
  ctx.translate(xmarge+font_size,corr+font_size);\
8483
  ctx.rotate(-0.5*Math.PI);\
8484
  ctx.fillText(yaxislabel,0,0);\
8485
  ctx.restore();\
8486
 };\
8487
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8488
 ctx.lineWidth = line_width;\
8489
 for(var p = x_min; p <= x_max ; p++){\
8490
  num = Math.pow(xlogbase,p);\
8491
  for(var i = 1 ; i < xlogbase ; i++){\
8492
   x_e = x2px(i*num);\
7735 schaersvoo 8493
   if( i == 1 ){\
7956 schaersvoo 8494
     ctx.lineWidth = line_width;\
7739 schaersvoo 8495
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
8496
    if( use_axis_numbering == 1 && p > x_min ){\
7735 schaersvoo 8497
      xtxt = xlogbase+'^'+p.toFixed(0);\
8498
      corr = 0.5*(ctx.measureText(xtxt).width);\
8499
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
8500
    };\
8501
   }else{\
7956 schaersvoo 8502
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 8503
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8504
   };\
7739 schaersvoo 8505
   if( x_e >= xmarge ){\
7956 schaersvoo 8506
    ctx.beginPath();\
8507
    ctx.moveTo(x_e,0);\
8508
    ctx.lineTo(x_e,ysize - ymarge);\
8509
    ctx.stroke();\
8510
    ctx.closePath();\
7739 schaersvoo 8511
   };\
8512
  };\
7956 schaersvoo 8513
 };\
7735 schaersvoo 8514
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
8515
 var minor_step = stepy / yminor;\
7749 schaersvoo 8516
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 8517
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 8518
  ctx.lineWidth = line_width;\
8519
  ctx.beginPath();\
8520
  ctx.moveTo(xmarge,y);\
8521
  ctx.lineTo(xsize,y);\
8522
  ctx.stroke();\
8523
  ctx.closePath();\
7735 schaersvoo 8524
  if( use_axis_numbering == 1){\
8525
   ytxt = (px2y(y)).toFixed(prec);\
8526
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
8527
  };\
8528
  for(var dy = 1 ; dy < yminor ; dy++){\
8529
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 8530
   ctx.lineWidth = 0.2*line_width;\
8531
   ctx.beginPath();\
7739 schaersvoo 8532
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 8533
   ctx.lineTo(xsize,y+dy*minor_step);\
8534
   ctx.stroke();\
8535
   ctx.closePath();\
7735 schaersvoo 8536
  };\
8537
 };\
7956 schaersvoo 8538
 ctx.restore();\
8539
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 8540
    break;
7729 schaersvoo 8541
case DRAW_YLOGSCALE:
8542
fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
8105 schaersvoo 8543
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 8544
 var obj;\
8545
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8546
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8547
 }\
8548
 else\
8549
 {\
8550
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8551
 };\
8552
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 8553
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 8554
 ctx.save();\
8555
 ctx.lineWidth = line_width;\
7735 schaersvoo 8556
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
8557
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
8109 schaersvoo 8558
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
7739 schaersvoo 8559
 if(use_axis_numbering == 1){\
7956 schaersvoo 8560
  ctx.font = font_family;\
8561
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
8562
  ymarge = 2*font_size;\
8563
  ctx.save();\
8564
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
8565
  ctx.rect(0,0,xmarge,ysize);\
8566
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
8567
  ctx.fill();\
8568
  ctx.restore();\
8569
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 8570
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 8571
  ctx.save();\
8572
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8573
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8574
  corr =  ctx.measureText(xaxislabel).width;\
8575
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
8576
  ctx.restore();\
8577
 };\
11088 schaersvoo 8578
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 8579
  ctx.save();\
8580
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8581
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8582
  corr = ctx.measureText(yaxislabel).width;\
8583
  ctx.translate(xmarge+font_size,corr+font_size);\
8584
  ctx.rotate(-0.5*Math.PI);\
8585
  ctx.fillText(yaxislabel,0,0);\
8586
  ctx.restore();\
8587
 };\
8588
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8589
 ctx.lineWidth = line_width;\
8590
 for(var p = y_min; p <= y_max ; p++){\
8591
  num = Math.pow(ylogbase,p);\
8592
  for(var i = 1 ; i < ylogbase ; i++){\
8593
   y_e = y2px(i*num);\
7729 schaersvoo 8594
   if( i == 1 ){\
7956 schaersvoo 8595
    ctx.lineWidth = line_width;\
7729 schaersvoo 8596
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7739 schaersvoo 8597
    if( use_axis_numbering == 1 && p > y_min){\
7735 schaersvoo 8598
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 8599
    };\
8600
   }else{\
7956 schaersvoo 8601
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 8602
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8603
   };\
7956 schaersvoo 8604
   ctx.beginPath();\
8605
   ctx.moveTo(xmarge,y_e);\
8606
   ctx.lineTo(xsize,y_e);\
8607
   ctx.stroke();\
8608
   ctx.closePath();\
8609
  };\
8610
 };\
7729 schaersvoo 8611
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
8612
 var minor_step = stepx / xminor;\
8613
 var prec = Math.log(precision)/Math.log(10);\
8614
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 8615
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 8616
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 8617
  ctx.lineWidth = line_width;\
8618
  ctx.beginPath();\
8619
  ctx.moveTo(x,ysize-ymarge);\
8620
  ctx.lineTo(x,0);\
8621
  ctx.stroke();\
8622
  ctx.closePath();\
7729 schaersvoo 8623
  if( use_axis_numbering == 1){\
8624
   xtxt = (px2x(x)).toFixed(prec);\
8625
   corr = 0.5*(ctx.measureText(xtxt).width);\
8626
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
8627
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
8628
  };\
8629
  for(var dx = 1 ; dx < xminor ; dx++){\
8630
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 8631
   ctx.lineWidth = 0.2*line_width;\
8632
   ctx.beginPath();\
7739 schaersvoo 8633
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 8634
   ctx.lineTo(x+dx*minor_step,0);\
8635
   ctx.stroke();\
8636
   ctx.closePath();\
7735 schaersvoo 8637
  };\
8638
 };\
7956 schaersvoo 8639
 ctx.restore();\
8640
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 8641
    break;
9213 schaersvoo 8642
 
7614 schaersvoo 8643
    default:break;
8644
   }
8645
  }
8646
 }
8647
  return;
8648
}
8649
 
8650
void check_string_length(int L){
9466 schaersvoo 8651
 if( L > MAX_BUFFER-1){
7614 schaersvoo 8652
  canvas_error("problem with your arguments to command...");
8653
 }
8654
 return;
8655
}
8656
 
8657
 
8658
int get_token(FILE *infile){
8659
        int     c,i=0;
8660
        char    temp[MAX_INT], *input_type;
8661
        char    *line="line",
8662
        *audio="audio",
8663
        *blink="blink",
8664
        *arrowhead="arrowhead",
8665
        *crosshairsize="crosshairsize",
8666
        *crosshair="crosshair",
8667
        *crosshairs="crosshairs",
8668
        *audioobject="audioobject",
8669
        *style="style",
8670
        *mouse="mouse",
7991 schaersvoo 8671
        *mousex="mousex",
8672
        *mousey="mousey",
8071 schaersvoo 8673
        *mouse_display="display",
8674
        *mouse_degree="mouse_degree",
7614 schaersvoo 8675
        *userdraw="userdraw",
8676
        *highlight="highlight",
8677
        *http="http",
8678
        *rays="rays",
8679
        *dashtype="dashtype",
8680
        *dashed="dashed",
8681
        *filled="filled",
8682
        *lattice="lattice",
8683
        *parallel="parallel",
8684
        *segment="segment",
8299 schaersvoo 8685
        *segments="segments",
7614 schaersvoo 8686
        *dsegment="dsegment",
9374 schaersvoo 8687
        *dsegments="dsegments",
7614 schaersvoo 8688
        *seg="seg",
9383 schaersvoo 8689
        *segs="segs",
7614 schaersvoo 8690
        *bgimage="bgimage",
8691
        *bgcolor="bgcolor",
8692
        *strokecolor="strokecolor",
8693
        *backgroundimage="backgroundimage",
8694
        *text="text",
8695
        *textup="textup",
8696
        *mouseprecision="mouseprecision",
8697
        *precision="precision",
8698
        *plotsteps="plotsteps",
8699
        *plotstep="plotstep",
8700
        *tsteps="tsteps",
8701
        *curve="curve",
8702
        *dcurve="dcurve",
8703
        *plot="plot",
8704
        *dplot="dplot",
7788 schaersvoo 8705
        *levelcurve="levelcurve",
7614 schaersvoo 8706
        *fontsize="fontsize",
8707
        *fontcolor="fontcolor",
8708
        *axis="axis",
8709
        *axisnumbering="axisnumbering",
8710
        *axisnumbers="axisnumbers",
8711
        *arrow="arrow",
9382 schaersvoo 8712
        *vector="vector",
8713
        *vectors="vectors",
7614 schaersvoo 8714
        *darrow="darrow",
8715
        *arrow2="arrow2",
8716
        *darrow2="darrow2",
8304 schaersvoo 8717
        *arrows="arrows",
8347 schaersvoo 8718
        *arrows2="arrows2",
7614 schaersvoo 8719
        *zoom="zoom",
8720
        *grid="grid",
8721
        *hline="hline",
7786 schaersvoo 8722
        *dhline="dhline",
7614 schaersvoo 8723
        *drag="drag",
8724
        *horizontalline="horizontalline",
9383 schaersvoo 8725
        *horizontallines="horizontallines",
7614 schaersvoo 8726
        *vline="vline",
7786 schaersvoo 8727
        *dvline="dvline",
7614 schaersvoo 8728
        *verticalline="verticalline",
9383 schaersvoo 8729
        *verticallines="verticallines",
7614 schaersvoo 8730
        *triangle="triangle",
9306 schaersvoo 8731
        *triangles="triangles",
7614 schaersvoo 8732
        *ftriangle="ftriangle",
9374 schaersvoo 8733
        *ftriangles="ftriangles",
7614 schaersvoo 8734
        *mathml="mathml",
8735
        *html="html",
8736
        *input="input",
8146 schaersvoo 8737
        *clearbutton="clearbutton",
9386 schaersvoo 8738
        *erase="erase",
8739
        *delete="delete",
7614 schaersvoo 8740
        *inputstyle="inputstyle",
8741
        *textarea="textarea",
8742
        *trange="trange",
8743
        *ranget="ranget",
8744
        *xrange="xrange",
8745
        *yrange="yrange",
8746
        *rangex="rangex",
8747
        *rangey="rangey",
8370 schaersvoo 8748
        *path="path",
7614 schaersvoo 8749
        *polyline="polyline",
8351 schaersvoo 8750
        *brokenline="brokenline",
7614 schaersvoo 8751
        *lines="lines",
8752
        *poly="poly",
8753
        *polygon="polygon",
8754
        *fpolygon="fpolygon",
8755
        *fpoly="fpoly",
8756
        *filledpoly="filledpoly",
8757
        *filledpolygon="filledpolygon",
8758
        *rect="rect",
8759
        *frect="frect",
8760
        *rectangle="rectangle",
8761
        *frectangle="frectangle",
8762
        *square="square",
8763
        *fsquare="fsquare",
9374 schaersvoo 8764
        *fsquares="fsquares",
8363 schaersvoo 8765
        *rects="rects",
8766
        *frects="frects",
7614 schaersvoo 8767
        *dline="dline",
8768
        *arc="arc",
8769
        *filledarc="filledarc",
9374 schaersvoo 8770
        *farc="farc",
7614 schaersvoo 8771
        *size="size",
8772
        *string="string",
8773
        *stringup="stringup",
8774
        *copy="copy",
8775
        *copyresized="copyresized",
8776
        *opacity="opacity",
8777
        *transparent="transparent",
8778
        *fill="fill",
8779
        *point="point",
8780
        *points="points",
8781
        *linewidth="linewidth",
8782
        *circle="circle",
8304 schaersvoo 8783
        *circles="circles",
7614 schaersvoo 8784
        *fcircle="fcircle",
9374 schaersvoo 8785
        *fcircles="fcircles",
7614 schaersvoo 8786
        *disk="disk",
9374 schaersvoo 8787
        *disks="disks",
7614 schaersvoo 8788
        *comment="#",
8789
        *end="end",
8790
        *ellipse="ellipse",
8791
        *fellipse="fellipse",
8792
        *rotate="rotate",
7785 schaersvoo 8793
        *affine="affine",
9907 schaersvoo 8794
        *rotationcenter="rotationcenter",
8795
        *killrotate="killrotate",
7785 schaersvoo 8796
        *killaffine="killaffine",
7614 schaersvoo 8797
        *fontfamily="fontfamily",
8798
        *fillcolor="fillcolor",
8799
        *clicktile="clicktile",
8800
        *clicktile_colors="clicktile_colors",
8801
        *translation="translation",
8802
        *translate="translate",
8803
        *killtranslation="killtranslation",
8804
        *killtranslate="killtranslate",
8805
        *onclick="onclick",
8370 schaersvoo 8806
        *roundrects="roundrects",
7614 schaersvoo 8807
        *roundrect="roundrect",
8808
        *froundrect="froundrect",
9374 schaersvoo 8809
        *froundrects="froundrects",
7614 schaersvoo 8810
        *roundrectangle="roundrectangle",
8811
        *patternfill="patternfill",
8812
        *hatchfill="hatchfill",
8813
        *diafill="diafill",
7647 schaersvoo 8814
        *diamondfill="diamondfill",
7614 schaersvoo 8815
        *dotfill="dotfill",
8816
        *gridfill="gridfill",
8817
        *imagefill="imagefill",
7735 schaersvoo 8818
        *xlogbase="xlogbase",
8819
        *ylogbase="ylogbase",
7614 schaersvoo 8820
        *xlogscale="xlogscale",
8821
        *ylogscale="ylogscale",
8822
        *xylogscale="xylogscale",
8823
        *intooltip="intooltip",
9329 schaersvoo 8824
        *popup="popup",
7614 schaersvoo 8825
        *replyformat="replyformat",
8826
        *floodfill="floodfill",
11772 schaersvoo 8827
        *fillall="fillall",
7614 schaersvoo 8828
        *filltoborder="filltoborder",
8829
        *setpixel="setpixel",
8830
        *pixels="pixels",
8831
        *pixelsize="pixelsize",
8832
        *xaxis="xaxis",
9341 schaersvoo 8833
        *xaxisup="xaxisup",
7614 schaersvoo 8834
        *yaxis="yaxis",
8835
        *xaxistext="xaxistext",
9341 schaersvoo 8836
        *xaxistextup="xaxistextup",
7614 schaersvoo 8837
        *yaxistext="yaxistext",
8838
        *piechart="piechart",
9433 schaersvoo 8839
        *boxplot="boxplot",
9465 schaersvoo 8840
        *boxplotdata="boxplotdata",
8841
        *userboxplot="userboxplot",
8842
        *userboxplotdata="userboxplotdata",
7614 schaersvoo 8843
        *legend="legend",
8844
        *legendcolors="legendcolors",
8845
        *xlabel="xlabel",
8846
        *ylabel="ylabel",
8847
        *barchart="barchart",
8848
        *linegraph="linegraph",
8849
        *clock="clock",
8850
        *animate="animate",
8851
        *video="video",
8852
        *status="status",
7877 schaersvoo 8853
        *nostatus="nostatus",
7652 schaersvoo 8854
        *snaptogrid="snaptogrid",
7784 schaersvoo 8855
        *xsnaptogrid="xsnaptogrid",
8856
        *ysnaptogrid="ysnaptogrid",
8379 schaersvoo 8857
        *snaptopoints="snaptopoints",
9213 schaersvoo 8858
        *snaptofunction="snaptofunction",
8859
        *snaptofun="snaptofun",
7654 schaersvoo 8860
        *userinput_xy="userinput_xy",
8193 schaersvoo 8861
        *userinput_function="userinput_function",
7663 schaersvoo 8862
        *usertextarea_xy="usertextarea_xy",
8222 schaersvoo 8863
        *userinput="userinput",
7823 schaersvoo 8864
        *jsmath="jsmath",
7858 schaersvoo 8865
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 8866
        *setlimits="setlimits",
7858 schaersvoo 8867
        *jscurve="jscurve",
8868
        *jsplot="jsplot",
7983 schaersvoo 8869
        *sgraph="sgraph",
7984 schaersvoo 8870
        *title="title",
7996 schaersvoo 8871
        *centerstring="centerstring",
8872
        *xunit="xunit",
8071 schaersvoo 8873
        *yunit="yunit",
8101 schaersvoo 8874
        *slider="slider",
8105 schaersvoo 8875
        *killslider="killslider",
8244 schaersvoo 8876
        *angle="angle",
8365 schaersvoo 8877
        *halflines="halflines",
8878
        *demilines="demilines",
8244 schaersvoo 8879
        *halfline="halfline",
8297 schaersvoo 8880
        *demiline="demiline",
8366 schaersvoo 8881
        *hlines="hlines",
8882
        *vlines="vlines",
8370 schaersvoo 8883
        *bezier="bezier",
9213 schaersvoo 8884
        *functionlabel="functionlabel",
8885
        *sliderfunction_x="sliderfunction_x",
8886
        *sliderfunction_y="sliderfunction_y",
8887
        *multidraw="multidraw",
8888
        *multilinewidth="multilinewidth",
8889
        *multistrokecolors="multistrokecolors",
8890
        *multifillcolors="multifillcolors",
8891
        *multistrokeopacity="multistrokeopacity",
8892
        *multifillopacity="multifillopacity",
8893
        *multifill="multifill",
8894
        *multidash="multidash",
8895
        *multilabel="multilabel",
8896
        *multiuserinput="multiuserinput",
9289 schaersvoo 8897
        *multisnaptogrid="multisnaptogrid",
8898
        *protractor="protractor",
9386 schaersvoo 8899
        *ruler="ruler",
8900
        *cursor="cursor",
9427 schaersvoo 8901
        *pointer="pointer",
8902
        *yerrorbars="yerrorbars",
11006 schaersvoo 8903
        *xerrorbars="xerrorbars",
11044 schaersvoo 8904
        *noxaxis="noxaxis",
8905
        *noyaxis="noyaxis",
11767 schaersvoo 8906
        *colorpalette="colorpalette",
11802 schaersvoo 8907
        *xoffset="xoffset",
8908
        *centered="centered",
8909
        *xyoffset="xyoffset",
11811 schaersvoo 8910
        *yoffset="yoffset",
11802 schaersvoo 8911
        *resetoffset="resetoffset",
11006 schaersvoo 8912
        *canvastype="canvastype";
7614 schaersvoo 8913
 
10891 schaersvoo 8914
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
8915
         if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
8916
         }else{
8917
          if( c == ' ' ){
7614 schaersvoo 8918
            break;
10891 schaersvoo 8919
          }else{
8920
           temp[i] = c;
8921
           if(i > MAX_INT - 2){canvas_error("command string too long !");}
8922
           i++;
8923
          }
8924
         }
8925
         if(temp[0] == '#'){ break; }
7614 schaersvoo 8926
        }
10891 schaersvoo 8927
        if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
8928
        if (c == EOF) {finished=1;return 0;}
7614 schaersvoo 8929
 
8930
        temp[i]='\0';
8931
        input_type=(char*)my_newmem(strlen(temp));
8932
        snprintf(input_type,sizeof(temp),"%s",temp);
10891 schaersvoo 8933
/* fprintf(stdout,"temp = %s <br/>",input_type); */
7614 schaersvoo 8934
        if( strcmp(input_type, size) == 0 ){
8935
        free(input_type);
8936
        return SIZE;
8937
        }
8938
        if( strcmp(input_type, xrange) == 0 ){
8939
        free(input_type);
8940
        return XRANGE;
8941
        }
8942
        if( strcmp(input_type, rangex) == 0 ){
8943
        free(input_type);
8944
        return XRANGE;
8945
        }
8946
        if( strcmp(input_type, trange) == 0 ){
8947
        free(input_type);
8948
        return TRANGE;
8949
        }
8950
        if( strcmp(input_type, ranget) == 0 ){
8951
        free(input_type);
8952
        return TRANGE;
8953
        }
8954
        if( strcmp(input_type, yrange) == 0 ){
8955
        free(input_type);
8956
        return YRANGE;
8957
        }
8958
        if( strcmp(input_type, rangey) == 0 ){
8959
        free(input_type);
8960
        return YRANGE;
8961
        }
8962
        if( strcmp(input_type, linewidth) == 0 ){
8963
        free(input_type);
8964
        return LINEWIDTH;
8965
        }
8966
        if( strcmp(input_type, dashed) == 0 ){
8967
        free(input_type);
8968
        return DASHED;
8969
        }
8970
        if( strcmp(input_type, dashtype) == 0 ){
8971
        free(input_type);
8972
        return DASHTYPE;
8973
        }
8974
        if( strcmp(input_type, axisnumbering) == 0 ){
8975
        free(input_type);
8976
        return AXIS_NUMBERING;
8977
        }
8978
        if( strcmp(input_type, axisnumbers) == 0 ){
8979
        free(input_type);
8980
        return AXIS_NUMBERING;
8981
        }
8982
        if( strcmp(input_type, axis) == 0 ){
8983
        free(input_type);
8984
        return AXIS;
8985
        }
8986
        if( strcmp(input_type, grid) == 0 ){
8987
        free(input_type);
8988
        return GRID;
8989
        }
9383 schaersvoo 8990
        if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
8366 schaersvoo 8991
        free(input_type);
8992
        return HLINES;
8993
        }
9383 schaersvoo 8994
        if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
8366 schaersvoo 8995
        free(input_type);
8996
        return VLINES;
8997
        }
9383 schaersvoo 8998
        if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
7614 schaersvoo 8999
        free(input_type);
9000
        return HLINE;
9001
        }
9002
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
9003
        free(input_type);
9004
        return VLINE;
9005
        }
9006
        if( strcmp(input_type, line) == 0 ){
9007
        free(input_type);
9008
        return LINE;
9009
        }
9383 schaersvoo 9010
        if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
8299 schaersvoo 9011
        free(input_type);
9012
        return SEGMENTS;
9013
        }
7614 schaersvoo 9014
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
9015
        free(input_type);
9016
        return SEGMENT;
9017
        }
9374 schaersvoo 9018
        if( strcmp(input_type, dsegments) == 0 ){
9019
        free(input_type);
9020
        use_dashed = TRUE;
9021
        return SEGMENTS;
9022
        }
7614 schaersvoo 9023
        if( strcmp(input_type, dsegment) == 0 ){
9024
        free(input_type);
9025
        use_dashed = TRUE;
9026
        return SEGMENT;
9027
        }
9028
        if( strcmp(input_type, crosshairsize) == 0 ){
9029
        free(input_type);
9030
        return CROSSHAIRSIZE;
9031
        }
9032
        if( strcmp(input_type, arrowhead) == 0 ){
9033
        free(input_type);
9034
        return ARROWHEAD;
9035
        }
9036
        if( strcmp(input_type, crosshairs) == 0 ){
9037
        free(input_type);
9038
        return CROSSHAIRS;
9039
        }
9040
        if( strcmp(input_type, crosshair) == 0 ){
9041
        free(input_type);
9042
        return CROSSHAIR;
9043
        }
9044
        if( strcmp(input_type, onclick) == 0 ){
9045
        free(input_type);
9046
        return ONCLICK;
9047
        }
9048
        if( strcmp(input_type, drag) == 0 ){
9049
        free(input_type);
9050
        return DRAG;
9051
        }
9052
        if( strcmp(input_type, userdraw) == 0 ){
9053
        free(input_type);
9054
        return USERDRAW;
9055
        }
9056
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
9057
        free(input_type);
9058
        return STYLE;
9059
        }
9060
        if( strcmp(input_type, fillcolor) == 0 ){
9061
        free(input_type);
9062
        return FILLCOLOR;
9063
        }
9064
        if( strcmp(input_type, strokecolor) == 0 ){
9065
        free(input_type);
9066
        return STROKECOLOR;
9067
        }
9068
        if( strcmp(input_type, filled) == 0  ){
9069
        free(input_type);
9070
        return FILLED;
9071
        }
9072
        if( strcmp(input_type, http) == 0 ){
9073
        free(input_type);
9074
        return HTTP;
9075
        }
9076
        if( strcmp(input_type, rays) == 0 ){
9077
        free(input_type);
9078
        return RAYS;
9079
        }
9080
        if( strcmp(input_type, lattice) == 0 ){
9081
        free(input_type);
9082
        return LATTICE;
9083
        }
9084
        if( strcmp(input_type, bgimage) == 0 ){
9085
        free(input_type);
9086
        return BGIMAGE;
9087
        }
9088
        if( strcmp(input_type, bgcolor) == 0 ){
9089
        free(input_type);
9090
        return BGCOLOR;
9091
        }
9092
        if( strcmp(input_type, backgroundimage) == 0 ){
9093
        free(input_type);
9094
        return BGIMAGE;
9095
        }
9096
        if( strcmp(input_type, text) == 0 ){
9097
        free(input_type);
9098
        return FLY_TEXT;
9099
        }
9100
        if( strcmp(input_type, textup) == 0 ){
9101
        free(input_type);
9102
        return FLY_TEXTUP;
9103
        }
9104
        if( strcmp(input_type, mouse) == 0 ){
9105
        free(input_type);
9106
        return MOUSE;
9107
        }
7991 schaersvoo 9108
        if( strcmp(input_type, mousex) == 0 ){
9109
        free(input_type);
9110
        return MOUSEX;
9111
        }
9112
        if( strcmp(input_type, mousey) == 0 ){
9113
        free(input_type);
9114
        return MOUSEY;
9115
        }
8071 schaersvoo 9116
        if( strcmp(input_type, mouse_degree) == 0 ){
9117
        free(input_type);
9118
        return MOUSE_DEGREE;
9119
        }
9120
        if( strcmp(input_type, mouse_display) == 0 ){
9121
        free(input_type);
9122
        return MOUSE_DISPLAY;
9123
        }
7614 schaersvoo 9124
        if( strcmp(input_type, mouseprecision) == 0 ){
9125
        free(input_type);
9126
        return MOUSE_PRECISION;
9127
        }
9128
        if( strcmp(input_type, precision) == 0 ){
9129
        free(input_type);
9130
        return MOUSE_PRECISION;
9131
        }
9132
        if( strcmp(input_type, curve) == 0 ){
9133
        free(input_type);
9134
        return CURVE;
9135
        }
9136
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 9137
        use_dashed = TRUE;
7614 schaersvoo 9138
        free(input_type);
9139
        return CURVE;
9140
        }
9141
        if( strcmp(input_type, plot) == 0 ){
9142
        free(input_type);
9143
        return CURVE;
9144
        }
9145
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 9146
        use_dashed = TRUE;
7614 schaersvoo 9147
        free(input_type);
9148
        return CURVE;
9149
        }
7788 schaersvoo 9150
        if( strcmp(input_type, levelcurve) == 0 ){
9151
        free(input_type);
9152
        return LEVELCURVE;
9153
        }
7614 schaersvoo 9154
        if( strcmp(input_type, plotsteps) == 0 ){
9155
        free(input_type);
9156
        return PLOTSTEPS;
9157
        }
9158
        if( strcmp(input_type, plotstep) == 0 ){
9159
        free(input_type);
9160
        return PLOTSTEPS;
9161
        }
9162
        if( strcmp(input_type, tsteps) == 0 ){
9163
        free(input_type);
9164
        return PLOTSTEPS;
9165
        }
9166
        if( strcmp(input_type, fontsize) == 0 ){
9167
        free(input_type);
9168
        return FONTSIZE;
9169
        }
9170
        if( strcmp(input_type, fontcolor) == 0 ){
9171
        free(input_type);
9172
        return FONTCOLOR;
9173
        }
9174
        if( strcmp(input_type, arrow2) == 0 ){
9175
        free(input_type);
9176
        return ARROW2;
9177
        }
9178
        if( strcmp(input_type, darrow) == 0 ){
9179
        free(input_type);
8071 schaersvoo 9180
        use_dashed = TRUE;
7614 schaersvoo 9181
        return ARROW;
9182
        }
9183
        if( strcmp(input_type, darrow2) == 0 ){
9184
        free(input_type);
9185
        use_dashed = TRUE;
9186
        return ARROW2;
9187
        }
8347 schaersvoo 9188
        if( strcmp(input_type, arrows2) == 0 ){
9189
        free(input_type);
9190
        return ARROWS2;
9191
        }
9382 schaersvoo 9192
        if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
8304 schaersvoo 9193
        free(input_type);
9194
        return ARROWS;
9195
        }
9382 schaersvoo 9196
        if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
8304 schaersvoo 9197
        free(input_type);
9198
        return ARROW;
9199
        }
7614 schaersvoo 9200
        if( strcmp(input_type, zoom) == 0 ){
9201
        free(input_type);
9202
        return ZOOM;
9203
        }
9204
        if( strcmp(input_type, triangle) == 0 ){
9205
        free(input_type);
9206
        return TRIANGLE;
9207
        }
9306 schaersvoo 9208
        if( strcmp(input_type, triangles) == 0 ){
9209
        free(input_type);
9210
        return TRIANGLES;
9211
        }
9374 schaersvoo 9212
        if( strcmp(input_type, ftriangles) == 0 ){
9213
        free(input_type);
9214
        use_filled = TRUE;
9215
        return TRIANGLES;
9216
        }
7614 schaersvoo 9217
        if( strcmp(input_type, ftriangle) == 0 ){
9218
        free(input_type);
9219
        use_filled = TRUE;
9220
        return TRIANGLE;
9221
        }
9222
        if( strcmp(input_type, input) == 0 ){
9223
        free(input_type);
9224
        return INPUT;
9225
        }
9226
        if( strcmp(input_type, inputstyle) == 0 ){
9227
        free(input_type);
9228
        return INPUTSTYLE;
9229
        }
9230
        if( strcmp(input_type, textarea) == 0 ){
9231
        free(input_type);
9232
        return TEXTAREA;
9233
        }
9234
        if( strcmp(input_type, mathml) == 0 ){
9235
        free(input_type);
9236
        return MATHML;
9237
        }
9238
        if( strcmp(input_type, html) == 0 ){
9239
        free(input_type);
9240
        return MATHML;
9241
        }
9242
        if( strcmp(input_type, fontfamily) == 0 ){
9243
        free(input_type);
9244
        return FONTFAMILY;
9245
        }
10975 schaersvoo 9246
        if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
7614 schaersvoo 9247
        free(input_type);
9248
        return POLYLINE;
9249
        }
8351 schaersvoo 9250
        if( strcmp(input_type, lines) == 0 ){
9251
        free(input_type);
9252
        return LINES;
9253
        }
9374 schaersvoo 9254
        if( strcmp(input_type, rects) == 0){
8363 schaersvoo 9255
        free(input_type);
9256
        return RECTS;
9257
        }
9383 schaersvoo 9258
        if( strcmp(input_type, frects) == 0 ){
8363 schaersvoo 9259
        free(input_type);
9374 schaersvoo 9260
        use_filled = TRUE;
8363 schaersvoo 9261
        return RECTS;
9262
        }
7614 schaersvoo 9263
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
9264
        free(input_type);
9265
        return RECT;
9266
        }
9374 schaersvoo 9267
        if( strcmp(input_type, square) == 0 ){
9268
        free(input_type);
9269
        return RECT;
9270
        }
9271
        if( strcmp(input_type, fsquare) == 0 ){
9272
        free(input_type);
9273
        use_filled = TRUE;
9274
        return SQUARE;
9275
        }
9276
        if( strcmp(input_type, fsquares) == 0 ){
9277
        free(input_type);
9278
        use_filled = TRUE;
9279
        return RECTS;
9280
        }
8370 schaersvoo 9281
        if( strcmp(input_type, roundrects) == 0 ){
9282
        free(input_type);
9283
        return ROUNDRECTS;
9284
        }
7614 schaersvoo 9285
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
9286
        free(input_type);
9287
        return ROUNDRECT;
9288
        }
9374 schaersvoo 9289
        if( strcmp(input_type, froundrects) == 0 ){
7614 schaersvoo 9290
        free(input_type);
9291
        use_filled = TRUE;
9374 schaersvoo 9292
        return ROUNDRECTS;
7614 schaersvoo 9293
        }
9374 schaersvoo 9294
        if( strcmp(input_type, froundrect) == 0 ){
7614 schaersvoo 9295
        free(input_type);
9296
        use_filled = TRUE;
9374 schaersvoo 9297
        return ROUNDRECT;
7614 schaersvoo 9298
        }
9299
        if( strcmp(input_type, dline) == 0 ){
9300
        use_dashed = TRUE;
9301
        free(input_type);
9302
        return LINE;
9303
        }
7786 schaersvoo 9304
        if( strcmp(input_type, dvline) == 0 ){
9305
        use_dashed = TRUE;
9306
        free(input_type);
9307
        return VLINE;
9308
        }
9309
        if( strcmp(input_type, dhline) == 0 ){
9310
        use_dashed = TRUE;
9311
        free(input_type);
9312
        return HLINE;
9313
        }
9386 schaersvoo 9314
        if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
9315
        free(input_type);
9316
        return HALFLINES;
9317
        }
9318
        if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
9319
        free(input_type);
9320
        return HALFLINE;
9321
        }
7614 schaersvoo 9322
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
9323
        use_filled = TRUE;
9324
        free(input_type);
9325
        return RECT;
9326
        }
8304 schaersvoo 9327
        if( strcmp(input_type, circles) == 0 ){
9328
        free(input_type);
9329
        return CIRCLES;
9330
        }
7614 schaersvoo 9331
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
9332
        use_filled = TRUE;
9333
        free(input_type);
9334
        return CIRCLE;
9335
        }
9374 schaersvoo 9336
        if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
9337
        use_filled = TRUE;
9338
        free(input_type);
9339
        return CIRCLES;
9340
        }
7614 schaersvoo 9341
        if( strcmp(input_type, circle) == 0 ){
9342
        free(input_type);
9343
        return CIRCLE;
9344
        }
9345
        if( strcmp(input_type, point) == 0 ){
9346
        free(input_type);
9347
        return POINT;
9348
        }
9349
        if( strcmp(input_type, points) == 0 ){
9350
        free(input_type);
9351
        return POINTS;
9352
        }
9374 schaersvoo 9353
        if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
7614 schaersvoo 9354
        use_filled = TRUE;
9355
        free(input_type);
9356
        return ARC;
9357
        }
9358
        if( strcmp(input_type, arc) == 0 ){
9359
        free(input_type);
9360
        return ARC;
9361
        }
9362
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
9363
        free(input_type);
9364
        return POLY;
9365
        }
9366
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
9367
        use_filled = TRUE;
9368
        free(input_type);
9369
        return POLY;
9370
        }
9371
        if( strcmp(input_type, ellipse) == 0){
9372
        free(input_type);
9373
        return ELLIPSE;
9374
        }
9375
        if( strcmp(input_type, string) == 0 ){
9376
        free(input_type);
9377
        return STRING;
9378
        }
9379
        if( strcmp(input_type, stringup) == 0 ){
9380
        free(input_type);
9381
        return STRINGUP;
9382
        }
9385 schaersvoo 9383
        if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
7614 schaersvoo 9384
        free(input_type);
9385
        return OPACITY;
9386
        }
9387
        if( strcmp(input_type, comment) == 0){
9388
        free(input_type);
9389
        return COMMENT;
9390
        }
9391
        if( strcmp(input_type, fellipse) == 0){
9392
        free(input_type);
9393
        use_filled = TRUE;
9394
        return ELLIPSE;
8224 bpr 9395
        }
9386 schaersvoo 9396
        if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
7614 schaersvoo 9397
        free(input_type);
8146 schaersvoo 9398
        return CLEARBUTTON;
7614 schaersvoo 9399
        }
9400
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
9401
        free(input_type);
9402
        return TRANSLATION;
9403
        }
9404
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
9405
        free(input_type);
9406
        return KILLTRANSLATION;
9407
        }
9408
        if( strcmp(input_type, rotate) == 0){
9409
        free(input_type);
9410
        return ROTATE;
9411
        }
9907 schaersvoo 9412
        if( strcmp(input_type, killrotate) == 0){
9413
        free(input_type);
9414
        return KILLROTATE;
9415
        }
9416
        if( strcmp(input_type, rotationcenter) == 0){
9417
        free(input_type);
9418
        return ROTATION_CENTER;
9419
        }
7785 schaersvoo 9420
        if( strcmp(input_type, affine) == 0){
9421
        free(input_type);
9422
        return AFFINE;
9423
        }
9424
        if( strcmp(input_type, killaffine) == 0){
9425
        free(input_type);
9426
        return KILLAFFINE;
9427
        }
7614 schaersvoo 9428
        if( strcmp(input_type, slider) == 0 ){
9429
        free(input_type);
9430
        return SLIDER;
9431
        }
8101 schaersvoo 9432
        if( strcmp(input_type, killslider) == 0 ){
9433
        free(input_type);
9434
        return KILLSLIDER;
9435
        }
7614 schaersvoo 9436
        if( strcmp(input_type, copy) == 0 ){
9437
        free(input_type);
9438
        return COPY;
9439
        }
9440
        if( strcmp(input_type, copyresized) == 0 ){
9441
        free(input_type);
9442
        return COPYRESIZED;
9443
        }
9444
        if( strcmp(input_type, xlogscale) == 0 ){
9445
        free(input_type);
9446
        return XLOGSCALE;
9447
        }
9448
        if( strcmp(input_type, ylogscale) == 0 ){
9449
        free(input_type);
9450
        return YLOGSCALE;
9451
        }
9452
        if( strcmp(input_type, xylogscale) == 0 ){
9453
        free(input_type);
9454
        return XYLOGSCALE;
9455
        }
9456
        if( strcmp(input_type, ylogscale) == 0 ){
9457
        free(input_type);
9458
        return YLOGSCALE;
9459
        }
7735 schaersvoo 9460
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 9461
        free(input_type);
7735 schaersvoo 9462
        return XLOGBASE;
7614 schaersvoo 9463
        }
7735 schaersvoo 9464
        if( strcmp(input_type, ylogbase) == 0 ){
9465
        free(input_type);
9466
        return YLOGBASE;
9467
        }
7614 schaersvoo 9468
        if( strcmp(input_type, intooltip) == 0 ){
9469
        free(input_type);
9470
        return INTOOLTIP;
9471
        }
9329 schaersvoo 9472
        if( strcmp(input_type, popup) == 0 ){
9473
        free(input_type);
9474
        return POPUP;
9475
        }
7614 schaersvoo 9476
        if( strcmp(input_type,video) == 0 ){
9477
        free(input_type);
9478
        return VIDEO;
9479
        }
11772 schaersvoo 9480
        if( strcmp(input_type,fillall) == 0 ){
9481
        free(input_type);
9482
        return FILLALL;
9483
        }
7614 schaersvoo 9484
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
9485
        free(input_type);
9486
        return FLOODFILL;
8224 bpr 9487
        }
7614 schaersvoo 9488
        if( strcmp(input_type,filltoborder) == 0 ){
9489
        free(input_type);
9490
        return FILLTOBORDER;
8224 bpr 9491
        }
7614 schaersvoo 9492
        if( strcmp(input_type, replyformat) == 0 ){
9493
        free(input_type);
9494
        return REPLYFORMAT;
9495
        }
9496
        if( strcmp(input_type, pixelsize) == 0 ){
9497
        free(input_type);
9498
        return PIXELSIZE;
9499
        }
9500
        if( strcmp(input_type, setpixel) == 0 ){
9501
        free(input_type);
9502
        return SETPIXEL;
9503
        }
9504
        if( strcmp(input_type, pixels) == 0 ){
9505
        free(input_type);
9506
        return PIXELS;
9507
        }
9508
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
9509
        free(input_type);
9510
        return X_AXIS_STRINGS;
9511
        }
9341 schaersvoo 9512
        if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
9513
        free(input_type);
9514
        return X_AXIS_STRINGS_UP;
9515
        }
7614 schaersvoo 9516
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
9517
        free(input_type);
9518
        return Y_AXIS_STRINGS;
9519
        }
9520
        if( strcmp(input_type, legend) == 0  ){
9521
        free(input_type);
9522
        return LEGEND;
9523
        }
9524
        if( strcmp(input_type, legendcolors) == 0  ){
9525
        free(input_type);
9526
        return LEGENDCOLORS;
9527
        }
9528
        if( strcmp(input_type, xlabel) == 0  ){
9529
        free(input_type);
9530
        return XLABEL;
9531
        }
9532
        if( strcmp(input_type, ylabel) == 0  ){
9533
        free(input_type);
9534
        return YLABEL;
9535
        }
8370 schaersvoo 9536
        if( strcmp(input_type, bezier) == 0  ){
9537
        free(input_type);
9538
        return BEZIER;
9539
        }
7614 schaersvoo 9540
        if( strcmp(input_type, animate) == 0  ){
9541
        free(input_type);
9542
        return ANIMATE;
9543
        }
9354 schaersvoo 9544
        /* these are bitmap related flydraw commands...must be removed. eventually */
7614 schaersvoo 9545
        if( strcmp(input_type, transparent) == 0 ){
9546
        free(input_type);
9547
        return TRANSPARENT;
9548
        }
7877 schaersvoo 9549
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 9550
        free(input_type);
9551
        return STATUS;
9552
        }
7784 schaersvoo 9553
        if( strcmp(input_type, xsnaptogrid) == 0 ){
9554
        free(input_type);
9555
        return XSNAPTOGRID;
9556
        }
9557
        if( strcmp(input_type, ysnaptogrid) == 0 ){
9558
        free(input_type);
9559
        return YSNAPTOGRID;
9560
        }
8379 schaersvoo 9561
        if( strcmp(input_type, snaptogrid) == 0 ){
9562
        free(input_type);
9563
        return SNAPTOGRID;
9564
        }
9565
        if( strcmp(input_type, snaptopoints) == 0 ){
9566
        free(input_type);
9567
        return SNAPTOPOINTS;
9568
        }
9213 schaersvoo 9569
        if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
9570
        free(input_type);
9571
        return SNAPTOFUNCTION;
9572
        }
7652 schaersvoo 9573
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 9574
        free(input_type);
7652 schaersvoo 9575
        return USERINPUT_XY;
9576
        }
8193 schaersvoo 9577
        if( strcmp(input_type, userinput_function) == 0 ){
9578
        free(input_type);
9579
        return USERINPUT_FUNCTION;
9580
        }
7663 schaersvoo 9581
        if( strcmp(input_type, usertextarea_xy) == 0 ){
9582
        free(input_type);
9583
        return USERTEXTAREA_XY;
9584
        }
8222 schaersvoo 9585
        if( strcmp(input_type, userinput) == 0 ){
9586
        free(input_type);
9587
        return USERINPUT;
9588
        }
8105 schaersvoo 9589
        if( strcmp(input_type, angle) == 0 ){
7996 schaersvoo 9590
        free(input_type);
8105 schaersvoo 9591
        return ANGLE;
9592
        }
8297 schaersvoo 9593
        if( strcmp(input_type, functionlabel) == 0 ){
8244 schaersvoo 9594
        free(input_type);
8297 schaersvoo 9595
        return FUNCTION_LABEL;
9596
        }
9213 schaersvoo 9597
        if( strcmp(input_type, sliderfunction_x) == 0 ){
8297 schaersvoo 9598
        free(input_type);
9213 schaersvoo 9599
        return SLIDER_X;
9600
        }
9601
        if( strcmp(input_type, sliderfunction_y) == 0 ){
9602
        free(input_type);
9603
        return SLIDER_Y;
9604
        }
9605
        if( strcmp(input_type, multidraw) == 0 ){
9606
        free(input_type);
9607
        return MULTIDRAW;
9608
        }
9609
        if( strcmp(input_type, multistrokeopacity) == 0 ){
9610
        free(input_type);
9611
        return MULTISTROKEOPACITY;
9612
        }
9613
        if( strcmp(input_type, multifillopacity) == 0 ){
9614
        free(input_type);
9615
        return MULTIFILLOPACITY;
9616
        }
9617
        if( strcmp(input_type, multilinewidth) == 0 ){
9618
        free(input_type);
9619
        return MULTILINEWIDTH;
9620
        }
9621
        if( strcmp(input_type, multistrokecolors) == 0 ){
9622
        free(input_type);
9623
        return MULTISTROKECOLORS;
9624
        }
9625
        if( strcmp(input_type, multifill) == 0 ){
9626
        free(input_type);
9627
        return MULTIFILL;
9628
        }
9629
        if( strcmp(input_type, multifillcolors) == 0 ){
9630
        free(input_type);
9631
        return MULTIFILLCOLORS;
9632
        }
9633
        if( strcmp(input_type, multilabel) == 0 ){
9634
        free(input_type);
9635
        return MULTILABEL;
9636
        }
9637
        if( strcmp(input_type, multidash) == 0 ){
9638
        free(input_type);
9639
        return MULTIDASH;
9640
        }
9641
        if( strcmp(input_type, multisnaptogrid) == 0 ){
9642
        free(input_type);
9643
        return MULTISNAPTOGRID;
9644
        }
9645
        if( strcmp(input_type, multiuserinput) == 0 ){
9646
        free(input_type);
9647
        return MULTIUSERINPUT;
9648
        }
9386 schaersvoo 9649
        if( strcmp(input_type, parallel) == 0 ){
9650
        free(input_type);
9651
        return PARALLEL;
9652
        }
9289 schaersvoo 9653
        if( strcmp(input_type, protractor) == 0 ){
9654
        free(input_type);
9655
        return PROTRACTOR;
9656
        }
9657
        if( strcmp(input_type, ruler) == 0 ){
9658
        free(input_type);
9659
        return RULER;
9660
        }
9386 schaersvoo 9661
        if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
9213 schaersvoo 9662
        free(input_type);
9386 schaersvoo 9663
        return CURSOR;
9664
        }
9665
        if( strcmp(input_type, sgraph) == 0 ){
9666
        free(input_type);
9667
        return SGRAPH;
9668
        }
9669
        if( strcmp(input_type, jsmath) == 0 ){
9670
        free(input_type);
9671
        return JSMATH;
9672
        }
9673
        if( strcmp(input_type, trace_jscurve) == 0 ){
9674
        free(input_type);
9675
        return TRACE_JSCURVE;
9676
        }
9677
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
9678
        free(input_type);
9679
        return JSCURVE;
9680
        }
9681
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
9682
        free(input_type);
9683
        return CENTERSTRING;
9684
        }
9685
        if( strcmp(input_type, setlimits) == 0 ){
9686
        free(input_type);
9687
        return SETLIMITS;
9688
        }
9689
        if( strcmp(input_type, xunit) == 0 ){
9690
        free(input_type);
9691
        return XUNIT;
9692
        }
9693
        if( strcmp(input_type, yunit) == 0 ){
9694
        free(input_type);
9695
        return YUNIT;
9696
        }
9697
        if( strcmp(input_type, fill) == 0 ){
9698
        free(input_type);
9699
        return FLOODFILL;
9700
        }
9701
        if( strcmp(input_type, end) == 0){
9702
        free(input_type);
9703
        return END;
9704
        }
9705
        if( strcmp(input_type, blink) == 0 ){
9706
        free(input_type);
9707
        return BLINK;
9708
        }
9709
        if( strcmp(input_type, audio) == 0 ){
9710
        free(input_type);
9711
        return AUDIO;
9712
        }
9713
        if( strcmp(input_type, audioobject) == 0 ){
9714
        free(input_type);
9715
        return AUDIOOBJECT;
9716
        }
9717
        if( strcmp(input_type, patternfill) == 0 ){
9718
        free(input_type);
9719
        return PATTERNFILL;
9720
        }
9721
        if( strcmp(input_type, hatchfill) == 0 ){
9722
        free(input_type);
9723
        return HATCHFILL;
9724
        }
9725
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
9726
        free(input_type);
9727
        return DIAMONDFILL;
9728
        }
9729
        if( strcmp(input_type, dotfill) == 0 ){
9730
        free(input_type);
9731
        return DOTFILL;
9732
        }
9733
        if( strcmp(input_type, gridfill) == 0 ){
9734
        free(input_type);
9735
        return GRIDFILL;
9736
        }
9737
        if( strcmp(input_type, imagefill) == 0 ){
9738
        free(input_type);
9739
        return IMAGEFILL;
9740
        }
9741
        if( strcmp(input_type, clicktile_colors) == 0 ){
9742
        free(input_type);
9743
        return CLICKTILE_COLORS;
9744
        }
9745
        if( strcmp(input_type, clicktile) == 0 ){
9746
        free(input_type);
9747
        return CLICKTILE;
9748
        }
9749
        if( strcmp(input_type, piechart) == 0  ){
9750
        free(input_type);
9751
        return PIECHART;
9752
        }
9433 schaersvoo 9753
        if( strcmp(input_type, boxplot) == 0  ){
9754
        free(input_type);
9755
        return BOXPLOT;
9756
        }
9465 schaersvoo 9757
        if( strcmp(input_type, boxplotdata) == 0  ){
9433 schaersvoo 9758
        free(input_type);
9465 schaersvoo 9759
        return BOXPLOTDATA;
9433 schaersvoo 9760
        }
9465 schaersvoo 9761
        if( strcmp(input_type, userboxplot) == 0  ){
9762
        free(input_type);
9763
        return USERBOXPLOT;
9764
        }
9765
        if( strcmp(input_type, userboxplotdata) == 0  ){
9766
        free(input_type);
9767
        return USERBOXPLOT;
9768
        }
9386 schaersvoo 9769
        if( strcmp(input_type, barchart) == 0  ){
9770
        free(input_type);
9771
        return BARCHART;
9772
        }
9773
        if( strcmp(input_type, linegraph) == 0  ){
9774
        free(input_type);
9775
        return LINEGRAPH;
9776
        }
9777
        if( strcmp(input_type, clock) == 0  ){
9778
        free(input_type);
9779
        return CLOCK;
9780
        }
9427 schaersvoo 9781
        if( strcmp(input_type, yerrorbars) == 0  ){
9386 schaersvoo 9782
        free(input_type);
9427 schaersvoo 9783
        return YERRORBARS;
9784
        }
9785
        if( strcmp(input_type, xerrorbars) == 0  ){
9786
        free(input_type);
9787
        return XERRORBARS;
9788
        }
11006 schaersvoo 9789
        if( strcmp(input_type, canvastype) == 0  ){
9427 schaersvoo 9790
        free(input_type);
11006 schaersvoo 9791
        return CANVASTYPE;
9792
        }
11044 schaersvoo 9793
        if( strcmp(input_type, noyaxis) == 0  ){
11006 schaersvoo 9794
        free(input_type);
11044 schaersvoo 9795
        return NOYAXIS;
9796
        }
9797
        if( strcmp(input_type, noxaxis) == 0  ){
9798
        free(input_type);
9799
        return NOXAXIS;
9800
        }
11767 schaersvoo 9801
        if( strcmp(input_type, colorpalette) == 0  ){
11044 schaersvoo 9802
        free(input_type);
11767 schaersvoo 9803
        return COLORPALETTE;
9804
        }
11802 schaersvoo 9805
        if( strcmp(input_type, resetoffset) == 0  ){
11767 schaersvoo 9806
        free(input_type);
11802 schaersvoo 9807
        return RESETOFFSET;
9808
        }
9809
        if( strcmp(input_type, xyoffset) == 0  ){
9810
        free(input_type);
9811
        return XYOFFSET;
9812
        }
9813
        if( strcmp(input_type, xoffset) == 0 || strcmp(input_type, centered) == 0  ){
9814
        free(input_type);
9815
        return XOFFSET;
9816
        }
11811 schaersvoo 9817
        if( strcmp(input_type, yoffset) == 0 ){
11802 schaersvoo 9818
        free(input_type);
11811 schaersvoo 9819
        return YOFFSET;
9820
        }
9821
        free(input_type);
7614 schaersvoo 9822
        ungetc(c,infile);
9823
        return 0;
9824
}