Subversion Repositories wimsdev

Rev

Rev 11820 | Rev 11822 | 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
        */
1137
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
11820 schaersvoo 1138
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1139
             js_function[DRAW_FILLTOBORDER] = 1;
1140
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1141
            }
1142
            decimals = find_number_of_digits(precision);
7614 schaersvoo 1143
            for(i=0;i<5;i++){
1144
                switch(i){
11820 schaersvoo 1145
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
1146
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
1147
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1148
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1149
                    case 4: stroke_color = get_color(infile,1);
1150
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
11820 schaersvoo 1151
                    string_length = snprintf(NULL,0,  "draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_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 1152
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11820 schaersvoo 1153
                    snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_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 1154
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1155
                    fill_cnt++;
11806 schaersvoo 1156
                    break;
1157
                    default:break;
1158
                }
1159
            }
1160
            reset();
1161
        break;
8224 bpr 1162
 
11806 schaersvoo 1163
        case DOTFILL:
1164
        /*
1165
        @ dotfill x0,y0,dx,dy,color
1166
        @ x0,y0 in xrange / yrange
1167
        @ distances dx,dy in pixels
1168
        @ radius of dots is linewidth
1169
        */
1170
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
11817 schaersvoo 1171
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1172
             js_function[DRAW_FILLTOBORDER] = 1;
1173
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1174
            }
1175
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1176
            for(i=0;i<5;i++){
1177
                switch(i){
11817 schaersvoo 1178
                    case 0: double_data[0] = get_real(infile,0); break; /* x in px */
1179
                    case 1: double_data[1] = get_real(infile,0); break; /* y in py */
1180
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1181
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1182
                    case 4: stroke_color = get_color(infile,1);
1183
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
11817 schaersvoo 1184
                    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 1185
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11817 schaersvoo 1186
                    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 1187
                    add_to_buffer(tmp_buffer);
11817 schaersvoo 1188
                    fill_cnt++;
7614 schaersvoo 1189
                    break;
11806 schaersvoo 1190
                    default:break;
7614 schaersvoo 1191
                }
1192
            }
11806 schaersvoo 1193
            reset();
1194
        break;
1195
 
1196
        case DRAG:
1197
        /*
1198
         @ drag [x][y][xy]
1199
         @ the next object will be draggable in x / y / xy direction
1200
         @ the displacement can be read by 'javascript:read_dragdrop();'
1201
         @ 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' !
1202
         @ 'onclick' and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both )
1203
         @ '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)
1204
         @ <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
1205
         @ 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)
1206
         @ use keyword 'snaptogrid' , 'xsnaptogrid' , 'ysnaptogrid' or command 'snaptopoints x1,y1,x2,y2,...' to switch from free to discrete movement
1207
         @ 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.
1208
         @ 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 !!
1209
        */
1210
            temp = get_string(infile,1);
1211
            if(strstr(temp,"xy") != NULL ){
1212
                drag_type = 0;
1213
            }
1214
            else
1215
            {
1216
                if(strstr(temp,"x") != NULL ){
1217
                    drag_type = 1;
1218
                }
1219
                else
1220
                {
1221
                    drag_type = 2;
1222
                }
1223
            }
1224
            /* assuming all drag&drop coordinates the same precision: so set only once */
1225
            if( print_drag_params_only_once == FALSE ){
1226
             fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
1227
             print_drag_params_only_once = TRUE;
1228
            }
1229
            onclick = 2;
1230
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
7614 schaersvoo 1231
            break;
8386 schaersvoo 1232
 
11806 schaersvoo 1233
        case ELLIPSE:
8351 schaersvoo 1234
        /*
11806 schaersvoo 1235
        @ ellipse xc,yc,radius_x,radius_y,color
1236
        @ a ellipse with center xc/yc in x/y-range
1237
        @ radius_x and radius_y are in pixels
9406 schaersvoo 1238
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
11806 schaersvoo 1239
        @ will shrink / expand on zoom out / zoom in
8351 schaersvoo 1240
        */
11806 schaersvoo 1241
            for(i=0;i<5;i++){
1242
                switch(i){
1243
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
1244
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
1245
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
1246
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
1247
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
1248
                        decimals = find_number_of_digits(precision);
1249
                        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);
1250
                        if(onclick > 0){click_cnt++;}
1251
                        /* click_cnt++; */
1252
                        reset();
1253
                    break;
1254
                }
1255
            }
1256
            break;
1257
        case FILLALL:
1258
        /*
1259
        @ fillall color,x1,y1,x2,y2...x_n,y_n
1260
        @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
1261
        @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill
1262
        @ use this command  after all boundary objects are declared.
1263
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1264
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1265
        @ 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..
1266
        */
1267
            decimals = find_number_of_digits(precision);
1268
            fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
8351 schaersvoo 1269
            i=0;
11806 schaersvoo 1270
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1271
             js_function[DRAW_FILLTOBORDER] = 1;
1272
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1273
            }
8351 schaersvoo 1274
            while( ! done ){     /* get next item until EOL*/
1275
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1276
                if(i%2 == 0 ){
1277
                    double_data[i] = get_real(infile,0); /* x */
1278
                }
1279
                else
1280
                {
1281
                    double_data[i] = get_real(infile,1); /* y */
11818 schaersvoo 1282
                    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 1283
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1284
                    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 1285
                    add_to_buffer(tmp_buffer);
1286
                    fill_cnt++;
8351 schaersvoo 1287
                }
1288
                i++;
1289
            }
11806 schaersvoo 1290
        break;
1291
 
1292
        case FILLED:
1293
        /*
1294
        @ filled
1295
        @ keyword (no arguments required)
1296
        @ the next 'fillable' object (only) will be filled
1297
        @ use command "fillcolor color" to set fillcolor
1298
        @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
1299
        @ 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 !
1300
        */
1301
            use_filled = TRUE;
1302
            break;
1303
 
1304
        case FILLCOLOR:
1305
        /*
1306
        @ fillcolor colorname or #hex
1307
        @ set the color for a filled object : mainly used for command 'userdraw obj,stroke_color'
1308
        @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
1309
        */
1310
            fill_color = get_color(infile,1);
1311
            break;
1312
 
1313
        case FILLTOBORDER:
1314
        /*
1315
        @ filltoborder x,y,bordercolor,color
1316
        @ fill the region  of point (x:y)  with color 'color'
1317
        @ any other color will not act as border to the bucket fill
1318
        @ use this command  after all boundary objects are declared.
1319
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1320
        @ 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..
1321
        @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
1322
        */
1323
            for(i=0 ;i < 4 ; i++){
1324
                switch(i){
1325
                    case 0:double_data[0] = get_real(infile,0);break;
1326
                    case 1:double_data[1] = get_real(infile,0);break;
1327
                    case 2:bgcolor = get_color(infile,0);break;
1328
                    case 3:fill_color = get_color(infile,1);
1329
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1330
                                js_function[DRAW_FILLTOBORDER] = 1;
1331
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1332
                           }
1333
                           decimals = find_number_of_digits(precision);
1334
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
11818 schaersvoo 1335
                           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 1336
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1337
                           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 1338
                           add_to_buffer(tmp_buffer);
1339
                           fill_cnt++;
1340
                           break;
1341
                    default:break;
8351 schaersvoo 1342
                }
11806 schaersvoo 1343
            }
1344
            reset();
1345
        break;
1346
        case FLOODFILL:
1347
        /*
1348
        @ floodfill x,y,color
1349
        @ alternative : fill x,y,color
1350
        @ fill the region of point (x:y) with color 'color'
1351
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
1352
        @ use this command  after all boundary objects are declared.
1353
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1354
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1355
        @ 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..
1356
        */
1357
            for(i=0 ;i < 4 ; i++){
1358
                switch(i){
1359
                    case 0:double_data[0] = get_real(infile,0);break;
1360
                    case 1:double_data[1] = get_real(infile,0);break;
1361
                    case 2:fill_color = get_color(infile,1);
1362
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1363
                                js_function[DRAW_FILLTOBORDER] = 1;
1364
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1365
                           }
1366
                           decimals = find_number_of_digits(precision);
1367
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
11818 schaersvoo 1368
                           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 1369
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1370
                           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 1371
                           add_to_buffer(tmp_buffer);
1372
                           fill_cnt++;
1373
                           break;
1374
                    default:break;
1375
                }
1376
            }
1377
            reset();
1378
        break;
1379
 
1380
        case FONTCOLOR:
1381
        /*
1382
         @ fontcolor color
1383
         @ color: hexcolor or colorname
1384
         @ default: black
1385
         @ example usage: x/y-axis text
1386
        */
1387
            font_color = get_color(infile,1);
1388
            break;
1389
 
1390
        case FONTFAMILY:
1391
        /*
1392
         @ fontfamily font_description
1393
         @ set the font family; for browsers that support it
1394
         @ font_description: Ariel ,Courier, Helvetica etc
1395
         @ 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
1396
         @ use correct syntax : 'font style' 'font size'px 'fontfamily'
1397
        */
1398
            font_family = get_string(infile,1);
1399
            break;
1400
 
1401
        case FONTSIZE:
1402
        /*
1403
         @ fontsize font_size
1404
         @ default value 12
1405
         @ 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
1406
        */
1407
            font_size = (int) (get_real(infile,1));
1408
            break;
1409
 
1410
        case FUNCTION_LABEL:
1411
        /*
1412
         @ functionlabel 'some string'
1413
         @ default value "f(x)="
1414
         @ no mathml allowed (just ascii string)
1415
         @ use command 'fontsize int' to adjust the size
1416
         @ use command 'strokecolor colorname' to adjust the labels (individually, if needed)
1417
         @ if needed, use before every command 'userinput function | inputfield | textarea'
1418
        */
1419
            function_label = get_string_argument(infile,1);
1420
            break;
1421
 
1422
        case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/
1423
        /*
1424
         @ grid step_x,step_y,gridcolor
1425
         @ 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
1426
         @ 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
1427
         @ 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)
1428
         @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a>
1429
         @ 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' !
1430
         @ 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')
1431
         @ 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')
1432
        */
1433
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
1434
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
1435
            for(i=0;i<4;i++){
1436
                switch(i){
1437
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
1438
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
1439
                    case 2:
1440
                    if( use_axis == TRUE ){
1441
                        stroke_color = get_color(infile,0);
1442
                        done = FALSE;
1443
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
1444
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
1445
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
1446
                        fill_color = get_color(infile,1); /* used as axis_color*/
8351 schaersvoo 1447
                    }
1448
                    else
1449
                    {
11806 schaersvoo 1450
                        int_data[0] = 1;
1451
                        int_data[1] = 1;
1452
                        stroke_color = get_color(infile,1);
1453
                        fill_color = stroke_color;
8351 schaersvoo 1454
                    }
11806 schaersvoo 1455
                    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 !");}
1456
                    /* set snap_x snap_y values in pixels */
1457
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
1458
                    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);
1459
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1460
                    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);
1461
                    add_to_buffer(tmp_buffer);
1462
                    break;
8351 schaersvoo 1463
                }
1464
            }
1465
            reset();
1466
            break;
11806 schaersvoo 1467
        case GRIDFILL:
1468
        /*
1469
        @ gridfill x0,y0,dx,dy,color
1470
        @ x0,y0 in xrange / yrange
1471
        @ distances dx,dy in pixels
1472
        */
1473
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
11820 schaersvoo 1474
            decimals = find_number_of_digits(precision);
1475
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1476
             js_function[DRAW_FILLTOBORDER] = 1;
1477
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1478
            }
11806 schaersvoo 1479
            for(i=0;i<5;i++){
1480
                switch(i){
11820 schaersvoo 1481
                    case 0: double_data[0] = get_real(infile,0); break; /* x  */
1482
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
1483
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1484
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1485
                    case 4: stroke_color = get_color(infile,1);
11820 schaersvoo 1486
                    string_length = snprintf(NULL,0,  "draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_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 1487
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11820 schaersvoo 1488
                    snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_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 1489
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1490
                    fill_cnt++;
11806 schaersvoo 1491
                    break;
1492
                    default:break;
1493
                }
1494
            }
1495
            reset();
1496
        break;
8386 schaersvoo 1497
 
8244 schaersvoo 1498
        case HALFLINE:
1499
        /*
1500
        @ demiline x1,y1,x2,y2,color
1501
        @ alternative : halfline
1502
        @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
9406 schaersvoo 1503
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8244 schaersvoo 1504
        */
1505
            for(i=0;i<5;i++){
1506
                switch(i){
1507
                    case 0: double_data[0]= get_real(infile,0);break; /* x-values */
1508
                    case 1: double_data[1]= get_real(infile,0);break; /* y-values */
1509
                    case 2: double_data[10]= get_real(infile,0);break; /* x-values */
1510
                    case 3: double_data[11]= get_real(infile,0);break; /* y-values */
1511
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
1512
                    if(double_data[0] == double_data[10]){ /* vertical halfline */
1513
                        if(double_data[1] < double_data[11]){
1514
                         double_data[3] = ymax + 1000;
1515
                        }
1516
                        else
1517
                        {
1518
                         double_data[3] = ymin - 1000;
1519
                        }
10953 bpr 1520
                        double_data[2] = double_data[0];
8244 schaersvoo 1521
                    }
1522
                    else
1523
                    { /* horizontal halfline*/
1524
                     if( double_data[1] == double_data[11] ){
1525
                      if( double_data[0] < double_data[10] ){
1526
                        double_data[2] = xmax + 1000; /* halfline to the right */
1527
                      }
1528
                      else
1529
                      {
1530
                        double_data[2] = xmin - 1000; /* halfline to the left */
1531
                      }
1532
                      double_data[3] = double_data[1];
1533
                     }
1534
                     else
1535
                     {
1536
                      /* any other halfline */
1537
                      /* slope */
1538
                      double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
1539
                      /* const */
1540
                      double_data[13] = double_data[1] - double_data[12]*double_data[0];
1541
                      if( double_data[0] < double_data[10] ){
1542
                       double_data[2] = double_data[2] + 1000;
1543
                      }
1544
                      else
1545
                      {
1546
                       double_data[2] = double_data[2] - 1000;
1547
                      }
1548
                      double_data[3] = double_data[12]*double_data[2] + double_data[13];
1549
                     }
10953 bpr 1550
                    }
11802 schaersvoo 1551
                    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 1552
                    if(onclick > 0){click_cnt++;}
1553
                    /* click_cnt++; */
1554
                    reset();
8244 schaersvoo 1555
                    break;
1556
                }
1557
            }
1558
            break;
8386 schaersvoo 1559
 
8365 schaersvoo 1560
        case HALFLINES:
1561
        /*
1562
        @ demilines color,x1,y1,x2,y2,....
1563
        @ alternative : halflines
1564
        @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc
9406 schaersvoo 1565
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
8365 schaersvoo 1566
        */
1567
            stroke_color=get_color(infile,0);
1568
            fill_color = stroke_color;
1569
            i=0;
1570
            while( ! done ){     /* get next item until EOL*/
1571
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1572
                if(i%2 == 0 ){
1573
                    double_data[i] = get_real(infile,0); /* x */
1574
                }
1575
                else
1576
                {
1577
                    double_data[i] = get_real(infile,1); /* y */
1578
                }
1579
                i++;
1580
            }
1581
            decimals = find_number_of_digits(precision);
1582
            for(c = 0 ; c < i-1 ; c = c+4){
1583
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
1584
                    if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
1585
                        double_data[c+3] = ymax + 1000;
1586
                    }
1587
                    else
1588
                    {
1589
                     double_data[c+3] = ymin - 1000;/* descending halfline */
1590
                    }
1591
                }
1592
                else
1593
                {
1594
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
1595
                        if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
1596
                            double_data[c+2] = xmax+100;
1597
                        }
1598
                        else
1599
                        {
1600
                            double_data[c+2] = xmin-1000; /* halfline to the right */
1601
                        }
1602
                    }
1603
                    else
1604
                    {
1605
                        /* m */
1606
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
1607
                        /* q */
1608
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
1609
                        if(double_data[c] < double_data[c+2]){ /* to the right */
1610
                            double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */
1611
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1612
                        }
1613
                        else
1614
                        { /* to the left */
1615
                            double_data[c+2] = xmin - 1000;
1616
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1617
                        }
1618
                    }
1619
                }
11802 schaersvoo 1620
                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 1621
                if(onclick > 0){click_cnt++;}
1622
                /* click_cnt++; */
8365 schaersvoo 1623
            }
1624
            reset();
1625
            break;
11806 schaersvoo 1626
        case HATCHFILL:
1627
        /*
1628
        @ hatchfill x0,y0,dx,dy,color
1629
        @ x0,y0 in xrange / yrange
1630
        @ distances dx,dy in pixels
1631
        */
1632
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
11820 schaersvoo 1633
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1634
             js_function[DRAW_FILLTOBORDER] = 1;
1635
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1636
            }
1637
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1638
            for(i=0;i<5;i++){
1639
                switch(i){
11820 schaersvoo 1640
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
1641
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
1642
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1643
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1644
                    case 4: stroke_color = get_color(infile,1);
1645
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
11820 schaersvoo 1646
                    string_length = snprintf(NULL,0,  "draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_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 1647
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11820 schaersvoo 1648
                    snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%.*f,%.*f,%d,%d,%d,\"%s\",%.2f,%d,%d);\n",STATIC_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 1649
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1650
                    fill_cnt++;
11806 schaersvoo 1651
                    break;
1652
                    default:break;
1653
                }
1654
            }
1655
            reset();
1656
        break;
8386 schaersvoo 1657
 
8224 bpr 1658
        case HLINE:
7614 schaersvoo 1659
        /*
1660
        @ hline x,y,color
9383 schaersvoo 1661
        @ alternative : horizontalline
7614 schaersvoo 1662
        @ draw a horizontal line through point (x:y) in color 'color'
9373 schaersvoo 1663
        @ 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 1664
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 1665
        */
1666
            for(i=0;i<3;i++) {
1667
                switch(i){
1668
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
1669
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
1670
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
1671
                    double_data[3] = double_data[1];
1672
                    decimals = find_number_of_digits(precision);
11802 schaersvoo 1673
                    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 1674
                    if(onclick > 0){click_cnt++;}
1675
                    /* click_cnt++; */
1676
                    reset();
7614 schaersvoo 1677
                    break;
1678
                }
1679
            }
1680
            break;
8366 schaersvoo 1681
 
1682
        case HLINES:
1683
        /*
1684
        @ hlines color,x1,y1,x2,y2,...
9383 schaersvoo 1685
        @ alternative : horizontallines
8366 schaersvoo 1686
        @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
9406 schaersvoo 1687
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
8366 schaersvoo 1688
        */
1689
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1690
            fill_color = stroke_color;
1691
            i=0;
1692
            while( ! done ){     /* get next item until EOL*/
1693
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
1694
                if(i%2 == 0 ){
1695
                    double_data[i] = get_real(infile,0); /* x */
1696
                }
1697
                else
1698
                {
1699
                    double_data[i] = get_real(infile,1); /* y */
1700
                }
1701
                i++;
1702
            }
1703
            decimals = find_number_of_digits(precision);
1704
            for(c = 0 ; c < i-1 ; c = c+2){
11802 schaersvoo 1705
                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 1706
                if(onclick > 0){click_cnt++;}
1707
                /* click_cnt++; */
8366 schaersvoo 1708
            }
1709
            reset();
1710
            break;
11806 schaersvoo 1711
        case HTTP:
7614 schaersvoo 1712
        /*
11806 schaersvoo 1713
         @ http x1,y1,x2,y2,http://some_adress.com
1714
         @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
1715
         @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
1716
         @ can <b>not</b> be 'set onclick' or 'drag xy'
7614 schaersvoo 1717
        */
11806 schaersvoo 1718
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
1719
            for(i=0;i<5;i++){
7614 schaersvoo 1720
                switch(i){
11806 schaersvoo 1721
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1722
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1723
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
1724
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
1725
                    case 4: decimals = find_number_of_digits(precision);
1726
                            temp = get_string(infile,1);
1727
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
1728
                            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);
1729
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
1730
                            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);
1731
                            add_to_buffer(tmp_buffer);
7614 schaersvoo 1732
                    break;
1733
                }
1734
            }
11806 schaersvoo 1735
            reset();
7614 schaersvoo 1736
            break;
11806 schaersvoo 1737
        case HTML:
8366 schaersvoo 1738
        /*
11806 schaersvoo 1739
         @ html x1,y1,x2,y2,html_string
1740
         @ 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.
1741
         @ can be set onclick <br />(however dragging not supported)
8366 schaersvoo 1742
        */
11806 schaersvoo 1743
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
1744
            for(i=0;i<5;i++){
1745
                switch(i){
1746
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
1747
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
1748
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
1749
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
1750
                    case 4: decimals = find_number_of_digits(precision);
1751
                            temp = get_string(infile,1);
1752
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
1753
                            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);
1754
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1755
                            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);
1756
                            add_to_buffer(tmp_buffer);
1757
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
1758
                            break;
1759
                    default:break;
8366 schaersvoo 1760
                }
1761
            }
1762
            reset();
1763
            break;
8386 schaersvoo 1764
 
11806 schaersvoo 1765
        case IMAGEFILL:
7614 schaersvoo 1766
        /*
11806 schaersvoo 1767
        @ imagefill dx,dy,image_url
1768
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
1769
        @ After pattern filling ,the fill-color should be reset !
1770
        @ wims getins / image from class directory : imagefill 80,80,my_image.gif
1771
        @ normal url : imagefill 80,80,$module_dir/gifs/my_image.gif
1772
        @ normal url : imagefill 80,80,http://adres/a/b/c/my_image.jpg
1773
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
7614 schaersvoo 1774
        */
11806 schaersvoo 1775
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
1776
            for(i=0 ;i < 3 ; i++){
7614 schaersvoo 1777
                switch(i){
11806 schaersvoo 1778
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
1779
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
1780
                    case 2: URL = get_string_argument(infile,1);
1781
                            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);
1782
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1783
                            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);
1784
                            add_to_buffer(tmp_buffer);
1785
                    break;
7614 schaersvoo 1786
                }
1787
            }
11806 schaersvoo 1788
            reset();
1789
        break;
1790
 
1791
        case INPUTSTYLE:
1792
        /*
1793
        @ inputstyle style_description
1794
        @ 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
1795
        @ example: inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt
1796
        */
1797
            input_style = get_string(infile,1);
7614 schaersvoo 1798
            break;
11806 schaersvoo 1799
        case INPUT:
1800
        /*
1801
         @ input x,y,size,editable,value
1802
         @ to set inputfield "readonly", use editable = 0
1803
         @ only active inputfields (editable = 1) will be read with read_canvas();
1804
         @ 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>
1805
         @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...)
1806
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
1807
         @ 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)
1808
        */
1809
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
1810
            for(i = 0 ; i<5;i++){
1811
                switch(i){
1812
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
1813
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
1814
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
1815
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
1816
                    case 4:
1817
                            temp = get_string_argument(infile,1);
1818
                            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);
1819
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1820
                            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);
1821
                            add_to_buffer(tmp_buffer);
1822
                            input_cnt++;break;
1823
                    default: break;
1824
                }
1825
            }
1826
            if(reply_format == 0 ){reply_format = 15;}
1827
            reset();
1828
            break;
8386 schaersvoo 1829
 
11806 schaersvoo 1830
        case INTOOLTIP:
1831
            /*
1832
            @ intooltip link_text
1833
            @ link_text is a single line (span-element)
1834
            @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg'
1835
            @ link_text may contain HTML markup
1836
            @ the canvas will be displayed in a tooltip on 'link_text'
1837
            @ 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'.
1838
            @ 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...
1839
            */
1840
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
1841
            if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
1842
            tooltip_text = get_string(infile,1);
1843
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
1844
            use_tooltip = 1;
1845
            break;
1846
 
1847
        case JSCURVE:
7614 schaersvoo 1848
        /*
11806 schaersvoo 1849
         @ jscurve color,formula(x)
1850
         @ alternative : jsplot color,formula(x)
1851
         @ your function will be plotted by the javascript engine of the client browser.
1852
         @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
1853
         @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
1854
         @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
1855
         @ no validity check is done by wims.
1856
         @ 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
1857
         @ 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
1858
         @ use command 'trace_jscurve formula(x)` for tracing
1859
         @ use command 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
1860
         @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
1861
         @ commands plotjump / plotstep are not active for 'jscurve'
1862
         @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
1863
         @ 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...)
1864
        */
1865
            stroke_color = get_color(infile,0);
1866
            if( use_js_math == FALSE){/* add this stuff only once...*/
1867
                add_to_js_math(js_include_file);
1868
                use_js_math = TRUE;
1869
            }
1870
            if( use_js_plot == FALSE){
1871
                use_js_plot = TRUE;
1872
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
1873
            }
1874
            temp = get_string(infile,1);
1875
            temp = str_replace(temp,",","\",\"");
1876
            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]);
1877
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1878
            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]);
1879
            add_to_buffer(tmp_buffer);
1880
            jsplot_cnt++;
1881
             /* we need to create multiple canvasses, so we may zoom and pan ?? */
1882
        break;
1883
 
1884
        case JSMATH:
1885
        /*
1886
            @ jsmath some_math_function
1887
            @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
1888
            @ 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
1889
            @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y'
1890
            @ example: jsmath sin(x^2)
1891
            @ 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...
1892
            @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
1893
        */
1894
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
1895
            if( use_js_math == FALSE){
1896
                add_to_js_math(js_include_file);
1897
                use_js_math = TRUE;
1898
            }
1899
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
1900
            break;
1901
        case KILLAFFINE:
1902
        /*
1903
        @ killaffine
1904
        @ keyword : resets the transformation matrix to 1,0,0,1,0,0
1905
        */
1906
            use_affine = FALSE;
1907
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
1908
            break;
1909
 
1910
        case KILLROTATE:
1911
        /*
1912
         @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
1913
         @ a following rotate command will have the first object point as rotation center
1914
         @ if not set, the rotation center will remain unchanged
1915
        */
1916
            rotation_center= my_newmem(6);
1917
            snprintf(rotation_center,5,"null");
1918
         break;
1919
 
1920
        case KILLSLIDER:
1921
        /*
1922
         @ killslider
1923
         @ keyword (no arguments required)
1924
         @ ends grouping of object under a previously defined slider
1925
        */
1926
            slider = 0;
1927
            break;
1928
 
1929
        case KILLTRANSLATION:
1930
        /*
1931
         @ killtranslation
1932
         @ alternative : killtranslate
1933
         @ resets the translation matrix to 1,0,0,1,0,0
1934
        */
1935
            use_affine = FALSE;
1936
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
1937
            break;
1938
 
1939
        case LINE:
1940
        /*
1941
        @ line x1,y1,x2,y2,color
1942
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
1943
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
9406 schaersvoo 1944
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 1945
        */
8386 schaersvoo 1946
            for(i=0;i<5;i++){
7614 schaersvoo 1947
                switch(i){
11806 schaersvoo 1948
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
1949
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
1950
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
1951
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
1952
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
1953
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
1954
                        double_data[1] = xmin;
1955
                        double_data[3] = ymax;
1956
                        double_data[0] = double_data[10];
1957
                        double_data[2] = double_data[10];
1958
                    }
1959
                    else
1960
                    {
1961
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
1962
                            double_data[1] = double_data[11];
1963
                            double_data[3] = double_data[11];
1964
                            double_data[0] = ymin;
1965
                            double_data[2] = xmax;
1966
                        }
1967
                        else
1968
                        {
1969
                        /* m */
1970
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
1971
                        /* q */
1972
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
1973
 
1974
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
1975
 
1976
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
1977
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
1978
                            double_data[0] = xmin;
1979
                            double_data[2] = xmax;
1980
                        }
1981
                    }
1982
                    decimals = find_number_of_digits(precision);
1983
                    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);
1984
                    if(onclick > 0){click_cnt++;}
1985
                    /* click_cnt++;*/
1986
                    reset();
1987
                    break;
7614 schaersvoo 1988
                }
1989
            }
1990
            break;
8386 schaersvoo 1991
 
11806 schaersvoo 1992
        case LINES:
8370 schaersvoo 1993
        /*
11806 schaersvoo 1994
        @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
1995
        @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
1996
        @ 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)
1997
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1998
        @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a>
8370 schaersvoo 1999
        */
2000
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2001
            fill_color = stroke_color;
2002
            i=0;
2003
            while( ! done ){     /* get next item until EOL*/
2004
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2005
                if(i%2 == 0 ){
2006
                    double_data[i] = get_real(infile,0); /* x */
2007
                }
2008
                else
2009
                {
2010
                    double_data[i] = get_real(infile,1); /* y */
2011
                }
2012
                i++;
2013
            }
2014
            decimals = find_number_of_digits(precision);
2015
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 2016
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
2017
                    double_data[c+1] = xmin;
2018
                    double_data[c+3] = ymax;
2019
                    double_data[c+2] = double_data[c];
2020
                }
2021
                else
2022
                {
2023
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
2024
                        double_data[c+3] = double_data[c+1];
2025
                        double_data[c] = ymin;
2026
                        double_data[c+2] = xmax;
2027
                    }
2028
                    else
2029
                    {
2030
                        /* m */
2031
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
2032
                        /* q */
2033
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
2034
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
2035
                        double_data[c+1] = (m)*(xmin)+(q);
2036
                        double_data[c+3] = (m)*(xmax)+(q);
2037
                        double_data[c] = xmin;
2038
                        double_data[c+2] = xmax;
2039
                    }
2040
                }
2041
                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 2042
                if(onclick > 0){click_cnt++;}
2043
                /* click_cnt++; */
8370 schaersvoo 2044
            }
2045
            reset();
2046
            break;
8386 schaersvoo 2047
 
11806 schaersvoo 2048
 
2049
        case LINEWIDTH:
7614 schaersvoo 2050
        /*
11806 schaersvoo 2051
        @ linewidth int
2052
        @ default 1
7614 schaersvoo 2053
        */
11806 schaersvoo 2054
            line_width = (int) (get_real(infile,1));
2055
            break;
2056
 
2057
        case LATTICE:
2058
        /*
2059
         @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
2060
         @ can <b>not</b> be set "onclick" or "drag xy"
2061
        */
2062
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
2063
            for( i = 0; i<9; i++){
7614 schaersvoo 2064
                switch(i){
11806 schaersvoo 2065
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
2066
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
2067
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
2068
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
2069
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
2070
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
2071
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
2072
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
2073
                    case 8: stroke_color=get_color(infile,1);
7614 schaersvoo 2074
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 2075
                        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);
2076
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2077
                        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);
2078
                        add_to_buffer(tmp_buffer);break;
2079
                    default:break;
7614 schaersvoo 2080
                }
2081
            }
11806 schaersvoo 2082
            reset();
7614 schaersvoo 2083
            break;
8363 schaersvoo 2084
 
11806 schaersvoo 2085
        case LEVELCURVE:
8363 schaersvoo 2086
        /*
11806 schaersvoo 2087
        @ levelcurve color,expression in x/y,l1,l2,...
2088
        @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
2089
        @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
2090
        @ 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
2091
        @ note : the arrays for holding the javascript data are limited in size
2092
        @ 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 2093
        */
11806 schaersvoo 2094
            fill_color = get_color(infile,0);
2095
            char *fun1 = get_string_argument(infile,0);
2096
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
2097
            i = 0;
2098
            done = FALSE;
2099
            while( !done ){
2100
             double_data[i] = get_real(infile,1);
2101
             i++;
2102
            }
2103
            for(c = 0 ; c < i; c++){
2104
             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);
2105
             if(onclick > 0){click_cnt++;}
2106
             /* click_cnt++; */
2107
            }
2108
            reset();
2109
            break;
8386 schaersvoo 2110
 
11806 schaersvoo 2111
        case LEGEND:
2112
        /*
2113
        @ legend string1:string2:string3....string_n
2114
        @ will be used to create a legend for a graph
2115
        @ also see command <a href='#piechart'>'piechart'</a>
2116
        @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default
2117
        @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend")
2118
        */
2119
            temp = get_string(infile,1);
2120
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2121
            legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
2122
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
2123
            break;
2124
 
2125
        case LEGENDCOLORS:
2126
        /*
2127
        @ legendcolors color1:color2:color3:...:color_n
2128
        @ 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
2129
        @ make sure the number of colours match the number of legend items
2130
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
2131
        */
2132
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
2133
            temp = get_string(infile,1);
2134
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2135
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
2136
            break;
2137
 
2138
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
2139
        /*
2140
        @ linegraph x1:y1:x2:y2...x_n:y_n
2141
        @ will plot your data in a graph
2142
        @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
2143
        @ 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>
2144
        @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
2145
        @ also see command <a href='#piechart'>'piechart'</a>
2146
        @ multiple linegraphs may be used in a single plot
2147
        @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
2148
        @ <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>
2149
        */
2150
            temp = get_string(infile,1);
2151
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2152
            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);
2153
            linegraph_cnt++;
2154
            reset();
2155
            break;
2156
 
2157
        case MATHML:
2158
        /*
2159
        @ mathml x1,y1,x2,y2,mathml_string
2160
        @ 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.
2161
        @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor  of the mathml object
2162
        @ 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
2163
        @ 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...
2164
        @ 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
2165
        @ 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
2166
        @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
2167
        @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick  mathml
2168
        @ other drag objects (circles/rects etc) are supported , but read_dragdrop() will probably be difficult to interpret...
2169
        @ 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();"
2170
        @ 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....
2171
        */
2172
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
2173
            for(i=0;i<5;i++){
2174
                switch(i){
2175
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
2176
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
2177
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
2178
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
2179
                    case 4: decimals = find_number_of_digits(precision);
2180
                            temp = get_string(infile,1);
2181
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
2182
                            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);
2183
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2184
                            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);
2185
                            add_to_buffer(tmp_buffer);
2186
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
2187
                            /*
2188
                             in case inputs are present , trigger adding the read_mathml()
2189
                             if no other reply_format is defined
2190
                             note: all other reply types will include a reading of elements with id='mathml'+p)
2191
                             */
2192
                            if(strstr(temp,"mathml0") != NULL){
2193
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
2194
                            }
2195
                            break;
2196
                    default:break;
2197
                }
2198
            }
2199
            reset();
2200
            break;
2201
 
2202
        case MOUSE:
2203
        /*
2204
         @ mouse color,fontsize
2205
         @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
2206
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2207
 
2208
        */
2209
            stroke_color = get_color(infile,0);
2210
            font_size = (int) (get_real(infile,1));
2211
            tmp_buffer = my_newmem(26);
2212
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2213
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
2214
            break;
2215
 
2216
 
2217
        case MOUSE_DEGREE:
2218
        /*
2219
         @ mouse_degree color,fontsize
2220
         @ 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
2221
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
2222
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2223
 
2224
        */
2225
            stroke_color = get_color(infile,0);
2226
            font_size = (int) (get_real(infile,1));
2227
            tmp_buffer = my_newmem(26);
2228
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2229
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2230
            js_function[JS_FIND_ANGLE] = 1;
2231
            break;
2232
        case MOUSE_DISPLAY:
2233
        /*
2234
         @ display TYPE,color,fontsize
2235
         @ TYPE may be x | y | xy | degree | radian | radius
2236
         @ 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)
2237
         @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol)
2238
         @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
2239
        */
2240
        temp = get_string_argument(infile,0);
2241
        if( strstr(temp,"xy") != NULL ){
2242
            int_data[0] = 2;
2243
        }else{
2244
            if( strstr(temp,"y") != NULL ){
2245
                int_data[0] = 1;
2246
            }else{
2247
                if( strstr(temp,"x") != NULL ){
2248
                    int_data[0] = 0;
2249
                }else{
2250
                    if(strstr(temp,"degree") != NULL){
2251
                        int_data[0] = 3;
2252
                        js_function[JS_FIND_ANGLE] = 1;
2253
                    }else{
2254
                        if(strstr(temp,"radian") != NULL){
2255
                            int_data[0] = 4;
2256
                            js_function[JS_FIND_ANGLE] = 1;
2257
                        }else{
2258
                            if(strstr(temp,"radius") != NULL){
2259
                                int_data[0] = 5;
2260
                            }else{
2261
                                int_data[0] = 2;
2262
                            }
2263
                        }
2264
                    }
2265
                }
2266
            }
2267
        }
2268
        stroke_color = get_color(infile,0);
2269
        font_size = (int) (get_real(infile,1));
2270
        tmp_buffer = my_newmem(26);
2271
        snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2272
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2273
        break;
2274
 
2275
        case MOUSE_PRECISION:
2276
        /*
2277
            @ precision int
2278
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
2279
            @ may be used / changed before every object
2280
            @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer
2281
        */
2282
            precision = (int) (get_real(infile,1));
2283
            if(precision < 1 ){precision = 1;};
2284
            break;
2285
 
2286
        case MOUSEX:
2287
        /*
2288
         @ mousex color,fontsize
2289
         @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel
2290
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2291
 
2292
        */
2293
            stroke_color = get_color(infile,0);
2294
            font_size = (int) (get_real(infile,1));
2295
            tmp_buffer = my_newmem(26);
2296
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2297
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2298
            break;
2299
        case MOUSEY:
2300
        /*
2301
         @ mousey color,fontsize
2302
         @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
2303
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2304
 
2305
        */
2306
            stroke_color = get_color(infile,0);
2307
            font_size = (int) (get_real(infile,1));
2308
            tmp_buffer = my_newmem(26);
2309
            snprintf(tmp_buffer,25,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
2310
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2311
            break;
2312
 
2313
        case MULTIDASH:
2314
        /*
2315
         @ multidash 0,1,1
2316
         @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed
2317
         @ use before command <a href='#multidraw'>'multidraw'</a>
2318
         @ 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>
2319
         @ 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)
2320
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2321
         @ always use the same sequence as is used for 'multidraw'
2322
        */
2323
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2324
            temp = get_string(infile,1);
2325
            temp = str_replace(temp,",","\",\"");
2326
            fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
2327
            reset();/* if command 'dashed' was given...reset to not-dashed */
2328
            break;
2329
 
2330
        case MULTIDRAW:
2331
        /*
2332
         @ multidraw obj_type_1,obj_type_2...obj_type_11
2333
         @ for simple single object user drawings you could also use command <a href="#userdraw">'userdraw'</a>
2334
         @ 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>
2335
         @ 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
2336
         @ 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...
2337
         @ 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)
2338
         @ 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'
2339
         @ 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)
2340
         @ multidraw is incompatible with command 'tooltip' (the reserved div_area is used for the multidraw control buttons)
2341
         @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>.
2342
         @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's )
2343
         @ 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>
2344
         @ 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 />
2345
         @ <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.
2346
         @ <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>
2347
        */
2348
        //    if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2349
            if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
2350
            use_userdraw = TRUE;
2351
            /* LET OP max 6 DRAW PRIMITIVES + TEXT */
2352
            temp = get_string(infile,1);
2353
            temp = str_replace(temp,",","\",\"");
2354
            /* if these are not set, set the default values for the 6 (!!!)  draw_primitives + draw_text */
2355
            fprintf(js_include_file,"\
2356
            if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null  ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
2357
            if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
2358
            if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
2359
            if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
2360
            if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2361
            if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2362
            if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2363
            if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
2364
            if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput= ['0','0','0','0','0','0','0','0'];};\
2365
            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];};};};};\
2366
            var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
2367
            stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,
2368
            fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,
2369
            stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,
2370
            fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,
2371
            line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,
2372
            use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,
2373
            use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,
2374
            temp,arrow_head,font_color,font_family);
2375
 
2376
            if(strstr(temp,"text") != NULL){
2377
             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2378
            }
2379
 
2380
            /* the canvasses range from 1000 ... 1008 */
2381
            add_js_multidraw(js_include_file,canvas_root_id,temp,input_style);
2382
            reply_precision = precision;
2383
            if( reply_format == 0){reply_format = 29;}
2384
            reset();/* if command 'filled' / 'dashed' was given...reset all */
2385
            break;
2386
        case MULTILABEL:
2387
        /*
2388
         @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
2389
         @ use before command <a href='#multidraw'>'multidraw'</a>
2390
         @ 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'...)
2391
         @ 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>
2392
         @ 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>
2393
         @ wims will not check the amount or validity of your input
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 multilabel = [\"%s\"];",temp);
2400
            break;
2401
        case MULTILINEWIDTH:
2402
        /*
2403
         @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
2404
         @ use before command <a href='#multidraw'>'multidraw'</a>
2405
         @ if not set all line width will be set by a previous command <em>'linewidth int'</em>
2406
         @ 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>
2407
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2408
         @ always use the same sequence as is used for 'multidraw'
2409
        */
2410
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2411
            temp = get_string(infile,1);
2412
            temp = str_replace(temp,",","\",\"");
2413
            fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
2414
            break;
2415
        case MULTIFILL:
2416
        /*
2417
         @ multifill 0,0,1,0,1,0,0
2418
         @ 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...)
2419
         @ use before command <a href='#multidraw'>'multidraw'</a>
2420
         @ if not set all objects -except point|points-  will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill'
2421
         @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon'
2422
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2423
         @ always use the same sequence as is used for 'multidraw'
2424
        */
2425
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2426
            temp = get_string(infile,1);
2427
            temp = str_replace(temp,",","\",\"");
2428
            fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
2429
            break;
2430
 
2431
        case MULTIFILLCOLORS:
2432
        /*
2433
         @ multifillcolors color_name_1,color_name_2,...,color_name_8
2434
         @ use before command <a href='#multidraw'>'multidraw'</a>
2435
         @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity'
2436
         @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n
2437
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
2438
         @ always use the same sequence as is used for 'multidraw'
2439
         @ 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>
2440
        */
2441
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2442
            fprintf(js_include_file,"var multifillcolors = [");
2443
            while( ! done ){
2444
                temp = get_color(infile,1);
2445
                fprintf(js_include_file,"\"%s\",",temp);
2446
            }
2447
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2448
            break;
2449
 
2450
        case MULTIFILLOPACITY:
2451
        /*
2452
         @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
2453
         @ float values 0 - 1 or integer values 0 - 255
2454
         @ use before command <a href='#multidraw'>'multidraw'</a>
2455
         @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em>
2456
         @ 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>
2457
         @ wims will not check the amount or validity of your input
2458
         @ always use the same sequence as is used for 'multidraw'
2459
        */
2460
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2461
            temp = get_string(infile,1);
2462
            temp = str_replace(temp,",","\",\"");
2463
            fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
2464
            break;
2465
        case MULTISNAPTOGRID:
2466
        /*
2467
         @ multisnaptogrid 0,1,1
2468
         @ 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>)
2469
         @ only the x-values snap_to_grid: <em>multisnaptogrid 0,2,2</em>
2470
         @ only the y-values snap_to_grid: <em>multisnaptogrid 0,3,3</em>
2471
         @ 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
2472
         @ use before command <a href='#multidraw'>'multidraw'</a>
2473
         @ if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw'
2474
         @ 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
2475
         @ always use the same sequence as is used for 'multidraw'
2476
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2477
        */
2478
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2479
            temp = get_string(infile,1);
2480
            temp = str_replace(temp,",","\",\"");
2481
            fprintf(js_include_file,"var multisnaptogrid = [\"%s\"];",temp);
2482
            reset();/* if command 'dashed' was given...reset to not-dashed */
2483
            break;
2484
        case MULTISTROKECOLORS:
2485
        /*
2486
         @ multistrokecolors color_name_1,color_name_2,...,color_name_8
2487
         @ use before command <a href='#multidraw'>'multidraw'</a>
2488
         @ if not set all colors will be 'stroke_color' , 'stroke_opacity'
2489
         @ 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>
2490
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
2491
         @ always use the same sequence as is used for 'multidraw'
2492
        */
2493
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2494
            fprintf(js_include_file,"var multistrokecolors = [");
2495
            while( ! done ){
2496
                temp = get_color(infile,1);
2497
                fprintf(js_include_file,"\"%s\",",temp);
2498
            }
2499
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2500
            break;
2501
        case MULTISTROKEOPACITY:
2502
        /*
2503
         @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
2504
         @ float values 0 - 1 or integer values 0 - 255
2505
         @ use before command <a href='#multidraw'>'multidraw'</a>
2506
         @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em>
2507
         @ 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>
2508
         @ wims will not check the amount or validity of your input
2509
         @ always use the same sequence as is used for 'multidraw'
2510
        */
2511
            if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2512
            temp = get_string(infile,1);
2513
            temp = str_replace(temp,",","\",\"");
2514
            fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
2515
            break;
2516
 
2517
        case MULTIUSERINPUT:
2518
        /*
2519
        @ multiuserinput 0,1,1,0
2520
        @ 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
2521
        @ 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
2522
        @ 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...
2523
        @ in case of a triangle | poly3, three inputfields are provided.
2524
        @ in case of 'text' and multiuserinput=1 , 3 inputfields will be shown : x,y,text
2525
        @ in case of 'text' and multiuserinput=0 , 1 inputfield will be shown : text ... a mouse click will place the text on the canvas.
2526
        @ may be styled using command <a href="#inputstyle">"inputstyle"</a>
2527
        @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&amp;drop' or 'onclick' elements
2528
        @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status'
2529
        @ use before command <a href='#multidraw'>'multidraw'</a>
2530
        @ always use the same sequence as is used for 'multidraw'
2531
        */
2532
            /* simple rawmath and input check */
2533
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2534
            temp = get_string(infile,1);
2535
            temp = str_replace(temp,",","\",\"");
2536
            fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
2537
            break;
2538
 
2539
        case NOXAXIS:
2540
        /*
2541
        @ noaxis
2542
        @ keyword
2543
        @ if set, the automatic x-axis numbering will be ignored
2544
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
2545
        @ to be used before command grid (see <a href="#grid">command grid</a>)
2546
        */
2547
            fprintf(js_include_file,"x_strings = [0,\" \"];\n");
2548
            use_axis_numbering = 1;
2549
            break;
2550
        case NOYAXIS:
2551
        /*
2552
        @ noayis
2553
        @ keyword
2554
        @ if set, the automatic y-axis numbering will be ignored
2555
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="grid">grid</a>
2556
        @ to be used before command grid (see <a href="#grid">command grid</a>)
2557
        */
2558
            fprintf(js_include_file,"y_strings = [0,\" \"];\n");
2559
            use_axis_numbering = 1;
2560
            break;
2561
        case OPACITY:
2562
        /*
2563
        @ opacity 0-255,0-255
2564
        @ opacity 0.0 - 1.0,0.0 - 1.0
2565
        @ alternative : transparent
2566
        @ first item is stroke opacity, second is fill opacity
2567
        */
2568
            for(i = 0 ; i<2;i++){
2569
                switch(i){
2570
                    case 0: double_data[0]= get_real(infile,0);break;
2571
                    case 1: double_data[1]= get_real(infile,1);break;
2572
                    default: break;
2573
                }
2574
            }
2575
            if( double_data[0] > 255 ||  double_data[1] > 255  ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */
2576
            if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = double_data[0];} /* 0.0 - 1.0 */
2577
            if( double_data[0] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = double_data[0];} /* 0.0 - 1.0 */
2578
            break;
2579
 
2580
        case ONCLICK:
2581
        /*
2582
         @ onclick
2583
         @ keyword (no arguments required)
2584
         @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas();
2585
         @ 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'
2586
         @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked.
2587
         @ the click zone (accuracy) is determined by 2&times; the line width of the object
2588
         @ 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...)
2589
         @ note: not all objects may be set onclick
2590
        */
2591
            fprintf(js_include_file,"use_dragdrop_reply = true;");
2592
            onclick = 1;
2593
 
2594
            break;
2595
 
2596
        case PARALLEL:
2597
        /*
2598
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
2599
         @ can <b>not</b> be set "onclick" or "drag xy"
2600
        */
2601
            for( i = 0;i < 8; i++ ){
2602
                switch(i){
2603
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
2604
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
2605
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
2606
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
2607
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
2608
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
2609
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
2610
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
2611
                    decimals = find_number_of_digits(precision);
2612
                    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);
2613
                    if(onclick > 0){click_cnt++;}
2614
                    /* click_cnt++*/;
2615
                    reset();
2616
                    break;
2617
                    default: break;
2618
                }
2619
            }
2620
            break;
2621
 
2622
 
2623
        case PLOTSTEPS:
2624
            /*
2625
             @ plotsteps a_number
2626
             @ default 150
2627
             @ only used for commands <a href="#curve">"curve / plot"</a> and  <a href="#levelcurve">"levelcurve"</a>
2628
             @ use with care !
2629
            */
2630
            plot_steps = (int) (get_real(infile,1));
2631
            break;
2632
 
2633
        case POINT:
2634
        /*
2635
        @ point x,y,color
2636
        @ draw a single point at (x;y) in color 'color'
2637
        @ use command 'linewidth int'  to adust size
2638
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
2639
        @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
2640
        @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range
2641
        */
2642
            for(i=0;i<3;i++){
2643
                switch(i){
2644
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
2645
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
2646
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
2647
                    decimals = find_number_of_digits(precision);
2648
                    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);
2649
                    /* click_cnt++; */
2650
                    if(onclick > 0){click_cnt++;}
2651
                    break;
2652
                    default: break;
2653
                }
2654
            }
2655
            reset();
2656
            break;
2657
 
2658
        case POINTS:
2659
        /*
2660
        @ points color,x1,y1,x2,y2,...,x_n,y_n
2661
        @ draw multiple points at given coordinates in color 'color'
2662
        @ use command 'linewidth int'  to adust size
2663
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
2664
        @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range
2665
        */
8363 schaersvoo 2666
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2667
            fill_color = stroke_color;
2668
            i=0;
2669
            while( ! done ){     /* get next item until EOL*/
2670
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2671
                if(i%2 == 0 ){
2672
                    double_data[i] = get_real(infile,0); /* x */
2673
                }
2674
                else
2675
                {
2676
                    double_data[i] = get_real(infile,1); /* y */
2677
                }
2678
                i++;
2679
            }
2680
            decimals = find_number_of_digits(precision);
11806 schaersvoo 2681
            for(c = 0 ; c < i-1 ; c = c+2){
2682
                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 2683
                /* click_cnt++; */
11806 schaersvoo 2684
                if(onclick > 0){click_cnt++;}
8363 schaersvoo 2685
            }
2686
            reset();
2687
            break;
11806 schaersvoo 2688
 
2689
        case POLY:
2690
        /*
2691
        @ poly color,x1,y1,x2,y2...x_n,y_n
2692
        @ polygon color,x1,y1,x2,y2...x_n,y_n
2693
        @ draw closed polygon
2694
        @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a>
2695
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
2696
        */
2697
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2698
            i=0;
2699
            c=0;
2700
            while( ! done ){     /* get next item until EOL*/
2701
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2702
                for( c = 0 ; c < 2; c++){
2703
                    if(c == 0 ){
2704
                        double_data[i] = get_real(infile,0);
2705
                        i++;
2706
                    }
2707
                    else
2708
                    {
2709
                        double_data[i] = get_real(infile,1);
2710
                        i++;
2711
                    }
2712
                }
2713
            }
2714
            /* draw path :  closed & optional filled */
2715
                decimals = find_number_of_digits(precision);
2716
                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);
2717
                if(onclick > 0){click_cnt++;}
2718
                /* click_cnt++; */
2719
                reset();
2720
            break;
2721
 
7614 schaersvoo 2722
        case POLYLINE:
2723
        /*
2724
        @ polyline color,x1,y1,x2,y2...x_n,y_n
10975 schaersvoo 2725
        @ brokenline color,x1,y1,x2,y2...x_n,y_n
2726
        @ path color,x1,y1,x2,y2...x_n,y_n
2727
        @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n"
2728
        @ 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
2729
        @ 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)
2730
        @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually
9406 schaersvoo 2731
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 2732
        */
2733
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2734
            i=0;
2735
            c=0;
2736
            while( ! done ){     /* get next item until EOL*/
2737
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2738
                for( c = 0 ; c < 2; c++){
2739
                    if(c == 0 ){
2740
                        double_data[i] = get_real(infile,0);
2741
                        i++;
2742
                    }
2743
                    else
2744
                    {
2745
                        double_data[i] = get_real(infile,1);
2746
                        i++;
2747
                    }
2748
                }
2749
            }
2750
            /* draw path : not closed & not filled */
2751
            decimals = find_number_of_digits(precision);
11802 schaersvoo 2752
            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 2753
            if(onclick > 0){click_cnt++;}
2754
            /* click_cnt++;*/
2755
            reset();
7614 schaersvoo 2756
            break;
11806 schaersvoo 2757
 
2758
        case POPUP:
2759
            /*
2760
            @ popup
2761
            @ keyword (no arguments)
2762
            @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
2763
            @ 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'
2764
            @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a>
2765
            @ 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>
2766
            @ 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
2767
            */
2768
            use_tooltip = 2;
2769
            break;
2770
 
2771
        case PROTRACTOR:
7614 schaersvoo 2772
        /*
11806 schaersvoo 2773
         @ protractor x,y,x_width,type,mode,use_a_scale
2774
         @ x,y are the initial location
2775
         @ x_width : give the width in x-coordinate system (e.g. not in pixels !)
2776
         @ type = 1 : a triangle range  0 - 180<br />type = 2 : a circle shape 0 - 360
2777
         @ 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
2778
         @ 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>
2779
         @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable
2780
         @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
2781
         @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor.
2782
         @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision.
2783
         @ if combined with a ruler, use replyformat = 32
2784
         @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor
2785
         @ 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>
2786
         @ only one protractor allowed (for the time being)
2787
         @ 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 2788
        */
11806 schaersvoo 2789
            for( i = 0;i < 6; i++ ){
2790
                switch(i){
2791
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
2792
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
2793
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
2794
                    case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
2795
                    case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
2796
                    case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
2797
                    decimals = find_number_of_digits(precision);
11821 schaersvoo 2798
                    if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
11806 schaersvoo 2799
                    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]);
2800
 
2801
                    string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
2802
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2803
                    snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
2804
                    add_to_buffer(tmp_buffer);
2805
                    reply_precision = precision;
2806
                    /* no reply from protractor if non-interactive */
2807
                    if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
2808
                    break;
2809
                    default: break;
2810
                }
2811
            }
2812
            break;
2813
 
2814
        case PIXELS:
2815
        /*
2816
        @ pixels color,x1,y1,x2,y2,x3,y3...
2817
        @ draw rectangular "points" with diameter 1 pixel
2818
        @ pixels can <b>not</b> be dragged or clicked
2819
        @ "pixelsize = 1" may be changed by command "pixelsize int"
2820
        */
2821
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
2822
            stroke_color=get_color(infile,0);
7614 schaersvoo 2823
            i=0;
2824
            c=0;
2825
            while( ! done ){     /* get next item until EOL*/
2826
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2827
                for( c = 0 ; c < 2; c++){
2828
                    if(c == 0 ){
2829
                        double_data[i] = get_real(infile,0);
2830
                        i++;
2831
                    }
2832
                    else
2833
                    {
2834
                        double_data[i] = get_real(infile,1);
2835
                        i++;
2836
                    }
2837
                }
2838
            }
11806 schaersvoo 2839
            decimals = find_number_of_digits(precision);
2840
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
2841
            string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2842
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2843
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
2844
            add_to_buffer(tmp_buffer);
2845
            reset();
7614 schaersvoo 2846
            break;
11806 schaersvoo 2847
 
2848
        case PIXELSIZE:
7614 schaersvoo 2849
        /*
11806 schaersvoo 2850
        @ pixelsize int
2851
        @ in case you want to deviate from default pixelsize = 1(...)
7614 schaersvoo 2852
        */
11806 schaersvoo 2853
            pixelsize = (int) get_real(infile,1);
2854
        break;
8105 schaersvoo 2855
 
11806 schaersvoo 2856
        case PIECHART:
7614 schaersvoo 2857
        /*
11806 schaersvoo 2858
        @ piechart xc,yc,radius,'data+colorlist'
2859
        @ (xc : yc) center of circle diagram in xrange/yrange
2860
        @ radius in pixels
2861
        @ 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
2862
        @ example data+colorlist : 132:red:23565:green:323:black:234324:orange:23434:yellow:2543:white
2863
        @ the number of colors must match the number of data.
2864
        @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours
2865
        @ 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 2866
        */
11806 schaersvoo 2867
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
7614 schaersvoo 2868
            for(i=0;i<5;i++){
2869
                switch(i){
11806 schaersvoo 2870
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
2871
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
2872
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
2873
                    case 3: temp = get_string(infile,1);
2874
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
2875
                            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);
2876
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2877
                            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);
2878
                            add_to_buffer(tmp_buffer);
2879
                           break;
2880
                    default:break;
7614 schaersvoo 2881
                }
2882
            }
11806 schaersvoo 2883
            reset();
7614 schaersvoo 2884
        break;
8304 schaersvoo 2885
 
7614 schaersvoo 2886
        case RAYS:
2887
        /*
2888
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
2889
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 2890
         @ may be set draggable or onclick (every individual ray)
7614 schaersvoo 2891
        */
2892
            stroke_color=get_color(infile,0);
7786 schaersvoo 2893
            fill_color = stroke_color;
2894
            double_data[0] = get_real(infile,0);/* xc */
2895
            double_data[1] = get_real(infile,0);/* yc */
2896
            i=2;
2897
            while( ! done ){     /* get next item until EOL*/
2898
                if(i > MAX_INT - 1){canvas_error("in command rays to many points / rays in argument: repeat command multiple times to fit");}
2899
                if(i%2 == 0 ){
2900
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 2901
                }
7786 schaersvoo 2902
                else
2903
                {
2904
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 2905
                }
7786 schaersvoo 2906
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
2907
                i++;
7614 schaersvoo 2908
            }
8224 bpr 2909
 
2910
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
2911
            decimals = find_number_of_digits(precision);
7786 schaersvoo 2912
            for(c=2; c<i;c = c+2){
11802 schaersvoo 2913
                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 2914
                /* click_cnt++; */
2915
                if(onclick > 0){click_cnt++;}
7614 schaersvoo 2916
            }
2917
            reset();
2918
            break;
8304 schaersvoo 2919
 
11806 schaersvoo 2920
        case RECT:
8386 schaersvoo 2921
        /*
11806 schaersvoo 2922
        @ rect x1,y1,x2,y2,color
2923
        @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle
2924
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color'
9406 schaersvoo 2925
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8386 schaersvoo 2926
        */
11806 schaersvoo 2927
            for(i=0;i<5;i++){
2928
                switch(i){
2929
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
2930
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
2931
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
2932
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
2933
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
8386 schaersvoo 2934
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 2935
                        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);
2936
                        if(onclick > 0){click_cnt++;}
2937
                        /* click_cnt++; */
8386 schaersvoo 2938
                        reset();
2939
                        break;
11806 schaersvoo 2940
                }
2941
            }
2942
            break;
8386 schaersvoo 2943
 
11806 schaersvoo 2944
        case RECTS:
8304 schaersvoo 2945
        /*
11806 schaersvoo 2946
        @ rects color,x1,y1,x2,y2,.....
2947
        @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle
2948
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....'
2949
        @ use command 'fillcolor color' before 'frects' to set the fill colour.
9406 schaersvoo 2950
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
8304 schaersvoo 2951
        */
2952
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2953
            fill_color = stroke_color;
2954
            i=0;
2955
            while( ! done ){     /* get next item until EOL*/
2956
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
2957
                if(i%2 == 0 ){
2958
                    double_data[i] = get_real(infile,0); /* x */
2959
                }
2960
                else
2961
                {
2962
                    double_data[i] = get_real(infile,1); /* y */
2963
                }
2964
                i++;
2965
            }
2966
            decimals = find_number_of_digits(precision);
2967
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 2968
                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);
2969
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 2970
                /* click_cnt++; */
8304 schaersvoo 2971
            }
2972
            reset();
2973
            break;
8386 schaersvoo 2974
 
11806 schaersvoo 2975
        case REPLYFORMAT:
7614 schaersvoo 2976
        /*
11806 schaersvoo 2977
        @ replyformat number
2978
        @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
2979
        @ default values should be fine !
2980
        @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
2981
        @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
2982
        @ 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>
2983
 
2984
        */
2985
         reply_format = (int) get_real(infile,1);
2986
         reply_precision = precision;
2987
        break;
2988
 
2989
        case ROUNDRECT:
2990
        /*
2991
        @ roundrect x1,y1,x2,y2,radius in px,color
2992
        @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
2993
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color'
2994
        @ fillcolor will be identical to 'color'
9406 schaersvoo 2995
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 2996
        */
11806 schaersvoo 2997
            for(i=0;i<6;i++){
2998
                switch(i){
2999
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
3000
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
3001
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
3002
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
3003
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
3004
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
3005
                        /* ensure no inverted roundrect is produced... */
3006
                        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];}
3007
                        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 3008
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 3009
                        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 3010
                        if(onclick > 0){click_cnt++;}
3011
                        /* click_cnt++;*/
3012
                        reset();
11806 schaersvoo 3013
                    break;
3014
                }
3015
            }
3016
            break;
8386 schaersvoo 3017
 
11806 schaersvoo 3018
        case ROUNDRECTS:
8347 schaersvoo 3019
        /*
11806 schaersvoo 3020
        @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
3021
        @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command
9406 schaersvoo 3022
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
8347 schaersvoo 3023
        */
11806 schaersvoo 3024
 
8347 schaersvoo 3025
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
11806 schaersvoo 3026
            int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
8347 schaersvoo 3027
            fill_color = stroke_color;
3028
            i=0;
3029
            while( ! done ){     /* get next item until EOL*/
3030
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3031
                if(i%2 == 0 ){
3032
                    double_data[i] = get_real(infile,0); /* x */
3033
                }
3034
                else
3035
                {
3036
                    double_data[i] = get_real(infile,1); /* y */
3037
                }
3038
                i++;
3039
            }
3040
            decimals = find_number_of_digits(precision);
3041
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 3042
                /* ensure no inverted roundrect is produced... */
3043
                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];}
3044
                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];}
3045
                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);
3046
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 3047
                /* click_cnt++; */
8347 schaersvoo 3048
            }
3049
            reset();
3050
            break;
8386 schaersvoo 3051
 
11806 schaersvoo 3052
        case RULER:
7614 schaersvoo 3053
        /*
11806 schaersvoo 3054
        @ ruler x,y,x-width ,y-height,mode
3055
        @ x,y are the initial location
3056
        @ x-width , y-height are the ruler dimensions width &amp; height in xy-coordinate system
3057
        @ 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
3058
        @ 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
3059
        @ if combined with a protractor, use replyformat = 32
3060
        @ only one ruler allowed (for the time being)
3061
        @ 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>
3062
        @ 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 3063
        */
11806 schaersvoo 3064
            for( i = 0;i < 5; i++ ){
7614 schaersvoo 3065
                switch(i){
11806 schaersvoo 3066
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
3067
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
3068
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
3069
                    case 3: double_data[3] = get_real(infile,0);break; /* y-width */
3070
                    case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
3071
                    decimals = find_number_of_digits(precision);
3072
                    if( int_data[0] < 0 ){
3073
                      if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
3074
                    }
3075
                    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]);
3076
                    string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
3077
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3078
                    snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
3079
                    add_to_buffer(tmp_buffer);
3080
                    reply_precision = precision;
3081
                    /* no reply from ruler if non-interactive */
3082
                    if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
7614 schaersvoo 3083
                    break;
3084
                    default: break;
3085
                }
3086
            }
3087
            break;
8386 schaersvoo 3088
 
11806 schaersvoo 3089
        case RESETOFFSET:
7614 schaersvoo 3090
        /*
11806 schaersvoo 3091
         @ resetoffset
3092
         @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
3093
         @ 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 3094
        */
11806 schaersvoo 3095
         use_offset = 0;
3096
         break;
3097
 
3098
        case ROTATE:
3099
        /*
3100
         @ rotate rotation_angle
3101
         @ angle in degrees
3102
         @ (only) the next object will be rotated is given angle
3103
         @ positive values rotate counter clockwise
3104
         @ 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)
3105
         @ 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>
3106
         @ 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
3107
        */
3108
            use_rotate = TRUE;
3109
            angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
7614 schaersvoo 3110
            break;
11806 schaersvoo 3111
        case ROTATION_CENTER:
9306 schaersvoo 3112
        /*
11806 schaersvoo 3113
        @ rotationcenter x_center,y_center
3114
        @ define an rotation center in your x/y-coordinate system
3115
        @ wims will not check the validity of your input; use javascript console to debug any erors
3116
        @ if not defined a rotation will be around the first point of an object
3117
        @ to be used before command <a href="#rotate">rotate</a>
3118
        @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
9306 schaersvoo 3119
        */
11806 schaersvoo 3120
            temp = get_string(infile,1);
3121
            string_length = snprintf(NULL,0,"[ %s ]",temp);
3122
            check_string_length(string_length);
3123
            rotation_center = my_newmem(string_length+1);
3124
            snprintf(rotation_center,string_length,"[%s]",temp);
9306 schaersvoo 3125
            break;
11806 schaersvoo 3126
 
3127
        case SIZE:
3128
            /*
3129
            @ size width,height
3130
            @ set canvas size in pixels
3131
            @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>)
3132
            @ 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
3133
            */
3134
            found_size_command = 1;
3135
            /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
3136
            xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
3137
            ysize = (int)(fabs(round(get_real(infile,1))));
3138
            /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
3139
            xmin = 0;xmax = xsize;
3140
            ymin = 0;ymax = ysize;
3141
 
3142
/*
3143
 The sequence in which stuff is finally printed is important !!
3144
*/
3145
fprintf(stdout,"\n\
3146
<script type=\"text/javascript\">\n\
3147
/*<![CDATA[*/\n\
3148
if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
3149
if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
3150
if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
3151
canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
3152
",canvas_root_id);
3153
 
3154
/* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
3155
if( use_tooltip != 2){
3156
 fprintf(stdout,"<!-- canvasdraw div  -->\n\
3157
<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\
3158
<!-- tooltip and input placeholder  -->\n\
3159
<div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
3160
<!-- include actual object code via include file -->\n\
3161
<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);
3162
}
3163
else
3164
{
3165
/*
3166
set canvas_div invisible and do not include placeholder in main html page :
3167
the js-include will also be in a popup window...to be shown when wims $status = done
3168
*/
3169
 fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
3170
<div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
3171
<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>\
3172
<!-- include actual object code via include file -->\n\
3173
<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);
3174
}
3175
 
3176
/* these must be global...it's all really very poor javascript :( */
3177
fprintf(js_include_file,"\n<!-- begin generated javascript include for canvasdraw -->\n\
3178
\"use strict\";\n\
3179
<!-- these variables and functions must be global -->\n\
3180
var read_dragdrop%d;\
3181
var read_canvas%d;\
3182
var set_clock;\
3183
var clear_draw_area%d;\
3184
var update_draw_area%d;\
3185
var draw_boxplot;\
3186
var redraw_all%d;\
3187
var userdraw_primitive;\n\
3188
var wims_canvas_function%d = function(){\n<!-- common used stuff -->\n\
3189
var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
3190
var xsize = %d;\
3191
var ysize = %d;\
3192
var precision = 100;\
3193
var canvas_div = document.getElementById(\"canvas_div%d\");\
3194
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;};\
3195
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;};\
3196
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);};};\
3197
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);};};\
3198
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);};};\
3199
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);};};\
3200
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
3201
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
3202
function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
3203
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) ));};\
3204
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;};\
3205
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;};\
3206
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));\
3207
var x_use_snap_to_grid = 0;var y_use_snap_to_grid = 0;var snap_x = 1;var snap_y = 1;\
3208
var use_snap_to_points = 0;\
3209
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
3210
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\n\
3211
var xlogbase = 10;\
3212
var ylogbase = 10;\
3213
var use_xlogscale = 0;\
3214
var use_ylogscale = 0;\
3215
var x_strings = null;var x_strings_up = null;\
3216
var y_strings = null;\
3217
var use_pan_and_zoom = 0;\
3218
var use_jsmath = 0;\
3219
var xstart = 0;\
3220
var ystart = 0;\
3221
var unit_x=\" \";\
3222
var unit_y=\" \";\
3223
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);
3224
/* default add the drag code : nearly always used ...*/
3225
  add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
3226
 
3227
            break;
3228
 
3229
 
3230
        case SEGMENT:
7614 schaersvoo 3231
        /*
11806 schaersvoo 3232
        @ segment x1,y1,x2,y2,color
3233
        @ alternative : seg
3234
        @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
3235
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
7614 schaersvoo 3236
        */
11806 schaersvoo 3237
            for(i=0;i<5;i++) {
7614 schaersvoo 3238
                switch(i){
11806 schaersvoo 3239
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
3240
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
3241
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
3242
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
3243
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
3244
                        decimals = find_number_of_digits(precision);
3245
                        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);
3246
                        if(onclick > 0){click_cnt++;}
3247
                        /* click_cnt++; */
3248
                        reset();
3249
                        break;
3250
                    default: break;
7614 schaersvoo 3251
                }
3252
            }
3253
            break;
10953 bpr 3254
 
11806 schaersvoo 3255
        case SEGMENTS:
9213 schaersvoo 3256
        /*
11806 schaersvoo 3257
        @ segments color,x1,y1,x2,y2,...,x_n,y_n
3258
        @ alternative : segs
3259
        @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color'
3260
        @ use command 'linewidth int'  to adust size
3261
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
9213 schaersvoo 3262
        */
11806 schaersvoo 3263
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3264
            fill_color = stroke_color;
3265
            i=0;
3266
            while( ! done ){     /* get next item until EOL*/
3267
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3268
                if(i%2 == 0 ){
3269
                    double_data[i] = get_real(infile,0); /* x */
3270
                }
3271
                else
3272
                {
3273
                    double_data[i] = get_real(infile,1); /* y */
3274
                }
3275
                i++;
3276
            }
3277
            decimals = find_number_of_digits(precision);
3278
            for(c = 0 ; c < i-1 ; c = c+4){
3279
                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);
3280
                if(onclick > 0){click_cnt++;}
3281
                /* click_cnt++;*/
3282
            }
3283
            reset();
9213 schaersvoo 3284
            break;
11806 schaersvoo 3285
 
3286
        case SETLIMITS:
9213 schaersvoo 3287
        /*
11806 schaersvoo 3288
            @ setlimits
3289
            @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
3290
            @ may be used for inputfield based zooming / panning
3291
            @ may be styled using command <a href="#inputstyle">inputstyle</a>
3292
            @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc
3293
            @ note:the input value will not be checked on validity
9213 schaersvoo 3294
        */
11806 schaersvoo 3295
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
3296
            add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
3297
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
3298
            use_pan_and_zoom = TRUE;
3299
            done = TRUE;
9213 schaersvoo 3300
            break;
11806 schaersvoo 3301
 
3302
        case SETPIXEL:
9213 schaersvoo 3303
        /*
11806 schaersvoo 3304
        @ setpixel x,y,color
3305
        @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
3306
        @ pixels can <b>not</b> be dragged or clicked
3307
        @ "pixelsize = 1" may be changed by command "pixelsize int"
9213 schaersvoo 3308
        */
11806 schaersvoo 3309
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
3310
            for(i=0;i<3;i++){
3311
                switch(i){
3312
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
3313
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
3314
                    case 2: stroke_color = get_color(infile,1);
3315
                           string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3316
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3317
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3318
                           add_to_buffer(tmp_buffer);
3319
                           break;
3320
                    default:break;
3321
                }
3322
            }
3323
            reset();
3324
        break;
3325
 
3326
 
3327
        case SLIDER:
9213 schaersvoo 3328
        /*
11806 schaersvoo 3329
        @ slider start_value,end_value,width px,height px,<em>type</em>,label
3330
        @ <em>type</em> may be : xy,x,y,angle
3331
        @ 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
3332
        @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit'
3333
        @ 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
3334
        @ use command 'slider' before draggable/clickable objects.
3335
        @ 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>
3336
        @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x'
3337
        @ 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'
3338
        @ amount of sliders is not limited.
3339
        @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
3340
        @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
3341
        @ every draggable object may have its own slider (no limit in amount of sliders)
3342
        @ label: some slider text
3343
        @ use fillcolor for slider ball
3344
        @ use strokecolor for slider bar
3345
        @ use fontfamily / fontcolor to set used fonts
3346
        @ use opacity (only fill opacity will be used) to set transparency
3347
        @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
9213 schaersvoo 3348
        */
11806 schaersvoo 3349
            slider_cnt++;/* slider starts at 1 */
3350
            for(i=0; i<6 ; i++){
3351
                switch(i){
3352
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
3353
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
3354
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
3355
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
3356
                    case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
3357
                            if(strstr(temp,"xy")!= 0){
3358
                                slider = 4;
3359
                            }
3360
                            else
3361
                            {
3362
                                if(strstr(temp,"x") != 0){
3363
                                    slider = 1;
3364
                                }
3365
                                else
3366
                                {
3367
                                    if(strstr(temp,"y") != 0){
3368
                                        slider = 2;
3369
                                    }
3370
                                    else
3371
                                    {
3372
                                        if(strstr(temp,"angle") != 0){ /* angle diplay radian */
3373
                                            slider = 3;
3374
                                        }
3375
                                        else
3376
                                        {
3377
                                            canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
3378
                                        }
3379
                                    }
3380
                                }
3381
                            }
3382
                            if(strstr(temp,"display")!=0){
3383
                                if( slider == 4 ){ /* show x:y */
3384
                                    use_slider_display = 1; /* show x xy values in canvas window */
3385
                                }
3386
                                else
3387
                                {
3388
                                    if( slider == 1 ){ /* show only x -values */
3389
                                     use_slider_display = 10;
3390
                                    }
3391
                                    else
3392
                                    {
3393
                                     use_slider_display = 11; /* show only y -values*/
3394
                                    }
3395
                                }
3396
                            }
3397
                            else
3398
                            {
3399
                                if(strstr(temp,"degree")!= 0){
3400
                                    use_slider_display = 2; /* show angle values in canvas window */
3401
                                }
3402
                                else
3403
                                {
3404
                                    if(strstr(temp,"radian")!=0){
3405
                                        use_slider_display = 3; /* show radian values in canvas window */
3406
                                    }
3407
                                }
3408
                            }
3409
                            if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */
3410
                                add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
3411
                            }
3412
                            if(strstr(temp,"fun")!= 0){
3413
                                if( use_js_math == FALSE){/* add this stuff only once...*/
3414
                                    add_to_js_math(js_include_file); use_js_math = TRUE;
3415
                                }
3416
                                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);
3417
                                slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/
3418
                            }
3419
                            else
3420
                            {
3421
                                fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt);
3422
                                /* we must define these, otherwise 'use stict' will cause an error */
3423
                            }
3424
                    break;
3425
                    case 5: /* some string used for slider description  */
3426
                            if(slider == 4){
3427
                                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);
3428
                            }
3429
                            else
3430
                            {
3431
                                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);
3432
                            }
3433
                    break;
3434
                }
3435
             }
9213 schaersvoo 3436
            break;
11806 schaersvoo 3437
        case SLIDER_X:
9213 schaersvoo 3438
        /*
11806 schaersvoo 3439
         @ sliderfunction_x some_function_in_x
3440
         @ default value "x"
3441
         @ the x-value of the slider object(s) will be calculated with this function.
3442
         @ default is the x-slider value itself
3443
         @ only used by command 'slider'
3444
         @ define before a slider command !
9213 schaersvoo 3445
        */
11806 schaersvoo 3446
         slider_function_x = get_string(infile,1);
3447
        break;
3448
        case SLIDER_Y:
3449
         slider_function_y = get_string(infile,1);
3450
         /*
3451
         @ sliderfunction_y some_function_in_y
3452
         @ default value "y"
3453
         @ the y-value of the slider object(s) will be calculated with this function.
3454
         @ only used by command 'slider'
3455
         @ define before a slider command !
3456
         */
3457
        break;
3458
        case SGRAPH:
3459
        /*
3460
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
3461
         @ primitive implementation of a 'broken scale' graph...
3462
         @ 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 />
3463
         @ 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
3464
        */
3465
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
3466
            for(i = 0 ; i < 8 ;i++){
3467
                switch(i){
3468
                    case 0:double_data[0] = get_real(infile,0);break;
3469
                    case 1:double_data[1] = get_real(infile,0);break;
3470
                    case 2:double_data[2] = get_real(infile,0);break;
3471
                    case 3:double_data[3] = get_real(infile,0);break;
3472
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
3473
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
3474
                    case 6:stroke_color = get_color(infile,0);break;
3475
                    case 7:font_color = get_color(infile,1);
3476
                    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);
3477
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3478
                    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);
3479
                    add_to_buffer(tmp_buffer);
3480
                    break;
3481
                    default:break;
3482
                }
3483
            }
3484
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
9213 schaersvoo 3485
            break;
11806 schaersvoo 3486
 
3487
        case SNAPTOFUNCTION:
9213 schaersvoo 3488
        /*
11806 schaersvoo 3489
        @ snaptofunction some_function_in_x,some_funtion_in_y
3490
        @ alternative : snaptofun some_function_in_x,some_funtion_in_y
3491
        @ the next object will snap to the calculated values
3492
        @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y)
3493
        @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y
3494
        @ for now only one instance of 'snaptofunction' is allowed
3495
        @ use rawmath on your functions: no validity checking is done by wims !
3496
        @ example:<br />....<br />snaptofunction 5*(cos(x),4*sin(y)<br />linewidth 3<br />userdraw points,blue<br />....<br />
3497
        @ example : switching x and y coordinates?<br />snaptofunction y,x
9213 schaersvoo 3498
        */
11806 schaersvoo 3499
        temp = get_string_argument(infile,0);
3500
        fprintf(js_include_file,"\nuse_snap_to_points = 2;");
3501
        if( use_js_math == FALSE){/* add this stuff only once...*/
3502
            add_to_js_math(js_include_file); use_js_math = TRUE;
3503
        }
3504
        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));
3505
        break;
3506
        case SNAPTOPOINTS:
3507
        /*
3508
        @ snaptopoints x1,y1,x2,y2,x3,y3....
3509
        @ a userdraw object will snap to these points.
3510
        @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h)
3511
        @ a draggable object (use command "drag  x|y|xy") will snap to the clossed of these points when dragged (mouseup)
3512
        @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid"
3513
        */
3514
            i = 0;
3515
            while( ! done ){     /* get next item until EOL*/
3516
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3517
                if(i%2 == 0 ){
3518
                    double_data[i] = get_real(infile,0); /* x */
3519
                }
3520
                else
3521
                {
3522
                    double_data[i] = get_real(infile,1); /* y */
3523
                }
3524
                i++;
3525
            }
3526
            decimals = find_number_of_digits(precision);
3527
            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));
3528
        break;
3529
 
3530
        case SNAPTOGRID:
3531
        /*
3532
         @ snaptogrid
3533
         @ keyword (no arguments required)
3534
         @ a draggable object (use command "drag  x|y|xy") will snap to the given grid when dragged (mouseup)
3535
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
3536
         @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
3537
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
3538
         @ 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 />
3539
        */
3540
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 1;");
3541
        break;
3542
 
3543
        case SQUARE:
3544
        /*
3545
        @ square x,y,side (px) ,color
3546
        @ draw a square with left top corner (x:y) with side 'side' in color 'color'
3547
        @ use command 'fsquare x,y,side,color' for a filled square
3548
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'square x,y,side,color'
3549
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
3550
        */
3551
            for(i=0;i<5;i++){
3552
                switch(i){
3553
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
3554
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
3555
                    case 2:double_data[2] = (int) (get_real(infile,0));break; /* width in px */
3556
                    case 3:
3557
                        stroke_color = get_color(infile,1);/* name or hex color */
3558
                        decimals = find_number_of_digits(precision);
3559
                        double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
3560
                        double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
3561
                        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);
3562
                        if(onclick > 0){click_cnt++;}
3563
                        /* click_cnt++; */
3564
                        reset();
3565
                        break;
3566
                }
3567
            }
9213 schaersvoo 3568
            break;
11806 schaersvoo 3569
 
3570
        case STATUS:
9213 schaersvoo 3571
        /*
11806 schaersvoo 3572
        @ status
3573
        @ keyword
3574
        @ alernative : nostatus
3575
        @ used to override the effects of "status=done" in wims (answer.phtml)
3576
        @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands
3577
        @ 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 3578
        */
11806 schaersvoo 3579
 
3580
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
9213 schaersvoo 3581
            break;
11806 schaersvoo 3582
 
3583
        case STRING:
9213 schaersvoo 3584
        /*
11806 schaersvoo 3585
         @ string color,x,y,the text string
3586
         @ may be set "onclick" or "drag xy"
3587
         @ unicode supported: string red,0,0,\\u2232
3588
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
9213 schaersvoo 3589
        */
11806 schaersvoo 3590
            for(i=0;i<5;i++){
3591
                switch(i){
3592
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
3593
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
3594
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
3595
                    case 3: decimals = find_number_of_digits(precision);
3596
                        temp = get_string_argument(infile,1);
3597
                        decimals = find_number_of_digits(precision);
3598
                        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);
3599
                        if(onclick > 0){click_cnt++;}
3600
                        /* click_cnt++;*/
3601
                        reset();
3602
                        break;
3603
                    default:break;
3604
                }
9213 schaersvoo 3605
            }
3606
            break;
11806 schaersvoo 3607
 
3608
        case STRINGUP:
9213 schaersvoo 3609
        /*
11806 schaersvoo 3610
         @ stringup color,x,y,rotation_degrees,the text string
3611
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
3612
         @ unicode supported: stringup red,0,0,45,\\u2232
3613
         @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
3614
 
9213 schaersvoo 3615
        */
11806 schaersvoo 3616
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
3617
            for(i=0;i<6;i++){
3618
                switch(i){
3619
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
3620
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
3621
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
3622
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
3623
                    case 4: decimals = find_number_of_digits(precision);
3624
                            temp = get_string_argument(infile,1);
11811 schaersvoo 3625
                            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 3626
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11811 schaersvoo 3627
                            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 3628
                            add_to_buffer(tmp_buffer);
3629
                            break;
3630
                    default:break;
3631
                }
9213 schaersvoo 3632
            }
11806 schaersvoo 3633
            reset();
9213 schaersvoo 3634
            break;
11767 schaersvoo 3635
 
11806 schaersvoo 3636
        case STYLE:
11767 schaersvoo 3637
        /*
11806 schaersvoo 3638
         @ highlight color,opacity,linewidth
3639
         @ NOT IMPLEMENTED
3640
         @ use command "onclick" : when the object receives a userclick it will increase its linewidth
11767 schaersvoo 3641
        */
3642
            break;
11806 schaersvoo 3643
 
3644
 
3645
        case STROKECOLOR:
9213 schaersvoo 3646
        /*
11806 schaersvoo 3647
        @ strokecolor colorname or #hex
3648
        @ to be used for commands that do not supply a color argument (like command 'linegraph')
9213 schaersvoo 3649
        */
11806 schaersvoo 3650
            stroke_color = get_color(infile,1);
9213 schaersvoo 3651
            break;
11806 schaersvoo 3652
 
3653
        case FLY_TEXT:
9213 schaersvoo 3654
        /*
11806 schaersvoo 3655
        @ text fontcolor,x,y,font,text_string
3656
        @ font may be described by keywords : giant,huge,normal,small,tiny
3657
        @ use command 'fontsize' to increase base fontsize for these keywords
3658
        @ may be set "onclick" or "drag xy"
3659
        @ backwards compatible with flydraw
3660
        @ unicode supported: text red,0,0,huge,\\u2232
3661
        @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
3662
        @ 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 3663
        */
11806 schaersvoo 3664
            for(i = 0; i < 5 ;i++){
3665
                switch(i){
3666
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
3667
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
3668
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
3669
                    case 3: fly_font = get_string_argument(infile,0);
3670
                            if(strcmp(fly_font,"giant") == 0){
3671
                                fly_font_size = (int)(font_size + 24);
3672
                            }
3673
                            else
3674
                            {
3675
                                if(strcmp(fly_font,"huge") == 0){
3676
                                    fly_font_size = (int)(font_size + 14);
3677
                                }
3678
                                else
3679
                                {
3680
                                    if(strcmp(fly_font,"large") == 0){
3681
                                        fly_font_size = (int)(font_size + 6);
3682
                                        }
3683
                                        else
3684
                                        {
3685
                                            if(strcmp(fly_font,"small") == 0){
3686
                                                fly_font_size = (int)(font_size - 4);
3687
                                                if(fly_font_size<0){fly_font_size = 8;}
3688
                                        }
3689
                                    }
3690
                                }
3691
                            }
3692
                            break;
3693
                    case 4:
3694
                        temp = get_string_argument(infile,1);
3695
                        decimals = find_number_of_digits(precision);
3696
                        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);
3697
                        if(onclick > 0){click_cnt++;}
3698
                        /* click_cnt++;*/
3699
                        reset();
3700
                        break;
3701
                    default:break;
3702
                }
10953 bpr 3703
            }
9213 schaersvoo 3704
            break;
11806 schaersvoo 3705
        case TEXTAREA:
9289 schaersvoo 3706
        /*
11806 schaersvoo 3707
         @ textarea x,y,cols,rows,readonly,value
3708
         @ may be further controlled by <a href="#inputstyle">"inputstyle"</a>
3709
         @ 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>
3710
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
3711
         @ keyword 'xoffset | centered' is not active for commande 'textarea'
9289 schaersvoo 3712
        */
11806 schaersvoo 3713
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
3714
            for(i = 0 ; i<6;i++){
9289 schaersvoo 3715
                switch(i){
11806 schaersvoo 3716
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
3717
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
3718
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
3719
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
3720
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
3721
                    case 5: temp = get_string_argument(infile,1);
3722
                            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);
3723
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3724
                            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);
3725
                            add_to_buffer(tmp_buffer);
3726
                            input_cnt++;break;
9289 schaersvoo 3727
                    default: break;
3728
                }
3729
            }
11806 schaersvoo 3730
            if(reply_format == 0 ){reply_format = 15;}
3731
            reset();
9289 schaersvoo 3732
            break;
11806 schaersvoo 3733
 
3734
        case FLY_TEXTUP:
9289 schaersvoo 3735
        /*
11806 schaersvoo 3736
         @ textup fontcolor,x,y,font,text_string
3737
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
3738
         @ font may be described by keywords : giant,huge,normal,small,tiny
3739
         @ use command 'fontsize' to increase base fontsize for the keywords
3740
         @ backwards compatible with flydraw
3741
         @ unicode supported: textup red,0,0,huge,\\u2232
3742
         @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
3743
         @ 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 3744
        */
11806 schaersvoo 3745
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
3746
            for(i = 0; i<5 ;i++){
9289 schaersvoo 3747
                switch(i){
11806 schaersvoo 3748
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
3749
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
3750
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
3751
                    case 3: fly_font = get_string_argument(infile,0);
3752
                            if(strcmp(fly_font,"giant") == 0){
3753
                                fly_font_size = (int)(font_size + 24);
3754
                            }
3755
                            else
3756
                            {
3757
                                if(strcmp(fly_font,"huge") == 0){
3758
                                    fly_font_size = (int)(font_size + 14);
3759
                                }
3760
                                else
3761
                                {
3762
                                    if(strcmp(fly_font,"large") == 0){
3763
                                        fly_font_size = (int)(font_size + 6);
3764
                                        }
3765
                                        else
3766
                                        {
3767
                                            if(strcmp(fly_font,"small") == 0){
3768
                                                fly_font_size = (int)(font_size - 4);
3769
                                                if(fly_font_size<0){fly_font_size = 8;}
3770
                                        }
3771
                                    }
3772
                                }
3773
                            }
3774
                            break;
3775
                    case 4:
9289 schaersvoo 3776
                    decimals = find_number_of_digits(precision);
11806 schaersvoo 3777
                    temp = get_string_argument(infile,1);
11811 schaersvoo 3778
                    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 3779
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11811 schaersvoo 3780
                    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 3781
                    add_to_buffer(tmp_buffer);
3782
                    break;
11806 schaersvoo 3783
                    default:break;
3784
                }
3785
            }
3786
            reset();
3787
            break;
3788
 
3789
 
3790
        case TRACE_JSCURVE:
3791
        /*
3792
         @ trace_jscurve some_math_function
3793
         @ will use a crosshair to trace the jsmath curve
3794
         @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
3795
         @ 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
3796
         @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
3797
         @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair.
3798
         @ 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...
3799
        @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
3800
        */
3801
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
3802
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
3803
            if( use_js_math == FALSE){
3804
                add_to_js_math(js_include_file);
3805
                use_js_math = TRUE;
3806
            }
3807
            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);
3808
            break;
3809
 
3810
 
3811
        case TRANGE:
3812
        /*
3813
        @ trange tmin,tmax
3814
        @ alternative : ranget
3815
        @ default -2,2
3816
        */
3817
            use_parametric = TRUE;
3818
            for(i = 0 ; i<2; i++){
3819
                switch(i){
3820
                    case 0: tmin = get_real(infile,0);break;
3821
                    case 1: tmax = get_real(infile,1);break;
9289 schaersvoo 3822
                    default: break;
3823
                }
3824
            }
11806 schaersvoo 3825
            if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
9289 schaersvoo 3826
            break;
11806 schaersvoo 3827
        case TRANSLATION:
3828
        /*
3829
         @ translation tx,ty
3830
         @ alternative : translate
3831
         @ will translate the next objects tx in xrange and ty in yrange
3832
         @ use command 'killtranstation' to end the command
3833
        */
3834
            for(i = 0 ; i<2;i++){
3835
                switch(i){
3836
                    case 0: double_data[0] = get_real(infile,0);break;
3837
                    case 1: double_data[1] = get_real(infile,1);
3838
                        use_affine = TRUE;
3839
                        decimals = find_number_of_digits(precision);
3840
                        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));
3841
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
3842
                        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));
3843
                        break;
3844
                    default: break;
3845
                }
3846
            }
3847
        break;
3848
 
3849
        case TRIANGLE:
3850
        /*
3851
         @ triangle x1,y1,x2,y2,x3,y3,color
3852
         @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle
3853
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
3854
        */
3855
            for(i=0;i<7;i++){
3856
                switch(i){
3857
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
3858
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
3859
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
3860
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
3861
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
3862
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
3863
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
3864
                        decimals = find_number_of_digits(precision);
3865
                        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);
3866
                        if(onclick > 0){click_cnt++;}
3867
                        /* click_cnt++;*/
3868
                        reset();
3869
                        break;
3870
                    default: break;
3871
                }
3872
            }
3873
            break;
3874
        case TRIANGLES:
3875
        /*
3876
         @ triangles color,x1,y1,x2,y2,x3,y3,...
3877
         @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles
3878
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
3879
        */
3880
            stroke_color = get_color(infile,0);/* name or hex color */
3881
            i = 0;
3882
            decimals = find_number_of_digits(precision);
3883
            while( ! done ){
3884
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
3885
                double_data[0] = get_real(infile,0); /* x1 */
3886
                double_data[1] = get_real(infile,0); /* y1 */
3887
                double_data[2] = get_real(infile,0); /* x2 */
3888
                double_data[3] = get_real(infile,0); /* y2 */
3889
                double_data[4] = get_real(infile,0); /* x3 */
3890
                double_data[5] = get_real(infile,1); /* y3 */
3891
                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);
3892
                if(onclick > 0){click_cnt++;}
3893
                i = i + 6;
3894
            }
3895
            reset();
3896
            break;
3897
        case USERBOXPLOT:
3898
        /*
3899
         @ userboxplot
3900
         @ keyword, no arguments
3901
         @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
3902
         @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function
3903
         @ 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)
3904
        */
3905
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
3906
            fprintf(js_include_file,"var boxplot_source = 3;\n");
3907
            js_function[DRAW_JSBOXPLOT] = 2;
3908
        break;
3909
 
3910
        case USERBOXPLOTDATA:
3911
        /*
3912
         @ userboxplotdata
3913
         @ keyword, no arguments
3914
         @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
3915
         @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data"
3916
         @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
3917
         @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()'
3918
        */
3919
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
3920
            fprintf(js_include_file,"var boxplot_source = 2;\n");
3921
            js_function[DRAW_JSBOXPLOT] = 1;
3922
 
3923
        break;
3924
 
7614 schaersvoo 3925
        case USERDRAW:
3926
        /*
3927
        @ userdraw object_type,color
9213 schaersvoo 3928
        @ only a single object_type is allowed.
9385 schaersvoo 3929
        @ for multiple object user drawings use command <a href="#multidraw">'multidraw'</a>
11764 schaersvoo 3930
        @ 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 3931
        @ 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)
3932
        @ 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 3933
        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 3934
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
3935
        @ 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 3936
        @ use command "filled", "opacity int,int"  and "fillcolor color" to trigger coloured filling of fillable objects
8224 bpr 3937
        @ use command "dashed" and/or "dashtype int,int" to trigger dashing
7614 schaersvoo 3938
        @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas();
3939
        @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very usefull...)
10953 bpr 3940
        @ may be combined with keyword 'userinput_xy'
11088 schaersvoo 3941
        @ 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 3942
        */
3943
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
9213 schaersvoo 3944
                canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
7614 schaersvoo 3945
            }
8074 schaersvoo 3946
            reply_precision = precision;
7614 schaersvoo 3947
            use_userdraw = TRUE;
11041 schaersvoo 3948
            fprintf(js_include_file,"\n<!-- begin userdraw mouse events -->\nuserdraw_x = new Array();userdraw_y = new Array();\
3949
            userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
11001 schaersvoo 3950
            var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
3951
            if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
3952
            if(wims_status != \"done\"){\
11006 schaersvoo 3953
            canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
3954
            canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
3955
            canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
3956
            canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
3957
            canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
11001 schaersvoo 3958
            }\n<!-- end userdraw mouse & touch events -->",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
7614 schaersvoo 3959
            draw_type = get_string_argument(infile,0);
3960
            stroke_color = get_color(infile,1);
3961
            if( strcmp(draw_type,"point") == 0 ){
3962
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 3963
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 3964
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 3965
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 3966
                if(use_input_xy == 1){
7652 schaersvoo 3967
                    add_input_circle(js_include_file,1,1);
8815 schaersvoo 3968
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 3969
                }
7614 schaersvoo 3970
                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);
3971
            }
3972
            else
3973
            if( strcmp(draw_type,"points") == 0 ){
3974
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 3975
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 3976
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 3977
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 3978
                if(use_input_xy == 1){
7652 schaersvoo 3979
                    add_input_circle(js_include_file,1,2);
8815 schaersvoo 3980
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 3981
                }
7614 schaersvoo 3982
                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);
3983
            }
3984
            else
3985
            if( strcmp(draw_type,"segment") == 0 ){
3986
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
3987
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 3988
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 3989
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 3990
                if(use_input_xy == 1){
7652 schaersvoo 3991
                    add_input_segment(js_include_file,1);
8815 schaersvoo 3992
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 3993
                }
7614 schaersvoo 3994
                add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
3995
            }
3996
            else
10975 schaersvoo 3997
            if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
7663 schaersvoo 3998
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 3999
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 4000
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 4001
                if( use_input_xy == 1 ){
4002
                    add_input_polyline(js_include_file);
8815 schaersvoo 4003
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7663 schaersvoo 4004
                }
4005
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4006
            }
4007
            else
7614 schaersvoo 4008
            if( strcmp(draw_type,"segments") == 0 ){
4009
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4010
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 4011
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 4012
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4013
                if(use_input_xy == 1){
7652 schaersvoo 4014
                    add_input_segment(js_include_file,2);
8815 schaersvoo 4015
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4016
                }
7614 schaersvoo 4017
                add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4018
            }
4019
            else
4020
            if( strcmp(draw_type,"circle") == 0 ){
4021
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4022
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 4023
                /* 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 4024
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4025
                if(use_input_xy == 1){
7652 schaersvoo 4026
                    add_input_circle(js_include_file,2,1);
8815 schaersvoo 4027
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4028
                }
7614 schaersvoo 4029
                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]);
4030
            }
4031
            else
4032
            if( strcmp(draw_type,"circles") == 0 ){
4033
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4034
                if(reply_format == 0){reply_format = 10;}
7614 schaersvoo 4035
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
4036
                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 4037
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4038
                if(use_input_xy == 1){
7652 schaersvoo 4039
                    add_input_circle(js_include_file,2,2);
8815 schaersvoo 4040
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4041
                }
7614 schaersvoo 4042
            }
4043
            else
4044
            if(strcmp(draw_type,"crosshair") == 0 ){
4045
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4046
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4047
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
4048
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 4049
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4050
                if(use_input_xy == 1){
7654 schaersvoo 4051
                    add_input_crosshair(js_include_file,1);
8815 schaersvoo 4052
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4053
                }
7614 schaersvoo 4054
            }
4055
            else
4056
            if(strcmp(draw_type,"crosshairs") == 0 ){
4057
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4058
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4059
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
4060
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity);
8071 schaersvoo 4061
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4062
                if(use_input_xy == 1){
7654 schaersvoo 4063
                    add_input_crosshair(js_include_file,2);
8815 schaersvoo 4064
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4065
                }
7614 schaersvoo 4066
            }
4067
            else
4068
            if(strcmp(draw_type,"freehandline") == 0 ){
4069
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4070
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4071
                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 4072
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4073
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4074
            }
4075
            else
4076
            if(strcmp(draw_type,"freehandlines") == 0 ){
4077
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4078
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4079
                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 4080
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4081
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4082
            }
4083
            else
4084
            if(strcmp(draw_type,"path") == 0 ){
4085
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4086
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4087
                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 4088
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4089
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4090
            }
4091
            else
4092
            if(strcmp(draw_type,"paths") == 0 ){
4093
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4094
                if(reply_format == 0){reply_format = 6;}
8224 bpr 4095
                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 4096
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4097
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4098
            }
4099
            else
4100
            if(strcmp(draw_type,"arrows") == 0 ){
4101
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4102
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4103
                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 4104
                if(use_input_xy == 1){
7654 schaersvoo 4105
                    add_input_arrow(js_include_file,2);
8815 schaersvoo 4106
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4107
                }
8071 schaersvoo 4108
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4109
            }
4110
            else
7874 schaersvoo 4111
            if(strcmp(draw_type,"arrows2") == 0 ){
4112
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4113
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4114
                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 4115
                if(use_input_xy == 1){
7874 schaersvoo 4116
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4117
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4118
                }
8071 schaersvoo 4119
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4120
            }
4121
            else
4122
            if(strcmp(draw_type,"arrow2") == 0 ){
4123
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4124
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4125
                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 4126
                if(use_input_xy == 1){
7874 schaersvoo 4127
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4128
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4129
                }
8071 schaersvoo 4130
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4131
            }
4132
            else
7614 schaersvoo 4133
            if(strcmp(draw_type,"arrow") == 0 ){
4134
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4135
                if(reply_format == 0){reply_format = 11;}
7874 schaersvoo 4136
                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 4137
                if(use_input_xy == 1){
7654 schaersvoo 4138
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4139
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4140
                }
8071 schaersvoo 4141
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4142
            }
4143
            else
4144
            if(strcmp(draw_type,"polygon") == 0){
4145
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4146
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4147
                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 4148
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4149
                if(use_input_xy == 2){
7780 schaersvoo 4150
                  add_textarea_polygon(js_include_file);
8815 schaersvoo 4151
                  add_textarea_xy(js_include_file,canvas_root_id,input_style);
7746 schaersvoo 4152
                }
7614 schaersvoo 4153
            }
8224 bpr 4154
            else
7614 schaersvoo 4155
            if(strncmp(draw_type,"poly",4) == 0){
4156
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
4157
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4158
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4159
                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 4160
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4161
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4162
            }
8224 bpr 4163
            else
7614 schaersvoo 4164
            if(strcmp(draw_type,"triangle") == 0){
4165
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4166
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4167
                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 4168
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4169
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4170
            }
8224 bpr 4171
            else
7989 schaersvoo 4172
            if( strcmp(draw_type,"hline") == 0 ){
4173
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4174
                if(reply_format == 0){reply_format = 11;}
4175
                add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4176
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4177
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4178
            }
4179
            else
4180
            if( strcmp(draw_type,"hlines") == 0 ){
4181
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4182
                if(reply_format == 0){reply_format = 11;}
4183
                add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4184
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4185
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4186
            }
4187
            else
4188
            if( strcmp(draw_type,"vline") == 0 ){
4189
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4190
                if(reply_format == 0){reply_format = 11;}
4191
                add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4192
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4193
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4194
            }
4195
            else
4196
            if( strcmp(draw_type,"vlines") == 0 ){
4197
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4198
                if(reply_format == 0){reply_format = 11;}
4199
                add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
8071 schaersvoo 4200
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4201
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4202
            }
4203
            else
7614 schaersvoo 4204
            if( strcmp(draw_type,"line") == 0 ){
4205
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4206
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4207
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 4208
                add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 4209
                if( use_input_xy == 1 ){
7780 schaersvoo 4210
                    add_input_line(js_include_file,1);
8815 schaersvoo 4211
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7747 schaersvoo 4212
                }
8071 schaersvoo 4213
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4214
            }
4215
            else
4216
            if( strcmp(draw_type,"lines") == 0 ){
4217
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4218
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4219
                if(reply_format == 0){reply_format = 11;}
7614 schaersvoo 4220
                add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
7747 schaersvoo 4221
                if( use_input_xy == 1 ){
7780 schaersvoo 4222
                    add_input_line(js_include_file,2);
8815 schaersvoo 4223
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7746 schaersvoo 4224
                }
8071 schaersvoo 4225
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4226
            }
4227
            else
8362 schaersvoo 4228
            if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
8244 schaersvoo 4229
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4230
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4231
                if(reply_format == 0){reply_format = 11;}
4232
                add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4233
                if( use_input_xy == 1 ){
4234
                    add_input_demiline(js_include_file,2);
8815 schaersvoo 4235
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4236
                }
4237
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4238
            }
4239
            else
8362 schaersvoo 4240
            if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
8244 schaersvoo 4241
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4242
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4243
                if(reply_format == 0){reply_format = 11;}
4244
                add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1]);
4245
                if( use_input_xy == 1 ){
4246
                    add_input_demiline(js_include_file,1);
8815 schaersvoo 4247
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4248
                }
4249
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4250
            }
4251
            else
7614 schaersvoo 4252
            if( strcmp(draw_type,"rects") == 0){
4253
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 4254
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4255
                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 4256
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4257
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4258
            }
8224 bpr 4259
            else
7614 schaersvoo 4260
            if( strcmp(draw_type,"roundrects") == 0){
4261
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 4262
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4263
                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 4264
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4265
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4266
            }
8224 bpr 4267
            else
7614 schaersvoo 4268
            if( strcmp(draw_type,"rect") == 0){
4269
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
7876 schaersvoo 4270
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4271
                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 4272
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4273
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4274
            }
8224 bpr 4275
            else
7614 schaersvoo 4276
            if( strcmp(draw_type,"roundrect") == 0){
4277
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
7876 schaersvoo 4278
                if(reply_format == 0){reply_format = 2;}
7614 schaersvoo 4279
                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 4280
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4281
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4282
            }
4283
            else
8083 schaersvoo 4284
            if( strcmp(draw_type,"arcs") == 0){
4285
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
4286
                if(reply_format == 0){reply_format = 25;}
4287
                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]);
4288
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4289
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4290
            }
4291
            else
8071 schaersvoo 4292
            if( strcmp(draw_type,"arc") == 0){
4293
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
11017 schaersvoo 4294
                if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
8083 schaersvoo 4295
                if(reply_format == 0){reply_format = 25;}
4296
                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 4297
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4298
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4299
            }
4300
            else
7614 schaersvoo 4301
            if( strcmp(draw_type,"text") == 0){
7876 schaersvoo 4302
                if(reply_format == 0){reply_format = 17;}
11084 schaersvoo 4303
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity);
7652 schaersvoo 4304
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4305
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4306
            }
8116 schaersvoo 4307
            else
4308
            if( strcmp(draw_type,"inputs") == 0){
8224 bpr 4309
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 4310
                if(reply_format == 0){reply_format = 27;}
11803 schaersvoo 4311
                add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset);
8116 schaersvoo 4312
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4313
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4314
            }
4315
            else
4316
            if( strcmp(draw_type,"input") == 0){
8224 bpr 4317
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 4318
                if(reply_format == 0){reply_format = 27;}
11803 schaersvoo 4319
                add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset);
8116 schaersvoo 4320
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4321
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4322
            }
8193 schaersvoo 4323
            else
11005 schaersvoo 4324
            if( strcmp(draw_type,"clickfill") == 0){
4325
                decimals = find_number_of_digits(precision);
4326
                if(reply_format == 0){reply_format = 22;}
4327
                add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215));
4328
                if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
4329
                 js_function[DRAW_FILLTOBORDER] = 1;
11006 schaersvoo 4330
                 add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
11005 schaersvoo 4331
                }
4332
            }
4333
            else
7614 schaersvoo 4334
            {
4335
                canvas_error("unknown drawtype or typo? ");
4336
            }
4337
            reset();
4338
        break;
8386 schaersvoo 4339
 
4340
        case USERINPUT:
4341
        /*
4342
         @ userinput function | textarea | inputfield
9382 schaersvoo 4343
         @ alternative : userinput_function
4344
         @ alternative : userinput_textarea
4345
         @ alternative : userinput_xy
8386 schaersvoo 4346
         @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
4347
         @ function may be used any time (e.g. without userdraw)
8815 schaersvoo 4348
         @ multiple 'userinput function' commands may be used.
8386 schaersvoo 4349
         @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)="
4350
         @ use command 'strokecolor some_color' to adjust the plot / functionlabel color
8815 schaersvoo 4351
         @ use command 'inputstyle some_css' to adjust the inputfields
4352
         @ use command 'fontsize int' to adjust the label fonts. (default 12px)
4353
         @ 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 4354
        */
4355
            temp = get_string_argument(infile,1);
4356
            if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
4357
             if( js_function[DRAW_JSFUNCTION] != 1 ){
4358
              add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
4359
              js_function[DRAW_JSFUNCTION] = 1;
4360
              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 4361
              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 4362
              input_cnt++;
4363
             }
10953 bpr 4364
             else
8386 schaersvoo 4365
             {
4366
              /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
8815 schaersvoo 4367
              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 4368
              input_cnt++;
4369
             }
4370
             if( use_js_math == FALSE){/* add this stuff only once...*/
4371
              add_to_js_math(js_include_file);
4372
              use_js_math = TRUE;
4373
             }
4374
             if( use_js_plot == FALSE){
4375
              use_js_plot = TRUE;
4376
              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
4377
             }
4378
            }
4379
            else
4380
            {
4381
             if(strstr(temp,"inputfield") != 0 ){
4382
              if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
4383
              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4384
              use_input_xy = 1;
4385
             }
4386
             else
4387
             {
4388
              if(strstr(temp,"textarea") != 0 ){
4389
               if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
4390
               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4391
               use_input_xy = 2;
4392
              }
4393
              else
4394
              {
4395
                canvas_error("userinput argument may be \"function,inputfield,textarea\"");
4396
              }
4397
             }
4398
            }
4399
            break;
4400
        case USERINPUT_XY:
4401
        /*
4402
        @ userinput_xy
9372 schaersvoo 4403
        @ keyword (no arguments required)
8386 schaersvoo 4404
        @ to be used in combination with command "userdraw object_type,color"
4405
        @ 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)
4406
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
4407
        @ 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 4408
        @ can <b>not</b> be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
8386 schaersvoo 4409
        @ user drawings will not zoom on zooming (or pan on panning)
8815 schaersvoo 4410
        @ use command 'inputstyle some_css' to adjust the inputarea.
4411
        @ use command 'fontsize int' to adjust the text labels (if needed)
8386 schaersvoo 4412
        */
4413
            /* add simple eval check to avoid code injection with unprotected eval(string) */
4414
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
4415
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4416
            use_input_xy = 1;
4417
            break;
4418
 
4419
        case USERINPUT_FUNCTION:
4420
        /*
4421
        @ userinput_function
9372 schaersvoo 4422
        @ keyword (no arguments required)
8386 schaersvoo 4423
        @ if set , a inputfield will be added to the page
4424
        @ repeat keyword for more function input fields
4425
        @ the userinput value will be plotted in the canvas
10953 bpr 4426
        @ 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 4427
        @ 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 4428
        @ fontsize can be set using command 'fontsize int'
8386 schaersvoo 4429
        @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
4430
        */
4431
            if( js_function[DRAW_JSFUNCTION] != 1 ){
4432
             js_function[DRAW_JSFUNCTION] = 1;
4433
             add_rawmath(js_include_file);
4434
             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 4435
             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 4436
             input_cnt++;
4437
            }
10953 bpr 4438
            else
8386 schaersvoo 4439
            {
4440
              /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
8815 schaersvoo 4441
             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 4442
             input_cnt++;
4443
            }
4444
            if( use_js_math == FALSE){/* add this stuff only once...*/
4445
             add_to_js_math(js_include_file);
4446
             use_js_math = TRUE;
4447
            }
4448
            if( use_js_plot == FALSE){
4449
             use_js_plot = TRUE;
4450
             add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
4451
            }
4452
            break;
4453
 
4454
 
4455
 
11806 schaersvoo 4456
        case USERTEXTAREA_XY:
7788 schaersvoo 4457
        /*
11806 schaersvoo 4458
        @ usertextarea_xy
4459
        @ keyword (no arguments required)
4460
        @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
4461
        @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
4462
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
4463
        @ user drawings will not zoom on zooming (or pan on panning)
4464
        @ use command 'inputstyle some_css' to adjust the inputarea.
4465
        @ use command 'fontsize int' to adjust the text labels (if needed)
7788 schaersvoo 4466
        */
11806 schaersvoo 4467
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
4468
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
4469
            use_input_xy = 2;
7788 schaersvoo 4470
            break;
8386 schaersvoo 4471
 
11806 schaersvoo 4472
        case VLINE:
8386 schaersvoo 4473
        /*
11806 schaersvoo 4474
        @ vline x,y,color
4475
        @ alternative : verticalline
4476
        @ draw a vertical line through point (x:y) in color 'color'
4477
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8386 schaersvoo 4478
        */
11806 schaersvoo 4479
            for(i=0;i<3;i++) {
7614 schaersvoo 4480
                switch(i){
11806 schaersvoo 4481
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
4482
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
4483
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
4484
                        double_data[2] = double_data[0];
7614 schaersvoo 4485
                        decimals = find_number_of_digits(precision);
11806 schaersvoo 4486
                        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);
4487
                        if(onclick > 0){click_cnt++;}
4488
                        /* click_cnt++; */
8379 schaersvoo 4489
                        reset();
7614 schaersvoo 4490
                    break;
4491
                }
4492
            }
4493
            break;
4494
 
11806 schaersvoo 4495
        case VLINES:
11802 schaersvoo 4496
        /*
11806 schaersvoo 4497
        @ vlines color,x1,y1,x2,y2....
4498
        @ alternative : verticallines
4499
        @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
4500
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
11802 schaersvoo 4501
        */
11806 schaersvoo 4502
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
4503
            fill_color = stroke_color;
4504
            i=0;
4505
            while( ! done ){     /* get next item until EOL*/
4506
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
4507
                if(i%2 == 0 ){
4508
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 4509
                }
11806 schaersvoo 4510
                else
4511
                {
4512
                    double_data[i] = get_real(infile,1); /* y */
7983 schaersvoo 4513
                }
11806 schaersvoo 4514
                i++;
7983 schaersvoo 4515
            }
11806 schaersvoo 4516
            decimals = find_number_of_digits(precision);
4517
            for(c = 0 ; c < i-1 ; c = c+2){
4518
                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);
4519
                if(onclick > 0){click_cnt++;}
4520
                /* click_cnt++; */
4521
            }
4522
            reset();
7983 schaersvoo 4523
            break;
11806 schaersvoo 4524
 
4525
 
4526
        case VIDEO:
7614 schaersvoo 4527
        /*
11806 schaersvoo 4528
        @ video x,y,w,h,videofile location
4529
        @ x,y : left top corner of audio element (in xrange / yrange)
4530
        @ w,y : width and height in pixels
4531
        @ example:<br />wims getfile : video 0,0,120,120,myvideo.mp4
4532
        @ video format may be in *.mp4 (todo:other formats)
7614 schaersvoo 4533
        */
11806 schaersvoo 4534
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
7614 schaersvoo 4535
            for(i=0;i<5;i++){
4536
                switch(i){
11806 schaersvoo 4537
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
4538
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
4539
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
4540
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
4541
                    case 4: temp = get_string(infile,1);
4542
                            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 4543
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11806 schaersvoo 4544
                            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 4545
                            add_to_buffer(tmp_buffer);
4546
                            break;
4547
                    default:break;
4548
                }
4549
            }
4550
            reset();
4551
            break;
11806 schaersvoo 4552
 
7614 schaersvoo 4553
        case X_AXIS_STRINGS:
4554
        /*
4555
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9385 schaersvoo 4556
         @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9346 schaersvoo 4557
         @ use these x-axis num1...num_n values instead of default xmin...xmax
11044 schaersvoo 4558
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
4559
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
11088 schaersvoo 4560
         @ 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 4561
         @ a javascript error message will flag non-matching value:name pairs
9341 schaersvoo 4562
         @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied
11044 schaersvoo 4563
         @ to be used before command grid (see <a href="#grid">command grid</a>)
7614 schaersvoo 4564
         @ 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
4565
        */
4566
            temp = get_string(infile,1);
4567
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
4568
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
4569
            fprintf(js_include_file,"x_strings = [\"%s\"];\n ",temp);
4570
            use_axis_numbering = 1;
4571
            break;
9341 schaersvoo 4572
        case X_AXIS_STRINGS_UP:
4573
        /*
4574
         @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9385 schaersvoo 4575
         @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9341 schaersvoo 4576
         @ the text will be rotated 90&deg; up
11044 schaersvoo 4577
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
4578
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
9346 schaersvoo 4579
         @ use these x-axis num1...num_n values instead of default xmin...xmax
11088 schaersvoo 4580
         @ 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 4581
         @ a javascript error message will flag non-matching value:name pairs
9341 schaersvoo 4582
         @ 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 4583
         @ to be used before command grid (see <a href="#grid">command grid</a>)
9341 schaersvoo 4584
         @ 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
4585
        */
4586
            temp = get_string(infile,1);
4587
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
4588
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
4589
            fprintf(js_include_file,"x_strings_up = 1;x_strings = [\"%s\"];\n ",temp);
4590
            use_axis_numbering = 1;
4591
            break;
8224 bpr 4592
 
11806 schaersvoo 4593
        case XERRORBARS:
7614 schaersvoo 4594
        /*
11806 schaersvoo 4595
        @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
4596
        @ 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'
4597
        @ the errors E1 and E2 values are in xrange.
4598
        @ use command 'linewidth int' to adust size
4599
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
7614 schaersvoo 4600
        */
11806 schaersvoo 4601
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
4602
            fill_color = stroke_color;
4603
            i=0;
4604
            while( ! done ){     /* get next item until EOL*/
4605
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
4606
                if(i%2 == 0 ){
4607
                    double_data[i] = get_real(infile,0); /* x */
8071 schaersvoo 4608
                }
11806 schaersvoo 4609
                else
4610
                {
4611
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 4612
                }
11806 schaersvoo 4613
                i++;
7614 schaersvoo 4614
            }
11806 schaersvoo 4615
            decimals = find_number_of_digits(precision);
4616
            for(c = 2 ; c < i-1 ; c = c+2){
4617
                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);
4618
                /* click_cnt++; */
4619
                if(onclick > 0){click_cnt++;}
4620
            }
7614 schaersvoo 4621
            reset();
4622
            break;
11806 schaersvoo 4623
 
4624
        case XRANGE:
7614 schaersvoo 4625
        /*
11806 schaersvoo 4626
        @ xrange xmin,xmax
4627
        @ alternative : rangex
4628
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 4629
        */
11806 schaersvoo 4630
            for(i = 0 ; i<2; i++){
7614 schaersvoo 4631
                switch(i){
11806 schaersvoo 4632
                    case 0: xmin = get_real(infile,0);break;
4633
                    case 1: xmax = get_real(infile,1);break;
7614 schaersvoo 4634
                    default: break;
4635
                }
4636
            }
11806 schaersvoo 4637
            if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
4638
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
4639
            found_size_command++;
7614 schaersvoo 4640
            break;
8386 schaersvoo 4641
 
4642
 
4643
 
11806 schaersvoo 4644
        case XSNAPTOGRID:
7614 schaersvoo 4645
        /*
11806 schaersvoo 4646
         @ xsnaptogrid
4647
         @ keyword (no arguments required)
4648
         @ a draggable object (use command "drag  x|y|xy") will snap to the given x-grid values when dragged (mouseup)
4649
         @ in case of userdraw the drawn points will snap to xmajor grid
4650
         @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1)
4651
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
4652
         @ 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 4653
        */
11806 schaersvoo 4654
        fprintf(js_include_file,"\nx_use_snap_to_grid = 1;y_use_snap_to_grid = 0;");
4655
        break;
8386 schaersvoo 4656
 
11806 schaersvoo 4657
        case XOFFSET:
7614 schaersvoo 4658
        /*
11806 schaersvoo 4659
         @ xoffset | centered
4660
         @ keyword ; to place the text centered above the text coordinates(x:y) ...
4661
         @ may be used for points or other things requirering centered labels
11811 schaersvoo 4662
         @ 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 4663
        */
11806 schaersvoo 4664
         use_offset = 1;
4665
         break;
8386 schaersvoo 4666
 
11806 schaersvoo 4667
        case XYOFFSET:
7614 schaersvoo 4668
        /*
11806 schaersvoo 4669
         @ xyoffset
4670
         @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
4671
         @ may be used for points or other things requirering labels
4672
         @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
4673
         @ 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 4674
        */
11806 schaersvoo 4675
         use_offset = 2;
4676
         break;
8386 schaersvoo 4677
 
7996 schaersvoo 4678
        case XUNIT:
4679
        /*
4680
         @ xunit some_unit_for_x-values
4681
         @ unicode allowed (no html code)
4682
         @ use together with command mousex
9372 schaersvoo 4683
         @ will display the cursor x-coordinate in 'unit'
7996 schaersvoo 4684
        */
4685
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
4686
            break;
11806 schaersvoo 4687
 
4688
        case XLABEL:
7996 schaersvoo 4689
        /*
11806 schaersvoo 4690
        @ xlabel some_string
4691
        @ will be used to create a label for the x-axis (label is in quadrant I)
4692
        @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
4693
        @ 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 4694
        */
11806 schaersvoo 4695
            temp = get_string(infile,1);
4696
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7996 schaersvoo 4697
            break;
8071 schaersvoo 4698
 
11806 schaersvoo 4699
        case XLOGBASE:
7991 schaersvoo 4700
        /*
11806 schaersvoo 4701
        @ xlogbase number
4702
        @ sets the logbase number for the x-axis
4703
        @ default value 10
4704
        @ use together with commands xlogscale / xylogscale
7991 schaersvoo 4705
        */
11806 schaersvoo 4706
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7991 schaersvoo 4707
            break;
4708
 
11806 schaersvoo 4709
        case XLOGSCALE:
7614 schaersvoo 4710
        /*
11806 schaersvoo 4711
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
4712
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
4713
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
4714
         @ the linewidth is set using command 'linewidth int'
4715
         @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>'
4716
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
4717
         @ 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>
4718
         @ note: the complete canvas will be used for the 'log paper'
4719
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
4720
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
4721
         @ 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
4722
         @ note: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy !
4723
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 4724
        */
11806 schaersvoo 4725
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
4726
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
4727
            for(i=0;i<4;i++){
7614 schaersvoo 4728
                switch(i){
11806 schaersvoo 4729
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
4730
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
4731
                    case 2: stroke_color = get_color(infile,0); break;
4732
                    case 3: fill_color = get_color(infile,1);
4733
                        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);
4734
                        tmp_buffer = my_newmem(string_length+1);
4735
                        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);
4736
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
4737
                        add_to_buffer(tmp_buffer);
4738
                        break;
7614 schaersvoo 4739
                    default:break;
4740
                }
4741
            }
4742
            break;
11806 schaersvoo 4743
 
4744
        case XYLOGSCALE:
7614 schaersvoo 4745
        /*
11806 schaersvoo 4746
         @ xylogscale majorcolor,minorcolor
4747
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
4748
         @ the linewidth is set using command 'linewidth int'
4749
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
4750
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
4751
         @ 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>
4752
         @ note: the complete canvas will be used for the 'log paper'
4753
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
4754
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
4755
         @ 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')
4756
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
4757
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7614 schaersvoo 4758
        */
11806 schaersvoo 4759
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
4760
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
4761
            for(i=0;i<2;i++){
7614 schaersvoo 4762
                switch(i){
11806 schaersvoo 4763
                    case 0: stroke_color = get_color(infile,0); break;
4764
                    case 1: fill_color = get_color(infile,1);
4765
                        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);
4766
                        tmp_buffer = my_newmem(string_length+1);
4767
                        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);
4768
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
4769
                        add_to_buffer(tmp_buffer);
4770
                        break;
7614 schaersvoo 4771
                    default:break;
4772
                }
4773
            }
4774
        break;
11806 schaersvoo 4775
 
4776
 
4777
        case Y_AXIS_STRINGS:
7647 schaersvoo 4778
        /*
11806 schaersvoo 4779
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
4780
         @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
4781
         @ 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>)
4782
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
4783
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="grid">grid</a>
4784
         @ use these y-axis num1...num_n  values instead of default ymin...ymax
4785
         @ a javascript error message will flag non-matching value:name pairs
4786
         @ to be used before command grid (see <a href="#grid">command grid</a>)
4787
         @ 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 4788
        */
11806 schaersvoo 4789
            temp = get_string(infile,1);
4790
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
4791
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
4792
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
4793
            use_axis_numbering = 1;
4794
            break;
4795
 
4796
 
4797
        case YERRORBARS:
7614 schaersvoo 4798
        /*
11806 schaersvoo 4799
        @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
4800
        @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
4801
        @ the errors E1 and E2 values are in yrange.
4802
        @ use command 'linewidth int' to adust size
4803
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
7614 schaersvoo 4804
        */
11806 schaersvoo 4805
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
4806
            fill_color = stroke_color;
11772 schaersvoo 4807
            i=0;
4808
            while( ! done ){     /* get next item until EOL*/
4809
                if(i > MAX_INT - 1){canvas_error("to many points in argument: repeat command multiple times to fit");}
4810
                if(i%2 == 0 ){
4811
                    double_data[i] = get_real(infile,0); /* x */
4812
                }
4813
                else
4814
                {
4815
                    double_data[i] = get_real(infile,1); /* y */
4816
                }
4817
                i++;
4818
            }
11806 schaersvoo 4819
            for(c = 2 ; c < i-1 ; c = c+2){
4820
                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);
4821
                /* click_cnt++; */
4822
                if(onclick > 0){click_cnt++;}
8083 schaersvoo 4823
            }
11806 schaersvoo 4824
            decimals = find_number_of_digits(precision);
8083 schaersvoo 4825
            reset();
11806 schaersvoo 4826
            break;
4827
 
11811 schaersvoo 4828
        case YOFFSET:
4829
        /*
4830
         @ yoffset
4831
         @ keyword, only active for commands <a href="#textup">textup</a> and <a href="#stringup">stringup</a>
4832
         @ 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)
4833
         @ string ending on (x:y) is valid for all rotation angles
4834
         @ may be used for points or other things requirering labels in y-direction
4835
         @ 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.
4836
        */
4837
        use_offset = 3;
4838
         break;
4839
 
11806 schaersvoo 4840
        case YRANGE:
7614 schaersvoo 4841
        /*
11806 schaersvoo 4842
        @ yrange ymin,ymax
4843
        @ alternative : rangey
4844
        @ if not given 0,ysize (eg in pixels)
7614 schaersvoo 4845
        */
11806 schaersvoo 4846
            for(i = 0 ; i<2; i++){
7614 schaersvoo 4847
                switch(i){
11806 schaersvoo 4848
                    case 0: ymin = get_real(infile,0);break;
4849
                    case 1: ymax = get_real(infile,1);break;
4850
                    default: break;
7614 schaersvoo 4851
                }
4852
            }
11806 schaersvoo 4853
            if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
4854
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
4855
            found_size_command++;
4856
            break;
4857
 
4858
        case YSNAPTOGRID:
7614 schaersvoo 4859
        /*
11806 schaersvoo 4860
         @ ysnaptogrid
4861
         @ keyword (no arguments required)
4862
         @ a draggable object (use command "drag  x|y|xy") will snap to the given y-grid values when dragged (mouseup)
4863
         @ in case of userdraw the drawn points will snap to ymajor grid
4864
         @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1)
4865
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
4866
         @ 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 4867
        */
11806 schaersvoo 4868
        fprintf(js_include_file,"\nx_use_snap_to_grid = 0;y_use_snap_to_grid = 1;");
7614 schaersvoo 4869
        break;
11080 schaersvoo 4870
 
7614 schaersvoo 4871
        case YLABEL:
4872
        /*
4873
        @ ylabel some_string
8224 bpr 4874
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
9379 schaersvoo 4875
        @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
10953 bpr 4876
        @ 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 4877
        */
4878
            temp = get_string(infile,1);
7653 schaersvoo 4879
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 4880
            break;
7735 schaersvoo 4881
        case YLOGBASE:
4882
        /*
4883
        @ ylogbase number
4884
        @ sets the logbase number for the y-axis
4885
        @ default value 10
4886
        @ use together with commands ylogscale / xylogscale
4887
        */
4888
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
4889
            break;
7614 schaersvoo 4890
        case YLOGSCALE:
7729 schaersvoo 4891
        /*
4892
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
4893
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
4894
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
4895
         @ the linewidth is set using command 'linewidth int'
4896
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
7735 schaersvoo 4897
         @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
8224 bpr 4898
         @ 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 4899
         @ note: the complete canvas will be used for the 'log paper'
4900
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
4901
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
4902
         @ 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')
4903
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
9383 schaersvoo 4904
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7729 schaersvoo 4905
        */
4906
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
4907
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
4908
            for(i=0;i<4;i++){
4909
                switch(i){
4910
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
4911
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
4912
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 4913
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 4914
                        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 4915
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 4916
                        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 4917
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 4918
                        add_to_buffer(tmp_buffer);
4919
                        break;
4920
                    default:break;
4921
                }
4922
            }
7614 schaersvoo 4923
            break;
11806 schaersvoo 4924
 
4925
        case YUNIT:
7735 schaersvoo 4926
        /*
11806 schaersvoo 4927
         @ yunit some_unit_for_y-values
4928
         @ unicode allowed (no html code)
4929
         @ use together with command mousey
4930
         @ will display the cursor y-coordinate in 'unit'
7735 schaersvoo 4931
        */
11806 schaersvoo 4932
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
4933
            break;
4934
 
4935
        case ZOOM:
4936
        /*
4937
         @ zoom button_color
4938
         @ introduce a very small 'controlpanel' at the lower right corner
4939
         @ 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
4940
         @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
4941
         @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
4942
         @ command 'opacity' may be used to set stroke_opacity of 'buttons
4943
         @ note: use command 'zoom' at the end of your script code (the same is true for command 'mouse')
4944
         @ note: only objects that may be set draggable / clickable will be zoomed / panned
4945
         @ 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 !!
4946
        */
4947
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
4948
            use_pan_and_zoom = TRUE;
4949
            stroke_color = get_color(infile,1);
4950
            /* we use BG_CANVAS (0) */
4951
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
4952
            done = TRUE;
4953
            break;
4954
 
4955
/* ready */
7614 schaersvoo 4956
        default:sync_input(infile);
4957
        break;
4958
    }
8224 bpr 4959
  }
7614 schaersvoo 4960
  /* we are done parsing script file */
7983 schaersvoo 4961
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
4962
  if( found_size_command == 1 ){
4963
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
4964
  }
4965
  else
4966
  {
4967
    if( found_size_command != 3 ){
8222 schaersvoo 4968
     canvas_error("Please specify both xrange and yrange ...");
7983 schaersvoo 4969
    }
4970
  }
8257 schaersvoo 4971
 
8222 schaersvoo 4972
  /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
11021 schaersvoo 4973
  add_javascript_function(js_function,canvas_root_id);
7614 schaersvoo 4974
   /* add read_canvas() etc functions if needed */
8257 schaersvoo 4975
  if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
7797 schaersvoo 4976
  if( use_pan_and_zoom == TRUE ){
4977
  /* in case of zooming ... */
7729 schaersvoo 4978
  fprintf(js_include_file,"\n<!-- some extra global stuff : need to rethink panning and zooming !!! -->\n\
7797 schaersvoo 4979
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 4980
  var ymin_start=ymin;var ymax_start=xmax;\
4981
  var zoom_x_increment=0;var zoom_y_increment=0;\
4982
  var pan_x_increment=0;var pan_y_increment=0;\
4983
  if(use_ylogscale == 0 ){\
7956 schaersvoo 4984
   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 4985
  }else{\
4986
   zoom_x_increment = (xmax - xmin)/20;\
4987
   pan_x_increment = (xmax - xmin)/20;\
4988
  };\
9406 schaersvoo 4989
  var zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 4990
  function start_canvas%d(type){\
9406 schaersvoo 4991
   zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 4992
   switch(type){\
7729 schaersvoo 4993
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
4994
    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 4995
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
4996
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
4997
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
4998
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
11004 schaersvoo 4999
    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
7653 schaersvoo 5000
    default:break;\
5001
   };\
5002
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
5003
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
9406 schaersvoo 5004
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
11088 schaersvoo 5005
   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
9406 schaersvoo 5006
   %s ;\
7653 schaersvoo 5007
  };\
7797 schaersvoo 5008
  start_canvas%d(333);\
9438 schaersvoo 5009
 };\
5010
\n<!-- end wims_canvas_function -->\n\
9406 schaersvoo 5011
wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
7797 schaersvoo 5012
  }
5013
  else
5014
  {
5015
  /* no zoom, just add buffer */
5016
  fprintf(js_include_file,"\n<!-- add buffer -->\n\
5017
  %s\
5018
 };\n\
5019
<!-- end wims_canvas_function -->\n\
5020
wims_canvas_function%d();\n",buffer,canvas_root_id);
5021
  }
7614 schaersvoo 5022
/* done writing the javascript include file */
5023
fclose(js_include_file);
5024
 
5025
}
5026
 
5027
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
9329 schaersvoo 5028
 if( use_tooltip > 0 ){
5029
  if( use_tooltip == 1 ){
5030
   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
5031
  }
5032
  else
5033
  {
5034
   if( use_tooltip == 2 ){
5035
    add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
5036
   }
5037
  }
5038
 }
7614 schaersvoo 5039
exit(EXIT_SUCCESS);
5040
}
5041
/* end main() */
5042
 
5043
/******************************************************************************
5044
**
5045
**  sync_input
5046
**
5047
**  synchronises input line - reads to end of line, leaving file pointer
5048
**  at first character of next line.
5049
**
5050
**  Used by:
5051
**  main program - error handling.
5052
**
5053
******************************************************************************/
5054
void sync_input(FILE *infile)
5055
{
5056
        int c = 0;
5057
 
7658 schaersvoo 5058
        if( c == '\n' || c == ';' ) return;
5059
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 5060
        if( c == EOF ) finished = 1;
7658 schaersvoo 5061
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 5062
        return;
5063
}
5064
 
5065
/******************************************************************************/
5066
 
5067
char *str_replace(const char *str, const char *old, const char *new){
5068
/* http://creativeandcritical.net/str-replace-c/ */
5069
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
5070
    char *ret, *r;
5071
    const char *p, *q;
5072
    size_t oldlen = strlen(old);
5073
    size_t count = 0;
5074
    size_t retlen = 0;
5075
    size_t newlen = strlen(new);
5076
    if (oldlen != newlen){
5077
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
5078
            count++;
5079
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
5080
        }
8224 bpr 5081
    }
7614 schaersvoo 5082
    else
5083
    {
5084
        retlen = strlen(str);
5085
    }
8224 bpr 5086
 
7614 schaersvoo 5087
    if ((ret = malloc(retlen + 1)) == NULL){
5088
        ret = NULL;
5089
        canvas_error("string argument is NULL");
5090
    }
5091
    else
5092
    {
5093
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
5094
            size_t l = q - p;
5095
            memcpy(r, p, l);
5096
            r += l;
5097
            memcpy(r, new, newlen);
5098
            r += newlen;
5099
        }
5100
        strcpy(r, p);
5101
    }
5102
    return ret;
5103
}
5104
 
5105
/******************************************************************************/
7848 bpr 5106
 
7614 schaersvoo 5107
char *get_color(FILE *infile , int last){
5108
    int c,i = 0,is_hex = 0;
5109
    char temp[MAX_COLOR_STRING], *string;
8305 schaersvoo 5110
    const char *not_allowed = "0123456789";
10891 schaersvoo 5111
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
7614 schaersvoo 5112
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
5113
        if( c == '#' ){
5114
            is_hex = 1;
5115
        }
5116
        if( c != ' '){
8304 schaersvoo 5117
            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 5118
            temp[i]=tolower(c);
5119
            i++;
5120
        }
5121
    }
10891 schaersvoo 5122
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5123
    if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5124
    if( c == EOF ){finished = 1;}
5125
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
5126
    temp[i]='\0';
5127
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
5128
    if( is_hex == 1 ){
5129
        char red[3], green[3], blue[3];
5130
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
5131
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
5132
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
5133
        int r = (int) strtol(red,   NULL, 16);
5134
        int g = (int) strtol(green, NULL, 16);
5135
        int b = (int) strtol(blue,  NULL, 16);
5136
        string = (char *)my_newmem(12);
5137
        snprintf(string,11,"%d,%d,%d",r,g,b);
5138
        return string;
5139
    }
5140
    else
5141
    {
5142
        string = (char *)my_newmem(sizeof(temp));
5143
        snprintf(string,sizeof(temp),"%s",temp);
8304 schaersvoo 5144
        for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
7614 schaersvoo 5145
            if( strcmp( colors[i].name , string ) == 0 ){
5146
                return colors[i].rgb;
5147
            }
5148
        }
8304 schaersvoo 5149
        canvas_error("I was expecting a color name or hexnumber...but found nothing.");
7614 schaersvoo 5150
    }
8304 schaersvoo 5151
    return "0,0,255";
7614 schaersvoo 5152
}
5153
 
5154
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
5155
    int c,i=0;
5156
    char  temp[MAX_BUFFER], *string;
10891 schaersvoo 5157
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
7614 schaersvoo 5158
        temp[i]=c;
5159
        i++;
5160
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
5161
    }
10891 schaersvoo 5162
    if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
5163
    if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
11022 schaersvoo 5164
    if( c == EOF ) {finished = 1;}
7614 schaersvoo 5165
    temp[i]='\0';
11022 schaersvoo 5166
    if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
7614 schaersvoo 5167
    string=(char *)my_newmem(strlen(temp));
5168
    snprintf(string,sizeof(temp),"%s",temp);
5169
    return string;
5170
}
5171
 
5172
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
5173
    int c,i=0;
5174
    char temp[MAX_BUFFER], *string;
10891 schaersvoo 5175
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
7614 schaersvoo 5176
        temp[i]=c;
5177
        i++;
5178
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
5179
    }
8224 bpr 5180
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
10891 schaersvoo 5181
    if( c == '\n' || c == '\t' ) { line_number++; }
7614 schaersvoo 5182
    if( c == EOF ) {finished = 1;}
9478 schaersvoo 5183
    if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
7614 schaersvoo 5184
    temp[i]='\0';
10953 bpr 5185
/*
8322 schaersvoo 5186
    17.10.2014 removed (question Perrin)
5187
    may cause some unwanted effects...
7614 schaersvoo 5188
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
8322 schaersvoo 5189
*/
7614 schaersvoo 5190
    string=(char *)my_newmem(sizeof(temp));
5191
    snprintf(string,sizeof(temp),"%s",temp);
5192
    done = TRUE;
5193
    return string;
5194
}
5195
 
5196
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
5197
    int c,i=0,found_calc = 0;
5198
    double y;
5199
    char tmp[MAX_INT];
10953 bpr 5200
    /*
5201
     these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
8383 schaersvoo 5202
     but there should be a better way to avoid segfaults !
8348 schaersvoo 5203
    */
5204
    const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
5205
    const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
10891 schaersvoo 5206
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
7614 schaersvoo 5207
     if( c != ' ' ){
8224 bpr 5208
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 5209
       continue;
8224 bpr 5210
      }
7614 schaersvoo 5211
      else
5212
      {
8304 schaersvoo 5213
       c = tolower(c);
5214
       if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
5215
       if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
7614 schaersvoo 5216
       tmp[i] = c;
5217
       i++;
5218
      }
5219
     }
5220
     if( i > MAX_INT - 1){canvas_error("number too large");}
5221
    }
10891 schaersvoo 5222
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5223
    if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5224
    if( c == EOF ){done = TRUE ; finished = 1;}
5225
    tmp[i]='\0';
5226
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
8304 schaersvoo 5227
    if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
7848 bpr 5228
     void *f = eval_create(tmp);
7614 schaersvoo 5229
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 5230
     y = eval_x(f, 1);
7614 schaersvoo 5231
     /* if function is bogus; y = 1 : so no core dumps */
7848 bpr 5232
     eval_destroy(f);
7614 schaersvoo 5233
    }
5234
    else
5235
    {
5236
     y = atof(tmp);
5237
    }
5238
    return y;
5239
}
8304 schaersvoo 5240
 
5241
 
7614 schaersvoo 5242
void canvas_error(char *msg){
8383 schaersvoo 5243
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
7614 schaersvoo 5244
    finished = 1;
5245
    exit(EXIT_SUCCESS);
5246
}
5247
 
5248
 
5249
/* convert x/y coordinates to pixel */
5250
int x2px(double x){
5251
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
5252
}
5253
 
5254
int y2px(double y){
5255
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
5256
}
5257
 
5258
double px2x(int x){
5259
 return (x*(xmax - xmin)/xsize + xmin);
5260
}
5261
double px2y(int y){
5262
 return (y*(ymax - ymin)/ysize + ymin);
5263
}
5264
 
5265
void add_to_buffer(char *tmp){
5266
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
5267
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
5268
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
5269
 if( space_left > strlen(tmp)){
5270
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
5271
 }
5272
 else
5273
 {
5274
  canvas_error("buffer is too big\n");
5275
 }
5276
 tmp = NULL;free(tmp);
5277
 return;
5278
}
5279
 
5280
void reset(){
5281
 if(use_filled == TRUE){use_filled = FALSE;}
5282
 if(use_dashed == TRUE){use_dashed = FALSE;}
5283
 if(use_rotate == TRUE){use_rotate = FALSE;}
8379 schaersvoo 5284
 onclick = 0;
7614 schaersvoo 5285
}
5286
 
5287
 
5288
 
5289
/* What reply format in read_canvas();
5290
 
5291
note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
5292
1 = x1,x2,x3,x4....x_n
5293
    y1,y2,y3,y4....y_n
5294
 
5295
    x/y in pixels
5296
 
5297
2 = x1,x2,x3,x4....x_n
5298
    y1,y2,y3,y4....y_n
5299
    x/y in  xrange / yrange coordinate system
5300
 
5301
3 = x1,x2,x3,x4....x_n
5302
    y1,y2,y3,y4....y_n
5303
    r1,r2,r3,r4....r_n
5304
 
8224 bpr 5305
    x/y in pixels
7614 schaersvoo 5306
    r in pixels
5307
 
5308
4 = x1,x2,x3,x4....x_n
5309
    y1,y2,y3,y4....y_n
5310
    r1,r2,r3,r4....r_n
5311
 
5312
    x/y in  xrange / yrange coordinate system
5313
    r in pixels
5314
 
5315
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
5316
    Ay1,Ay2,Ay3,Ay4....Ay_n
5317
    Bx1,Bx2,Bx3,Bx4....Bx_n
5318
    By1,By2,By3,By4....By_n
5319
    Cx1,Cx2,Cx3,Cx4....Cx_n
5320
    Cy1,Cy2,Cy3,Cy4....Cy_n
5321
    ....
5322
    Zx1,Zx2,Zx3,Zx4....Zx_n
5323
    Zy1,Zy2,Zy3,Zy4....Zy_n
8224 bpr 5324
 
7614 schaersvoo 5325
    x/y in pixels
5326
 
5327
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
5328
    Ay1,Ay2,Ay3,Ay4....Ay_n
5329
    Bx1,Bx2,Bx3,Bx4....Bx_n
5330
    By1,By2,By3,By4....By_n
5331
    Cx1,Cx2,Cx3,Cx4....Cx_n
5332
    Cy1,Cy2,Cy3,Cy4....Cy_n
5333
    ....
5334
    Zx1,Zx2,Zx3,Zx4....Zx_n
5335
    Zy1,Zy2,Zy3,Zy4....Zy_n
5336
 
5337
    x/y in  xrange / yrange coordinate system
8224 bpr 5338
 
7614 schaersvoo 5339
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 5340
 
7614 schaersvoo 5341
    x/y in pixels
5342
 
5343
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 5344
 
7614 schaersvoo 5345
    x/y in  xrange / yrange coordinate system
5346
 
8224 bpr 5347
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 5348
 
5349
    x/y in pixels
5350
 
8224 bpr 5351
10 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 5352
 
5353
    x/y in  xrange / yrange coordinate system
5354
 
5355
11 = Ax1,Ay1,Ax2,Ay2
5356
     Bx1,By1,Bx2,By2
5357
     Cx1,Cy1,Cx2,Cy2
5358
     Dx1,Dy1,Dx2,Dy2
5359
     ......
5360
     Zx1,Zy1,Zx2,Zy2
8224 bpr 5361
 
7614 schaersvoo 5362
    x/y in  xrange / yrange coordinate system
5363
 
5364
12 = Ax1,Ay1,Ax2,Ay2
5365
     Bx1,By1,Bx2,By2
5366
     Cx1,Cy1,Cx2,Cy2
5367
     Dx1,Dy1,Dx2,Dy2
5368
     ......
5369
     Zx1,Zy1,Zx2,Zy2
8224 bpr 5370
 
7614 schaersvoo 5371
    x/y in pixels
5372
 
5373
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
5374
 
5375
    x/y in  xrange / yrange coordinate system
5376
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
5377
    x/y in pixels
5378
15 = reply from inputfields,textareas
5379
    reply1,reply2,reply3,...,reply_n
7984 schaersvoo 5380
    only fields set write (a.g. will not read 'readonly' inputfield values'
7614 schaersvoo 5381
 
5382
16 = read mathml inputfields only
5383
 
11080 schaersvoo 5384
17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
7614 schaersvoo 5385
 when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
5386
 
5387
18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
5388
19 = return clicked object number (analogue to shape-library onclick)
5389
20 = return x/y-data in x-range/y-range of all 'draggable' images
5390
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
5391
22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
5392
    x/y in  xrange / yrange coordinate system
8224 bpr 5393
23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
7984 schaersvoo 5394
24 = read all inputfield values: even those set 'readonly'
8224 bpr 5395
25 = return all userdrawn arcs in degrees:
5396
26 = return all userdrawn arcs in radians:
11080 schaersvoo 5397
27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
8322 schaersvoo 5398
28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
10953 bpr 5399
    x/y/r in  xrange / yrange coordinate system: may be used to reinput into command
8322 schaersvoo 5400
    'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'
5401
    will not return anything else (e.g. no inputfields , text etc)
10953 bpr 5402
29 = mulidraw read :
5403
 
7614 schaersvoo 5404
*/
5405
 
5406
 
8257 schaersvoo 5407
void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
7614 schaersvoo 5408
/* just 1 reply type allowed */
8074 schaersvoo 5409
fprintf(js_include_file,"\
5410
\n<!-- begin set_reply_precision() -->\n\
5411
function set_reply_precision(){\
5412
 var len = userdraw_x.length;\
5413
 var prec = %d;\
5414
 for(var p = 0 ; p < len ; p++ ){\
5415
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
5416
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
5417
 };\
5418
 len = userdraw_radius.length;\
5419
 if( len > 0 ){\
5420
  for(var p = 0 ; p < len ; p++ ){\
5421
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
5422
  };\
5423
 };\
5424
};",reply_precision);
7963 schaersvoo 5425
 
7614 schaersvoo 5426
switch(type_reply){
8224 bpr 5427
/*
7614 schaersvoo 5428
answers may have:
5429
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
5430
*/
5431
    case 1: fprintf(js_include_file,"\
8257 schaersvoo 5432
\n<!-- begin function 1 read_canvas%d() -->\n\
5433
read_canvas%d = function(){\
7614 schaersvoo 5434
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 5435
 set_reply_precision();\
7614 schaersvoo 5436
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5437
  var p = 0;var input_reply = new Array();\
5438
  if( document.getElementById(\"canvas_input0\")){\
5439
   var t = 0;\
5440
   while(document.getElementById(\"canvas_input\"+t)){\
5441
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5442
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5443
     p++;\
5444
    };\
5445
    t++;\
5446
   };\
5447
  };\
11088 schaersvoo 5448
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5449
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
5450
  }\
5451
  else\
5452
  {\
5453
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
5454
  }\
5455
 }\
5456
 else\
5457
 {\
11088 schaersvoo 5458
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5459
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
5460
  }\
5461
  else\
5462
  {\
5463
   return userdraw_x+\"\\n\"+userdraw_y;\
5464
  }\
5465
 };\
8108 schaersvoo 5466
};\n\
8257 schaersvoo 5467
<!-- end function 1 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5468
    break;
5469
    case 2: fprintf(js_include_file,"\
8257 schaersvoo 5470
\n<!-- begin function 2 read_canvas%d() -->\n\
5471
read_canvas%d = function(){\
7614 schaersvoo 5472
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 5473
 set_reply_precision();\
7614 schaersvoo 5474
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 5475
 var prec = %d;\
7614 schaersvoo 5476
 while(userdraw_x[p]){\
8074 schaersvoo 5477
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
5478
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 5479
  p++;\
5480
 };\
11806 schaersvoo 5481
 if(p == 0){return;};\
7614 schaersvoo 5482
 if( document.getElementById(\"canvas_input0\")){\
5483
  var p = 0;var input_reply = new Array();\
5484
  if( document.getElementById(\"canvas_input0\")){\
5485
   var t = 0;\
5486
   while(document.getElementById(\"canvas_input\"+t)){\
5487
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5488
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5489
     p++;\
5490
    };\
5491
    t++;\
5492
   };\
5493
  };\
11088 schaersvoo 5494
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5495
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5496
  }\
5497
  else\
5498
  {\
5499
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
5500
  }\
5501
 }\
5502
 else\
5503
 {\
11088 schaersvoo 5504
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5505
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
5506
  }\
5507
  else\
5508
  {\
5509
   return reply_x+\"\\n\"+reply_y;\
5510
  };\
5511
 };\
8108 schaersvoo 5512
};\n\
8257 schaersvoo 5513
<!-- end function 2 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5514
    break;
5515
    case 3: fprintf(js_include_file,"\
8257 schaersvoo 5516
\n<!-- begin function 3 read_canvas%d() -->\n\
5517
read_canvas%d = function(){\
7614 schaersvoo 5518
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 5519
 set_reply_precision();\
7614 schaersvoo 5520
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5521
  var p = 0;var input_reply = new Array();\
5522
  if( document.getElementById(\"canvas_input0\")){\
5523
   var t = 0;\
5524
   while(document.getElementById(\"canvas_input\"+t)){\
5525
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5526
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5527
     p++;\
5528
    };\
5529
    t++;\
5530
   };\
5531
  };\
11088 schaersvoo 5532
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5533
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5534
  }\
5535
  else\
5536
  {\
5537
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
5538
  }\
5539
 }\
5540
 else\
5541
 {\
11088 schaersvoo 5542
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5543
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
5544
  }\
5545
  else\
5546
  {\
5547
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
5548
  }\
5549
 }\
8108 schaersvoo 5550
};\n\
8257 schaersvoo 5551
<!-- end function 3 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5552
    break;
5553
    case 4: fprintf(js_include_file,"\
8257 schaersvoo 5554
\n<!-- begin function 4 read_canvas%d() -->\n\
5555
read_canvas%d = function(){\
8074 schaersvoo 5556
 var prec = %d;\
7614 schaersvoo 5557
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
5558
 while(userdraw_x[p]){\
8074 schaersvoo 5559
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
5560
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 5561
  p++;\
5562
 };\
11806 schaersvoo 5563
 if(p == 0){return;};\
7614 schaersvoo 5564
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5565
  var p = 0;var input_reply = new Array();\
5566
  if( document.getElementById(\"canvas_input0\")){\
5567
   var t = 0;\
5568
   while(document.getElementById(\"canvas_input\"+t)){\
5569
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5570
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5571
     p++;\
5572
    };\
5573
    t++;\
5574
   };\
5575
  };\
11088 schaersvoo 5576
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5577
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5578
  }\
5579
  else\
5580
  {\
5581
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
5582
  }\
5583
 }\
5584
 else\
5585
 {\
11088 schaersvoo 5586
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5587
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
5588
  }\
5589
  else\
5590
  {\
5591
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
5592
  }\
5593
 };\
8108 schaersvoo 5594
};\n\
8257 schaersvoo 5595
<!-- end function 4 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5596
    break;
8224 bpr 5597
    /*
5598
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
5599
        used for userdraw multiple paths
7614 schaersvoo 5600
    */
5601
    case 5: fprintf(js_include_file,"\
8257 schaersvoo 5602
\n<!-- begin function 5 read_canvas%d() -->\n\
5603
read_canvas%d = function(){\
8074 schaersvoo 5604
 set_reply_precision();\
7614 schaersvoo 5605
 var p = 0;\
5606
 var reply = \"\";\
5607
 for(p = 0; p < userdraw_x.length;p++){\
5608
  if(userdraw_x[p] != null ){\
5609
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
5610
  };\
5611
 };\
11806 schaersvoo 5612
 if(p == 0){return;};\
7614 schaersvoo 5613
 userdraw_x = [];userdraw_y = [];\
5614
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5615
  var p = 0;var input_reply = new Array();\
5616
  if( document.getElementById(\"canvas_input0\")){\
5617
   var t = 0;\
5618
   while(document.getElementById(\"canvas_input\"+t)){\
5619
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5620
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5621
     p++;\
5622
    };\
5623
    t++;\
5624
   };\
5625
  };\
11088 schaersvoo 5626
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5627
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5628
  }\
5629
  else\
5630
  {\
5631
   return reply +\"\\n\"+input_reply;\
5632
  }\
5633
 }\
5634
 else\
5635
 {\
11088 schaersvoo 5636
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5637
   return reply+\"\\n\"+userdraw_text;\
5638
  }\
5639
  else\
5640
  {\
5641
   return reply;\
5642
  }\
5643
 };\
8108 schaersvoo 5644
};\n\
8257 schaersvoo 5645
<!-- end function 5 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5646
    break;
8224 bpr 5647
    /*
5648
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
5649
        used for userdraw multiple paths
7614 schaersvoo 5650
    */
5651
    case 6: fprintf(js_include_file,"\
8257 schaersvoo 5652
\n<!-- begin function 6 read_canvas%d() -->\n\
5653
read_canvas%d = function(){\
7614 schaersvoo 5654
 var p = 0;\
5655
 var reply = \"\";\
5656
 var tmp_x = new Array();\
5657
 var tmp_y = new Array();\
8074 schaersvoo 5658
 var prec = %d;\
7614 schaersvoo 5659
 for(p = 0 ; p < userdraw_x.length; p++){\
5660
  tmp_x = userdraw_x[p];\
5661
  tmp_y = userdraw_y[p];\
5662
  if(tmp_x != null){\
5663
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 5664
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
5665
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 5666
   };\
5667
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
5668
  };\
5669
 };\
11806 schaersvoo 5670
 if(p == 0){return;};\
7614 schaersvoo 5671
 userdraw_x = [];userdraw_y = [];\
5672
 if( document.getElementById(\"canvas_input0\") ){\
5673
  var p = 0;var input_reply = new Array();\
5674
  if( document.getElementById(\"canvas_input0\")){\
5675
   var t = 0;\
5676
   while(document.getElementById(\"canvas_input\"+t)){\
5677
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5678
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5679
     p++;\
5680
    };\
5681
    t++;\
5682
   };\
5683
  };\
11088 schaersvoo 5684
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5685
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5686
  }\
5687
  else\
5688
  {\
5689
   return reply +\"\\n\"+input_reply;\
5690
  }\
5691
 }\
5692
 else\
5693
 {\
11088 schaersvoo 5694
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5695
   return reply +\"\\n\"+userdraw_text;\
5696
  }\
5697
  else\
5698
  {\
5699
   return reply;\
5700
  }\
5701
 };\
8108 schaersvoo 5702
};\n\
8257 schaersvoo 5703
<!-- end function 6 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5704
    break;
5705
    case 7: fprintf(js_include_file,"\
8257 schaersvoo 5706
\n<!-- begin function 7 read_canvas%d() -->\n\
5707
read_canvas%d = function(){\
8074 schaersvoo 5708
 set_reply_precision();\
7614 schaersvoo 5709
 var reply = new Array();\
5710
 var p = 0;\
5711
 while(userdraw_x[p]){\
5712
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
5713
  p++;\
5714
 };\
11806 schaersvoo 5715
 if(p == 0){return;};\
7614 schaersvoo 5716
 if( document.getElementById(\"canvas_input0\") ){\
5717
  var p = 0;var input_reply = new Array();\
5718
  if( document.getElementById(\"canvas_input0\")){\
5719
   var t = 0;\
5720
   while(document.getElementById(\"canvas_input\"+t)){\
5721
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5722
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5723
     p++;\
5724
    };\
5725
    t++;\
5726
   };\
5727
  };\
11088 schaersvoo 5728
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5729
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5730
  }\
5731
  else\
5732
  {\
5733
   return reply+\"\\n\"+input_reply;\
5734
  }\
7862 schaersvoo 5735
 }\
7614 schaersvoo 5736
 else\
5737
 {\
11088 schaersvoo 5738
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5739
   return reply+\"\\n\"+userdraw_text;\
5740
  }\
5741
  else\
5742
  {\
5743
   return reply;\
5744
  }\
5745
 };\
8108 schaersvoo 5746
};\n\
8257 schaersvoo 5747
<!-- end function 7 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5748
    break;
5749
    case 8: fprintf(js_include_file,"\
8257 schaersvoo 5750
\n<!-- begin function 8 read_canvas%d() -->\n\
5751
read_canvas%d = function(){\
7614 schaersvoo 5752
 var reply = new Array();\
5753
 var p = 0;\
8074 schaersvoo 5754
 var prec = %d;\
7614 schaersvoo 5755
 while(userdraw_x[p]){\
8074 schaersvoo 5756
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 5757
  p++;\
5758
 };\
11806 schaersvoo 5759
 if(p == 0){return;};\
7614 schaersvoo 5760
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5761
  var p = 0;var input_reply = new Array();\
5762
  if( document.getElementById(\"canvas_input0\")){\
5763
   var t = 0;\
5764
   while(document.getElementById(\"canvas_input\"+t)){\
5765
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5766
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5767
     p++;\
5768
    };\
5769
    t++;\
5770
   };\
5771
  };\
11088 schaersvoo 5772
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5773
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5774
  }\
5775
  else\
5776
  {\
5777
   return reply +\"\\n\"+input_reply;\
5778
  }\
5779
 }\
5780
 else\
5781
 {\
11088 schaersvoo 5782
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5783
   return reply +\"\\n\"+userdraw_text;\
5784
  }\
5785
  else\
5786
  {\
5787
   return reply;\
5788
  }\
5789
 };\
8108 schaersvoo 5790
};\n\
8257 schaersvoo 5791
<!-- end function 8 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5792
    break;
5793
    case 9: fprintf(js_include_file,"\
8257 schaersvoo 5794
\n<!-- begin function 9 read_canvas%d() -->\n\
5795
read_canvas%d = function(){\
8074 schaersvoo 5796
 set_reply_precision();\
7614 schaersvoo 5797
 var reply = new Array();\
5798
 var p = 0;\
5799
 while(userdraw_x[p]){\
5800
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
5801
  p++;\
5802
 };\
11806 schaersvoo 5803
 if(p == 0){return;};\
7614 schaersvoo 5804
 if( document.getElementById(\"canvas_input0\") ){\
5805
  var p = 0;var input_reply = new Array();\
5806
  if( document.getElementById(\"canvas_input0\")){\
5807
   var t = 0;\
5808
   while(document.getElementById(\"canvas_input\"+t)){\
5809
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5810
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5811
     p++;\
5812
    };\
5813
    t++;\
5814
   };\
5815
  };\
11088 schaersvoo 5816
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5817
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5818
  }\
5819
  else\
5820
  {\
5821
   return reply +\"\\n\"+input_reply;\
5822
  }\
5823
 }\
5824
 else\
5825
 {\
11088 schaersvoo 5826
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5827
   return reply +\"\\n\"+userdraw_text;\
5828
  }\
5829
  else\
5830
  {\
5831
   return reply;\
5832
  }\
5833
 };\
8108 schaersvoo 5834
};\n\
8257 schaersvoo 5835
<!-- end function 9 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5836
    break;
5837
    case 10: fprintf(js_include_file,"\
8257 schaersvoo 5838
\n<!-- begin function 10 read_canvas%d() -->\n\
5839
read_canvas%d = function(){\
7614 schaersvoo 5840
 var reply = new Array();\
5841
 var p = 0;\
8074 schaersvoo 5842
 var prec = %d;\
7614 schaersvoo 5843
 while(userdraw_x[p]){\
8074 schaersvoo 5844
  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 5845
  p++;\
5846
 };\
11806 schaersvoo 5847
 if(p == 0){return;};\
7614 schaersvoo 5848
 if( document.getElementById(\"canvas_input0\") ){\
5849
  var p = 0;var input_reply = new Array();\
5850
  if( document.getElementById(\"canvas_input0\")){\
5851
   var t = 0;\
5852
   while(document.getElementById(\"canvas_input\"+t)){\
5853
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5854
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5855
     p++;\
5856
    };\
5857
    t++;\
5858
   };\
5859
  };\
11088 schaersvoo 5860
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5861
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5862
  }\
5863
  else\
5864
  {\
5865
   return reply +\"\\n\"+input_reply;\
5866
  }\
5867
 }\
5868
 else\
5869
 {\
11088 schaersvoo 5870
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5871
   return reply +\"\\n\"+userdraw_text;\
5872
  }\
5873
  else\
5874
  {\
5875
   return reply;\
5876
  }\
5877
 };\
8108 schaersvoo 5878
};\n\
8257 schaersvoo 5879
<!-- end function 10 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5880
    break;
5881
    case 11: fprintf(js_include_file,"\
8257 schaersvoo 5882
\n<!-- begin function 11 read_canvas%d() -->\n\
5883
read_canvas%d = function(){\
7614 schaersvoo 5884
 var reply = \"\";\
5885
 var p = 0;\
8074 schaersvoo 5886
 var prec = %d;\
7614 schaersvoo 5887
 while(userdraw_x[p]){\
8074 schaersvoo 5888
  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 5889
  p = p+2;\
5890
 };\
11806 schaersvoo 5891
 if(p == 0){return;};\
7614 schaersvoo 5892
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
5893
  var p = 0;var input_reply = new Array();\
5894
  if( document.getElementById(\"canvas_input0\")){\
5895
   var t = 0;\
5896
   while(document.getElementById(\"canvas_input\"+t)){\
5897
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5898
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5899
     p++;\
5900
    };\
5901
    t++;\
5902
   };\
5903
  };\
11088 schaersvoo 5904
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5905
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5906
  }\
5907
  else\
5908
  {\
5909
   return reply +\"\\n\"+input_reply;\
5910
  }\
5911
 }\
5912
 else\
5913
 {\
11088 schaersvoo 5914
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5915
   return reply +\"\\n\"+userdraw_text;\
5916
  }\
5917
  else\
5918
  {\
5919
   return reply;\
5920
  }\
5921
 };\
8108 schaersvoo 5922
};\n\
8257 schaersvoo 5923
<!-- end function 11 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 5924
    break;
5925
    case 12: fprintf(js_include_file,"\
8257 schaersvoo 5926
\n<!-- begin function 12 read_canvas%d() -->\n\
5927
read_canvas%d = function(){\
8074 schaersvoo 5928
 set_reply_precision();\
7614 schaersvoo 5929
 var reply = \"\";\
5930
 var p = 0;\
5931
 for(p = 0; p< userdraw_x.lenght;p = p+2){\
5932
  if(userdraw_x[p] != null){\
5933
    reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
5934
  };\
5935
 };\
11806 schaersvoo 5936
 if(p == 0){return;};\
7614 schaersvoo 5937
 if( document.getElementById(\"canvas_input0\") ){\
5938
  var p = 0;var input_reply = new Array();\
5939
  if( document.getElementById(\"canvas_input0\")){\
5940
   var t = 0;\
5941
   while(document.getElementById(\"canvas_input\"+t)){\
5942
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5943
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5944
     p++;\
5945
    };\
5946
    t++;\
5947
   };\
5948
  };\
11088 schaersvoo 5949
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5950
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5951
  }\
5952
  else\
5953
  {\
5954
   return reply +\"\\n\"+input_reply;\
5955
  }\
5956
 }\
5957
 else\
5958
 {\
11088 schaersvoo 5959
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5960
   return reply +\"\\n\"+userdraw_text\
5961
  }\
5962
  else\
5963
  {\
5964
   return reply;\
5965
  }\
5966
 };\
8108 schaersvoo 5967
};\n\
8257 schaersvoo 5968
<!-- end function 12 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 5969
    break;
5970
    case 13: fprintf(js_include_file,"\
8257 schaersvoo 5971
\n<!-- begin function 13 read_canvas%d() -->\n\
5972
read_canvas%d = function(){\
7614 schaersvoo 5973
 var reply = new Array();\
5974
 var p = 0;var i = 0;\
8074 schaersvoo 5975
 var prec = %d;\
7614 schaersvoo 5976
 while(userdraw_x[p]){\
8074 schaersvoo 5977
  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 5978
  p = p+2;i++;\
5979
 };\
11806 schaersvoo 5980
 if(p == 0){return;};\
7614 schaersvoo 5981
 if( document.getElementById(\"canvas_input0\") ){\
5982
  var p = 0;var input_reply = new Array();\
5983
  if( document.getElementById(\"canvas_input0\")){\
5984
   var t = 0;\
5985
   while(document.getElementById(\"canvas_input\"+t)){\
5986
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
5987
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
5988
     p++;\
5989
    };\
5990
    t++;\
5991
   };\
5992
  };\
11088 schaersvoo 5993
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 5994
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
5995
  }\
5996
  else\
5997
  {\
5998
   return reply +\"\\n\"+input_reply;\
5999
  }\
6000
 }\
6001
 else\
6002
 {\
11088 schaersvoo 6003
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6004
   return reply +\"\\n\"+userdraw_text\
6005
  }\
6006
  else\
6007
  {\
6008
   return reply;\
6009
  }\
6010
 };\
8108 schaersvoo 6011
};\n\
8257 schaersvoo 6012
<!-- end function 13 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6013
    break;
6014
    case 14: fprintf(js_include_file,"\
8257 schaersvoo 6015
\n<!-- begin function 14 read_canvas%d() -->\n\
6016
read_canvas%d = function(){\
8074 schaersvoo 6017
 set_reply_precision();\
7614 schaersvoo 6018
 var reply = new Array();\
6019
 var p = 0;var i = 0;\
6020
 while(userdraw_x[p]){\
6021
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
6022
  p = p+2;i++;\
6023
 };\
11806 schaersvoo 6024
 if(p == 0){return;};\
7614 schaersvoo 6025
 if( document.getElementById(\"canvas_input0\") ){\
6026
  var p = 0;var input_reply = new Array();\
6027
  if( document.getElementById(\"canvas_input0\")){\
6028
   var t = 0;\
6029
   while(document.getElementById(\"canvas_input\"+t)){\
6030
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6031
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6032
     p++;\
6033
    };\
6034
    t++;\
6035
   };\
6036
  };\
11088 schaersvoo 6037
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6038
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6039
  }\
6040
  else\
6041
  {\
6042
   return reply +\"\\n\"+input_reply;\
6043
  }\
6044
 }\
6045
 else\
6046
 {\
11088 schaersvoo 6047
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6048
   return reply +\"\\n\"+userdraw_text;\
6049
  }\
6050
  else\
6051
  {\
6052
   return reply;\
6053
  }\
6054
 };\
8108 schaersvoo 6055
};\n\
8257 schaersvoo 6056
<!-- end function 14 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6057
    break;
6058
    case 15: fprintf(js_include_file,"\
8257 schaersvoo 6059
\n<!-- begin function 15  read_canvas%d() -->\n\
6060
read_canvas%d = function(){\
7614 schaersvoo 6061
 var input_reply = new Array();\
6062
 var p = 0;\
6063
 if( document.getElementById(\"canvas_input0\")){\
6064
  var t = 0;\
6065
  while(document.getElementById(\"canvas_input\"+t)){\
6066
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6067
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6068
    p++;\
6069
   };\
6070
   t++;\
6071
  };\
6072
 };\
11088 schaersvoo 6073
 if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6074
   return input_reply +\"\\n\"+userdraw_text;\
6075
 }\
6076
 else\
6077
 {\
6078
  return input_reply;\
6079
 };\
8108 schaersvoo 6080
};\n\
8257 schaersvoo 6081
<!-- end function 15 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6082
    break;
6083
    case 16: fprintf(js_include_file,"\
7653 schaersvoo 6084
\n<!-- begin function 16 read_mathml() -->\n\
7614 schaersvoo 6085
function read_mathml(){\
6086
 var reply = new Array();\
6087
 var p = 0;\
6088
 if( document.getElementById(\"mathml0\")){\
6089
  while(document.getElementById(\"mathml\"+p)){\
6090
   reply[p] = document.getElementById(\"mathml\"+p).value;\
6091
   p++;\
6092
  };\
6093
 };\
6094
return reply;\
6095
};\
6096
this.read_mathml = read_mathml;\n\
7653 schaersvoo 6097
<!-- end function 16 read_mathml() -->");
7614 schaersvoo 6098
    break;
6099
    case 17:  fprintf(js_include_file,"\
8257 schaersvoo 6100
\n<!-- begin function 17 read_canvas%d() -->\n\
6101
read_canvas%d = function(){\
11080 schaersvoo 6102
 var len = userdraw_x.length;\
6103
 if( len == 0){alert(\"no text typed...\");return;}\
6104
 var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
6105
 for(var p = 1 ; p < len ; p++){\
6106
  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
6107
 };\
6108
 return rep;\
8108 schaersvoo 6109
};\n\
8257 schaersvoo 6110
<!-- end function 17 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6111
    break;
6112
    case 18: fprintf(js_include_file,"\
10956 schaersvoo 6113
\n<!-- javascript has no real modulo function -->\n\
6114
function mod(n, m){\
6115
 var m = parseInt(((n %% m) + m) %% m);\
6116
 return m;\
6117
};\
8257 schaersvoo 6118
\n<!-- begin function 18 read_canvas%d() -->\n\
6119
read_canvas%d = function(){\
7614 schaersvoo 6120
 var p = 0;\
6121
 var reply = new Array();\
6122
 var name;\
6123
 var t = true;\
8000 schaersvoo 6124
 var h;var m;var s;\
7614 schaersvoo 6125
 while(t){\
8000 schaersvoo 6126
  try{\
6127
   name = eval('clocks'+p);\
6128
   h = name.H;m = name.M;s = name.S;\
10956 schaersvoo 6129
   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
8000 schaersvoo 6130
   reply[p] = h+\":\"+m+\":\"+s;\
6131
   p++;\
6132
  }catch(e){t=false;};\
7614 schaersvoo 6133
 };\
8000 schaersvoo 6134
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 6135
 return reply;\
8108 schaersvoo 6136
};\n\
8257 schaersvoo 6137
<!-- end function 18 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6138
    break;
6139
    case 19: fprintf(js_include_file,"\
8257 schaersvoo 6140
\n<!-- begin function 19 read_canvas%d() -->\n\
6141
read_canvas%d = function(){\
7614 schaersvoo 6142
 return reply[0];\
8108 schaersvoo 6143
};\n\
8257 schaersvoo 6144
<!-- end function 19 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
8130 schaersvoo 6145
    break;
7614 schaersvoo 6146
    case 20: fprintf(js_include_file,"\
8257 schaersvoo 6147
\n<!-- begin function 20 read_canvas%d() -->\n\
6148
read_canvas%d = function(){\
8074 schaersvoo 6149
 var prec = %d;\
7614 schaersvoo 6150
 var len  = ext_drag_images.length;\
6151
 var reply = new Array(len);\
6152
 for(var p = 0 ; p < len ; p++){\
6153
    var img = ext_drag_images[p];\
8556 schaersvoo 6154
    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 6155
 };\
6156
 return reply;\
8108 schaersvoo 6157
};\n\
8257 schaersvoo 6158
<!-- end function 20 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6159
    break;
6160
    case 21: fprintf(js_include_file,"\
8257 schaersvoo 6161
\n<!-- begin function 21 read_canvas%d() -->\n\
6162
read_canvas%d = function(){\
7614 schaersvoo 6163
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
6164
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 6165
 var prec = %d;\
7614 schaersvoo 6166
 while(userdraw_x[p]){\
8074 schaersvoo 6167
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 6168
  p++;\
6169
 };\
11806 schaersvoo 6170
 if(p == 0){return;};\
7614 schaersvoo 6171
 if( document.getElementById(\"canvas_input0\") ){\
6172
  var p = 0;var input_reply = new Array();\
6173
  if( document.getElementById(\"canvas_input0\")){\
6174
   var t = 0;\
6175
   while(document.getElementById(\"canvas_input\"+t)){\
6176
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6177
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6178
     p++;\
6179
    };\
6180
    t++;\
6181
   };\
6182
  };\
11088 schaersvoo 6183
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6184
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6185
  }\
6186
  else\
6187
  {\
6188
   return reply_coord+\"\\n\"+input_reply;\
6189
  }\
6190
 }\
6191
 else\
6192
 {\
11088 schaersvoo 6193
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6194
   return reply_coord+\"\\n\"+userdraw_text;\
6195
  }\
6196
  else\
6197
  {\
6198
   return reply_coord;\
6199
  };\
6200
 };\
8108 schaersvoo 6201
};\n\
8257 schaersvoo 6202
<!-- end function 21 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6203
    break;
6204
    case 22: fprintf(js_include_file,"\
8257 schaersvoo 6205
\n<!-- begin function 22 read_canvas%d() -->\n\
6206
read_canvas%d = function(){\
7614 schaersvoo 6207
 var reply = new Array();\
7963 schaersvoo 6208
 var lu = userdraw_x.length;\
11806 schaersvoo 6209
 if(lu == 0){return;};\
7614 schaersvoo 6210
 var idx = 0;\
8074 schaersvoo 6211
 var prec = %d;\
7963 schaersvoo 6212
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 6213
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
6214
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 6215
 };\
6216
 if( document.getElementById(\"canvas_input0\") ){\
6217
  var p = 0;var input_reply = new Array();\
6218
  if( document.getElementById(\"canvas_input0\")){\
6219
   var t = 0;\
6220
   while(document.getElementById(\"canvas_input\"+t)){\
6221
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6222
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6223
     p++;\
6224
    };\
6225
    t++;\
6226
   };\
6227
  };\
11088 schaersvoo 6228
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6229
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6230
  }\
6231
  else\
6232
  {\
6233
   return reply +\"\\n\"+input_reply;\
6234
  }\
6235
 }\
6236
 else\
6237
 {\
11088 schaersvoo 6238
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6239
   return reply +\"\\n\"+userdraw_text;\
6240
  }\
6241
  else\
6242
  {\
6243
   return reply;\
6244
  }\
6245
 };\
8108 schaersvoo 6246
};\n\
8257 schaersvoo 6247
<!-- end function 22 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6248
    break;
7782 schaersvoo 6249
    case 23: fprintf(js_include_file,"\
8257 schaersvoo 6250
\n<!-- begin function 23 read_canvas%d() default 5 px marge -->\n\
6251
read_canvas%d = function(){\
7782 schaersvoo 6252
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
6253
 var lu = userdraw_x.length;\
6254
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 6255
 var reply_x = new Array();var reply_y = new Array();\
6256
 var marge = 5;var p = 0;\
8074 schaersvoo 6257
 var prec = %d;\
7782 schaersvoo 6258
 for(var i = 0; i < lu - 1 ; i++ ){\
10987 schaersvoo 6259
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
8074 schaersvoo 6260
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 6261
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
6262
   p++;\
7782 schaersvoo 6263
  };\
8074 schaersvoo 6264
  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 6265
 };\
6266
 if( document.getElementById(\"canvas_input0\")){\
6267
  var p = 0;var input_reply = new Array();\
6268
  if( document.getElementById(\"canvas_input0\")){\
6269
   var t = 0;\
6270
   while(document.getElementById(\"canvas_input\"+t)){\
6271
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6272
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6273
     p++;\
6274
    };\
6275
    t++;\
6276
   };\
6277
  };\
11088 schaersvoo 6278
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6279
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6280
  }\
6281
  else\
6282
  {\
6283
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
6284
  }\
6285
 }\
6286
 else\
6287
 {\
11088 schaersvoo 6288
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6289
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
6290
  }\
6291
  else\
6292
  {\
6293
   return reply_x+\"\\n\"+reply_y;\
6294
  };\
6295
 };\
8108 schaersvoo 6296
};\n\
8257 schaersvoo 6297
<!-- end function 23 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7782 schaersvoo 6298
    break;
7984 schaersvoo 6299
    case 24: fprintf(js_include_file,"\n\
8257 schaersvoo 6300
<!-- begin function 24  read_canvas%d() -->\n\
6301
read_canvas%d = function(){\
7984 schaersvoo 6302
 var input_reply = new Array();\
6303
 var p = 0;\
6304
 if( document.getElementById(\"canvas_input0\")){\
6305
  while(document.getElementById(\"canvas_input\"+p)){\
6306
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
6307
    p++;\
6308
  };\
6309
  return input_reply;\
6310
 };\
8108 schaersvoo 6311
};\n\
8257 schaersvoo 6312
<!-- end function 24 read_canvas%d() -->",canvas_root_id,canvas_root_id,canvas_root_id);
7984 schaersvoo 6313
    break;
8083 schaersvoo 6314
    case 25:
8257 schaersvoo 6315
    fprintf(js_include_file,"\n<!-- begin function 25 read_canvas%d() : angle(s) in degrees-->\n\
6316
read_canvas%d = function(){\
8083 schaersvoo 6317
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
6318
 var lu = userdraw_radius.length;\
6319
 var prec = %d;\
6320
 var angle_reply = new Array(lu);\
6321
 for(var p = 0 ; p < lu ; p++){\
6322
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
6323
 };\
6324
 return angle_reply;\
8108 schaersvoo 6325
};\n\
8257 schaersvoo 6326
<!-- end function 25 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 6327
    break;
6328
    case 26:
8257 schaersvoo 6329
    fprintf(js_include_file,"\n<!-- begin function 26 read_canvas%d() : angle(s) in radians-->\n\
6330
read_canvas%d = function(){\
8083 schaersvoo 6331
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
6332
 var lu = userdraw_radius.length;\
6333
 var prec = %d;\
6334
 var angle_reply = new Array(lu);\
6335
 for(var p = 0 ; p < lu ; p++){\
6336
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
6337
 };\
6338
 return angle_reply;\
8108 schaersvoo 6339
};\n\
8257 schaersvoo 6340
<!-- end function 26 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 6341
    break;
8127 schaersvoo 6342
    case 27:
8257 schaersvoo 6343
    fprintf(js_include_file,"\n<!-- begin function 27 read_canvas%d()  : inputfield(s) location and their values : -->\n\
6344
read_canvas%d = function(){\
8127 schaersvoo 6345
 var lu = userdraw_x.length;\
6346
 if( lu < 1){alert(\"nothing drawn...\");return;}\
6347
 set_reply_precision();\
6348
 var prec = %d;\
11080 schaersvoo 6349
 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 6350
 for(var p = 0 ; p < lu ; p++){\
11080 schaersvoo 6351
   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 6352
 };\
11080 schaersvoo 6353
 return rep;\
8127 schaersvoo 6354
};\n\
8257 schaersvoo 6355
<!-- end function 27 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8127 schaersvoo 6356
    break;
8322 schaersvoo 6357
    case 28:
6358
    fprintf(js_include_file,"\n<!-- begin function 28 read_canvas%d() -->\n\
6359
read_canvas%d = function(){\
6360
 var prec = %d;\
6361
 var reply = new Array();var p = 0;\
6362
 var idx = 0;\
6363
 while(userdraw_x[p]){\
6364
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
6365
  idx++;\
6366
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
6367
  idx++;\
6368
  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
6369
  idx++;\
6370
  p++;\
6371
 };\
6372
 if( p == 0){alert(\"nothing drawn...\");return;}\
6373
 return reply;\
6374
};\n\
9213 schaersvoo 6375
<!-- end function 28 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8322 schaersvoo 6376
    break;
9213 schaersvoo 6377
    case 29:
6378
    fprintf(js_include_file,"\n<!-- begin function 29 read_canvas%d() -->\n\
6379
function xy_precision(array_x,array_y){\
6380
 var len = array_x.length;\
6381
 var x_array = new Array(len);\
6382
 var y_array = new Array(len);\
6383
 var prec = %d;\
6384
 for(var p = 0 ; p < len ; p++ ){\
6385
  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
6386
  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
6387
 };\
9230 schaersvoo 6388
 return x_array+\";\"+y_array;\
9213 schaersvoo 6389
};\n\
6390
function round_to_pixel(array_r){\
6391
var len = array_r.length;\
6392
 for(var p = 0 ; p < len ; p++ ){\
6393
  array_r[p] = Math.round(array_r[p]);\
6394
 };\
6395
 return array_r;\
6396
};\
6397
read_canvas%d = function(){\
9300 schaersvoo 6398
 var reply=\" \";\
6399
 if( points_x && points_x.length > 0 ){reply = reply + xy_precision(points_x,points_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6400
 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\
6401
 if( segments_x && segments_x.length > 0 ){ reply = reply +  xy_precision(segments_x,segments_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6402
 if( arrows_x && arrows_x.length > 0 ){ reply = reply +  xy_precision(arrows_x,arrows_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6403
 if( lines_x && lines_x.length > 0 ){ reply = reply + xy_precision(lines_x,lines_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
6404
 if( triangles_x && triangles_x.length > 0){ reply = reply + xy_precision(triangles_x,triangles_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
11226 schaersvoo 6405
 if( polys_x && polys_x.length > 0){ reply = reply + xy_precision(polys_x,polys_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9372 schaersvoo 6406
 if( rects_x && rects_x.length > 0 ){ reply = reply + xy_precision(rects_x,rects_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9300 schaersvoo 6407
 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 6408
 if( parallelogram_x && parallelogram_x.length > 0){ reply = reply + xy_precision(parallelogram_x,parallelogram_y)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\n\
9338 schaersvoo 6409
 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 6410
 return reply;\
6411
};\n\
6412
<!-- end function 29 read_canvas%d() -->",canvas_root_id,reply_precision,canvas_root_id,canvas_root_id);
6413
    break;
9289 schaersvoo 6414
    case 30:
6415
    fprintf(js_include_file,"\n<!-- begin function 30 read_canvas%d() -->\n\
6416
read_canvas%d = function(){\
6417
 var reply = new Array(3);\
6418
 var prec = %d;\
6419
 reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
6420
 reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
6421
 reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
6422
 return reply;\
6423
};\n\
6424
<!-- end function 30 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
6425
    break;
6426
    case 31:
6427
    fprintf(js_include_file,"\n<!-- begin function 31 read_canvas%d() -->\n\
6428
read_canvas%d = function(){\
6429
 var reply = new Array(3);\
6430
 var prec = %d;\
6431
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
6432
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
6433
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
6434
 return reply;\
6435
};\n\
6436
<!-- end function 31 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
6437
    break;
6438
    case 32:
6439
    fprintf(js_include_file,"\n<!-- begin function 32 read_canvas%d() -->\n\
6440
read_canvas%d = function(){\
6441
 var reply = new Array(6);\
6442
 var prec = %d;\
6443
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
6444
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
6445
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
6446
 reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
6447
 reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
6448
 reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
6449
 return reply;\
6450
};\n\
6451
<!-- end function 32 read_canvas%d() -->",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
6452
    break;
7614 schaersvoo 6453
    default: canvas_error("hmmm unknown replyformat...");break;
6454
}
6455
 return;
6456
}
6457
 
6458
 
8224 bpr 6459
/*
6460
 add drawfunction :
7614 schaersvoo 6461
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
6462
 - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
6463
 - grid / mathml
6464
 - will not scale or zoom in
6465
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
8224 bpr 6466
 - is printed directly into 'js_include_file'
7614 schaersvoo 6467
*/
6468
 
11021 schaersvoo 6469
void add_javascript_function(int js_function[],int canvas_root_id){
7614 schaersvoo 6470
int i;
6471
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
11017 schaersvoo 6472
 if( js_function[i] == 1){
7614 schaersvoo 6473
    switch(i){
11026 bpr 6474
    case JS_FIND_ANGLE:
11025 schaersvoo 6475
    fprintf(js_include_file,"\n\
6476
<!-- function find_angle() -->\n\
6477
 function find_angle(xc,yc,x1,y1){\
11019 schaersvoo 6478
 var dx = x1 - xc;\
6479
 var dy = yc - y1;\
6480
 if( dx > 0 && dy < 0){ return Math.atan(-1*dy/dx);};\
6481
 if( dx < 0 && dy < 0){ return Math.PI + Math.atan(-1*dy/dx);};\
6482
 if( dx < 0 && dy > 0){ return Math.PI + Math.atan(-1*dy/dx);};\
6483
 if( dx > 0 && dy > 0){ return 2*Math.PI + Math.atan(-1*dy/dx);};};");
11017 schaersvoo 6484
    break;
8448 schaersvoo 6485
    case DRAW_EXTERNAL_IMAGE:
10953 bpr 6486
/* the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
8448 schaersvoo 6487
 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]);
6488
*/
7614 schaersvoo 6489
fprintf(js_include_file,"\n<!-- drag external images --->\n\
7653 schaersvoo 6490
var external_ctx = external_canvas.getContext(\"2d\");\
6491
var external_canvas_rect = external_canvas.getBoundingClientRect();\
6492
canvas_div.addEventListener(\"mousedown\",setxy,false);\
6493
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
6494
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
6495
var selected_image = null;\
6496
var ext_image_cnt = 0;\
6497
var ext_drag_images = new Array();\
8448 schaersvoo 6498
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt){\
7653 schaersvoo 6499
 ext_image_cnt = idx;\
8448 schaersvoo 6500
 if(draggable == 1 ){\
6501
  reply[click_cnt] = 0;\
6502
 };\
7653 schaersvoo 6503
 var image = new Image();\
6504
 image.src = URL;\
6505
 image.onload = function(){\
8448 schaersvoo 6506
  if( sx < 1 ){ sx = 0; };\
6507
  if( sy < 1 ){ sy = 0; };\
6508
  if( swidth < 1 ){swidth = image.width;};\
6509
  if( sheight < 1 ){sheight = image.height;};\
6510
  if( width < 1 ){width = image.width;};\
6511
  if( height < 1 ){height = image.height;};\
6512
  if( resizable == 0 ){\
6513
   if( swidth > image.width ){ swidth = image.width; };\
6514
   if( sheight > image.height){ sheight = image.height;};\
6515
   if( width > image.width ){ width = image.width; };\
6516
   if( height > image.height){ height = image.height;};\
6517
  };\
6518
  var img = new Array(11);\
7653 schaersvoo 6519
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
8448 schaersvoo 6520
  img[6] = x0;img[7] = y0;img[8] = width;img[9] = height;img[10] = click_cnt;\
7653 schaersvoo 6521
  ext_drag_images[idx] = img;\
6522
  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
6523
 };\
6524
};\
6525
function dragstop(evt){\
6526
 selected_image = null;return;\
6527
};\
6528
function dragxy(evt){\
6529
 if( selected_image != null ){\
6530
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
6531
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
6532
  var s_img = ext_drag_images[selected_image];\
6533
  s_img[6] = evt.clientX - external_canvas_rect.left + xoff;\
6534
  s_img[7] = evt.clientY - external_canvas_rect.top + yoff;\
8386 schaersvoo 6535
  if( use_snap_to_points == 1){\
6536
   var img_xy = snap_to_points(s_img[6],s_img[7]);\
6537
   s_img[6] = img_xy[0];s_img[7] = img_xy[1];\
6538
  }\
6539
  else\
6540
  {\
6541
   if( x_use_snap_to_grid == 1 ){\
6542
    s_img[6] = snap_to_x(s_img[6]);\
6543
   };\
6544
   if( y_use_snap_to_grid == 1 ){\
6545
    s_img[7] = snap_to_x(s_img[7]);\
6546
   };\
6547
  };\
7653 schaersvoo 6548
  ext_drag_images[selected_image] = s_img;\
6549
  external_ctx.clearRect(0,0,xsize,ysize);\
6550
  for(var i = 0; i <= ext_image_cnt ; i++){\
6551
   var img = ext_drag_images[i];\
6552
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
6553
  };\
6554
 };\
6555
};\
6556
function setxy(evt){\
6557
 if( ! selected_image && evt.which == 1 ){\
6558
  var xoff = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);\
6559
  var yoff = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);\
6560
  var xm = evt.clientX - external_canvas_rect.left + xoff;\
6561
  var ym = evt.clientY - external_canvas_rect.top + yoff;\
8448 schaersvoo 6562
  var img;\
7653 schaersvoo 6563
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
8448 schaersvoo 6564
   if( ext_drag_images[p] ){\
6565
    img = ext_drag_images[p];\
6566
    if( img[0] != 0 ){\
6567
     if( xm > img[6] && xm < img[6] + img[8]){\
6568
      if( ym > img[7] && ym < img[7] + img[9]){\
6569
       if( img[0] == 1){\
6570
        if( reply[img[10]] == 1 ){\
6571
         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
6572
        }\
6573
        else\
6574
        {\
6575
         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
6576
        };\
6577
        external_ctx.lineWidth = 6;\
6578
        external_ctx.beginPath();\
6579
        external_ctx.rect(img[6],img[7],img[8],img[9]);\
6580
        external_ctx.closePath();\
6581
        external_ctx.stroke();\
6582
        return;\
6583
       }\
6584
       else\
6585
       {\
6586
        img[6] = xm;\
6587
        img[7] = ym;\
6588
        ext_drag_images[p] = img;\
6589
        selected_image = p;\
6590
        dragxy(evt);\
6591
       };\
6592
      };\
7653 schaersvoo 6593
     };\
6594
    };\
6595
   };\
6596
  };\
6597
 }\
6598
 else\
6599
 {\
6600
  selected_image = null;\
6601
 };\
8448 schaersvoo 6602
};");
7614 schaersvoo 6603
    break;
8370 schaersvoo 6604
    case DRAW_BEZIER:
6605
fprintf(js_include_file,"\n<!-- draw bezier curve -->\n\
6606
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){\
6607
 var obj;\
6608
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6609
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6610
 }\
6611
 else\
6612
 {\
6613
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6614
 };\
6615
 var ctx = obj.getContext(\"2d\");\
6616
 ctx.save();\
6617
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6618
 ctx.lineWidth = linewidth;\
11088 schaersvoo 6619
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8370 schaersvoo 6620
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
6621
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
6622
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6623
 ctx.beginPath();\
6624
 ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
6625
 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]));\
6626
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
6627
 ctx.stroke();\
6628
 ctx.restore();\
6629
};\n",canvas_root_id,canvas_root_id,canvas_root_id);
6630
    break;
7614 schaersvoo 6631
    case DRAW_GRIDFILL:/* not used for userdraw */
6632
fprintf(js_include_file,"\n<!-- draw gridfill -->\n\
11820 schaersvoo 6633
if( typeof(click_fill_pattern) == 'undefined'){var click_fill_pattern;};\
8105 schaersvoo 6634
var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize){\
11820 schaersvoo 6635
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
6636
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
6637
 var fc = %d+canvas_type;\n\
6638
 fill_canvas_no.push(fc);\
6639
 var obj = create_canvas%d(fc,xsize,ysize);\n\
6640
 var ctx = obj.getContext('2d');\n\
7614 schaersvoo 6641
 var x,y;\
11820 schaersvoo 6642
 ctx.fillStyle='rgba(255,255,255,0.01)';\n\
6643
 ctx.rect(0,0,xsize,ysize);\n\
6644
 ctx.fill();\n\
6645
 ctx.lineWidth = linewidth;\
6646
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
6647
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
6648
 for( x = 0 ; x < xsize ; x = x + dx ){\
6649
  ctx.beginPath();\
6650
  ctx.moveTo(x,0);\
6651
  ctx.lineTo(x,ysize);\
6652
  ctx.closePath();\
6653
  ctx.stroke();\
7614 schaersvoo 6654
 };\
11820 schaersvoo 6655
 for( y = 0 ; y < ysize; y = y + dy ){\
6656
  ctx.beginPath();\
6657
  ctx.moveTo(0,y);\
6658
  ctx.lineTo(xsize,y);\
6659
  ctx.closePath();\
6660
  ctx.stroke();\
7614 schaersvoo 6661
 };\
11820 schaersvoo 6662
 click_fill_pattern = ctx;\n\
6663
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\n\
6664
 return;};",canvas_root_id,canvas_root_id);
7614 schaersvoo 6665
    break;
8224 bpr 6666
 
7614 schaersvoo 6667
    case DRAW_IMAGEFILL:/* not  used for userdraw */
6668
fprintf(js_include_file,"\n<!-- draw imagefill -->\n\
8105 schaersvoo 6669
var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize){\
7614 schaersvoo 6670
 var obj;\
6671
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
6672
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
6673
 }\
6674
 else\
6675
 {\
6676
  obj = create_canvas%d(canvas_type,xsize,ysize);\
6677
 };\
6678
 var ctx = obj.getContext(\"2d\");\
6679
 ctx.save();\
6680
 var img = new Image();\
6681
 img.src = URL;\
6682
 img.onload = function(){\
6683
  if( (img.width > xsize-x0) && (img.height > ysize-y0) ){\
6684
    ctx.drawImage(img,x0,y0,xsize,ysize);\
6685
  }\
6686
  else\
6687
  {\
6688
    var repeat = \"repeat\";\
6689
    if(img.width > xsize - x0){\
6690
        repeat = \"repeat-y\";\
6691
    }\
6692
    else\
6693
    {\
6694
     if( img.height > ysize -x0 ){\
6695
      repeat = \"repeat-x\";\
6696
     }\
6697
    }\
6698
    var pattern = ctx.createPattern(img,repeat);\
6699
    ctx.rect(x0,y0,xsize,ysize);\
6700
    ctx.fillStyle = pattern;\
6701
  }\
6702
  ctx.fill();\
6703
 };\
6704
 ctx.restore();\
6705
 return;\
7653 schaersvoo 6706
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6707
    break;
8224 bpr 6708
 
7614 schaersvoo 6709
    case DRAW_DOTFILL:/* not  used for userdraw */
6710
fprintf(js_include_file,"\n<!-- draw dotfill -->\n\
11820 schaersvoo 6711
if( typeof(click_fill_pattern) == 'undefined'){var click_fill_pattern;};\
11817 schaersvoo 6712
var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize){\n\
11820 schaersvoo 6713
if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
11818 schaersvoo 6714
if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
11820 schaersvoo 6715
var fc = %d+canvas_type;\
11818 schaersvoo 6716
fill_canvas_no.push(fc);\
11820 schaersvoo 6717
 var obj = create_canvas%d(fc,xsize,ysize);\
6718
 var ctx = obj.getContext('2d');\
6719
 var x,y;\
6720
 ctx.fillStyle='rgba(255,255,255,0.01)';\
6721
 ctx.rect(0,0,xsize,ysize);\
6722
 ctx.fill();\
6723
 ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
6724
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
6725
 for( x = 0 ; x < xsize ; x = x + dx ){\
6726
  for( y = 0 ; y < ysize ; y = y + dy ){\
6727
   ctx.beginPath();\
6728
   ctx.arc(x,y,radius,0,2*Math.PI,false);\
6729
   ctx.closePath();\
6730
   ctx.fill();\
6731
  };\
6732
 };\
6733
 click_fill_pattern = ctx;\
6734
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
11818 schaersvoo 6735
 return;};",canvas_root_id,canvas_root_id);
7614 schaersvoo 6736
    break;
7645 schaersvoo 6737
 
7647 schaersvoo 6738
    case DRAW_DIAMONDFILL:/* not used for userdraw */
7614 schaersvoo 6739
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
11820 schaersvoo 6740
if( typeof(click_fill_pattern) == 'undefined'){var click_fill_pattern;};\
6741
var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize){\
6742
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
6743
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
6744
 var fc = %d+canvas_type;\
6745
 fill_canvas_no.push(fc);\
6746
 var obj = create_canvas%d(fc,xsize,ysize);\
6747
 var ctx = obj.getContext('2d');\
7614 schaersvoo 6748
 var x;\
6749
 var y;\
6750
 ctx.lineWidth = linewidth;\
11820 schaersvoo 6751
 ctx.fillStyle='rgba(255,255,255,0.01)';\
6752
 ctx.rect(0,0,xsize,ysize);\
6753
 ctx.fill();\
11088 schaersvoo 6754
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
11820 schaersvoo 6755
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7614 schaersvoo 6756
 y = ysize;\
11820 schaersvoo 6757
 ctx.beginPath();\
6758
 for( x = 0 ; x < xsize ; x = x + dx ){\
6759
  ctx.moveTo(x,0);\
7614 schaersvoo 6760
  ctx.lineTo(xsize,y);\
6761
  y = y - dy;\
6762
 };\
11820 schaersvoo 6763
 y=0;\
7614 schaersvoo 6764
 for( x = xsize ; x > 0 ; x = x - dx){\
6765
  ctx.moveTo(x,ysize);\
11820 schaersvoo 6766
  ctx.lineTo(0,y);\
7614 schaersvoo 6767
  y = y + dy;\
6768
 };\
11820 schaersvoo 6769
 y = 0;\
6770
 for( x = 0 ; x < xsize ; x = x + dx ){\
6771
  ctx.moveTo(x,0);\
6772
  ctx.lineTo(0,y);\
6773
  y = y + dy;\
6774
 };\
6775
 y = 0;\
6776
 for( x = 0 ; x < xsize ; x = x + dx ){\
7614 schaersvoo 6777
  ctx.moveTo(xsize,y);\
6778
  ctx.lineTo(x,ysize);\
11820 schaersvoo 6779
  y = y + dy;\
7614 schaersvoo 6780
 };\
11820 schaersvoo 6781
 ctx.closePath();\
7614 schaersvoo 6782
 ctx.stroke();\
11820 schaersvoo 6783
 click_fill_pattern = ctx;\
6784
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
7614 schaersvoo 6785
 return;\
11820 schaersvoo 6786
 }",canvas_root_id,canvas_root_id);
7614 schaersvoo 6787
    break;
8224 bpr 6788
 
7647 schaersvoo 6789
    case DRAW_HATCHFILL:/* not used for userdraw */
6790
fprintf(js_include_file,"\n<!-- draw hatch fill -->\n\
11820 schaersvoo 6791
if( typeof(click_fill_pattern) == 'undefined'){var click_fill_pattern;};\
6792
var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize){\
6793
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
6794
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
6795
 var fc = %d+canvas_type;\
6796
 fill_canvas_no.push(fc);\
6797
 var obj = create_canvas%d(fc,xsize,ysize);\
6798
 var ctx = obj.getContext('2d');\
6799
 var x,y;\
6800
 ctx.fillStyle='rgba(255,255,255,0.01)';\
6801
 ctx.rect(0,0,xsize,ysize);\
6802
 ctx.fill();\
6803
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7647 schaersvoo 6804
 ctx.lineWidth = linewidth;\
11088 schaersvoo 6805
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7647 schaersvoo 6806
 y = ysize;\
11820 schaersvoo 6807
 ctx.beginPath();\
6808
 for( x = 0 ; x < xsize ; x = x + dx ){\
6809
  ctx.moveTo(x,0);\
7647 schaersvoo 6810
  ctx.lineTo(xsize,y);\
6811
  y = y - dy;\
6812
 };\
11820 schaersvoo 6813
 y = 0;\
7647 schaersvoo 6814
 for( x = xsize ; x >= dx ; x = x - dx){\
6815
  ctx.moveTo(x,ysize);\
11820 schaersvoo 6816
  ctx.lineTo(0,y);\
7647 schaersvoo 6817
  y = y + dy;\
6818
 };\
11820 schaersvoo 6819
 ctx.closePath();\
7647 schaersvoo 6820
 ctx.stroke();\
11820 schaersvoo 6821
 click_fill_pattern = ctx;\
6822
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
7647 schaersvoo 6823
 return;\
11820 schaersvoo 6824
 };",canvas_root_id,canvas_root_id);
7647 schaersvoo 6825
    break;
7614 schaersvoo 6826
    case DRAW_CIRCLES:/*  used for userdraw */
6827
fprintf(js_include_file,"\n<!-- draw circles -->\n\
8105 schaersvoo 6828
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 6829
 ctx.save();\
8071 schaersvoo 6830
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 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)};\
7614 schaersvoo 6834
 for(var p = 0 ; p < x_points.length ; p++ ){\
6835
  ctx.beginPath();\
6836
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
6837
  ctx.closePath();\
6838
  if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6839
  if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
6840
  ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6841
  ctx.stroke();\
6842
 }\
6843
 ctx.restore();\
6844
 return;\
7653 schaersvoo 6845
};");
7614 schaersvoo 6846
    break;
7663 schaersvoo 6847
    case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
6848
fprintf(js_include_file,"\n<!-- draw polyline -->\n\
8105 schaersvoo 6849
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 6850
 ctx.save();\
8071 schaersvoo 6851
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 6852
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6853
 ctx.lineWidth = line_width;\
11088 schaersvoo 6854
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7663 schaersvoo 6855
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6856
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6857
 ctx.clearRect(0,0,xsize,ysize);\
6858
 ctx.beginPath();\
6859
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
6860
  ctx.moveTo(x_points[p],y_points[p]);\
6861
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
6862
 }\
6863
 ctx.closePath();\
6864
 ctx.stroke();\
6865
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6866
 for(var p = 0 ; p < x_points.length ; p++ ){\
6867
  ctx.beginPath();\
6868
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
6869
  ctx.closePath();ctx.fill();ctx.stroke();\
6870
 };\
6871
 ctx.restore();\
6872
 return;\
6873
};");
6874
    break;
8224 bpr 6875
 
7614 schaersvoo 6876
    case DRAW_SEGMENTS:/*  used for userdraw */
6877
fprintf(js_include_file,"\n<!-- draw segments -->\n\
8105 schaersvoo 6878
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 6879
 ctx.save();\
8071 schaersvoo 6880
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6881
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6882
 ctx.lineWidth = line_width;\
11088 schaersvoo 6883
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6884
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6885
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6886
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
6887
  ctx.beginPath();\
6888
  ctx.moveTo(x_points[p],y_points[p]);\
6889
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
6890
  ctx.closePath();\
6891
  ctx.stroke();\
6892
  }\
6893
  ctx.restore();\
6894
  return;\
6895
 };");
6896
    break;
8224 bpr 6897
 
7614 schaersvoo 6898
    case DRAW_LINES:/*  used for userdraw */
6899
fprintf(js_include_file,"\n<!-- draw lines -->\n\
6900
function calc_line(x1,x2,y1,y2){\
6901
 var marge = 2;\
6902
 if(x1 < x2+marge && x1>x2-marge){\
6903
  return [x1,0,x1,ysize];\
6904
 };\
6905
 if(y1 < y2+marge && y1>y2-marge){\
6906
  return [0,y1,xsize,y1];\
6907
 };\
6908
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
6909
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
6910
 return [0,Y1,xsize,Y2];\
6911
};\
8105 schaersvoo 6912
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 6913
 ctx.save();\
6914
 var line = new Array(4);\
8071 schaersvoo 6915
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6916
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6917
 ctx.lineWidth = line_width;\
11088 schaersvoo 6918
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6919
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6920
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6921
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
6922
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
6923
  ctx.beginPath();\
6924
  ctx.moveTo(line[0],line[1]);\
6925
  ctx.lineTo(line[2],line[3]);\
6926
  ctx.closePath();\
6927
  ctx.stroke();\
6928
  }\
6929
  ctx.restore();\
6930
  return;\
6931
 };");
6932
    break;
6933
 
8244 schaersvoo 6934
    case DRAW_DEMILINES:/*  used for userdraw */
6935
fprintf(js_include_file,"\n<!-- draw demilines -->\n\
6936
function find_inf_point(x1,y1,x2,y2){\
6937
 if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
6938
 var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
6939
 if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
6940
};\
6941
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){\
6942
 ctx.save();\
6943
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
6944
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6945
 ctx.lineWidth = line_width;\
11088 schaersvoo 6946
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8244 schaersvoo 6947
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6948
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
6949
 var pair = new Array(4);\
6950
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
6951
  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
6952
  ctx.beginPath();\
6953
  ctx.moveTo(pair[0],pair[1]);\
6954
  ctx.lineTo(pair[2],pair[3]);\
6955
  ctx.closePath();\
6956
  ctx.stroke();\
6957
  }\
6958
  ctx.restore();\
6959
  return;\
6960
 };");
6961
    break;
6962
 
7614 schaersvoo 6963
    case DRAW_CROSSHAIRS:/*  used for userdraw */
6964
fprintf(js_include_file,"\n<!-- draw crosshairs  -->\n\
8105 schaersvoo 6965
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 6966
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6967
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6968
 ctx.lineWidth = line_width;\
11088 schaersvoo 6969
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 6970
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
6971
 var x1,x2,y1,y2;\
6972
 for(var p = 0 ; p < x_points.length ; p++ ){\
6973
  x1 = x_points[p] - crosshair_size;\
6974
  x2 = x_points[p] + crosshair_size;\
6975
  y1 = y_points[p] - crosshair_size;\
6976
  y2 = y_points[p] + crosshair_size;\
6977
  ctx.beginPath();\
6978
  ctx.moveTo(x1,y1);\
6979
  ctx.lineTo(x2,y2);\
6980
  ctx.closePath();\
6981
  ctx.stroke();\
6982
  ctx.beginPath();\
6983
  ctx.moveTo(x2,y1);\
6984
  ctx.lineTo(x1,y2);\
6985
  ctx.closePath();\
6986
  ctx.stroke();\
6987
 }\
6988
 ctx.restore();\
6989
  return;\
7653 schaersvoo 6990
};");
7614 schaersvoo 6991
    break;
6992
 
6993
    case DRAW_RECTS:/*  used for userdraw */
6994
fprintf(js_include_file,"\n<!-- draw rects -->\n\
8105 schaersvoo 6995
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 6996
 ctx.save();\
8071 schaersvoo 6997
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 6998
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
6999
 ctx.lineWidth = line_width;\
11088 schaersvoo 7000
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8448 schaersvoo 7001
 ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
7614 schaersvoo 7002
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
7003
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
7004
  ctx.beginPath();\
7005
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
7006
  ctx.closePath();\
8448 schaersvoo 7007
  if(use_filled == 1 ){ctx.fillStyle = 'rgba('+fill_color+','+fill_opacity+')';ctx.fill();}\
7614 schaersvoo 7008
  ctx.stroke();\
7009
 };\
7010
 ctx.restore();\
7011
 return;\
7653 schaersvoo 7012
};");
7614 schaersvoo 7013
    break;
7014
 
7015
    case DRAW_ROUNDRECTS:/*  used for userdraw */
7016
fprintf(js_include_file,"\n<!-- draw round rects -->\n\
8105 schaersvoo 7017
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 7018
 ctx.save();\
8071 schaersvoo 7019
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7020
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7021
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
9462 schaersvoo 7022
 ctx.lineWidth = line_width;\
11088 schaersvoo 7023
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7024
 var x,y,w,h,r;\
7025
 for(var p = 0; p < x_points.length; p = p+2){\
7026
  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);\
7027
  ctx.beginPath();ctx.moveTo(x + r, y);\
7028
  ctx.lineTo(x + w - r, y);\
7029
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
7030
  ctx.lineTo(x + w, y + h - r);\
7031
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
7032
  ctx.lineTo(x + r, y + h);\
7033
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
7034
  ctx.lineTo(x, y + r);\
7035
  ctx.quadraticCurveTo(x, y, x + r, y);\
7036
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
7037
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7038
  if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();};\
7039
  ctx.stroke();\
7040
 }\
7041
 ctx.restore();\
7653 schaersvoo 7042
};");
8224 bpr 7043
    break;
7614 schaersvoo 7044
 
7045
    case DRAW_ELLIPSES:/* not  used for userdraw */
7046
fprintf(js_include_file,"\n<!-- draw ellipses -->\n\
8105 schaersvoo 7047
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 7048
 var obj;\
7049
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7050
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7051
 }\
7052
 else\
7053
 {\
7054
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7055
 };\
7056
 var ctx = obj.getContext(\"2d\");\
7057
 ctx.save();\
8071 schaersvoo 7058
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7059
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7060
 var cx,cy,ry,rx;\
7061
 ctx.lineWidth = line_width;\
11088 schaersvoo 7062
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7063
 if( use_filled == 1 ){ctx.fillStyle =\"rgba(\"+fill_color+\",\"+fill_opacity+\")\";};\
7064
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7065
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7066
 for(var p=0;p< x_points.length;p = p+2){\
7067
  ctx.beginPath();\
7068
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
7069
  ctx.translate(cx - rx, cy - ry);\
7070
  ctx.scale(rx, ry);\
7071
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
7072
  if( use_filled == 1 ){ctx.fill();}\
7073
  ctx.stroke();\
7074
 };\
7075
 ctx.restore();\
7653 schaersvoo 7076
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 7077
    break;
7078
 
7079
    case DRAW_PATHS: /*  used for userdraw */
7080
fprintf(js_include_file,"\n<!-- draw paths -->\n\
8105 schaersvoo 7081
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 7082
 ctx.save();\
8071 schaersvoo 7083
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7084
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7085
 ctx.lineWidth = line_width;\
11088 schaersvoo 7086
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7087
 ctx.lineJoin = \"round\";\
7088
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7089
 ctx.beginPath();\
7090
 ctx.moveTo(x_points[0],y_points[0]);\
7091
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
7092
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
7093
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7094
 if(use_filled == 1){ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";ctx.fill();}\
7095
 ctx.stroke();\
7096
 ctx.restore();\
7097
 return;\
7098
};");
8224 bpr 7099
 
7614 schaersvoo 7100
    break;
7101
    case DRAW_ARROWS:/*  used for userdraw */
7102
fprintf(js_include_file,"\n<!-- draw arrows -->\n\
8105 schaersvoo 7103
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 7104
 ctx.save();\
8071 schaersvoo 7105
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7106
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7107
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7108
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7109
 ctx.lineWidth = line_width;\
11088 schaersvoo 7110
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7111
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7112
 ctx.lineCap = \"round\";\
7113
 var x1,y1,x2,y2,dx,dy,len;\
7114
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 7115
   ctx.save();\
7614 schaersvoo 7116
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
7117
   len = Math.sqrt(dx*dx+dy*dy);\
7118
   ctx.translate(x2,y2);\
7119
   ctx.rotate(Math.atan2(dy,dx));\
7120
   ctx.lineCap = \"round\";\
7121
   ctx.beginPath();\
7122
   ctx.moveTo(0,0);\
7123
   ctx.lineTo(-len,0);\
7124
   ctx.closePath();\
7125
   ctx.stroke();\
7126
   ctx.beginPath();\
7127
   ctx.moveTo(0,0);\
7128
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
7129
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
7130
   ctx.closePath();\
7131
   ctx.fill();\
7874 schaersvoo 7132
   ctx.restore();\
7614 schaersvoo 7133
   if( type == 2 ){\
7134
     ctx.save();\
7135
     ctx.translate(x1,y1);\
7136
     ctx.rotate(Math.atan2(-dy,-dx));\
7137
     ctx.beginPath();\
7138
     ctx.moveTo(0,0);\
8347 schaersvoo 7139
     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
7140
     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
7614 schaersvoo 7141
     ctx.closePath();\
7142
     ctx.stroke();\
7143
     ctx.fill();\
7874 schaersvoo 7144
     ctx.restore();\
8379 schaersvoo 7145
   };\
7146
  };\
7614 schaersvoo 7147
  ctx.restore();\
7148
  return;\
7653 schaersvoo 7149
};");
7614 schaersvoo 7150
    break;
7151
 
7152
    case DRAW_VIDEO:/* not  used for userdraw */
7153
fprintf(js_include_file,"\n<!-- draw video -->\n\
8105 schaersvoo 7154
var draw_video = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 7155
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7156
 var video_div = document.createElement(\"div\");\
7157
 canvas_div.appendChild(video_div);\
7158
 video_div.style.position = \"absolute\";\
7159
 video_div.style.left = x+\"px\";\
7160
 video_div.style.top = y+\"px\";\
7161
 video_div.style.width = w+\"px\";\
7162
 video_div.style.height = h+\"px\";\
7163
 var video = document.createElement(\"video\");\
7164
 video_div.appendChild(video);\
7165
 video.style.width = w+\"px\";\
7166
 video.style.height = h+\"px\";\
7167
 video.autobuffer = true;\
7168
 video.controls = true;video.autoplay = false;\
7169
 var src = document.createElement(\"source\");\
7170
 src.type = \"video/mp4\";\
7171
 src.src = URL;\
7172
 video.appendChild(src);\
7173
 video.load();\
7174
 return;\
8224 bpr 7175
};");
7614 schaersvoo 7176
    break;
8224 bpr 7177
 
7614 schaersvoo 7178
    case DRAW_AUDIO:/* not used for userdraw */
7179
fprintf(js_include_file,"\n<!-- draw audio -->\n\
8105 schaersvoo 7180
var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
7614 schaersvoo 7181
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7182
 var audio_div = document.createElement(\"div\");\
7183
 canvas_div.appendChild(audio_div);\
7184
 audio_div.style.position = \"absolute\";\
7185
 audio_div.style.left = x+\"px\";\
7186
 audio_div.style.top = y+\"px\";\
7187
 audio_div.style.width = w+\"px\";\
7188
 audio_div.style.height = h+\"px\";\
7189
 var audio = document.createElement(\"audio\");\
7190
 audio_div.appendChild(audio);\
7191
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
7192
 audio.autobuffer = true;\
8379 schaersvoo 7193
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
7194
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
7614 schaersvoo 7195
 var src1 = document.createElement(\"source\");\
7196
 src1.type = \"audio/ogg\";\
7197
 src1.src = URL1;\
7198
 audio.appendChild(src1);\
7199
 var src2 = document.createElement(\"source\");\
7200
 src2.type = \"audio/mpeg\";\
7201
 src2.src = URL2;\
7202
 audio.appendChild(src2);\
7203
 audio.load();\
7204
 return;\
7653 schaersvoo 7205
};");
7614 schaersvoo 7206
    break;
8224 bpr 7207
 
7614 schaersvoo 7208
    case DRAW_HTTP:/* not  used for userdraw */
7209
fprintf(js_include_file,"\n<!-- draw http -->\n\
8105 schaersvoo 7210
var draw_http = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 7211
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7212
 var http_div = document.createElement(\"div\");\
7213
 var iframe = document.createElement(\"iframe\");\
7214
 canvas_div.appendChild(http_div);\
7215
 http_div.appendChild(iframe);\
7216
 iframe.src = URL;\
7217
 iframe.setAttribute(\"width\",w);\
7218
 iframe.setAttribute(\"height\",h);\
7219
 return;\
7653 schaersvoo 7220
};");
7614 schaersvoo 7221
    break;
8224 bpr 7222
 
11238 schaersvoo 7223
    case DRAW_XML: /*
7224
    onclick=1 : click
7225
    onclick=2 drag
7226
    xy:drag_type = 0;
7227
    x:    drag_type = 1;
7228
    y:    drag_type = 2;
7229
    */
7230
 
7614 schaersvoo 7231
fprintf(js_include_file,"\n<!-- draw xml -->\n\
11756 schaersvoo 7232
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 7233
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7234
 var xml_div = document.createElement(\"div\");\
7235
 canvas_div.appendChild(xml_div);\
7236
 xml_div.innerHTML = mathml;\
8379 schaersvoo 7237
 xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11745 schaersvoo 7238
 var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11756 schaersvoo 7239
 var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7240
 var no_color = \"rgba(255,255,255,0)\";\
7241
 xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
11745 schaersvoo 7242
 var dragging = false;\
11747 schaersvoo 7243
 if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
7244
 if( onclick == 1 ){reply[click_cnt] = 0;};\
7245
 if( onclick == 2 ){\
7246
  xml_div.onclick = function(){\
11756 schaersvoo 7247
   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 7248
   canvas_div.onmousemove = function(evt){\
7249
    if(!dragging){return;};\
7250
    var x1;var y1;\
7251
    var mouse = dragstuff.getMouse(evt,xml_div);\
7252
    switch(drag_type){\
7253
     case 0: x1 = mouse.x;y1 = mouse.y;break;\
7254
     case 1: x1 = mouse.x;y1 = y;break;\
7255
     case 2: x1 = x;y1 = mouse.y;break;\
7256
     default:x1 = x;y1 = y; break;\
7257
    };\
7258
    if( x_use_snap_to_grid == 1 ){ x1 = snap_to_x(x1);};\
7259
    if( y_use_snap_to_grid == 1 ){ y1 = snap_to_y(y1);};\
7260
    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];};\
7261
    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
7262
    reply[click_cnt] = px2x(x1)+','+px2y(y1);\
11238 schaersvoo 7263
   };\
7614 schaersvoo 7264
  };\
11238 schaersvoo 7265
 };\
7266
 if(onclick == 1){\
11747 schaersvoo 7267
  xml_div.onclick = function(){\
11756 schaersvoo 7268
  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 7269
 };\
7270
 return;\
11745 schaersvoo 7271
};");
7614 schaersvoo 7272
    break;
7654 schaersvoo 7273
    case DRAW_SGRAPH:
8224 bpr 7274
/*
7654 schaersvoo 7275
 xstart = given
7276
 ystart = given
7277
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
7278
*/
7279
fprintf(js_include_file,"\n<!-- draw sgraph -->\n\
8105 schaersvoo 7280
var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
7658 schaersvoo 7281
 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);};\
7282
 var ctx = obj.getContext(\"2d\");\
7283
 ctx.font = fontfamily;\
7284
 var minor_opacity = 0.8*opacity;\
7285
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 7286
 var zero_x = 0.1*xsize;\
7287
 var zero_y = 0.9*ysize;\
8129 schaersvoo 7288
 var snor_x;var snor_y;\
7654 schaersvoo 7289
 if( xstart != xmin){\
7658 schaersvoo 7290
  snor_x = 0.1*xsize;\
7291
 }\
7292
 else\
7293
 {\
7294
  snor_x = 0;\
7295
  xstart = xmin;\
7296
 };\
7297
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7298
 ctx.lineWidth = 2;\
7299
 ctx.beginPath();\
7300
 ctx.moveTo(xsize,zero_y);\
7301
 ctx.lineTo(zero_x,zero_y);\
7302
 ctx.lineTo(zero_x,0);\
7303
 ctx.stroke();\
7304
 ctx.closePath();\
7305
 ctx.beginPath();\
7306
 ctx.moveTo(zero_x,zero_y);\
7307
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
7308
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
7309
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
7310
 ctx.lineTo(zero_x + snor_x,zero_y);\
7311
 ctx.stroke();\
7312
 ctx.closePath();\
7313
 ctx.beginPath();\
7314
 var num = xstart;\
7660 schaersvoo 7315
 var flipflop = 1;\
7658 schaersvoo 7316
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 7317
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 7318
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 7319
  txtsize = ctx.measureText(num).width;\
7320
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
7321
  if( flipflop == 1){\
7322
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
7323
  }\
7324
  else\
7325
  {\
7326
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
8379 schaersvoo 7327
  };\
7976 schaersvoo 7328
  num = num + xmajor;\
7658 schaersvoo 7329
 };\
7330
 ctx.stroke();\
7331
 ctx.closePath();\
7332
 ctx.lineWidth = 1;\
7333
 ctx.beginPath();\
7334
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7335
   ctx.moveTo(x,zero_y);\
7336
   ctx.lineTo(x,0);\
7337
 };\
7338
 ctx.stroke();\
7339
 ctx.closePath();\
7340
 if( xminor > 1){\
7341
  ctx.lineWidth = 0.5;\
7342
  ctx.beginPath();\
7343
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
7344
  var minor_step_x = step_x / xminor;\
7345
  var nx;\
7346
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
7347
    num = 1;\
7348
    for(var p = 1 ; p < xminor ; p++){\
7349
     nx = x + num*minor_step_x;\
7350
     ctx.moveTo(nx,zero_y);\
7351
     ctx.lineTo(nx,0);\
7352
     num++;\
7353
    };\
7354
  };\
7355
  ctx.stroke();\
7356
  ctx.closePath();\
7357
  ctx.beginPath();\
7358
  ctx.lineWidth = 2;\
7359
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7360
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7361
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
7362
  };\
7363
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
7364
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
7365
  };\
7366
  ctx.stroke();\
7367
  ctx.closePath();\
7368
  ctx.lineWidth = 0.5;\
7369
 };\
7370
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
7371
 if( ystart != ymin){\
7372
  snor_y = 0.1*ysize;\
7373
 }\
7374
 else\
7375
 {\
7376
  snor_y = 0;\
7377
  ystart = ymin;\
7378
 };\
7379
 ctx.lineWidth = 2;\
7380
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7381
 ctx.beginPath();\
7382
 ctx.moveTo(zero_x,zero_y);\
7383
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
7384
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
7385
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
7386
 ctx.lineTo(zero_x,zero_y - snor_y);\
7387
 ctx.stroke();\
7388
 ctx.closePath();\
7389
 ctx.beginPath();\
7390
 ctx.lineWidth = 1;\
7391
 num = ystart;\
7392
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
7393
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
7394
  ctx.moveTo(zero_x,y);\
7395
  ctx.lineTo(xsize,y);\
7396
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
7397
  num = num + ymajor;\
7398
 };\
7399
 ctx.stroke();\
7400
 ctx.closePath();\
7401
 if( yminor > 1){\
7402
  ctx.lineWidth = 0.5;\
7403
  ctx.beginPath();\
7404
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
7405
  var minor_step_y = step_y / yminor;\
7406
  var ny;\
7407
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
7408
   num = 1;\
7409
   for(var p = 1 ;p < yminor;p++){\
7410
     ny = y + num*minor_step_y;\
7411
     ctx.moveTo(zero_x,ny);\
7412
     ctx.lineTo(xsize,ny);\
7413
     num++;\
7414
    };\
7415
  };\
7416
  ctx.stroke();\
7417
  ctx.closePath();\
7418
  ctx.lineWidth = 2;\
7419
  ctx.beginPath();\
7420
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
7421
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
7422
   ctx.moveTo(zero_x,y);\
7423
   ctx.lineTo(zero_x+12,y);\
7424
  };\
7425
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
7426
   ctx.moveTo(zero_x,y);\
7427
   ctx.lineTo(zero_x+6,y);\
7428
  };\
7429
  ctx.stroke();\
7430
  ctx.closePath();\
7431
 };\
7432
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
11088 schaersvoo 7433
 if( typeof(legend%d)  !== 'undefined' ){\
7654 schaersvoo 7434
  ctx.globalAlpha = 1.0;\
7435
  var y_offset = 2*font_size;\
7436
  var txt;var txt_size;\
7437
  var x_offset = xsize - 2*font_size;\
7438
  var l_length = legend%d.length;var barcolor = new Array();\
11088 schaersvoo 7439
  if( typeof(legendcolors%d) !== 'undefined' ){\
7654 schaersvoo 7440
   for(var p = 0 ; p < l_length ; p++){\
7441
    barcolor[p] = legendcolors%d[p];\
7442
   };\
7443
  }else{\
7444
   if( barcolor.length == 0 ){\
7445
    for(var p = 0 ; p < l_length ; p++){\
7446
     barcolor[p] = stroke_color;\
7447
    };\
7448
   };\
7449
  };\
7450
  for(var p = 0; p < l_length; p++){\
7451
   ctx.fillStyle = barcolor[p];\
7452
   txt = legend%d[p];\
7453
   txt_size = ctx.measureText(txt).width;\
7454
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
7455
   y_offset = parseInt(y_offset + 1.5*font_size);\
7456
  };\
7457
 };\
11088 schaersvoo 7458
 if( typeof(xaxislabel) !== 'undefined' ){\
7658 schaersvoo 7459
   ctx.fillStyle = \'#000000\';\
7460
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
7461
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
7462
 };\
11088 schaersvoo 7463
 if( typeof(yaxislabel) !== 'undefined'){\
7658 schaersvoo 7464
   ctx.save();\
7465
   ctx.fillStyle = \'#000000\';\
7466
   var txt_size = ctx.measureText(yaxislabel).width;\
7467
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
7468
   ctx.rotate(-0.5*Math.PI);\
7469
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 7470
   ctx.restore();\
7658 schaersvoo 7471
 };\
7654 schaersvoo 7472
};\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);
7473
    break;
7614 schaersvoo 7474
 
7475
    case DRAW_GRID:/* not used for userdraw */
7476
fprintf(js_include_file,"\n<!-- draw grid -->\n\
8105 schaersvoo 7477
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 7478
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);};\
7479
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 7480
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7481
ctx.save();\
8071 schaersvoo 7482
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 7483
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
7484
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7485
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
7486
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
7487
ctx.font = font_family;\
7988 schaersvoo 7488
var barcolor = new Array();\
7614 schaersvoo 7489
var xstep = xsize*xmajor/(xmax - xmin);\
7490
var ystep = ysize*ymajor/(ymax - ymin);\
7491
var x2step = xstep / xminor;\
7492
var y2step = ystep / yminor;\
7996 schaersvoo 7493
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
7494
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
7495
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
11088 schaersvoo 7496
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7497
ctx.beginPath();\
7498
ctx.lineWidth = line_width;\
7499
ctx.strokeStyle = stroke_color;\
7500
for(var p = zero_x ; p < xsize; p = p + xstep){\
7501
 ctx.moveTo(p,0);\
7502
 ctx.lineTo(p,ysize);\
7503
};\
7504
for(var p = zero_x ; p > 0; p = p - xstep){\
7505
 ctx.moveTo(p,0);\
7506
 ctx.lineTo(p,ysize);\
7507
};\
7508
for(var p = zero_y ; p < ysize; p = p + ystep){\
7509
 ctx.moveTo(0,p);\
7510
 ctx.lineTo(xsize,p);\
7511
};\
7512
for(var p = zero_y ; p > 0; p = p - ystep){\
7513
 ctx.moveTo(0,p);\
7514
 ctx.lineTo(xsize,p);\
7515
};\
11088 schaersvoo 7516
if( typeof(xaxislabel) !== 'undefined' ){\
7614 schaersvoo 7517
 ctx.save();\
7518
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7519
 var corr =  ctx.measureText(xaxislabel).width;\
7520
 ctx.fillText(xaxislabel,xsize - 1.5*corr,zero_y - tics_length - 0.4*font_size);\
7521
 ctx.restore();\
7522
};\
11088 schaersvoo 7523
if( typeof(yaxislabel) !== 'undefined' ){\
7614 schaersvoo 7524
 ctx.save();\
7525
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
7988 schaersvoo 7526
 var corr =  ctx.measureText(yaxislabel).width;\
7614 schaersvoo 7527
 ctx.translate(zero_x+tics_length + font_size,corr+font_size);\
7528
 ctx.rotate(-0.5*Math.PI);\
7529
 ctx.fillText(yaxislabel,0,0);\
7530
 ctx.restore();\
7531
};\
7532
ctx.stroke();\
7533
ctx.closePath();\
7534
if( use_axis == 1 ){\
7988 schaersvoo 7535
 ctx.save();\
7614 schaersvoo 7536
 ctx.beginPath();\
7537
 ctx.strokeStyle = stroke_color;\
7538
 ctx.lineWidth = 0.6*line_width;\
7539
 for(var p = zero_x ; p < xsize; p = p + x2step){\
7540
  ctx.moveTo(p,0);\
7541
  ctx.lineTo(p,ysize);\
7542
 };\
7543
 for(var p = zero_x ; p > 0; p = p - x2step){\
7544
  ctx.moveTo(p,0);\
7545
  ctx.lineTo(p,ysize);\
7546
 };\
7547
 for(var p = zero_y ; p < ysize; p = p + y2step){\
7548
  ctx.moveTo(0,p);\
7549
  ctx.lineTo(xsize,p);\
7550
 };\
7551
 for(var p = zero_y ; p > 0; p = p - y2step){\
7552
  ctx.moveTo(0,p);\
7553
  ctx.lineTo(xsize,p);\
7554
 };\
7555
 ctx.stroke();\
7556
 ctx.closePath();\
7557
 ctx.beginPath();\
7558
 ctx.lineWidth = 2*line_width;\
7559
 ctx.strokeStyle = axis_color;\
7560
 ctx.moveTo(0,zero_y);\
7561
 ctx.lineTo(xsize,zero_y);\
7562
 ctx.moveTo(zero_x,0);\
7563
 ctx.lineTo(zero_x,ysize);\
7564
 ctx.stroke();\
7565
 ctx.closePath();\
7566
 ctx.lineWidth = line_width+0.5;\
7567
 ctx.beginPath();\
7568
 for(var p = zero_x ; p < xsize; p = p + xstep){\
7569
  ctx.moveTo(p,zero_y-tics_length);\
7570
  ctx.lineTo(p,zero_y+tics_length);\
7571
 };\
7572
 for(var p = zero_x ; p > 0; p = p - xstep){\
7573
  ctx.moveTo(p,zero_y-tics_length);\
7574
  ctx.lineTo(p,zero_y+tics_length);\
7575
 };\
7576
 for(var p = zero_y ; p < ysize; p = p + ystep){\
7577
  ctx.moveTo(zero_x-tics_length,p);\
7578
  ctx.lineTo(zero_x+tics_length,p);\
7579
 };\
7580
 for(var p = zero_y ; p > 0; p = p - ystep){\
7581
  ctx.moveTo(zero_x-tics_length,p);\
7582
  ctx.lineTo(zero_x+tics_length,p);\
7583
 };\
7584
 for(var p = zero_x ; p < xsize; p = p + x2step){\
7585
  ctx.moveTo(p,zero_y-0.5*tics_length);\
7586
  ctx.lineTo(p,zero_y+0.5*tics_length);\
7587
 };\
7588
 for(var p = zero_x ; p > 0; p = p - x2step){\
7589
  ctx.moveTo(p,zero_y-0.5*tics_length);\
7590
  ctx.lineTo(p,zero_y+0.5*tics_length);\
7591
 };\
7592
 for(var p = zero_y ; p < ysize; p = p + y2step){\
7593
  ctx.moveTo(zero_x-0.5*tics_length,p);\
7594
  ctx.lineTo(zero_x+0.5*tics_length,p);\
7595
 };\
7596
 for(var p = zero_y ; p > 0; p = p - y2step){\
7597
  ctx.moveTo(zero_x-0.5*tics_length,p);\
7598
  ctx.lineTo(zero_x+0.5*tics_length,p);\
7599
 };\
7600
 ctx.stroke();\
7601
 ctx.closePath();\
7988 schaersvoo 7602
 ctx.restore();\
7603
};\
7604
if( use_axis_numbering == 1 ){\
7605
 ctx.save();\
7606
 ctx.fillColor = axis_color;\
8110 schaersvoo 7607
 ctx.strokeStyle = axis_color;\
7608
 ctx.lineWidth = 2*line_width;\
7988 schaersvoo 7609
 ctx.font = font_family;\
7610
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
7611
 if( x_strings != null ){\
7612
  var len = x_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 7613
  ctx.beginPath();\
9341 schaersvoo 7614
  if( x_strings_up == null){\
7615
   for(var p = 0 ; p < len ; p = p+2){\
7616
    var x_nums = x2px(eval(x_strings[p]));\
7617
    var x_text = x_strings[p+1];\
7618
    corr = ctx.measureText(x_text).width;\
7619
    skip = 1.2*corr/xstep;\
7620
    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
7621
    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
7622
    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
7623
    ctx.moveTo(x_nums,zero_y - tics_length);\
7624
    ctx.lineTo(x_nums,zero_y + tics_length);\
7625
   };\
7626
  }\
7627
  else\
7628
  {\
7629
   for(var p = 0 ; p < len ; p = p+2){\
7630
    var x_nums = x2px(eval(x_strings[p]));\
7631
    var x_text = x_strings[p+1];\
7632
    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
7633
    if( corr > ysize ){corr = ysize;};\
7634
    ctx.save();\
9346 schaersvoo 7635
    ctx.translate(x_nums+0.25*font_size, corr);\
9341 schaersvoo 7636
    ctx.rotate(-1.5708);\
7637
    ctx.fillText(x_text,0,0);\
7638
    ctx.restore();\
7639
    ctx.moveTo(x_nums,zero_y - tics_length);\
7640
    ctx.lineTo(x_nums,zero_y + tics_length);\
7641
   };\
7988 schaersvoo 7642
  };\
8110 schaersvoo 7643
  ctx.closePath();\
7988 schaersvoo 7644
 }\
7645
 else\
7646
 {\
7647
  skip = 1;cnt = px2x(zero_x);\
7648
  prec = Math.log(precision)/(Math.log(10));\
7649
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
7650
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
7651
   if(skip == 0 ){\
7990 schaersvoo 7652
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7653
    corr = ctx.measureText(disp_cnt).width;\
7654
    skip = parseInt(1.2*corr/xstep);\
7655
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 7656
   }\
7988 schaersvoo 7657
   else\
7658
   {\
7659
    skip--;\
7614 schaersvoo 7660
   };\
7988 schaersvoo 7661
   cnt = cnt + xmajor;\
7614 schaersvoo 7662
  };\
7988 schaersvoo 7663
  cnt = px2x(zero_x);skip = 1;\
7664
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
7665
   if(skip == 0 ){\
7990 schaersvoo 7666
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7667
    corr = ctx.measureText(disp_cnt).width;\
7668
    skip = parseInt(1.2*corr/xstep);\
7669
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7670
   }\
7671
   else\
7672
   {\
7673
    skip--;\
7614 schaersvoo 7674
   };\
7988 schaersvoo 7675
   cnt = cnt - xmajor;\
7614 schaersvoo 7676
  };\
7677
 };\
7988 schaersvoo 7678
 if( y_strings != null ){\
7679
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 7680
  ctx.beginPath();\
7988 schaersvoo 7681
  for(var p = 0 ; p < len ; p = p+2){\
7682
   var y_nums = y2px(eval(y_strings[p]));\
7683
   var y_text = y_strings[p+1];\
7684
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
7685
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
8110 schaersvoo 7686
   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
7687
   ctx.moveTo(zero_x - tics_length,y_nums);\
7688
   ctx.lineTo(zero_x + tics_length,y_nums);\
7614 schaersvoo 7689
  };\
8110 schaersvoo 7690
  ctx.closePath();\
7988 schaersvoo 7691
 }\
7692
 else\
7693
 {\
7991 schaersvoo 7694
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 7695
  cnt = px2y(zero_y);skip = 1;\
7696
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
7697
   if(skip == 0 ){\
7698
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 7699
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7700
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
7701
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
7702
   }\
7703
   else\
7704
   {\
7705
    skip--;\
7706
   };\
7707
   cnt = cnt - ymajor;\
7614 schaersvoo 7708
  };\
7988 schaersvoo 7709
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 7710
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 7711
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
7712
   if(skip == 0 ){\
7713
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 7714
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 7715
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
7716
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
7717
   }\
7718
   else\
7719
   {\
7720
    skip--;\
7721
   };\
7722
   cnt = cnt + ymajor;\
7614 schaersvoo 7723
  };\
7724
 };\
7988 schaersvoo 7725
 ctx.stroke();\
7614 schaersvoo 7726
 ctx.restore();\
7727
};\
11088 schaersvoo 7728
if( typeof(legend0)  !== 'undefined' ){\
7988 schaersvoo 7729
 ctx.save();\
7614 schaersvoo 7730
 ctx.globalAlpha = 1.0;\
7731
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
7732
 var y_offset = 2*font_size;\
7733
 var txt;var txt_size;\
7734
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 7735
 var l_length = legend0.length;\
11088 schaersvoo 7736
 if( typeof(legendcolors0) !== 'undefined' ){\
7614 schaersvoo 7737
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 7738
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 7739
  };\
7988 schaersvoo 7740
 }\
7741
 else\
7742
 {\
7614 schaersvoo 7743
  if( barcolor.length == 0 ){\
7744
   for(var p = 0 ; p < l_length ; p++){\
7745
    barcolor[p] = stroke_color;\
7746
   };\
7747
  };\
7748
 };\
7749
 for(var p = 0; p < l_length; p++){\
7750
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 7751
  txt = legend0[p];\
7614 schaersvoo 7752
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 7753
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 7754
  y_offset = parseInt(y_offset + 1.5*font_size);\
7755
 };\
7988 schaersvoo 7756
 ctx.restore();\
7614 schaersvoo 7757
};\
11088 schaersvoo 7758
if( typeof(barchart_0)  !== 'undefined' ){\
7991 schaersvoo 7759
 ctx.save();\
7760
 var num_barcharts = 0;\
7761
 var bar_name = eval('barchart_0');\
11088 schaersvoo 7762
 while( typeof(bar_name) !== 'undefined' ){\
7991 schaersvoo 7763
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
7764
 };\
9346 schaersvoo 7765
 var bar_width = parseInt(0.8*x2step/(num_barcharts));\
7991 schaersvoo 7766
 for(var i=0 ; i< num_barcharts ; i++){\
7767
  bar_name = eval('barchart_'+i);\
7768
  var bar_x = new Array();\
7769
  var bar_y = new Array();\
7770
  var lb = bar_name.length;\
7771
  var idx = 0;\
7772
  var dx = parseInt(0.5*i*bar_width);\
7773
  for( var p = 0 ; p < lb ; p = p + 3 ){\
7774
   bar_x[idx] = x2px(bar_name[p]);\
7775
   bar_y[idx] = y2px(bar_name[p+1]);\
7776
   barcolor[idx] = bar_name[p+2];\
7777
   idx++;\
7778
  };\
7779
  ctx.globalAlpha = fill_opacity;\
7780
  for( var p = 0; p < idx ; p++ ){\
11739 schaersvoo 7781
   ctx.beginPath();\
7991 schaersvoo 7782
   ctx.strokeStyle = barcolor[p];\
7783
   ctx.fillStyle = barcolor[p];\
9346 schaersvoo 7784
   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
11739 schaersvoo 7785
   ctx.fill();\
7786
   ctx.stroke();\
7787
   ctx.closePath();\
7991 schaersvoo 7788
  };\
7789
 };\
7790
 ctx.restore();\
7791
};\
11088 schaersvoo 7792
if( typeof(linegraph_0) !== 'undefined' ){\
7996 schaersvoo 7793
 ctx.save();\
7794
 ctx.globalAlpha = 1.0;\
7795
 var i = 0;\
7796
 var line_name = eval('linegraph_'+i);\
11088 schaersvoo 7797
 while ( typeof(line_name) !== 'undefined' ){\
7996 schaersvoo 7798
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
7799
  ctx.lineWidth = parseInt(line_name[1]);\
7800
  if(line_name[2] == \"1\"){\
7801
   var d1 = parseInt(line_name[3]);\
7802
   var d2 = parseInt(line_name[4]);\
7803
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
7804
  }\
7805
  else\
7806
  {\
7807
  if(ctx.setLineDash){ctx.setLineDash = null;}\
7808
  if(ctx.mozDash){ctx.mozDash = null;}\
7809
  };\
7810
  var data_x = new Array();\
7811
  var data_y = new Array();\
7812
  var lb = line_name.length;\
7813
  var idx = 0;\
7814
  for( var p = 5 ; p < lb ; p = p + 2 ){\
7815
   data_x[idx] = x2px(line_name[p]);\
7816
   data_y[idx] = y2px(line_name[p+1]);\
7817
   idx++;\
7818
  };\
7819
  for( var p = 0; p < idx ; p++){\
7820
   ctx.beginPath();\
7821
   ctx.moveTo(data_x[p],data_y[p]);\
7822
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
7823
   ctx.stroke();\
7824
   ctx.closePath();\
7825
  };\
7826
  i++;\
7827
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
7828
 };\
7829
 ctx.restore();\
7830
};\
7614 schaersvoo 7831
return;\
7989 schaersvoo 7832
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 7833
    break;
8224 bpr 7834
 
7614 schaersvoo 7835
    case DRAW_PIECHART:
7987 schaersvoo 7836
fprintf(js_include_file,"\n<!-- draw piecharts -->\n\
7956 schaersvoo 7837
function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family){\
7614 schaersvoo 7838
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7839
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7840
 }\
7841
 else\
7842
 {\
7843
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7844
 };\
7845
 var ld = data_color_list.length;\
7846
 var sum = 0;\
7847
 var idx = 0;\
7956 schaersvoo 7848
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 7849
 var colors = new Array();\
7850
 var data = new Array();\
7851
 for(var p = 0;p < ld; p = p + 2){\
7852
  data[idx] = parseFloat(data_color_list[p]);\
7853
  sum = sum + data[idx];\
7854
  colors[idx] = data_color_list[p+1];\
7855
  idx++;\
7856
 };\
7857
 var ctx = obj.getContext(\"2d\");\
7858
 ctx.save();\
7859
 var angle;\
7860
 var angle_end = 0;\
7861
 var offset = Math.PI / 2;\
7862
 ctx.globalAlpha = fill_opacity;\
7863
 for(var p=0; p < idx; p++){\
7864
  ctx.beginPath();\
7865
  ctx.fillStyle = colors[p];\
7866
  ctx.moveTo(x_center,y_center);\
7867
  angle = Math.PI * (2 * data[p] / sum);\
7868
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
7869
  ctx.lineTo(x_center, y_center);\
7870
  ctx.fill();\
7871
  ctx.closePath();\
7872
  angle_end  = angle_end + angle;\
7873
 };\
11088 schaersvoo 7874
 if(typeof(legend0) !== 'undefined'){\
7956 schaersvoo 7875
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 7876
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 7877
  ctx.font = font_family;\
7614 schaersvoo 7878
  var y_offset = font_size; \
7879
  var x_offset = 0;\
7880
  var txt;var txt_size;\
7881
  for(var p = 0; p < idx; p++){\
7882
   ctx.fillStyle = colors[p];\
7956 schaersvoo 7883
   txt = legenda[p];\
7614 schaersvoo 7884
   txt_size = ctx.measureText(txt).width;\
7885
   if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
7956 schaersvoo 7886
   ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
7614 schaersvoo 7887
   y_offset = parseInt(y_offset + 1.5*font_size);\
7888
  };\
7889
 };\
7890
 ctx.restore();\
7956 schaersvoo 7891
};",canvas_root_id,canvas_root_id,canvas_root_id);
8224 bpr 7892
 
7614 schaersvoo 7893
    break;
9433 schaersvoo 7894
    case DRAW_JSBOXPLOT:
7895
fprintf(js_include_file,"\n<!-- draw jsboxplots -->\n\
7896
function statistics(data){\
7897
 var len = data.length;\
7898
 var min = 10000000;\
7899
 var max = -10000000;\
7900
 var sum = 0;var d;\
7901
 for(var i=0;i<len;i++){\
7902
  d = data[i];\
7903
  if(d < min){min = d;}else{if(d > max){max = d;};};\
7904
  sum+= parseFloat(data[i]);\
7905
 };\
7906
 var mean = parseFloat(sum/len);\
7907
 var variance = 0;\
7908
 for(var i=0;i<len;i++){\
7909
  d = data[i];\
7910
  variance += (d - mean)*(d - mean);\
7911
 };\
7912
 variance = parseFloat(variance / len);\
7913
 var std = Math.sqrt(variance);\
7914
 data.sort(function(a,b){return a - b;});\
7915
 var median;var Q1;var Q3;\
7916
 var half = Math.floor(0.5*len);\
7917
 var q1 = Math.floor(0.25*len);\
7918
 var q3 = Math.floor(0.75*len);\
7919
 var half = Math.floor(0.5*len);\
7920
 if(len %%2 == 1){\
7921
  median = data[half];\
7922
  Q1 = data[q1];\
7923
  Q3 = data[q3];\
7924
 }\
7925
 else\
7926
 {\
7927
  median = (data[half - 1] + data[half] )/2;\
7928
  Q1 = (data[q1 - 1] + data[q1] )/2;\
7929
  Q3 = (data[q3 - 1] + data[q3] )/2;\
7930
 };\
7931
 return [min,Q1,median,Q3,max];\
7932
};");
7933
    break;
7934
    case DRAW_BOXPLOT:
7935
fprintf(js_include_file,"\n<!-- draw boxplots -->\n\
9465 schaersvoo 7936
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 7937
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7938
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7939
 }\
7940
 else\
7941
 {\
7942
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7943
 };\
7944
 var ctx = obj.getContext(\"2d\");\
7945
 ctx.clearRect(0,0,xsize,ysize);\
7946
 ctx.save();\
7947
 ctx.lineWidth = line_width;\
11088 schaersvoo 7948
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
9433 schaersvoo 7949
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7950
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7951
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
7952
 var hh = 0.25*hw;\
9465 schaersvoo 7953
 switch(boxplot_source){\
11088 schaersvoo 7954
  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
7955
  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
7956
  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
9465 schaersvoo 7957
  default: break;\
9433 schaersvoo 7958
 };\
7959
 var min,Q1,median,Q3,max;\
7960
 if(xy == 1 ){\
7961
  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
7962
  hh = Math.abs(y2px(hh) - y2px(ystart));\
7963
  hw = Math.abs(y2px(hw) - y2px(ystart));\
7964
  cxy = y2px(cxy);\
9465 schaersvoo 7965
  ctx.beginPath();\
9433 schaersvoo 7966
  ctx.moveTo(min,cxy);\
7967
  ctx.lineTo(Q1,cxy);\
7968
  ctx.moveTo(Q3,cxy);\
7969
  ctx.lineTo(max,cxy);\
7970
  ctx.moveTo(min,cxy+hh);\
7971
  ctx.lineTo(min,cxy-hh);\
7972
  ctx.moveTo(max,cxy+hh);\
7973
  ctx.lineTo(max,cxy-hh);\
9465 schaersvoo 7974
  ctx.closePath();\
7975
  ctx.stroke();\
7976
  ctx.beginPath();\
9433 schaersvoo 7977
  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
9465 schaersvoo 7978
  ctx.closePath();\
7979
  if( use_filled == 1 ){\
7980
   ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\
7981
   ctx.fill();\
7982
  };\
7983
  ctx.stroke();\
7984
  ctx.beginPath();\
9433 schaersvoo 7985
  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
9465 schaersvoo 7986
  ctx.closePath();\
7987
  if( use_filled == 1 ){\
7988
   ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7989
   ctx.fill();\
7990
  };\
7991
  ctx.stroke();\
9433 schaersvoo 7992
 }else{\
7993
  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
7994
  hh = Math.abs(x2px(hh) - x2px(xstart));\
7995
  hw = Math.abs(x2px(hw) - x2px(xstart));\
7996
  cxy = x2px(cxy);\
9465 schaersvoo 7997
  ctx.beginPath();\
9433 schaersvoo 7998
  ctx.moveTo(cxy,min);\
7999
  ctx.lineTo(cxy,Q1);\
8000
  ctx.moveTo(cxy,Q3);\
8001
  ctx.lineTo(cxy,max);\
8002
  ctx.moveTo(cxy + hh,min);\
8003
  ctx.lineTo(cxy - hh,min);\
8004
  ctx.moveTo(cxy + hh,max);\
8005
  ctx.lineTo(cxy - hh,max);\
9465 schaersvoo 8006
  ctx.closePath;\
8007
  ctx.stroke();\
8008
  ctx.beginPath();\
9433 schaersvoo 8009
  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
9465 schaersvoo 8010
  ctx.closePath();\
8011
  if( use_filled == 1 ){\
8012
   ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+fill_opacity+\")\";\
8013
   ctx.fill();\
8014
  };\
8015
  ctx.stroke();\
8016
  ctx.beginPath();\
9433 schaersvoo 8017
  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
9465 schaersvoo 8018
  ctx.closePath();\
8019
  if( use_filled == 1 ){\
8020
   ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8021
   ctx.fill();\
8022
  };\
8023
  ctx.stroke();\
9433 schaersvoo 8024
 };\
8025
 ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
8026
    break;
7614 schaersvoo 8027
    case DRAW_ARCS:
8028
fprintf(js_include_file,"\n<!-- draw arcs -->\n\
8105 schaersvoo 8029
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 8030
 ctx.save();\
8031
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 8032
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 8033
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
8034
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 8035
 start = 360 - start;\
8036
 end = 360 - end;\
7614 schaersvoo 8037
 ctx.lineWidth = line_width;\
11088 schaersvoo 8038
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8039
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8071 schaersvoo 8040
 ctx.fillStyle = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8041
 ctx.beginPath();\
8042
 ctx.moveTo(xc,yc);\
8043
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
8044
 ctx.lineTo(xc,yc);\
8045
 ctx.closePath();\
7614 schaersvoo 8046
 if( use_filled == 1 ){\
8047
  ctx.fill();\
8071 schaersvoo 8048
 };\
8049
 ctx.stroke();\
7614 schaersvoo 8050
 ctx.restore();\
8071 schaersvoo 8051
};");
8224 bpr 8052
 
7614 schaersvoo 8053
    break;
7983 schaersvoo 8054
    case DRAW_CENTERSTRING:
8055
fprintf(js_include_file,"\n<!-- draw centerstring -->\n\
8105 schaersvoo 8056
var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
7983 schaersvoo 8057
 var obj;\
8058
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8059
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8060
 }\
8061
 else\
8062
 {\
8063
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8064
 };\
8065
 var ctx = obj.getContext(\"2d\");\
8066
 ctx.save();\
9481 schaersvoo 8067
 ctx.clearRect(0,0,xsize,ysize);\
7983 schaersvoo 8068
 ctx.font = font_family;\
8069
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8070
 var stringwidth = ctx.measureText(text).width;\
8071
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
8072
 ctx.fillText(text,x,y2px(y));\
9481 schaersvoo 8073
 ctx.restore();\
7983 schaersvoo 8074
return;\
8075
};",canvas_root_id,canvas_root_id,canvas_root_id);
8076
    break;
7614 schaersvoo 8077
    case DRAW_TEXTS:
8078
fprintf(js_include_file,"\n<!-- draw text -->\n\
11811 schaersvoo 8079
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 8080
  var obj;\
8081
  if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8082
   obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8083
  }\
8084
  else\
8085
  {\
8086
   obj = create_canvas%d(canvas_type,xsize,ysize);\
8087
  };\
8088
  var ctx = obj.getContext(\"2d\");\
9868 schaersvoo 8089
  if( font_family != 'null' ){\
8090
   ctx.font = font_family;\
8091
  }\
8092
  else\
8093
  {\
8094
   ctx.font = font_size+'px Ariel';\
8095
  };\
11811 schaersvoo 8096
  if( use_offset == 3 ){\
8097
   y = y + (Math.sin(angle2))*(ctx.measureText(text).width);\
8098
   x = x - (Math.cos(angle2))*(ctx.measureText(text).width);\
8099
  };\
7614 schaersvoo 8100
  if(angle2 == 0 && angle != 0){\
8101
   ctx.save();\
8071 schaersvoo 8102
   if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
11811 schaersvoo 8103
   if(use_rotate == 1 ){\
8104
   ctx.rotate(angle*Math.PI/180);};\
7614 schaersvoo 8105
  };\
8106
  ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8107
  if(angle2 != 0){\
8108
   ctx.save();\
8109
   ctx.translate(x,y);\
8110
   ctx.rotate((360-angle2)*(Math.PI / 180));\
8111
   ctx.fillText(text,0,0);\
8112
   ctx.restore();\
8113
  }else{ctx.fillText(text,x,y);};\
8114
 ctx.restore();\
8115
 return;\
7653 schaersvoo 8116
 };",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8117
    break;
8118
    case DRAW_CURVE:
8119
fprintf(js_include_file,"\n<!-- draw curve -->\n\
8105 schaersvoo 8120
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 8121
 var obj;\
8122
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8123
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8124
 }\
8125
 else\
8126
 {\
8127
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8128
 };\
8129
 var ctx = obj.getContext(\"2d\");\
8130
 ctx.save();\
8071 schaersvoo 8131
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 8132
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
8133
 ctx.beginPath();ctx.lineWidth = line_width;\
11088 schaersvoo 8134
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8135
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
8136
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8137
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
8138
 for(var p = 1 ; p < x_points.length ; p++){\
8139
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
8140
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
8141
  }\
8142
  else\
8143
  {\
8144
   ctx.stroke();\
8145
   ctx.beginPath();\
8146
   p++;\
8147
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
8148
  };\
8149
 };\
8150
 ctx.stroke();\
8151
 ctx.restore();\
7653 schaersvoo 8152
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8153
    break;
8224 bpr 8154
 
7614 schaersvoo 8155
    case DRAW_INPUTS:
8156
fprintf(js_include_file,"\n<!-- draw input fields -->\n\
11803 schaersvoo 8157
var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
7614 schaersvoo 8158
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
8159
var input = document.createElement(\"input\");\
8160
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
8161
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
8162
input.setAttribute(\"size\",size);\
8163
input.setAttribute(\"value\",value);\
7877 schaersvoo 8164
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
11803 schaersvoo 8165
canvas_div.appendChild(input);\
8166
if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
8167
};\
8168
function center_input(id,x,y,style){\
8169
 var inp = document.getElementById(id);\
8170
 var pos = inp.getBoundingClientRect();\
8171
 var center_x = parseInt(x - 0.5*(pos.width));\
8172
 var center_y = parseInt(y - 0.5*(pos.height));\
8173
 try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
8174
 catch(e){return;};\
8175
};");
7614 schaersvoo 8176
    break;
8224 bpr 8177
 
7614 schaersvoo 8178
    case DRAW_TEXTAREAS:
8179
fprintf(js_include_file,"\n<!-- draw text area inputfields -->\n\
8105 schaersvoo 8180
var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
7614 schaersvoo 8181
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
8182
var textarea = document.createElement(\"textarea\");\
8183
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
8184
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
8185
textarea.setAttribute(\"cols\",cols);\
8186
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 8187
textarea.value = value;\
8188
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 8189
canvas_div.appendChild(textarea);};");
7614 schaersvoo 8190
    break;
8224 bpr 8191
 
7614 schaersvoo 8192
case DRAW_PIXELS:
8193
fprintf(js_include_file,"\n<!-- draw pixel -->\n\
8105 schaersvoo 8194
var draw_setpixel = function(x,y,color,opacity,pixelsize){\
7614 schaersvoo 8195
 var canvas = create_canvas%d(10,xsize,ysize);\
8196
 var d = 0.5*pixelsize;\
8197
 var ctx = canvas.getContext(\"2d\");\
9462 schaersvoo 8198
 if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
7614 schaersvoo 8199
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
8200
 ctx.clearRect(0,0,xsize,ysize);\
8201
 for(var p=0; p<x.length;p++){\
8202
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
8203
 };\
8204
 ctx.fill();ctx.stroke();\
8205
};",canvas_root_id);
8206
break;
8207
 
8208
case DRAW_CLOCK:
8209
fprintf(js_include_file,"\n<!-- begin command clock -->\n\
8210
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
8211
var clock_ctx = clock_canvas.getContext(\"2d\");\
8212
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
8130 schaersvoo 8213
 clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
7614 schaersvoo 8214
 clock_ctx.save();\
7997 schaersvoo 8215
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 8216
 this.type = type || 0;\
8217
 this.interaction = interaction || 0;\
7862 schaersvoo 8218
 this.H = H;\
8219
 this.M = M;\
8220
 this.S = S;\
7614 schaersvoo 8221
 this.xc = xc || xsize/2;\
8222
 this.yc = yc || ysize/2;\
8223
 this.radius = radius || xsize/4;\
8224
 var font_size = parseInt(0.2*this.radius);\
8225
 this.H_color = h_color || \"blue\";\
8226
 this.M_color = m_color || \"blue\";\
8227
 this.S_color = s_color || \"blue\";\
8228
 this.fg_color = fg_color || \"red\";\
8229
 this.bg_color = bg_color || \"white\";\
8230
 clock_ctx.translate(this.xc,this.yc);\
8231
 clock_ctx.beginPath();\
8232
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
8233
 clock_ctx.fillStyle = this.bg_color;\
8234
 clock_ctx.fill();\
8235
 clock_ctx.closePath();\
8236
 clock_ctx.beginPath();\
8237
 clock_ctx.font = font_size+\"px Arial\";\
8238
 clock_ctx.fillStyle = this.fg_color;\
8239
 clock_ctx.textAlign = \"center\";\
8240
 clock_ctx.textBaseline = 'middle';\
8241
 var angle;var x1,y1,x2,y2;\
8242
 var angle_cos;var angle_sin;\
7997 schaersvoo 8243
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 8244
 switch(type){\
8245
 case 0:clock_ctx.beginPath();\
8246
 for(var p = 1; p <= 12 ; p++){\
8247
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
8248
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
8249
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8250
  clock_ctx.moveTo(x1,y1);\
8251
  clock_ctx.lineTo(x2,y2);\
8252
 };\
8253
 for(var p = 1; p <= 60 ; p++){\
8254
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
8255
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
8256
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8257
  clock_ctx.moveTo(x1,y1);\
8258
  clock_ctx.lineTo(x2,y2);\
8259
 };\
8260
 clock_ctx.closePath();\
8261
 clock_ctx.stroke();\
8262
 break;\
8263
 case 1:\
8264
 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 8265
 case 2:\
8266
 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 8267
 clock_ctx.beginPath();\
8268
 for(var p = 1; p <= 12 ; p++){\
8269
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
8270
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
8271
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8272
  clock_ctx.moveTo(x1,y1);\
8273
  clock_ctx.lineTo(x2,y2);\
8274
 };\
8275
 for(var p = 1; p <= 60 ; p++){\
8276
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
8277
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
8278
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
8279
  clock_ctx.moveTo(x1,y1);\
8280
  clock_ctx.lineTo(x2,y2);\
8281
 };\
8282
 clock_ctx.closePath();\
8283
 clock_ctx.stroke();\
8284
 break;\
8285
 };\
8286
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
8287
 clock_ctx.rotate(angle);\
8288
 clock_ctx.beginPath();\
8289
 clock_ctx.moveTo(-3, -2);\
8290
 clock_ctx.lineTo(-3, 2);\
11026 bpr 8291
 clock_ctx.lineTo(this.radius * 0.6, 1);\
8292
 clock_ctx.lineTo(this.radius  * 0.6, -1);\
7614 schaersvoo 8293
 clock_ctx.fillStyle = this.H_color;\
8294
 clock_ctx.fill();\
8295
 clock_ctx.rotate(-angle);\
8296
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
8297
 clock_ctx.rotate(angle);\
8298
 clock_ctx.beginPath();\
8299
 clock_ctx.moveTo(-3, -2);\
8300
 clock_ctx.lineTo(-3, 2);\
8301
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
8302
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
8303
 clock_ctx.fillStyle = this.M_color;\
8304
 clock_ctx.fill();\
8305
 clock_ctx.rotate(-angle);\
8306
 angle = (this.S - 15) * 2 * Math.PI / 60;\
8307
 clock_ctx.rotate(angle);\
8308
 clock_ctx.beginPath();\
8309
 clock_ctx.moveTo(0,0);\
11026 bpr 8310
 clock_ctx.lineTo(this.radius  * 0.9, 1);\
8311
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
7614 schaersvoo 8312
 clock_ctx.strokeStyle = this.S_color;\
8313
 clock_ctx.stroke();\
8314
 clock_ctx.restore();\
7653 schaersvoo 8315
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 8316
break;
8317
 
8318
case DRAW_LATTICE:
8319
fprintf(js_include_file,"\n<!-- draw lattice -->\n\
8105 schaersvoo 8320
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 8321
 var obj;\
8322
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8323
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8324
 }\
8325
 else\
8326
 {\
8327
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8328
 };\
8329
 var ctx = obj.getContext(\"2d\");\
8330
 ctx.save();\
8071 schaersvoo 8331
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 8332
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
8333
 ctx.fillStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8334
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8335
 var radius = line_width;\
8336
 var x = 0;\
8337
 var y = 0;\
8338
 var x_step_px = xsize/(xmax-xmin);\
8339
 var y_step_px = ysize/(ymax-ymin);\
8340
 var xv1 = dx1*x_step_px;\
8341
 var yv1 = dy1*y_step_px;\
8342
 var xv2 = dx2*x_step_px;\
8343
 var yv2 = dy2*y_step_px;\
8344
 for(var p = 0; p < n1 ;p++){\
8345
  x = p*xv1 + x0;\
8346
  y = p*yv1 + y0;\
8347
  for(var c = 0; c < n2 ; c++){\
8348
   ctx.beginPath();\
8349
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
8350
   ctx.fill();\
8351
   ctx.stroke();\
8352
   ctx.closePath();\
8353
  };\
8354
 };\
8355
 ctx.restore();\
8356
 return;\
7653 schaersvoo 8357
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8358
    break;
7735 schaersvoo 8359
case DRAW_XYLOGSCALE:
8360
fprintf(js_include_file,"\n<!-- draw xylogscale -->\n\
8105 schaersvoo 8361
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 8362
 var obj;\
8363
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8364
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8365
 }\
8366
 else\
8367
 {\
8368
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8369
 };\
8370
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 8371
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 8372
 ctx.save();\
7739 schaersvoo 8373
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 8374
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
8375
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
8376
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
8377
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
7739 schaersvoo 8378
 if(use_axis_numbering == 1){\
7956 schaersvoo 8379
  ctx.font = font_family;\
8380
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
8381
  ymarge = parseInt(1.5*font_size);\
8382
  ctx.save();\
8383
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
8384
  ctx.rect(0,0,xmarge,ysize);\
8385
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
8386
  ctx.fill();\
8387
  ctx.restore();\
8388
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 8389
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 8390
  ctx.save();\
8391
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8392
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8393
  corr =  ctx.measureText(xaxislabel).width;\
8394
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
8395
  ctx.restore();\
8396
 };\
11088 schaersvoo 8397
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 8398
  ctx.save();\
8399
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8400
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8401
  corr = ctx.measureText(yaxislabel).width;\
8402
  ctx.translate(xmarge+font_size,corr+font_size);\
8403
  ctx.rotate(-0.5*Math.PI);\
8404
  ctx.fillText(yaxislabel,0,0);\
8405
  ctx.restore();\
8406
 };\
8407
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8408
 ctx.lineWidth = line_width;\
8409
 for(var p = x_min; p <= x_max ; p++){\
8410
  num = Math.pow(xlogbase,p);\
8411
  for(var i = 1 ; i < xlogbase ; i++){\
8412
   x_e = x2px(i*num);\
7735 schaersvoo 8413
   if( i == 1 ){\
7956 schaersvoo 8414
    ctx.lineWidth = line_width;\
8415
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7738 schaersvoo 8416
    if( use_axis_numbering == 1 && p > x_min){\
7956 schaersvoo 8417
      xtxt = xlogbase+'^'+p.toFixed(0);\
8418
      corr = 0.5*(ctx.measureText(xtxt).width);\
8419
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
8420
    };\
7735 schaersvoo 8421
   }else{\
7956 schaersvoo 8422
    ctx.lineWidth = 0.2*line_width;\
8423
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8424
   };\
7738 schaersvoo 8425
   if( x_e >= xmarge ){\
7956 schaersvoo 8426
    ctx.beginPath();\
8427
    ctx.moveTo(x_e,0);\
8428
    ctx.lineTo(x_e,ysize - ymarge);\
8429
    ctx.stroke();\
8430
    ctx.closePath();\
7738 schaersvoo 8431
   };\
7956 schaersvoo 8432
  };\
8433
 };\
8434
 for(var p = y_min; p <= y_max ; p++){\
8435
  num = Math.pow(ylogbase,p);\
8436
  for(var i = 1 ; i < ylogbase ; i++){\
8437
   y_e = y2px(i*num);\
8438
   if( i == 1 ){\
8439
    ctx.lineWidth = line_width;\
7735 schaersvoo 8440
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 8441
    if( use_axis_numbering == 1 && p > y_min){\
8442
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
8443
    };\
8444
   }else{\
8445
    ctx.lineWidth = 0.2*line_width;\
8446
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8447
   };\
8448
   ctx.beginPath();\
8449
   ctx.moveTo(xmarge,y_e);\
8450
   ctx.lineTo(xsize,y_e);\
8451
   ctx.stroke();\
8452
   ctx.closePath();\
8453
  };\
8454
 };\
7735 schaersvoo 8455
 ctx.restore();\
8456
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
8457
    break;
7614 schaersvoo 8458
 
7735 schaersvoo 8459
case DRAW_XLOGSCALE:
8460
fprintf(js_include_file,"\n<!-- draw xlogscale -->\n\
8105 schaersvoo 8461
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 8462
 var obj;\
8463
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8464
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8465
 }\
8466
 else\
8467
 {\
8468
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8469
 };\
8470
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 8471
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 8472
 ctx.save();\
8473
 ctx.lineWidth = line_width;\
7739 schaersvoo 8474
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 8475
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
8476
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
8477
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 8478
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
8479
 if(use_axis_numbering == 1){\
7956 schaersvoo 8480
  ctx.font = font_family;\
8481
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
8482
  ymarge = parseInt(1.5*font_size);\
8483
  ctx.save();\
8484
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
8485
  ctx.rect(0,0,xmarge,ysize);\
8486
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
8487
  ctx.fill();\
8488
  ctx.restore();\
8489
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 8490
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 8491
  ctx.save();\
8492
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8493
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8494
  corr =  ctx.measureText(xaxislabel).width;\
8495
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
8496
  ctx.restore();\
8497
 };\
11088 schaersvoo 8498
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 8499
  ctx.save();\
8500
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8501
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8502
  corr = ctx.measureText(yaxislabel).width;\
8503
  ctx.translate(xmarge+font_size,corr+font_size);\
8504
  ctx.rotate(-0.5*Math.PI);\
8505
  ctx.fillText(yaxislabel,0,0);\
8506
  ctx.restore();\
8507
 };\
8508
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8509
 ctx.lineWidth = line_width;\
8510
 for(var p = x_min; p <= x_max ; p++){\
8511
  num = Math.pow(xlogbase,p);\
8512
  for(var i = 1 ; i < xlogbase ; i++){\
8513
   x_e = x2px(i*num);\
7735 schaersvoo 8514
   if( i == 1 ){\
7956 schaersvoo 8515
     ctx.lineWidth = line_width;\
7739 schaersvoo 8516
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
8517
    if( use_axis_numbering == 1 && p > x_min ){\
7735 schaersvoo 8518
      xtxt = xlogbase+'^'+p.toFixed(0);\
8519
      corr = 0.5*(ctx.measureText(xtxt).width);\
8520
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
8521
    };\
8522
   }else{\
7956 schaersvoo 8523
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 8524
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8525
   };\
7739 schaersvoo 8526
   if( x_e >= xmarge ){\
7956 schaersvoo 8527
    ctx.beginPath();\
8528
    ctx.moveTo(x_e,0);\
8529
    ctx.lineTo(x_e,ysize - ymarge);\
8530
    ctx.stroke();\
8531
    ctx.closePath();\
7739 schaersvoo 8532
   };\
8533
  };\
7956 schaersvoo 8534
 };\
7735 schaersvoo 8535
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
8536
 var minor_step = stepy / yminor;\
7749 schaersvoo 8537
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 8538
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 8539
  ctx.lineWidth = line_width;\
8540
  ctx.beginPath();\
8541
  ctx.moveTo(xmarge,y);\
8542
  ctx.lineTo(xsize,y);\
8543
  ctx.stroke();\
8544
  ctx.closePath();\
7735 schaersvoo 8545
  if( use_axis_numbering == 1){\
8546
   ytxt = (px2y(y)).toFixed(prec);\
8547
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
8548
  };\
8549
  for(var dy = 1 ; dy < yminor ; dy++){\
8550
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 8551
   ctx.lineWidth = 0.2*line_width;\
8552
   ctx.beginPath();\
7739 schaersvoo 8553
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 8554
   ctx.lineTo(xsize,y+dy*minor_step);\
8555
   ctx.stroke();\
8556
   ctx.closePath();\
7735 schaersvoo 8557
  };\
8558
 };\
7956 schaersvoo 8559
 ctx.restore();\
8560
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 8561
    break;
7729 schaersvoo 8562
case DRAW_YLOGSCALE:
8563
fprintf(js_include_file,"\n<!-- draw ylogscale -->\n\
8105 schaersvoo 8564
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 8565
 var obj;\
8566
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8567
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8568
 }\
8569
 else\
8570
 {\
8571
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8572
 };\
8573
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 8574
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 8575
 ctx.save();\
8576
 ctx.lineWidth = line_width;\
7735 schaersvoo 8577
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
8578
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
8109 schaersvoo 8579
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
7739 schaersvoo 8580
 if(use_axis_numbering == 1){\
7956 schaersvoo 8581
  ctx.font = font_family;\
8582
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
8583
  ymarge = 2*font_size;\
8584
  ctx.save();\
8585
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
8586
  ctx.rect(0,0,xmarge,ysize);\
8587
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
8588
  ctx.fill();\
8589
  ctx.restore();\
8590
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 8591
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 8592
  ctx.save();\
8593
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8594
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8595
  corr =  ctx.measureText(xaxislabel).width;\
8596
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
8597
  ctx.restore();\
8598
 };\
11088 schaersvoo 8599
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 8600
  ctx.save();\
8601
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
8602
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8603
  corr = ctx.measureText(yaxislabel).width;\
8604
  ctx.translate(xmarge+font_size,corr+font_size);\
8605
  ctx.rotate(-0.5*Math.PI);\
8606
  ctx.fillText(yaxislabel,0,0);\
8607
  ctx.restore();\
8608
 };\
8609
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
8610
 ctx.lineWidth = line_width;\
8611
 for(var p = y_min; p <= y_max ; p++){\
8612
  num = Math.pow(ylogbase,p);\
8613
  for(var i = 1 ; i < ylogbase ; i++){\
8614
   y_e = y2px(i*num);\
7729 schaersvoo 8615
   if( i == 1 ){\
7956 schaersvoo 8616
    ctx.lineWidth = line_width;\
7729 schaersvoo 8617
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7739 schaersvoo 8618
    if( use_axis_numbering == 1 && p > y_min){\
7735 schaersvoo 8619
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 8620
    };\
8621
   }else{\
7956 schaersvoo 8622
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 8623
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
8624
   };\
7956 schaersvoo 8625
   ctx.beginPath();\
8626
   ctx.moveTo(xmarge,y_e);\
8627
   ctx.lineTo(xsize,y_e);\
8628
   ctx.stroke();\
8629
   ctx.closePath();\
8630
  };\
8631
 };\
7729 schaersvoo 8632
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
8633
 var minor_step = stepx / xminor;\
8634
 var prec = Math.log(precision)/Math.log(10);\
8635
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 8636
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 8637
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 8638
  ctx.lineWidth = line_width;\
8639
  ctx.beginPath();\
8640
  ctx.moveTo(x,ysize-ymarge);\
8641
  ctx.lineTo(x,0);\
8642
  ctx.stroke();\
8643
  ctx.closePath();\
7729 schaersvoo 8644
  if( use_axis_numbering == 1){\
8645
   xtxt = (px2x(x)).toFixed(prec);\
8646
   corr = 0.5*(ctx.measureText(xtxt).width);\
8647
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
8648
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
8649
  };\
8650
  for(var dx = 1 ; dx < xminor ; dx++){\
8651
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 8652
   ctx.lineWidth = 0.2*line_width;\
8653
   ctx.beginPath();\
7739 schaersvoo 8654
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 8655
   ctx.lineTo(x+dx*minor_step,0);\
8656
   ctx.stroke();\
8657
   ctx.closePath();\
7735 schaersvoo 8658
  };\
8659
 };\
7956 schaersvoo 8660
 ctx.restore();\
8661
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 8662
    break;
9213 schaersvoo 8663
 
7614 schaersvoo 8664
    default:break;
8665
   }
8666
  }
8667
 }
8668
  return;
8669
}
8670
 
8671
void check_string_length(int L){
9466 schaersvoo 8672
 if( L > MAX_BUFFER-1){
7614 schaersvoo 8673
  canvas_error("problem with your arguments to command...");
8674
 }
8675
 return;
8676
}
8677
 
8678
 
8679
int get_token(FILE *infile){
8680
        int     c,i=0;
8681
        char    temp[MAX_INT], *input_type;
8682
        char    *line="line",
8683
        *audio="audio",
8684
        *blink="blink",
8685
        *arrowhead="arrowhead",
8686
        *crosshairsize="crosshairsize",
8687
        *crosshair="crosshair",
8688
        *crosshairs="crosshairs",
8689
        *audioobject="audioobject",
8690
        *style="style",
8691
        *mouse="mouse",
7991 schaersvoo 8692
        *mousex="mousex",
8693
        *mousey="mousey",
8071 schaersvoo 8694
        *mouse_display="display",
8695
        *mouse_degree="mouse_degree",
7614 schaersvoo 8696
        *userdraw="userdraw",
8697
        *highlight="highlight",
8698
        *http="http",
8699
        *rays="rays",
8700
        *dashtype="dashtype",
8701
        *dashed="dashed",
8702
        *filled="filled",
8703
        *lattice="lattice",
8704
        *parallel="parallel",
8705
        *segment="segment",
8299 schaersvoo 8706
        *segments="segments",
7614 schaersvoo 8707
        *dsegment="dsegment",
9374 schaersvoo 8708
        *dsegments="dsegments",
7614 schaersvoo 8709
        *seg="seg",
9383 schaersvoo 8710
        *segs="segs",
7614 schaersvoo 8711
        *bgimage="bgimage",
8712
        *bgcolor="bgcolor",
8713
        *strokecolor="strokecolor",
8714
        *backgroundimage="backgroundimage",
8715
        *text="text",
8716
        *textup="textup",
8717
        *mouseprecision="mouseprecision",
8718
        *precision="precision",
8719
        *plotsteps="plotsteps",
8720
        *plotstep="plotstep",
8721
        *tsteps="tsteps",
8722
        *curve="curve",
8723
        *dcurve="dcurve",
8724
        *plot="plot",
8725
        *dplot="dplot",
7788 schaersvoo 8726
        *levelcurve="levelcurve",
7614 schaersvoo 8727
        *fontsize="fontsize",
8728
        *fontcolor="fontcolor",
8729
        *axis="axis",
8730
        *axisnumbering="axisnumbering",
8731
        *axisnumbers="axisnumbers",
8732
        *arrow="arrow",
9382 schaersvoo 8733
        *vector="vector",
8734
        *vectors="vectors",
7614 schaersvoo 8735
        *darrow="darrow",
8736
        *arrow2="arrow2",
8737
        *darrow2="darrow2",
8304 schaersvoo 8738
        *arrows="arrows",
8347 schaersvoo 8739
        *arrows2="arrows2",
7614 schaersvoo 8740
        *zoom="zoom",
8741
        *grid="grid",
8742
        *hline="hline",
7786 schaersvoo 8743
        *dhline="dhline",
7614 schaersvoo 8744
        *drag="drag",
8745
        *horizontalline="horizontalline",
9383 schaersvoo 8746
        *horizontallines="horizontallines",
7614 schaersvoo 8747
        *vline="vline",
7786 schaersvoo 8748
        *dvline="dvline",
7614 schaersvoo 8749
        *verticalline="verticalline",
9383 schaersvoo 8750
        *verticallines="verticallines",
7614 schaersvoo 8751
        *triangle="triangle",
9306 schaersvoo 8752
        *triangles="triangles",
7614 schaersvoo 8753
        *ftriangle="ftriangle",
9374 schaersvoo 8754
        *ftriangles="ftriangles",
7614 schaersvoo 8755
        *mathml="mathml",
8756
        *html="html",
8757
        *input="input",
8146 schaersvoo 8758
        *clearbutton="clearbutton",
9386 schaersvoo 8759
        *erase="erase",
8760
        *delete="delete",
7614 schaersvoo 8761
        *inputstyle="inputstyle",
8762
        *textarea="textarea",
8763
        *trange="trange",
8764
        *ranget="ranget",
8765
        *xrange="xrange",
8766
        *yrange="yrange",
8767
        *rangex="rangex",
8768
        *rangey="rangey",
8370 schaersvoo 8769
        *path="path",
7614 schaersvoo 8770
        *polyline="polyline",
8351 schaersvoo 8771
        *brokenline="brokenline",
7614 schaersvoo 8772
        *lines="lines",
8773
        *poly="poly",
8774
        *polygon="polygon",
8775
        *fpolygon="fpolygon",
8776
        *fpoly="fpoly",
8777
        *filledpoly="filledpoly",
8778
        *filledpolygon="filledpolygon",
8779
        *rect="rect",
8780
        *frect="frect",
8781
        *rectangle="rectangle",
8782
        *frectangle="frectangle",
8783
        *square="square",
8784
        *fsquare="fsquare",
9374 schaersvoo 8785
        *fsquares="fsquares",
8363 schaersvoo 8786
        *rects="rects",
8787
        *frects="frects",
7614 schaersvoo 8788
        *dline="dline",
8789
        *arc="arc",
8790
        *filledarc="filledarc",
9374 schaersvoo 8791
        *farc="farc",
7614 schaersvoo 8792
        *size="size",
8793
        *string="string",
8794
        *stringup="stringup",
8795
        *copy="copy",
8796
        *copyresized="copyresized",
8797
        *opacity="opacity",
8798
        *transparent="transparent",
8799
        *fill="fill",
8800
        *point="point",
8801
        *points="points",
8802
        *linewidth="linewidth",
8803
        *circle="circle",
8304 schaersvoo 8804
        *circles="circles",
7614 schaersvoo 8805
        *fcircle="fcircle",
9374 schaersvoo 8806
        *fcircles="fcircles",
7614 schaersvoo 8807
        *disk="disk",
9374 schaersvoo 8808
        *disks="disks",
7614 schaersvoo 8809
        *comment="#",
8810
        *end="end",
8811
        *ellipse="ellipse",
8812
        *fellipse="fellipse",
8813
        *rotate="rotate",
7785 schaersvoo 8814
        *affine="affine",
9907 schaersvoo 8815
        *rotationcenter="rotationcenter",
8816
        *killrotate="killrotate",
7785 schaersvoo 8817
        *killaffine="killaffine",
7614 schaersvoo 8818
        *fontfamily="fontfamily",
8819
        *fillcolor="fillcolor",
8820
        *clicktile="clicktile",
8821
        *clicktile_colors="clicktile_colors",
8822
        *translation="translation",
8823
        *translate="translate",
8824
        *killtranslation="killtranslation",
8825
        *killtranslate="killtranslate",
8826
        *onclick="onclick",
8370 schaersvoo 8827
        *roundrects="roundrects",
7614 schaersvoo 8828
        *roundrect="roundrect",
8829
        *froundrect="froundrect",
9374 schaersvoo 8830
        *froundrects="froundrects",
7614 schaersvoo 8831
        *roundrectangle="roundrectangle",
8832
        *patternfill="patternfill",
8833
        *hatchfill="hatchfill",
8834
        *diafill="diafill",
7647 schaersvoo 8835
        *diamondfill="diamondfill",
7614 schaersvoo 8836
        *dotfill="dotfill",
8837
        *gridfill="gridfill",
8838
        *imagefill="imagefill",
7735 schaersvoo 8839
        *xlogbase="xlogbase",
8840
        *ylogbase="ylogbase",
7614 schaersvoo 8841
        *xlogscale="xlogscale",
8842
        *ylogscale="ylogscale",
8843
        *xylogscale="xylogscale",
8844
        *intooltip="intooltip",
9329 schaersvoo 8845
        *popup="popup",
7614 schaersvoo 8846
        *replyformat="replyformat",
8847
        *floodfill="floodfill",
11772 schaersvoo 8848
        *fillall="fillall",
7614 schaersvoo 8849
        *filltoborder="filltoborder",
8850
        *setpixel="setpixel",
8851
        *pixels="pixels",
8852
        *pixelsize="pixelsize",
8853
        *xaxis="xaxis",
9341 schaersvoo 8854
        *xaxisup="xaxisup",
7614 schaersvoo 8855
        *yaxis="yaxis",
8856
        *xaxistext="xaxistext",
9341 schaersvoo 8857
        *xaxistextup="xaxistextup",
7614 schaersvoo 8858
        *yaxistext="yaxistext",
8859
        *piechart="piechart",
9433 schaersvoo 8860
        *boxplot="boxplot",
9465 schaersvoo 8861
        *boxplotdata="boxplotdata",
8862
        *userboxplot="userboxplot",
8863
        *userboxplotdata="userboxplotdata",
7614 schaersvoo 8864
        *legend="legend",
8865
        *legendcolors="legendcolors",
8866
        *xlabel="xlabel",
8867
        *ylabel="ylabel",
8868
        *barchart="barchart",
8869
        *linegraph="linegraph",
8870
        *clock="clock",
8871
        *animate="animate",
8872
        *video="video",
8873
        *status="status",
7877 schaersvoo 8874
        *nostatus="nostatus",
7652 schaersvoo 8875
        *snaptogrid="snaptogrid",
7784 schaersvoo 8876
        *xsnaptogrid="xsnaptogrid",
8877
        *ysnaptogrid="ysnaptogrid",
8379 schaersvoo 8878
        *snaptopoints="snaptopoints",
9213 schaersvoo 8879
        *snaptofunction="snaptofunction",
8880
        *snaptofun="snaptofun",
7654 schaersvoo 8881
        *userinput_xy="userinput_xy",
8193 schaersvoo 8882
        *userinput_function="userinput_function",
7663 schaersvoo 8883
        *usertextarea_xy="usertextarea_xy",
8222 schaersvoo 8884
        *userinput="userinput",
7823 schaersvoo 8885
        *jsmath="jsmath",
7858 schaersvoo 8886
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 8887
        *setlimits="setlimits",
7858 schaersvoo 8888
        *jscurve="jscurve",
8889
        *jsplot="jsplot",
7983 schaersvoo 8890
        *sgraph="sgraph",
7984 schaersvoo 8891
        *title="title",
7996 schaersvoo 8892
        *centerstring="centerstring",
8893
        *xunit="xunit",
8071 schaersvoo 8894
        *yunit="yunit",
8101 schaersvoo 8895
        *slider="slider",
8105 schaersvoo 8896
        *killslider="killslider",
8244 schaersvoo 8897
        *angle="angle",
8365 schaersvoo 8898
        *halflines="halflines",
8899
        *demilines="demilines",
8244 schaersvoo 8900
        *halfline="halfline",
8297 schaersvoo 8901
        *demiline="demiline",
8366 schaersvoo 8902
        *hlines="hlines",
8903
        *vlines="vlines",
8370 schaersvoo 8904
        *bezier="bezier",
9213 schaersvoo 8905
        *functionlabel="functionlabel",
8906
        *sliderfunction_x="sliderfunction_x",
8907
        *sliderfunction_y="sliderfunction_y",
8908
        *multidraw="multidraw",
8909
        *multilinewidth="multilinewidth",
8910
        *multistrokecolors="multistrokecolors",
8911
        *multifillcolors="multifillcolors",
8912
        *multistrokeopacity="multistrokeopacity",
8913
        *multifillopacity="multifillopacity",
8914
        *multifill="multifill",
8915
        *multidash="multidash",
8916
        *multilabel="multilabel",
8917
        *multiuserinput="multiuserinput",
9289 schaersvoo 8918
        *multisnaptogrid="multisnaptogrid",
8919
        *protractor="protractor",
9386 schaersvoo 8920
        *ruler="ruler",
8921
        *cursor="cursor",
9427 schaersvoo 8922
        *pointer="pointer",
8923
        *yerrorbars="yerrorbars",
11006 schaersvoo 8924
        *xerrorbars="xerrorbars",
11044 schaersvoo 8925
        *noxaxis="noxaxis",
8926
        *noyaxis="noyaxis",
11767 schaersvoo 8927
        *colorpalette="colorpalette",
11802 schaersvoo 8928
        *xoffset="xoffset",
8929
        *centered="centered",
8930
        *xyoffset="xyoffset",
11811 schaersvoo 8931
        *yoffset="yoffset",
11802 schaersvoo 8932
        *resetoffset="resetoffset",
11006 schaersvoo 8933
        *canvastype="canvastype";
7614 schaersvoo 8934
 
10891 schaersvoo 8935
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
8936
         if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
8937
         }else{
8938
          if( c == ' ' ){
7614 schaersvoo 8939
            break;
10891 schaersvoo 8940
          }else{
8941
           temp[i] = c;
8942
           if(i > MAX_INT - 2){canvas_error("command string too long !");}
8943
           i++;
8944
          }
8945
         }
8946
         if(temp[0] == '#'){ break; }
7614 schaersvoo 8947
        }
10891 schaersvoo 8948
        if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
8949
        if (c == EOF) {finished=1;return 0;}
7614 schaersvoo 8950
 
8951
        temp[i]='\0';
8952
        input_type=(char*)my_newmem(strlen(temp));
8953
        snprintf(input_type,sizeof(temp),"%s",temp);
10891 schaersvoo 8954
/* fprintf(stdout,"temp = %s <br/>",input_type); */
7614 schaersvoo 8955
        if( strcmp(input_type, size) == 0 ){
8956
        free(input_type);
8957
        return SIZE;
8958
        }
8959
        if( strcmp(input_type, xrange) == 0 ){
8960
        free(input_type);
8961
        return XRANGE;
8962
        }
8963
        if( strcmp(input_type, rangex) == 0 ){
8964
        free(input_type);
8965
        return XRANGE;
8966
        }
8967
        if( strcmp(input_type, trange) == 0 ){
8968
        free(input_type);
8969
        return TRANGE;
8970
        }
8971
        if( strcmp(input_type, ranget) == 0 ){
8972
        free(input_type);
8973
        return TRANGE;
8974
        }
8975
        if( strcmp(input_type, yrange) == 0 ){
8976
        free(input_type);
8977
        return YRANGE;
8978
        }
8979
        if( strcmp(input_type, rangey) == 0 ){
8980
        free(input_type);
8981
        return YRANGE;
8982
        }
8983
        if( strcmp(input_type, linewidth) == 0 ){
8984
        free(input_type);
8985
        return LINEWIDTH;
8986
        }
8987
        if( strcmp(input_type, dashed) == 0 ){
8988
        free(input_type);
8989
        return DASHED;
8990
        }
8991
        if( strcmp(input_type, dashtype) == 0 ){
8992
        free(input_type);
8993
        return DASHTYPE;
8994
        }
8995
        if( strcmp(input_type, axisnumbering) == 0 ){
8996
        free(input_type);
8997
        return AXIS_NUMBERING;
8998
        }
8999
        if( strcmp(input_type, axisnumbers) == 0 ){
9000
        free(input_type);
9001
        return AXIS_NUMBERING;
9002
        }
9003
        if( strcmp(input_type, axis) == 0 ){
9004
        free(input_type);
9005
        return AXIS;
9006
        }
9007
        if( strcmp(input_type, grid) == 0 ){
9008
        free(input_type);
9009
        return GRID;
9010
        }
9383 schaersvoo 9011
        if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
8366 schaersvoo 9012
        free(input_type);
9013
        return HLINES;
9014
        }
9383 schaersvoo 9015
        if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
8366 schaersvoo 9016
        free(input_type);
9017
        return VLINES;
9018
        }
9383 schaersvoo 9019
        if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
7614 schaersvoo 9020
        free(input_type);
9021
        return HLINE;
9022
        }
9023
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
9024
        free(input_type);
9025
        return VLINE;
9026
        }
9027
        if( strcmp(input_type, line) == 0 ){
9028
        free(input_type);
9029
        return LINE;
9030
        }
9383 schaersvoo 9031
        if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
8299 schaersvoo 9032
        free(input_type);
9033
        return SEGMENTS;
9034
        }
7614 schaersvoo 9035
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
9036
        free(input_type);
9037
        return SEGMENT;
9038
        }
9374 schaersvoo 9039
        if( strcmp(input_type, dsegments) == 0 ){
9040
        free(input_type);
9041
        use_dashed = TRUE;
9042
        return SEGMENTS;
9043
        }
7614 schaersvoo 9044
        if( strcmp(input_type, dsegment) == 0 ){
9045
        free(input_type);
9046
        use_dashed = TRUE;
9047
        return SEGMENT;
9048
        }
9049
        if( strcmp(input_type, crosshairsize) == 0 ){
9050
        free(input_type);
9051
        return CROSSHAIRSIZE;
9052
        }
9053
        if( strcmp(input_type, arrowhead) == 0 ){
9054
        free(input_type);
9055
        return ARROWHEAD;
9056
        }
9057
        if( strcmp(input_type, crosshairs) == 0 ){
9058
        free(input_type);
9059
        return CROSSHAIRS;
9060
        }
9061
        if( strcmp(input_type, crosshair) == 0 ){
9062
        free(input_type);
9063
        return CROSSHAIR;
9064
        }
9065
        if( strcmp(input_type, onclick) == 0 ){
9066
        free(input_type);
9067
        return ONCLICK;
9068
        }
9069
        if( strcmp(input_type, drag) == 0 ){
9070
        free(input_type);
9071
        return DRAG;
9072
        }
9073
        if( strcmp(input_type, userdraw) == 0 ){
9074
        free(input_type);
9075
        return USERDRAW;
9076
        }
9077
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
9078
        free(input_type);
9079
        return STYLE;
9080
        }
9081
        if( strcmp(input_type, fillcolor) == 0 ){
9082
        free(input_type);
9083
        return FILLCOLOR;
9084
        }
9085
        if( strcmp(input_type, strokecolor) == 0 ){
9086
        free(input_type);
9087
        return STROKECOLOR;
9088
        }
9089
        if( strcmp(input_type, filled) == 0  ){
9090
        free(input_type);
9091
        return FILLED;
9092
        }
9093
        if( strcmp(input_type, http) == 0 ){
9094
        free(input_type);
9095
        return HTTP;
9096
        }
9097
        if( strcmp(input_type, rays) == 0 ){
9098
        free(input_type);
9099
        return RAYS;
9100
        }
9101
        if( strcmp(input_type, lattice) == 0 ){
9102
        free(input_type);
9103
        return LATTICE;
9104
        }
9105
        if( strcmp(input_type, bgimage) == 0 ){
9106
        free(input_type);
9107
        return BGIMAGE;
9108
        }
9109
        if( strcmp(input_type, bgcolor) == 0 ){
9110
        free(input_type);
9111
        return BGCOLOR;
9112
        }
9113
        if( strcmp(input_type, backgroundimage) == 0 ){
9114
        free(input_type);
9115
        return BGIMAGE;
9116
        }
9117
        if( strcmp(input_type, text) == 0 ){
9118
        free(input_type);
9119
        return FLY_TEXT;
9120
        }
9121
        if( strcmp(input_type, textup) == 0 ){
9122
        free(input_type);
9123
        return FLY_TEXTUP;
9124
        }
9125
        if( strcmp(input_type, mouse) == 0 ){
9126
        free(input_type);
9127
        return MOUSE;
9128
        }
7991 schaersvoo 9129
        if( strcmp(input_type, mousex) == 0 ){
9130
        free(input_type);
9131
        return MOUSEX;
9132
        }
9133
        if( strcmp(input_type, mousey) == 0 ){
9134
        free(input_type);
9135
        return MOUSEY;
9136
        }
8071 schaersvoo 9137
        if( strcmp(input_type, mouse_degree) == 0 ){
9138
        free(input_type);
9139
        return MOUSE_DEGREE;
9140
        }
9141
        if( strcmp(input_type, mouse_display) == 0 ){
9142
        free(input_type);
9143
        return MOUSE_DISPLAY;
9144
        }
7614 schaersvoo 9145
        if( strcmp(input_type, mouseprecision) == 0 ){
9146
        free(input_type);
9147
        return MOUSE_PRECISION;
9148
        }
9149
        if( strcmp(input_type, precision) == 0 ){
9150
        free(input_type);
9151
        return MOUSE_PRECISION;
9152
        }
9153
        if( strcmp(input_type, curve) == 0 ){
9154
        free(input_type);
9155
        return CURVE;
9156
        }
9157
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 9158
        use_dashed = TRUE;
7614 schaersvoo 9159
        free(input_type);
9160
        return CURVE;
9161
        }
9162
        if( strcmp(input_type, plot) == 0 ){
9163
        free(input_type);
9164
        return CURVE;
9165
        }
9166
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 9167
        use_dashed = TRUE;
7614 schaersvoo 9168
        free(input_type);
9169
        return CURVE;
9170
        }
7788 schaersvoo 9171
        if( strcmp(input_type, levelcurve) == 0 ){
9172
        free(input_type);
9173
        return LEVELCURVE;
9174
        }
7614 schaersvoo 9175
        if( strcmp(input_type, plotsteps) == 0 ){
9176
        free(input_type);
9177
        return PLOTSTEPS;
9178
        }
9179
        if( strcmp(input_type, plotstep) == 0 ){
9180
        free(input_type);
9181
        return PLOTSTEPS;
9182
        }
9183
        if( strcmp(input_type, tsteps) == 0 ){
9184
        free(input_type);
9185
        return PLOTSTEPS;
9186
        }
9187
        if( strcmp(input_type, fontsize) == 0 ){
9188
        free(input_type);
9189
        return FONTSIZE;
9190
        }
9191
        if( strcmp(input_type, fontcolor) == 0 ){
9192
        free(input_type);
9193
        return FONTCOLOR;
9194
        }
9195
        if( strcmp(input_type, arrow2) == 0 ){
9196
        free(input_type);
9197
        return ARROW2;
9198
        }
9199
        if( strcmp(input_type, darrow) == 0 ){
9200
        free(input_type);
8071 schaersvoo 9201
        use_dashed = TRUE;
7614 schaersvoo 9202
        return ARROW;
9203
        }
9204
        if( strcmp(input_type, darrow2) == 0 ){
9205
        free(input_type);
9206
        use_dashed = TRUE;
9207
        return ARROW2;
9208
        }
8347 schaersvoo 9209
        if( strcmp(input_type, arrows2) == 0 ){
9210
        free(input_type);
9211
        return ARROWS2;
9212
        }
9382 schaersvoo 9213
        if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
8304 schaersvoo 9214
        free(input_type);
9215
        return ARROWS;
9216
        }
9382 schaersvoo 9217
        if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
8304 schaersvoo 9218
        free(input_type);
9219
        return ARROW;
9220
        }
7614 schaersvoo 9221
        if( strcmp(input_type, zoom) == 0 ){
9222
        free(input_type);
9223
        return ZOOM;
9224
        }
9225
        if( strcmp(input_type, triangle) == 0 ){
9226
        free(input_type);
9227
        return TRIANGLE;
9228
        }
9306 schaersvoo 9229
        if( strcmp(input_type, triangles) == 0 ){
9230
        free(input_type);
9231
        return TRIANGLES;
9232
        }
9374 schaersvoo 9233
        if( strcmp(input_type, ftriangles) == 0 ){
9234
        free(input_type);
9235
        use_filled = TRUE;
9236
        return TRIANGLES;
9237
        }
7614 schaersvoo 9238
        if( strcmp(input_type, ftriangle) == 0 ){
9239
        free(input_type);
9240
        use_filled = TRUE;
9241
        return TRIANGLE;
9242
        }
9243
        if( strcmp(input_type, input) == 0 ){
9244
        free(input_type);
9245
        return INPUT;
9246
        }
9247
        if( strcmp(input_type, inputstyle) == 0 ){
9248
        free(input_type);
9249
        return INPUTSTYLE;
9250
        }
9251
        if( strcmp(input_type, textarea) == 0 ){
9252
        free(input_type);
9253
        return TEXTAREA;
9254
        }
9255
        if( strcmp(input_type, mathml) == 0 ){
9256
        free(input_type);
9257
        return MATHML;
9258
        }
9259
        if( strcmp(input_type, html) == 0 ){
9260
        free(input_type);
9261
        return MATHML;
9262
        }
9263
        if( strcmp(input_type, fontfamily) == 0 ){
9264
        free(input_type);
9265
        return FONTFAMILY;
9266
        }
10975 schaersvoo 9267
        if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
7614 schaersvoo 9268
        free(input_type);
9269
        return POLYLINE;
9270
        }
8351 schaersvoo 9271
        if( strcmp(input_type, lines) == 0 ){
9272
        free(input_type);
9273
        return LINES;
9274
        }
9374 schaersvoo 9275
        if( strcmp(input_type, rects) == 0){
8363 schaersvoo 9276
        free(input_type);
9277
        return RECTS;
9278
        }
9383 schaersvoo 9279
        if( strcmp(input_type, frects) == 0 ){
8363 schaersvoo 9280
        free(input_type);
9374 schaersvoo 9281
        use_filled = TRUE;
8363 schaersvoo 9282
        return RECTS;
9283
        }
7614 schaersvoo 9284
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
9285
        free(input_type);
9286
        return RECT;
9287
        }
9374 schaersvoo 9288
        if( strcmp(input_type, square) == 0 ){
9289
        free(input_type);
9290
        return RECT;
9291
        }
9292
        if( strcmp(input_type, fsquare) == 0 ){
9293
        free(input_type);
9294
        use_filled = TRUE;
9295
        return SQUARE;
9296
        }
9297
        if( strcmp(input_type, fsquares) == 0 ){
9298
        free(input_type);
9299
        use_filled = TRUE;
9300
        return RECTS;
9301
        }
8370 schaersvoo 9302
        if( strcmp(input_type, roundrects) == 0 ){
9303
        free(input_type);
9304
        return ROUNDRECTS;
9305
        }
7614 schaersvoo 9306
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
9307
        free(input_type);
9308
        return ROUNDRECT;
9309
        }
9374 schaersvoo 9310
        if( strcmp(input_type, froundrects) == 0 ){
7614 schaersvoo 9311
        free(input_type);
9312
        use_filled = TRUE;
9374 schaersvoo 9313
        return ROUNDRECTS;
7614 schaersvoo 9314
        }
9374 schaersvoo 9315
        if( strcmp(input_type, froundrect) == 0 ){
7614 schaersvoo 9316
        free(input_type);
9317
        use_filled = TRUE;
9374 schaersvoo 9318
        return ROUNDRECT;
7614 schaersvoo 9319
        }
9320
        if( strcmp(input_type, dline) == 0 ){
9321
        use_dashed = TRUE;
9322
        free(input_type);
9323
        return LINE;
9324
        }
7786 schaersvoo 9325
        if( strcmp(input_type, dvline) == 0 ){
9326
        use_dashed = TRUE;
9327
        free(input_type);
9328
        return VLINE;
9329
        }
9330
        if( strcmp(input_type, dhline) == 0 ){
9331
        use_dashed = TRUE;
9332
        free(input_type);
9333
        return HLINE;
9334
        }
9386 schaersvoo 9335
        if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
9336
        free(input_type);
9337
        return HALFLINES;
9338
        }
9339
        if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
9340
        free(input_type);
9341
        return HALFLINE;
9342
        }
7614 schaersvoo 9343
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
9344
        use_filled = TRUE;
9345
        free(input_type);
9346
        return RECT;
9347
        }
8304 schaersvoo 9348
        if( strcmp(input_type, circles) == 0 ){
9349
        free(input_type);
9350
        return CIRCLES;
9351
        }
7614 schaersvoo 9352
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
9353
        use_filled = TRUE;
9354
        free(input_type);
9355
        return CIRCLE;
9356
        }
9374 schaersvoo 9357
        if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
9358
        use_filled = TRUE;
9359
        free(input_type);
9360
        return CIRCLES;
9361
        }
7614 schaersvoo 9362
        if( strcmp(input_type, circle) == 0 ){
9363
        free(input_type);
9364
        return CIRCLE;
9365
        }
9366
        if( strcmp(input_type, point) == 0 ){
9367
        free(input_type);
9368
        return POINT;
9369
        }
9370
        if( strcmp(input_type, points) == 0 ){
9371
        free(input_type);
9372
        return POINTS;
9373
        }
9374 schaersvoo 9374
        if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
7614 schaersvoo 9375
        use_filled = TRUE;
9376
        free(input_type);
9377
        return ARC;
9378
        }
9379
        if( strcmp(input_type, arc) == 0 ){
9380
        free(input_type);
9381
        return ARC;
9382
        }
9383
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
9384
        free(input_type);
9385
        return POLY;
9386
        }
9387
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
9388
        use_filled = TRUE;
9389
        free(input_type);
9390
        return POLY;
9391
        }
9392
        if( strcmp(input_type, ellipse) == 0){
9393
        free(input_type);
9394
        return ELLIPSE;
9395
        }
9396
        if( strcmp(input_type, string) == 0 ){
9397
        free(input_type);
9398
        return STRING;
9399
        }
9400
        if( strcmp(input_type, stringup) == 0 ){
9401
        free(input_type);
9402
        return STRINGUP;
9403
        }
9385 schaersvoo 9404
        if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
7614 schaersvoo 9405
        free(input_type);
9406
        return OPACITY;
9407
        }
9408
        if( strcmp(input_type, comment) == 0){
9409
        free(input_type);
9410
        return COMMENT;
9411
        }
9412
        if( strcmp(input_type, fellipse) == 0){
9413
        free(input_type);
9414
        use_filled = TRUE;
9415
        return ELLIPSE;
8224 bpr 9416
        }
9386 schaersvoo 9417
        if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
7614 schaersvoo 9418
        free(input_type);
8146 schaersvoo 9419
        return CLEARBUTTON;
7614 schaersvoo 9420
        }
9421
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
9422
        free(input_type);
9423
        return TRANSLATION;
9424
        }
9425
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
9426
        free(input_type);
9427
        return KILLTRANSLATION;
9428
        }
9429
        if( strcmp(input_type, rotate) == 0){
9430
        free(input_type);
9431
        return ROTATE;
9432
        }
9907 schaersvoo 9433
        if( strcmp(input_type, killrotate) == 0){
9434
        free(input_type);
9435
        return KILLROTATE;
9436
        }
9437
        if( strcmp(input_type, rotationcenter) == 0){
9438
        free(input_type);
9439
        return ROTATION_CENTER;
9440
        }
7785 schaersvoo 9441
        if( strcmp(input_type, affine) == 0){
9442
        free(input_type);
9443
        return AFFINE;
9444
        }
9445
        if( strcmp(input_type, killaffine) == 0){
9446
        free(input_type);
9447
        return KILLAFFINE;
9448
        }
7614 schaersvoo 9449
        if( strcmp(input_type, slider) == 0 ){
9450
        free(input_type);
9451
        return SLIDER;
9452
        }
8101 schaersvoo 9453
        if( strcmp(input_type, killslider) == 0 ){
9454
        free(input_type);
9455
        return KILLSLIDER;
9456
        }
7614 schaersvoo 9457
        if( strcmp(input_type, copy) == 0 ){
9458
        free(input_type);
9459
        return COPY;
9460
        }
9461
        if( strcmp(input_type, copyresized) == 0 ){
9462
        free(input_type);
9463
        return COPYRESIZED;
9464
        }
9465
        if( strcmp(input_type, xlogscale) == 0 ){
9466
        free(input_type);
9467
        return XLOGSCALE;
9468
        }
9469
        if( strcmp(input_type, ylogscale) == 0 ){
9470
        free(input_type);
9471
        return YLOGSCALE;
9472
        }
9473
        if( strcmp(input_type, xylogscale) == 0 ){
9474
        free(input_type);
9475
        return XYLOGSCALE;
9476
        }
9477
        if( strcmp(input_type, ylogscale) == 0 ){
9478
        free(input_type);
9479
        return YLOGSCALE;
9480
        }
7735 schaersvoo 9481
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 9482
        free(input_type);
7735 schaersvoo 9483
        return XLOGBASE;
7614 schaersvoo 9484
        }
7735 schaersvoo 9485
        if( strcmp(input_type, ylogbase) == 0 ){
9486
        free(input_type);
9487
        return YLOGBASE;
9488
        }
7614 schaersvoo 9489
        if( strcmp(input_type, intooltip) == 0 ){
9490
        free(input_type);
9491
        return INTOOLTIP;
9492
        }
9329 schaersvoo 9493
        if( strcmp(input_type, popup) == 0 ){
9494
        free(input_type);
9495
        return POPUP;
9496
        }
7614 schaersvoo 9497
        if( strcmp(input_type,video) == 0 ){
9498
        free(input_type);
9499
        return VIDEO;
9500
        }
11772 schaersvoo 9501
        if( strcmp(input_type,fillall) == 0 ){
9502
        free(input_type);
9503
        return FILLALL;
9504
        }
7614 schaersvoo 9505
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
9506
        free(input_type);
9507
        return FLOODFILL;
8224 bpr 9508
        }
7614 schaersvoo 9509
        if( strcmp(input_type,filltoborder) == 0 ){
9510
        free(input_type);
9511
        return FILLTOBORDER;
8224 bpr 9512
        }
7614 schaersvoo 9513
        if( strcmp(input_type, replyformat) == 0 ){
9514
        free(input_type);
9515
        return REPLYFORMAT;
9516
        }
9517
        if( strcmp(input_type, pixelsize) == 0 ){
9518
        free(input_type);
9519
        return PIXELSIZE;
9520
        }
9521
        if( strcmp(input_type, setpixel) == 0 ){
9522
        free(input_type);
9523
        return SETPIXEL;
9524
        }
9525
        if( strcmp(input_type, pixels) == 0 ){
9526
        free(input_type);
9527
        return PIXELS;
9528
        }
9529
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
9530
        free(input_type);
9531
        return X_AXIS_STRINGS;
9532
        }
9341 schaersvoo 9533
        if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
9534
        free(input_type);
9535
        return X_AXIS_STRINGS_UP;
9536
        }
7614 schaersvoo 9537
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
9538
        free(input_type);
9539
        return Y_AXIS_STRINGS;
9540
        }
9541
        if( strcmp(input_type, legend) == 0  ){
9542
        free(input_type);
9543
        return LEGEND;
9544
        }
9545
        if( strcmp(input_type, legendcolors) == 0  ){
9546
        free(input_type);
9547
        return LEGENDCOLORS;
9548
        }
9549
        if( strcmp(input_type, xlabel) == 0  ){
9550
        free(input_type);
9551
        return XLABEL;
9552
        }
9553
        if( strcmp(input_type, ylabel) == 0  ){
9554
        free(input_type);
9555
        return YLABEL;
9556
        }
8370 schaersvoo 9557
        if( strcmp(input_type, bezier) == 0  ){
9558
        free(input_type);
9559
        return BEZIER;
9560
        }
7614 schaersvoo 9561
        if( strcmp(input_type, animate) == 0  ){
9562
        free(input_type);
9563
        return ANIMATE;
9564
        }
9354 schaersvoo 9565
        /* these are bitmap related flydraw commands...must be removed. eventually */
7614 schaersvoo 9566
        if( strcmp(input_type, transparent) == 0 ){
9567
        free(input_type);
9568
        return TRANSPARENT;
9569
        }
7877 schaersvoo 9570
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 9571
        free(input_type);
9572
        return STATUS;
9573
        }
7784 schaersvoo 9574
        if( strcmp(input_type, xsnaptogrid) == 0 ){
9575
        free(input_type);
9576
        return XSNAPTOGRID;
9577
        }
9578
        if( strcmp(input_type, ysnaptogrid) == 0 ){
9579
        free(input_type);
9580
        return YSNAPTOGRID;
9581
        }
8379 schaersvoo 9582
        if( strcmp(input_type, snaptogrid) == 0 ){
9583
        free(input_type);
9584
        return SNAPTOGRID;
9585
        }
9586
        if( strcmp(input_type, snaptopoints) == 0 ){
9587
        free(input_type);
9588
        return SNAPTOPOINTS;
9589
        }
9213 schaersvoo 9590
        if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
9591
        free(input_type);
9592
        return SNAPTOFUNCTION;
9593
        }
7652 schaersvoo 9594
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 9595
        free(input_type);
7652 schaersvoo 9596
        return USERINPUT_XY;
9597
        }
8193 schaersvoo 9598
        if( strcmp(input_type, userinput_function) == 0 ){
9599
        free(input_type);
9600
        return USERINPUT_FUNCTION;
9601
        }
7663 schaersvoo 9602
        if( strcmp(input_type, usertextarea_xy) == 0 ){
9603
        free(input_type);
9604
        return USERTEXTAREA_XY;
9605
        }
8222 schaersvoo 9606
        if( strcmp(input_type, userinput) == 0 ){
9607
        free(input_type);
9608
        return USERINPUT;
9609
        }
8105 schaersvoo 9610
        if( strcmp(input_type, angle) == 0 ){
7996 schaersvoo 9611
        free(input_type);
8105 schaersvoo 9612
        return ANGLE;
9613
        }
8297 schaersvoo 9614
        if( strcmp(input_type, functionlabel) == 0 ){
8244 schaersvoo 9615
        free(input_type);
8297 schaersvoo 9616
        return FUNCTION_LABEL;
9617
        }
9213 schaersvoo 9618
        if( strcmp(input_type, sliderfunction_x) == 0 ){
8297 schaersvoo 9619
        free(input_type);
9213 schaersvoo 9620
        return SLIDER_X;
9621
        }
9622
        if( strcmp(input_type, sliderfunction_y) == 0 ){
9623
        free(input_type);
9624
        return SLIDER_Y;
9625
        }
9626
        if( strcmp(input_type, multidraw) == 0 ){
9627
        free(input_type);
9628
        return MULTIDRAW;
9629
        }
9630
        if( strcmp(input_type, multistrokeopacity) == 0 ){
9631
        free(input_type);
9632
        return MULTISTROKEOPACITY;
9633
        }
9634
        if( strcmp(input_type, multifillopacity) == 0 ){
9635
        free(input_type);
9636
        return MULTIFILLOPACITY;
9637
        }
9638
        if( strcmp(input_type, multilinewidth) == 0 ){
9639
        free(input_type);
9640
        return MULTILINEWIDTH;
9641
        }
9642
        if( strcmp(input_type, multistrokecolors) == 0 ){
9643
        free(input_type);
9644
        return MULTISTROKECOLORS;
9645
        }
9646
        if( strcmp(input_type, multifill) == 0 ){
9647
        free(input_type);
9648
        return MULTIFILL;
9649
        }
9650
        if( strcmp(input_type, multifillcolors) == 0 ){
9651
        free(input_type);
9652
        return MULTIFILLCOLORS;
9653
        }
9654
        if( strcmp(input_type, multilabel) == 0 ){
9655
        free(input_type);
9656
        return MULTILABEL;
9657
        }
9658
        if( strcmp(input_type, multidash) == 0 ){
9659
        free(input_type);
9660
        return MULTIDASH;
9661
        }
9662
        if( strcmp(input_type, multisnaptogrid) == 0 ){
9663
        free(input_type);
9664
        return MULTISNAPTOGRID;
9665
        }
9666
        if( strcmp(input_type, multiuserinput) == 0 ){
9667
        free(input_type);
9668
        return MULTIUSERINPUT;
9669
        }
9386 schaersvoo 9670
        if( strcmp(input_type, parallel) == 0 ){
9671
        free(input_type);
9672
        return PARALLEL;
9673
        }
9289 schaersvoo 9674
        if( strcmp(input_type, protractor) == 0 ){
9675
        free(input_type);
9676
        return PROTRACTOR;
9677
        }
9678
        if( strcmp(input_type, ruler) == 0 ){
9679
        free(input_type);
9680
        return RULER;
9681
        }
9386 schaersvoo 9682
        if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
9213 schaersvoo 9683
        free(input_type);
9386 schaersvoo 9684
        return CURSOR;
9685
        }
9686
        if( strcmp(input_type, sgraph) == 0 ){
9687
        free(input_type);
9688
        return SGRAPH;
9689
        }
9690
        if( strcmp(input_type, jsmath) == 0 ){
9691
        free(input_type);
9692
        return JSMATH;
9693
        }
9694
        if( strcmp(input_type, trace_jscurve) == 0 ){
9695
        free(input_type);
9696
        return TRACE_JSCURVE;
9697
        }
9698
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
9699
        free(input_type);
9700
        return JSCURVE;
9701
        }
9702
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
9703
        free(input_type);
9704
        return CENTERSTRING;
9705
        }
9706
        if( strcmp(input_type, setlimits) == 0 ){
9707
        free(input_type);
9708
        return SETLIMITS;
9709
        }
9710
        if( strcmp(input_type, xunit) == 0 ){
9711
        free(input_type);
9712
        return XUNIT;
9713
        }
9714
        if( strcmp(input_type, yunit) == 0 ){
9715
        free(input_type);
9716
        return YUNIT;
9717
        }
9718
        if( strcmp(input_type, fill) == 0 ){
9719
        free(input_type);
9720
        return FLOODFILL;
9721
        }
9722
        if( strcmp(input_type, end) == 0){
9723
        free(input_type);
9724
        return END;
9725
        }
9726
        if( strcmp(input_type, blink) == 0 ){
9727
        free(input_type);
9728
        return BLINK;
9729
        }
9730
        if( strcmp(input_type, audio) == 0 ){
9731
        free(input_type);
9732
        return AUDIO;
9733
        }
9734
        if( strcmp(input_type, audioobject) == 0 ){
9735
        free(input_type);
9736
        return AUDIOOBJECT;
9737
        }
9738
        if( strcmp(input_type, patternfill) == 0 ){
9739
        free(input_type);
9740
        return PATTERNFILL;
9741
        }
9742
        if( strcmp(input_type, hatchfill) == 0 ){
9743
        free(input_type);
9744
        return HATCHFILL;
9745
        }
9746
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
9747
        free(input_type);
9748
        return DIAMONDFILL;
9749
        }
9750
        if( strcmp(input_type, dotfill) == 0 ){
9751
        free(input_type);
9752
        return DOTFILL;
9753
        }
9754
        if( strcmp(input_type, gridfill) == 0 ){
9755
        free(input_type);
9756
        return GRIDFILL;
9757
        }
9758
        if( strcmp(input_type, imagefill) == 0 ){
9759
        free(input_type);
9760
        return IMAGEFILL;
9761
        }
9762
        if( strcmp(input_type, clicktile_colors) == 0 ){
9763
        free(input_type);
9764
        return CLICKTILE_COLORS;
9765
        }
9766
        if( strcmp(input_type, clicktile) == 0 ){
9767
        free(input_type);
9768
        return CLICKTILE;
9769
        }
9770
        if( strcmp(input_type, piechart) == 0  ){
9771
        free(input_type);
9772
        return PIECHART;
9773
        }
9433 schaersvoo 9774
        if( strcmp(input_type, boxplot) == 0  ){
9775
        free(input_type);
9776
        return BOXPLOT;
9777
        }
9465 schaersvoo 9778
        if( strcmp(input_type, boxplotdata) == 0  ){
9433 schaersvoo 9779
        free(input_type);
9465 schaersvoo 9780
        return BOXPLOTDATA;
9433 schaersvoo 9781
        }
9465 schaersvoo 9782
        if( strcmp(input_type, userboxplot) == 0  ){
9783
        free(input_type);
9784
        return USERBOXPLOT;
9785
        }
9786
        if( strcmp(input_type, userboxplotdata) == 0  ){
9787
        free(input_type);
9788
        return USERBOXPLOT;
9789
        }
9386 schaersvoo 9790
        if( strcmp(input_type, barchart) == 0  ){
9791
        free(input_type);
9792
        return BARCHART;
9793
        }
9794
        if( strcmp(input_type, linegraph) == 0  ){
9795
        free(input_type);
9796
        return LINEGRAPH;
9797
        }
9798
        if( strcmp(input_type, clock) == 0  ){
9799
        free(input_type);
9800
        return CLOCK;
9801
        }
9427 schaersvoo 9802
        if( strcmp(input_type, yerrorbars) == 0  ){
9386 schaersvoo 9803
        free(input_type);
9427 schaersvoo 9804
        return YERRORBARS;
9805
        }
9806
        if( strcmp(input_type, xerrorbars) == 0  ){
9807
        free(input_type);
9808
        return XERRORBARS;
9809
        }
11006 schaersvoo 9810
        if( strcmp(input_type, canvastype) == 0  ){
9427 schaersvoo 9811
        free(input_type);
11006 schaersvoo 9812
        return CANVASTYPE;
9813
        }
11044 schaersvoo 9814
        if( strcmp(input_type, noyaxis) == 0  ){
11006 schaersvoo 9815
        free(input_type);
11044 schaersvoo 9816
        return NOYAXIS;
9817
        }
9818
        if( strcmp(input_type, noxaxis) == 0  ){
9819
        free(input_type);
9820
        return NOXAXIS;
9821
        }
11767 schaersvoo 9822
        if( strcmp(input_type, colorpalette) == 0  ){
11044 schaersvoo 9823
        free(input_type);
11767 schaersvoo 9824
        return COLORPALETTE;
9825
        }
11802 schaersvoo 9826
        if( strcmp(input_type, resetoffset) == 0  ){
11767 schaersvoo 9827
        free(input_type);
11802 schaersvoo 9828
        return RESETOFFSET;
9829
        }
9830
        if( strcmp(input_type, xyoffset) == 0  ){
9831
        free(input_type);
9832
        return XYOFFSET;
9833
        }
9834
        if( strcmp(input_type, xoffset) == 0 || strcmp(input_type, centered) == 0  ){
9835
        free(input_type);
9836
        return XOFFSET;
9837
        }
11811 schaersvoo 9838
        if( strcmp(input_type, yoffset) == 0 ){
11802 schaersvoo 9839
        free(input_type);
11811 schaersvoo 9840
        return YOFFSET;
9841
        }
9842
        free(input_type);
7614 schaersvoo 9843
        ungetc(c,infile);
9844
        return 0;
9845
}