Subversion Repositories wimsdev

Rev

Rev 14057 | Rev 14062 | 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;
11893 schaersvoo 51
double tmax = 0;
52
double tmin = 0;
7614 schaersvoo 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;
11875 schaersvoo 60
int use_filled = 0; /* 0:no fill , 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */
7614 schaersvoo 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 */
12104 schaersvoo 70
    struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);
71
    unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
7614 schaersvoo 72
    infile = stdin;/* read flyscript via stdin */
73
    int i,c;
74
    double double_data[MAX_INT+1];
75
    int int_data[MAX_INT+1];
76
    for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
77
    int use_parametric = FALSE;/* will be reset after parametric plotting */
78
    int use_axis = FALSE;
11891 schaersvoo 79
    int use_axis_numbering = -1;
14038 schaersvoo 80
    int use_snap = 0; /* 0 = none 1=grid : 2=x-grid : 3=y-grid : 4=snap to points */
81
    int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/
7797 schaersvoo 82
    int use_pan_and_zoom = FALSE;
7956 schaersvoo 83
    int use_safe_eval = FALSE; /* if true, add just once : js function to evaluate userinput values for plotting etc */
7858 schaersvoo 84
    int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
85
    int use_js_plot = FALSE; /* if true , let js-engine plot the curve */
11006 schaersvoo 86
    int jsplot_cnt = 0; /* keepint track on the curve identity */
8448 schaersvoo 87
    int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
14038 schaersvoo 88
    int include_special_OEF_reply = FALSE; /* used for including extra read_canvas_images();*/
7614 schaersvoo 89
    int line_width = 1;
90
    int decimals = 2;
8365 schaersvoo 91
    int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
92
    int use_userdraw = FALSE; /* flag to indicate user interaction */
7614 schaersvoo 93
    int drag_type = -1;/* 0,1,2 : xy,x,y */
9329 schaersvoo 94
    int use_tooltip = -1; /* 1= tooltip 2= popup window*/
7614 schaersvoo 95
    char *tooltip_text = "Click here";
96
    char *temp = ""; /* */
97
    char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
98
    char *stroke_color = "255,0,0";
99
    char *fill_color = "0,255,0";
100
    char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
101
    char *font_color = "#00000";
102
    char *draw_type = "points";
103
    char *fly_font = "normal";
8815 schaersvoo 104
    char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;";
7614 schaersvoo 105
    char *flytext = "";
7785 schaersvoo 106
    char *affine_matrix = "[1,0,0,1,0,0]";
8297 schaersvoo 107
    char *function_label = "f(x)=";
11839 schaersvoo 108
    int use_pattern = 0; /* used in drag&drop library : grid=2,hatch=3,diamond=4,dot=5*/
11006 schaersvoo 109
    int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
7614 schaersvoo 110
    int pixelsize = 1;
111
    int reply_format = 0;
112
    int input_cnt = 0;
113
    int ext_img_cnt = 0;
8071 schaersvoo 114
    int slider_cnt = 0;
11763 schaersvoo 115
    int fill_cnt = 0;
10953 bpr 116
    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 117
    int fly_font_size = 12; /*fly_font_size is relative to this... */
11837 schaersvoo 118
    int dashtype[2] = { 4 , 4 }; /* just line_px and space_px : may have more arguments...if needed in future */
7614 schaersvoo 119
    int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis : only once per object type */
120
    for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
8365 schaersvoo 121
    int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
7833 schaersvoo 122
    int crosshair_size = 5; /* size in px*/
8365 schaersvoo 123
    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  */
124
    int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange :just to flag an error message */
8448 schaersvoo 125
    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 126
    int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
127
    int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
7989 schaersvoo 128
    int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
9433 schaersvoo 129
    int boxplot_cnt = 0;
11890 schaersvoo 130
    int numberline_cnt = 0;
7956 schaersvoo 131
    int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
8074 schaersvoo 132
    int reply_precision = 100; /* used for precision of student answers / drawings */
7614 schaersvoo 133
    double angle = 0.0;
10953 bpr 134
    char *rotation_center = "null";
8365 schaersvoo 135
    int clickfillmarge = 20; /* in pixels : if the 'remove click' is within this marge, the filling is removed */
11893 schaersvoo 136
    int use_animate = 0; /* used for jscurve / js parametric  */
7823 schaersvoo 137
    int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
10953 bpr 138
    int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
8365 schaersvoo 139
    size_t string_length = 0; /* measure the size of the user input fly-string */
140
    double stroke_opacity = 0.8; /* use some opacity as default */
141
    double fill_opacity = 0.8;/* use some opacity as default */
7614 schaersvoo 142
    char *URL = "http://localhost/images";
9213 schaersvoo 143
    char *slider_function_x = "x";
144
    char *slider_function_y = "y";
7614 schaersvoo 145
    memset(buffer,'\0',MAX_BUFFER);
146
    void *tmp_buffer = "";
147
    /* default writing a unzipped js-include file into wims getfile directory */
148
    char *w_wims_session = getenv("w_wims_session");
12104 schaersvoo 149
    if(  w_wims_session == NULL || *w_wims_session == 0 ){canvas_error("Hmmm, your wims environment does not exist...\nCanvasdraw should be used within wims.");}
7614 schaersvoo 150
    int L0=strlen(w_wims_session) + 21;
151
    char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
152
    snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
153
    mode_t process_mask = umask(0); /* check if file exists */
154
    int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
155
    if( result == 0 || errno == EEXIST ){
156
     umask(process_mask); /* be sure to set correct permission */
8224 bpr 157
     char *w_session = getenv("w_session");
7614 schaersvoo 158
     int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
12104 schaersvoo 159
     getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
8224 bpr 160
     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 */
13306 obado 161
    /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
7614 schaersvoo 162
    /* now write file into getfile dir*/
163
    char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims" : we need absolute path for location */
164
    int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
165
    char *location = my_newmem(L2); /* create memory to fit string precisely */
166
    snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
167
    js_include_file = fopen(location,"w");/* open the file location for writing */
168
    /* check on opening...if nogood : mount readonly? disk full? permissions not set correctly? */
169
    if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN : could not write to javascript include file...check your system logfiles !" );}
170
 
171
/* ----------------------------------------------------- */
11997 schaersvoo 172
 
7614 schaersvoo 173
/* while more lines to process */
174
 
175
    while(!finished){
9329 schaersvoo 176
        if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
7614 schaersvoo 177
        type = get_token(infile);
178
        done = FALSE;
179
        /*
9385 schaersvoo 180
        @ canvasdraw
181
        @ 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...)
13936 bpr 182
        @ 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)<br />non-solid filling (grid,hatch,diamond,dot,text) is provided using command <a href="#fillpattern">fillpattern a_pattern</a><br />for <a href="#filltoborder">filltoborder x0,y0,color</a> or <a href="#filltoborder">fill x0,y0,color</a> type filling (eg fill a region around x0,y0 with color until a border is encountered),<br />there are non-solid pattern fill analogues:<ul><li><a href="#gridfill">gridfill x,y,dx,dy,color</a></li><li><a href="#hatchfill">hatchfill x,y,dx,dy,color</a></li><li><a href="#diamondfill">diamondfill x,y,dx,dy,color</a></li><li><a href="#dotfill">dotfill x,y,dx,dy,color</a></li><li><a href="#textfill">textfill x,y,color,sometext_or_char</a></li></ul></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 183
        @ 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 184
        @ 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 185
        @ 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 186
        @ 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 187
        @ 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.
13957 schaersvoo 188
        @ 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 (numeric, eg keyboard driven drawings) with canvasdraw on touch devices: use the command family <a href="#userinput_xy">userinput</a>
7614 schaersvoo 189
        */
190
        switch(type){
191
        case END:
192
        finished = 1;
193
        done = TRUE;
194
        break;
195
        case 0:
196
            sync_input(infile);
197
            break;
12063 schaersvoo 198
 
199
        case CENTERED:
200
         use_offset = 4;
201
         /*
202
         @ centered
203
         @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
13829 bpr 204
         @ may be used for text exactly centered on it's (x;y)
12063 schaersvoo 205
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
13957 schaersvoo 206
         @ 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')
12107 schaersvoo 207
         @%centered%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
12063 schaersvoo 208
        */
209
        break;
210
 
7614 schaersvoo 211
        case COMMENT:
212
            sync_input(infile);
213
            break;
11806 schaersvoo 214
        case AFFINE:
7614 schaersvoo 215
        /*
11806 schaersvoo 216
         @ affine a,b,c,d,tx,ty
217
         @ defines a transformation matrix for subsequent objects
13957 schaersvoo 218
         @ follows the HTML5 / Canvas transformation standards<br />note: images drawn by setting skew params a &amp; d will thus be very different from Flydraw's "affine a,b,c,d,e,tx,ty" !!
219
         @ use keyword <a href='#killaffine'>'killaffine'</a> to end the transformation...the next objects will be drawn in the original x/y-range
220
         @ note 1: only 'draggable' / 'onclick' type of objects (e.g. objects in the 'drag/drop/onclick-library') can be transformed.
221
         @ note 2: do not use 'onclick' or 'drag xy' with tranformation / rotation objects : the mouse coordinates do not get transformed (yet)
11806 schaersvoo 222
         @ note 3: no matrix operations on the transformation matrix implemented (yet)
223
         @ a : Scales the drawings horizontally
224
         @ b : Skews the drawings horizontally
225
         @ c : Skews the drawings vertically
226
         @ d : Scales the drawings vertically
227
         @ tx: Moves the drawings horizontally in xrange coordinate system
228
         @ ty: Moves the drawings vertically in yrange coordinate system
229
         @ the data precision may be set by preceding command "precision int"
12107 schaersvoo 230
         @%affine%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%fcircle 5,5,40,blue%affine 1,0,0,1,-10,-10%fcircle 5,5,40,green
7614 schaersvoo 231
        */
11806 schaersvoo 232
            for(i = 0 ; i<6;i++){
7614 schaersvoo 233
                switch(i){
11806 schaersvoo 234
                    case 0: double_data[0] = get_real(infile,0);break;
235
                    case 1: double_data[1] = get_real(infile,0);break;
236
                    case 2: double_data[2] = get_real(infile,0);break;
237
                    case 3: double_data[3] = get_real(infile,0);break;
238
                    case 4: double_data[4] = get_real(infile,0);break;
239
                    case 5: double_data[5] = get_real(infile,1);
240
                        use_affine = TRUE;
241
                        decimals = find_number_of_digits(precision);
242
                        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));
243
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
244
                        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));
245
                        break;
7614 schaersvoo 246
                    default: break;
247
                }
248
            }
11806 schaersvoo 249
        break;
8386 schaersvoo 250
 
11806 schaersvoo 251
        case ANGLE:
7614 schaersvoo 252
        /*
11806 schaersvoo 253
         @ angle xc,yc,width,start_angle,end_angle,color
254
         @ width is in x-range
255
         @ will zoom in/out
256
         @ if size is controlled by command <a href='#slider'>'slider'</a> use radians to set limits of slider.
12110 schaersvoo 257
         @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue
13961 schaersvoo 258
         @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%slider 0,2*pi,400,30,angle degrees,Rotate arrow%arrow 0,0,8,0,8,red%filled%fillcolor orange%angle 0,0,4,0,0,red
7614 schaersvoo 259
        */
11806 schaersvoo 260
            for(i=0;i<7;i++){
7614 schaersvoo 261
                switch(i){
11806 schaersvoo 262
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
263
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
264
                    case 2:double_data[2] = get_real(infile,0);break; /* width in pixels ! */
265
                    case 3:double_data[3] = get_real(infile,0);break; /* start angle in degrees */
266
                    case 4:double_data[4] = get_real(infile,0);break; /* end angle in degrees */
267
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
268
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 269
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 270
                        reset();
271
                    break;
7614 schaersvoo 272
                }
273
            }
274
            break;
8386 schaersvoo 275
 
11806 schaersvoo 276
        case ANIMATE:
7614 schaersvoo 277
        /*
11930 schaersvoo 278
         @ animate
11893 schaersvoo 279
         @ keyword
280
         @ the animated point is a filled rectangle ; adjust colour with command 'fillcolor colorname/hexnumber'
281
         @ use linewidth to adjust size of the points
13957 schaersvoo 282
         @ will animate a point on -only- the next <a href='#jsplot'>jsplot/jscurve command</a> . Only a single call to 'animate' is allowed...in case of multiple 'animate' keywords, only the last one is valid
283
         @ only usable for command jsplot (normal functions or parametric)<br />no other object/thing can be animated -for now
284
         @ moves repeatedly from <a href='#xrange'>xmin to xmax</a> or in case of a parametric function from <a href='#trange'>tmin to tmax</a>
285
         @ use commands <a href='#multilinewidth'>multilinewidth</a>, <a href='#multistrokecolor'>multistrokecolor</a> etc in case of multiple animated functions.<br/ >use multiple functions as argument in a single call to <a href='#jsplot'>jsplot color,fun1,fun2,fun3...fun_n</a>
13939 bpr 286
         @%animate_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%jsplot blue,7*cos(x),5*sin(2*x)
287
         @%animate_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%linewidth 4%fillcolor red%animate%trange -2*pi,2*pi%linewidth 1%opacity 255,50%canvastype 100%fill 1.2,1.2,red%canvastype 101%fill -1.2,-1.2,blue%multistrokecolors blue,blue,green,green,orange,orange%multilinewidth 2,2,3,3,1,1%jsplot blue,7*cos(x),5*sin(2*x),9*sin(x),5*cos(x),x^2,x
7614 schaersvoo 288
        */
13512 schaersvoo 289
            use_animate++;
290
            if( use_animate == 1 ){
291
            fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);\
292
            var trace_ctx = trace_canvas.getContext('2d');\
293
            trace_ctx.fillStyle = 'rgba(%s,%f)';\
294
            trace_ctx.strokeStyle = 'rgba(%s,%f)';\
295
            trace_ctx.lineWidth = %d;var anim_pos = 0;\n\
296
            function animate_this(){\
297
             var sync;\
298
             var synchrone = Math.floor(animation_steps/animation_funs);\
299
             trace_ctx.clearRect(0,0,xsize,ysize);\
300
             for(var p=0; p<animation_funs;p++){\
301
              sync = p*synchrone;\
302
              trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\
303
             };\
304
             setTimeout(function(){\
305
              requestAnimationFrame(animate_this);  anim_pos++;}, 50\
306
             );\
307
             if(anim_pos >= animation_steps){anim_pos = 0;};\
308
             };",canvas_root_id,ANIMATE_CANVAS,fill_color,fill_opacity,stroke_color,stroke_opacity,line_width,line_width,line_width,2*line_width,2*line_width);
309
            }
310
            else
311
            {
13514 schaersvoo 312
                canvas_error("animate can only be used once<br />multiple curves may be animated using something like:<br />jsplot red,sin(x),cos(x),x^2,sin(2*x)");
13512 schaersvoo 313
            }
7614 schaersvoo 314
            break;
8386 schaersvoo 315
 
11806 schaersvoo 316
        case ARC:
7614 schaersvoo 317
        /*
11997 schaersvoo 318
         @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
11806 schaersvoo 319
         @ can <b>not</b> be set "onclick" or "drag xy"
320
         @ <b>attention</b>: width in height in x/y-range
12110 schaersvoo 321
         @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue
13961 schaersvoo 322
         @%arc_filled%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%filled%fillcolor green%arc 0,0,4,4,10,135,red
323
         @%arc_slider%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%slider 0,2*pi,400,30,angle degree,Rotate arrow%arrow 0,0,8,0,8,red%filled%fillcolor orange%fillpatter hatch%opacity 255,80%arc 0,0,8,8,0,0,red
7614 schaersvoo 324
        */
11806 schaersvoo 325
            for(i=0;i<7;i++){
326
                switch(i){
327
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
328
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
329
                    case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
330
                    case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
331
                    case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
332
                    case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
333
                    case 6:stroke_color = get_color(infile,1);/* name or hex color */
334
                    /* in Shape library:
335
                        x[0] = x[1] = xc = double_data[0]
336
                        y[0] = y[1] = yc = double_data[1]
337
                        w[0] = width = double_data[2]
338
                        w[1] = height = double_data[3]
339
                        h[0] = start_angle = double_data[4]
340
                        h[1] = end_angle = double_data[5]
341
                    */
342
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 343
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 344
                        reset();
345
                    break;
346
                }
347
            }
7614 schaersvoo 348
            break;
11806 schaersvoo 349
        case ARROW:
7614 schaersvoo 350
        /*
11806 schaersvoo 351
        @ arrow x1,y1,x2,y2,h,color
352
        @ alternative : vector
353
        @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
354
        @ use command 'linewidth int' to adjust thickness of the arrow
9406 schaersvoo 355
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
13957 schaersvoo 356
        @%arrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%arrow 0,0,4,3,8,blue%drag xy%arrow 0,0,-4,3,8,green%drag xy%arrow 0,0,4,-3,8,orange%drag xy%arrow 0,0,-4,-3,8,cyan
357
        @%arrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%arrow 0,0,4,4,8,blue%onclick%arrow 0,0,-4,5,8,green%onclick%arrow 0,0,4,-6,8,orange%onclick%arrow 0,0,-4,-2,8,cyan
7614 schaersvoo 358
        */
11806 schaersvoo 359
            for(i=0;i<6;i++){
7614 schaersvoo 360
                switch(i){
361
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
362
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
11806 schaersvoo 363
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
364
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
365
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
366
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
7614 schaersvoo 367
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 368
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 369
                        if(onclick > 0){click_cnt++;}
370
                        /* click_cnt++;*/
371
                        reset();
372
                        break;
373
                }
374
            }
375
            break;
8386 schaersvoo 376
 
11806 schaersvoo 377
        case ARROWS:
7614 schaersvoo 378
        /*
11806 schaersvoo 379
        @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
380
        @ alternative : vectors
381
        @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
382
        @ use command 'linewidth int' to adjust thickness of the arrow
383
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
13957 schaersvoo 384
        @%arrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2%
385
        @%arrows_drag%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%arrows red,8,0,0,4,3,0,0,2,4,0,0,-2,4,0,0,-3,-4,0,0,3,-2%
7614 schaersvoo 386
        */
387
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
388
            fill_color = stroke_color;
11806 schaersvoo 389
            arrow_head = (int) get_real(infile,0);/* h */
7614 schaersvoo 390
            i=0;
391
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 392
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 393
                if(i%2 == 0 ){
394
                    double_data[i] = get_real(infile,0); /* x */
395
                }
396
                else
397
                {
398
                    double_data[i] = get_real(infile,1); /* y */
399
                }
400
                i++;
401
            }
402
            decimals = find_number_of_digits(precision);
11806 schaersvoo 403
            for(c = 0 ; c < i-1 ; c = c+4){
14045 schaersvoo 404
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 405
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 406
                /* click_cnt++; */
7614 schaersvoo 407
            }
408
            reset();
409
            break;
8386 schaersvoo 410
 
11806 schaersvoo 411
        case ARROW2:
7614 schaersvoo 412
        /*
11806 schaersvoo 413
        @ arrow2 x1,y1,x2,y2,h,color
414
        @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and  in color 'color'
415
        @ use command 'arrowhead int' to adjust the arrow head size
416
        @ use command 'linewidth int' to adjust thickness of the arrow
9406 schaersvoo 417
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 418
        @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
7614 schaersvoo 419
        */
11806 schaersvoo 420
            for(i=0;i<6;i++){
7614 schaersvoo 421
                switch(i){
422
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
423
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
11806 schaersvoo 424
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
425
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
426
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
427
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
428
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 429
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 430
                        if(onclick > 0){click_cnt++;}
431
                        /* click_cnt++;*/
432
                        reset();
433
                        break;
434
                }
435
            }
436
            break;
8386 schaersvoo 437
 
11806 schaersvoo 438
        case ARROWS2:
7614 schaersvoo 439
        /*
11806 schaersvoo 440
        @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
441
        @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
442
        @ use command 'linewidth int' to adjust thickness of the arrows
443
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
12107 schaersvoo 444
        @%arrows2%size 400,400%xrange -10,10%yrange -10,10%onclick%arrows2 red,8,0,0,4,3,1,1,2,4,2,2,-2,4,3,3,-3,-4,0,0,3,-2%
7614 schaersvoo 445
        */
446
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
447
            fill_color = stroke_color;
11806 schaersvoo 448
            arrow_head = (int) get_real(infile,0);/* h */
7614 schaersvoo 449
            i=0;
450
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 451
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 452
                if(i%2 == 0 ){
453
                    double_data[i] = get_real(infile,0); /* x */
454
                }
455
                else
456
                {
457
                    double_data[i] = get_real(infile,1); /* y */
458
                }
459
                i++;
460
            }
8224 bpr 461
            decimals = find_number_of_digits(precision);
11806 schaersvoo 462
            for(c = 0 ; c < i-1 ; c = c+4){
14045 schaersvoo 463
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 464
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 465
                /* click_cnt++; */
11806 schaersvoo 466
 
7614 schaersvoo 467
            }
468
            reset();
469
            break;
11806 schaersvoo 470
        case ARROWHEAD:
9427 schaersvoo 471
        /*
11806 schaersvoo 472
        @ arrowhead int
473
        @ default 8 (pixels)
9427 schaersvoo 474
        */
11806 schaersvoo 475
            arrow_head = (int) (get_real(infile,1));
476
            break;
477
 
478
        case AUDIO:
479
        /*
480
        @ audio x,y,w,h,loop,visible,audiofile location
481
        @ x,y : left top corner of audio element (in xrange / yrange)
482
        @ w,y : width and height in pixels
483
        @ loop : 0 or 1 ( 1 = loop audio fragment)
484
        @ visible : 0 or 1 (1 = show controls)
485
        @ audio format may be in *.mp3 or *.ogg
486
        @ If you are using *.mp3 : be aware that FireFox will not (never) play this ! (Pattented format)
487
        @ if you are using *.ogg : be aware that Microsoft based systems not support it natively
488
        @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
489
        */
490
            if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
491
            for(i=0;i<7;i++){
492
                switch(i){
493
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
494
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
495
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
496
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
497
                    case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
498
                    case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
499
                    case 6:
500
                    temp = get_string(infile,1);
501
                    if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
502
                    if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
503
                    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);
504
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
505
                    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);
506
                    add_to_buffer(tmp_buffer);
507
                    break;
508
                    default:break;
9427 schaersvoo 509
                }
11806 schaersvoo 510
            }
511
            reset();
512
            break;
513
 
514
 
515
        case AXIS_NUMBERING:
516
        /*
517
            @ axisnumbering
518
            @ keyword (no arguments required)
519
            @ 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>
520
            @ to be used before command grid (see <a href="#grid">command grid</a>)
521
        */
11891 schaersvoo 522
            use_axis_numbering++;
11806 schaersvoo 523
            break;
524
        case AXIS:
525
        /*
526
            @ axis
527
            @ keyword (no arguments required)
528
            @ to be used before command grid (see <a href="#grid">command grid</a>)
529
 
530
        */
531
            use_axis = TRUE;
532
            break;
533
 
534
        case BARCHART:
535
        /*
536
        @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
537
        @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
538
        @ 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>
539
        @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
540
        @ multiple barchart command may be used in a single script
541
        @ also see command <a href='#piechart'>'piechart'</a>
542
        @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
12107 schaersvoo 543
        @%barchart%size 400,400%xrange -1,10%yrange -2,14%legend legend Z:legend A:this is B:C:D:E:F:G:H:X%legendcolors green:red:orange:lightblue:cyan:gold:purple:darkred:yellow:lightgreen%xaxis 0:Z:1:A:2:B:3:C:4:D:5:E:6:F:7:G:8:H:9:X%noyaxis%precision 1%fontfamily bold 15px Ariel%grid 1,1,white%barchart 0:5.5:green:2:5.5:red:4:6.5:orange:6:8:lightblue:8:11:cyan:1:5.5:gold:3:9:purple:5:4:darkred:7:7:yellow:9:1:lightgreen%mouse red,14
11806 schaersvoo 544
        */
545
            temp = get_string(infile,1);
546
            if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
547
            fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
548
            barchart_cnt++;
549
            reset();
550
            break;
551
 
552
        case BEZIER:
553
        /*
554
        @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
555
        @ draw a bezier curve between points, starting from (x_start:y_start)
556
        @ can <b>not</b> be dragged or set onclick
557
        */
558
            if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
559
            decimals = find_number_of_digits(precision);
560
            for(i = 0 ; i < 9; i++){
561
                switch(i){
562
                    case 0: stroke_color = get_color(infile,0);break;
563
                    case 1: double_data[0] = get_real(infile,0);break;/* start x */
564
                    case 2: double_data[1] = get_real(infile,0);break;/* start y */
565
                    case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
566
                    case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
567
                    case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
568
                    case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
569
                    case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
570
                    case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
571
                        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);
572
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
573
                        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);
574
                        add_to_buffer(tmp_buffer);
575
                        break;
576
                    default: break;
9427 schaersvoo 577
                }
578
            }
579
            reset();
580
            break;
11806 schaersvoo 581
 
582
 
583
        case BGCOLOR:
9427 schaersvoo 584
        /*
11806 schaersvoo 585
         @ bgcolor colorname or #hex
586
         @ use this color as background of the "div" containing the canvas(es)
12110 schaersvoo 587
         @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
9427 schaersvoo 588
        */
11806 schaersvoo 589
        /* [255,255,255]*/
590
            bgcolor = get_string(infile,1);
591
            if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
592
                int found = 0;
593
                for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
594
                    if( strcmp( colors[i].name , bgcolor ) == 0 ){
595
                        bgcolor = colors[i].hex;
596
                        found = 1;
597
                        break;
598
                    }
9427 schaersvoo 599
                }
11806 schaersvoo 600
                if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list : use hexcolor...something like #a0ffc4");}
601
            }
13970 obado 602
            fprintf(js_include_file,"/* set background color of canvas div */\ncanvas_div.style.backgroundColor = \"%s\";canvas_div.style.opacity = %f;\n",bgcolor,fill_opacity);
11806 schaersvoo 603
            break;
604
 
605
        case BGIMAGE:
606
        /*
607
         @ bgimage image_location
608
         @ use an image as background .<br />technical: we use the background of 'canvas_div'
609
         @ the background image will be resized to match "width = xsize" and "height = ysize"
12110 schaersvoo 610
         @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
11806 schaersvoo 611
        */
612
        URL = get_string(infile,1);
13970 obado 613
        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);
11806 schaersvoo 614
            break;
615
 
616
        case BLINK:
617
        /*
618
         @ blink time(seconds)
619
         @ NOT IMPLEMETED -YET
620
        */
621
            break;
622
 
623
        case BOXPLOT:
624
        /*
625
        @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
11997 schaersvoo 626
        @ 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
627
        @ 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
11875 schaersvoo 628
        @ 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
629
        @ use command <a href='#fillpattern'>'fillpattern some_pattern'</a> to use a (diamond for Q1, hatch for Q3) pattern.
11806 schaersvoo 630
        @ use command <a href='#opacity'>'opacity'</a> to adjust fill_opacity of stroke and fill colours
631
        @ 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.
632
        @ there is no limit to the number of boxplots used.
13958 schaersvoo 633
        @ can <b>not</b> be set draggable and <a href='#onclick'>'onclick'</a> is not ready ,yet
11806 schaersvoo 634
        @ 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)
635
        @ use keyword <a href="#userboxplotdata">'userboxplotdata'</a> before command boxplot, if a pupil must generate the data by some means.
636
        @ use command <a href="#boxplotdata">'boxplotdata'</a> when the boxplot should be drawn from wims-generated raw statistical date
12110 schaersvoo 637
        @%boxplot_1%size 400,400%xrange 0,300%yrange 0,10%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot x,4,8,120,160,170,220,245
638
        @%boxplot_2%size 400,400%xrange 0,10%yrange 0,300%opacity 120,50%filled%fillcolor orange%strokecolor blue%linewidth 2%boxplot y,4,8,120,160,170,220,245
13958 schaersvoo 639
        @%boxplot_3%size 400,400%xrange 0,100%yrange 0,10%fillpattern hatch%linewidth 3%fillcolor red%strokecolor green%boxplot x,1,2,4,14,27,39,66%strokecolor blue%boxplot x,1,4,15,45,50,66,87%strokecolor red%boxplot x,1,6,45,70,80,90,100%strokecolor orange%boxplot x,1,8,28,38,48,56,77%mouse red,16
11806 schaersvoo 640
        */
641
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
642
            for(i=0;i<8;i++){
643
                switch(i){
644
                    case 0: temp = get_string_argument(infile,0);
645
                            if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
646
                    case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
647
                    case 2:
648
                    if( js_function[DRAW_JSBOXPLOT] == 0 ){
649
                     double_data[1] = get_real(infile,0);
650
                     fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
651
                    }
652
                    else
653
                    {
654
                     double_data[1] = get_real(infile,1);
655
                     double_data[2] = 1;
656
                     double_data[3] = 1;
657
                     double_data[4] = 1;
658
                     double_data[5] = 1;
659
                     double_data[6] = 1;
660
                     double_data[7] = 1;
661
                     i=8;
662
                    }
663
                    break;/* center value x or y */
664
                    case 3: double_data[2] = get_real(infile,0); break;/* min */
665
                    case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
666
                    case 5: double_data[4] = get_real(infile,0); break;/* median */
667
                    case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
668
                    case 7: double_data[6] = get_real(infile,1); break;/* max */
669
                    default:break;
9427 schaersvoo 670
                }
671
            }
672
            decimals = find_number_of_digits(precision);
11806 schaersvoo 673
            /*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)*/
674
            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]);
675
            check_string_length(string_length);
676
            tmp_buffer = my_newmem(string_length+1);
677
            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]);
678
            add_to_buffer(tmp_buffer);
679
            boxplot_cnt++;
680
            reset();
681
        break;
682
        case BOXPLOTDATA:
683
        /*
684
        @ boxplotdata some_data
685
        @ 'some_data' are a list of numbers separated by a comma "," (items)
686
        @ only be used before command 'boxplot': the command <a href="#boxplot">'boxplot'</a> will provide the boxplot drawing of the data.
687
        @ 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
688
        @ note: wims will not check your data input | format. use js-error console to debug any problems.
689
        @ 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.
13959 bpr 690
        @ only a single call to 'boxplotdata' can be made.<br />if multiple boxplots should be present in a single canvas, then use multiple calls to command <a href='#boxplot'>boxplot</a>
691
        @%boxplotdata%size 400,400%xrange 0,100%yrange 0,10%strokecolor orange%fillpattern hatch%linewidth 3%strokecolor green%boxplotdata 11,22,13,15,23,43,12,12,14,2,45,32,44,13,21,24,13,19,35,21,24,23%boxplot x,2,2%mouse red,16
11806 schaersvoo 692
        */
693
            if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
694
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
695
            fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
696
 
697
        break;
698
 
699
        case CANVASTYPE:
700
         canvas_type = (int) (get_real(infile,1));
701
        /*
702
        @ canvastype TYPE
13987 bpr 703
        @ for now only useful before commands  filltoborder / floodfill / clickfill etc operations<br />Only the images of this TYPE will be scanned and filled
11806 schaersvoo 704
        @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
705
        @ use another TYPE, if you know what you are doing...
706
        @ 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>
707
        */
708
        break;
709
 
710
        case CENTERSTRING:
711
        /*
712
         @ centerstring color,y-value,the text string
713
         @ title color,y-value,the text string
714
         @ draw a string centered on the canvas at y = y-value
715
         @ can not be set "onclick" or "drag xy" (...)
716
         @ unicode supported: centerstring red,5,\\u2232
12063 schaersvoo 717
         @ use a command like 'fontfamily italic 24pt Ariel' <br />to set fonts on browser that support font change
12110 schaersvoo 718
         @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
11806 schaersvoo 719
        */
720
            if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
721
            for(i=0;i<3;i++){
722
                switch(i){
723
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
724
                    case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
725
                    case 2: temp = get_string_argument(infile,1);
726
                            /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
727
                            decimals = find_number_of_digits(precision);
728
                            string_length = snprintf(NULL,0,
729
                            "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
730
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
731
                            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);
732
                            add_to_buffer(tmp_buffer);
733
                            break;
734
                    default:break;
735
                }
9427 schaersvoo 736
            }
737
            break;
8386 schaersvoo 738
 
11806 schaersvoo 739
 
8386 schaersvoo 740
        case CIRCLE:
8299 schaersvoo 741
        /*
8386 schaersvoo 742
        @ circle xc,yc,width (2*r in pixels),color
9383 schaersvoo 743
        @ use command 'fcircle xc,yc,d,color'
744
        @ alternative: disk for a filled circle
8386 schaersvoo 745
        @ use command 'fillcolor color' to set the fillcolor
9406 schaersvoo 746
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
8386 schaersvoo 747
        @ will shrink / expand on zoom out / zoom in
12110 schaersvoo 748
        @%circle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circle 0,0,60,red%zoom red
8299 schaersvoo 749
        */
8386 schaersvoo 750
            for(i=0;i<4;i++){
751
                switch(i){
752
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
753
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
754
                    case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out : radius in 'dx' xrange*/
755
                    case 3: stroke_color = get_color(infile,1);/* name or hex color */
756
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 757
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8386 schaersvoo 758
                        if(onclick > 0){click_cnt++;}
759
                        /* click_cnt++;*/
760
                        reset();
761
                        break;
762
                    default : break;
763
                }
764
            }
765
            break;
766
 
767
        case CIRCLES:
768
        /*
769
        @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
9383 schaersvoo 770
        @ <b>attention</b> r = radius in x-range (!)
771
        @ use keyword 'filled' or command 'fcircles' to produce solid circles
772
        @ alternative : disks for filled circles
8386 schaersvoo 773
        @ use command 'fillcolor color' to set the fillcolor
9406 schaersvoo 774
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (individually)
8386 schaersvoo 775
        @ will shrink / expand on zoom out / zoom in
12110 schaersvoo 776
        @%circles%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%drag xy%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red
8386 schaersvoo 777
        */
8299 schaersvoo 778
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
779
            fill_color = stroke_color;
8386 schaersvoo 780
            i=1;
8299 schaersvoo 781
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 782
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8386 schaersvoo 783
                switch (i%3){
784
                 case 1:double_data[i-1] = get_real(infile,0);break; /* x */
785
                 case 2:double_data[i-1] = get_real(infile,0);break; /* y */
786
                 case 0:double_data[i-1] = get_real(infile,1);break; /* r */
8299 schaersvoo 787
                }
788
                i++;
789
            }
790
            decimals = find_number_of_digits(precision);
8386 schaersvoo 791
            for(c = 0 ; c < i-1 ; c = c+3){
14045 schaersvoo 792
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 793
                if(onclick > 0){click_cnt++;}
8386 schaersvoo 794
                /* click_cnt++; */
8299 schaersvoo 795
            }
796
            reset();
797
            break;
11806 schaersvoo 798
        case CLEARBUTTON:
799
        /*
800
         @ clearbutton value
801
         @ alternative : delete
802
         @ alternative : erase
803
         @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text 'value'
13936 bpr 804
         @ <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)
11806 schaersvoo 805
         @ 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
806
         @ uses the tooltip placeholder div element: may not be used with command 'intooltip'
807
         @ use command <a href="#inputstyle">'inputstyle'</a> to style the button...
13935 bpr 808
         @ 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 />};</em>
809
         @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
11806 schaersvoo 810
        */
811
        if(reply_format == 29){/* eg multidraw is selected */
14054 schaersvoo 812
        // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
11806 schaersvoo 813
        }
814
            add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
815
        break;
8386 schaersvoo 816
 
11806 schaersvoo 817
        case CLOCK:
7614 schaersvoo 818
        /*
11806 schaersvoo 819
        @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
820
        @ use command 'opacity stroke-opacity,fill-opacity' to adjust foreground (stroke) and background (fill) transparency
821
        @ type hourglass:<br />type = 0 : only segments<br />type = 1 : only numbers<br />type = 2 : numbers and segments
822
        @ 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
823
        @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
824
        @ 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>
825
        @ canvasdraw will not check validity of colornames...the javascript console is your best friend
826
        @ no combinations with other reply_types allowed, for now
827
        @ 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
828
        @ 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
829
        @ note: clocks will not zoom or pan, when using command <a href='#zoom'>'zoom'</a>
12110 schaersvoo 830
        @%clock_1%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black
831
        @%clock_2%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black
832
        @%clock_3%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,3,15,65,2,2,red,green,blue,lightgrey,black
833
        @%clock_4%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,0,0,red,green,blue,lightgrey,black
834
        @%clock_5%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,1,1,red,green,blue,lightgrey,black
835
        @%clock_6%size 400,400%xrange -10,10%yrange -10,10%clock -5,0,80,4,35,45,2,2,red,green,blue,lightgrey,black%clock 5,0,80,8,55,15,2,2,red,green,blue,lightgrey,black
836
        @%clock_7%size 400,400%xrange -10,10%yrange -10,10%clock 0,0,120,4,35,45,2,0,red,green,blue,lightgrey,black
7614 schaersvoo 837
        */
11806 schaersvoo 838
            if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
839
 
840
        /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
841
            for(i=0;i<9;i++){
842
             switch(i){
843
              case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
844
              case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
845
              case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
846
              case 3: int_data[3] = get_real(infile,0);break;/* hours */
847
              case 4: int_data[4] = get_real(infile,0);break;/* minutes */
848
              case 5: int_data[5] = get_real(infile,0);break;/* seconds */
849
              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 */
850
              case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
851
                switch(int_data[7]){
852
                    case 0:break;
853
                    case 1:if(clock_cnt == 0){
854
                           if( reply_format == 0 ){
855
                            reply_format = 18; /* user sets clock */
856
                            /* 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");
857
                               check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
858
                               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");
859
                               add_to_buffer(tmp_buffer);
860
                           */
861
                            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");
862
                           }
863
                           else
864
                           {
865
                            canvas_error("interactive clock may not be used together with other reply_types...");
866
                           }
867
                          }
868
                          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);
869
                    break;
870
                    case 3:if(clock_cnt == 0){
871
                            if( reply_format == 0 ){
872
                             reply_format = 18; /* user sets clock */
873
                             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");
874
                            }
875
                            else
876
                            {
877
                             canvas_error("interactive clock may not be used together with other reply_types...");
878
                            }
879
                           }
880
                            /*
881
                            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);
882
                           */
883
                    break;
884
                    case 2:if( reply_format == 0 ){
885
                                reply_format = 19; /* "onclick */
13970 obado 886
                                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");
11806 schaersvoo 887
                            }
888
                            else
889
                            {
890
                                if( reply_format != 19){
891
                                   canvas_error("clickable clock(s) may not be used together with other reply_types...");
892
                                 }
893
                            }
894
                     break;
895
                     default: canvas_error("interactive must be set 0,1 or 2");break;
896
                }
897
                break;
898
                case 8:
899
                        if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock() , for now it's OK */
900
                            fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
901
                        }
902
                        temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
903
                        if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
904
                        else{
905
                        /* h_color,m_color,s_color,bg_color,fg_color */
11991 schaersvoo 906
                        temp = ",black\",\"black\",\"black\",\"white\",\"black";}
11806 schaersvoo 907
                        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);
908
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
909
                        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);
910
                        add_to_buffer(tmp_buffer);
911
                        fprintf(js_include_file,"var clocks%d;",clock_cnt);
912
                        clock_cnt++;
913
                        break;
914
                default:break;
915
             }
916
            }
917
            break;
918
 
919
 
920
        case COLORPALETTE:
921
        /*
922
         @ colorpalette color_name_1,color_name_2,...,color_name_8
923
         @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
924
         @ 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
13829 bpr 925
         @ make sure to include the 'remove button' by using command <a href='#clearbutton'>clearbutton some_text</a>
11806 schaersvoo 926
        */
927
            if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
928
            fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
929
            while( ! done ){
930
                temp = get_color(infile,1);
931
                fprintf(js_include_file,"\"%s\",",temp);
932
            }
933
            fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
934
            add_color_palette(js_include_file,canvas_root_id,input_style);
935
            break;
13829 bpr 936
 
11806 schaersvoo 937
        case COPY:
938
        /*
939
        @ copy x,y,x1,y1,x2,y2,[filename URL]
940
        @ The image may be "bitmap" or "SVG"
941
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
942
        @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
943
        @ [filename] is the URL of the image
944
        @ URL is normal URL of network reachable image file location<br />(eg special url for 'classexo' not -yet- implemented)
945
        @ 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...'
946
        @ 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
947
        @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
948
        @ you may draw / userdraw / drag other stuff on top of an "imported" image
14038 schaersvoo 949
        @ when set draggable, there will be special function 'read_canvas_images()'<br />now dragging external images may be combined with 'read_canvas()' from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a><br />set command <a href='#precision'>precision</a> before command 'copy'
950
        @ use keyword <a href='#centered'>centered</a> before command 'copy' to place image center at given coordinates.
13967 schaersvoo 951
        @%copy_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%onclick%copy 5,5,-1,-1,-1,-1,gifs/en.gif%onclick%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%onclick%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif
952
        @%copy_drag_xy%size 400,400%xrange -10,10%yrange -10,10%# attention : left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%copy -5,5,-1,-1,-1,-1,gifs/fr.gif%drag xy%copy 5,5,-1,-1,-1,-1,gifs/en.gif%drag xy%copy 5,-5,-1,-1,-1,-1,gifs/it.gif%drag xy%copy -5,-5,-1,-1,-1,-1,gifs/cn.gif
14038 schaersvoo 953
        @%copy_drag_xy_snaptogrid%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%# attention : left mouse click on the image will activate dragging...%# keep left mouse button pressed while moving the image !%drag xy%# a function read_canvas_images() %copy -6,6,-1,-1,-1,-1,gifs/fr.gif%snaptogrid%drag xy%copy 6,6,-1,-1,-1,-1,gifs/en.gif%snaptogrid%drag xy%copy 6,-6,-1,-1,-1,-1,gifs/it.gif%snaptogrid%drag xy%copy -6,-6,-1,-1,-1,-1,gifs/cn.gif
11806 schaersvoo 954
        */
955
            for(i = 0 ; i<7;i++){
7614 schaersvoo 956
                switch(i){
11806 schaersvoo 957
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
958
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
959
                    case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
960
                    case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
961
                    case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
962
                    case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
963
                    case 6: URL = get_string(infile,1);
964
                            int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
965
                            int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
966
                            if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
967
                            int_data[9] = click_cnt;
968
                            if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
14038 schaersvoo 969
                                 //if( reply_format == 0 ){ reply_format = 20; }
11806 schaersvoo 970
                                 int_data[8] = 2;/* drag & drop */
14044 schaersvoo 971
                                 if(use_offset == 0 ){use_offset = 4;} /* mouse is attached to the center of the image !! */
11806 schaersvoo 972
                            }
973
                            else
974
                            {
975
                                if( onclick == 1  ){
14038 schaersvoo 976
                                //    reply_format = 20;
11806 schaersvoo 977
                                    int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
978
                                    click_cnt++; /* will also be used in dragstuff ! */
979
                                }
980
                                else
981
                                {
982
                                    int_data[8] = 0; /* just static image */
983
                                }
984
                            }
14038 schaersvoo 985
                            if( include_special_OEF_reply == FALSE){
986
                             if( int_data[8] == 1 || int_data[8] == 2 ){
987
                              include_special_OEF_reply = TRUE;
988
                              fprintf(js_include_file,"\
989
                              \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
990
                              read_canvas_images = function(){\
991
                               var prec = %d;\
992
                               var len  = ext_drag_images.length;\
993
                               var reply = new Array(len);\
994
                               for(var p = 0 ; p < len ; p++){\
995
                                var img = ext_drag_images[p];\
996
                                reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
997
                               };\
998
                               return reply;\
999
                              };\n\
1000
                              /* end function 20 read_canvas_images() */",reply_precision);
1001
                             }
1002
                            }
11806 schaersvoo 1003
/*
1004
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,ext_img_cnt,resizable,draggable,click_cnt)
1005
*/
14044 schaersvoo 1006
                            string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
11806 schaersvoo 1007
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
14044 schaersvoo 1008
                            snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,0,%d,%d,%d,%d);\n",URL,int_data[2],int_data[3],int_data[6],int_data[7],int_data[0],int_data[1],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
14038 schaersvoo 1009
                            add_to_buffer(tmp_buffer);
11806 schaersvoo 1010
                            drag_type = -1; /* reset the drag_type indicator */
1011
                            ext_img_cnt++;
1012
                            onclick=0;
14038 schaersvoo 1013
                            use_offset=0;
1014
                            reset();
11806 schaersvoo 1015
                            break;
7614 schaersvoo 1016
                    default: break;
1017
                }
1018
            }
1019
            break;
11806 schaersvoo 1020
/*
1021
HTML5 specs:
1022
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
1023
img     Specifies the image, canvas, or video element to use
1024
sx      The x coordinate where to start clipping : x1 = int_data[0]
1025
sy      The y coordinate where to start clipping : x2 = int_data[1]
1026
swidth  The width of the clipped image : int_data[2] - int_data[0]
1027
sheight The height of the clipped image : int_data[3] - int_data[1]
1028
x       The x coordinate where to place the image on the canvas : dx1 = int_data[4]
1029
y       The y coordinate where to place the image on the canvas : dy1 = int_data[5]
1030
width   The width of the image to use (stretch or reduce the image) : dx2 - dx1 = int_data[6]
1031
height  The height of the image to use (stretch or reduce the image) : dy2 - dy1 = int_data[7]
1032
*/
1033
        case COPYRESIZED:
1034
        /*
1035
        @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
1036
        @ The image may be any "bitmap" or "SVG"
1037
        @ 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
1038
        @ (dx1:dy1) must be left top corner; (dx2 :dy2) must be right bottom corner of inserted image
1039
        @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
1040
        @ 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 !!)
1041
        @ 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...'
1042
        @ 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
1043
        @ 'onclick' for external images may be mixed with canvas generated stuff (like lines,curves etc)
1044
        @ you may draw / userdraw / drag stuff on top of an "imported" image
14038 schaersvoo 1045
        @ when set draggable, there will be special function 'read_canvas_images()'<br />now dragging external images may be combined with 'read_canvas()' from <a href='#userdraw'>userdraw</a> or <a href='#multidraw'>multidraw</a><br />set command <a href='#precision'>precision</a> before command 'copy'
1046
        @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates.
11806 schaersvoo 1047
        */
1048
            for(i = 0 ; i<9;i++){
1049
                switch(i){
1050
                    case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
1051
                    case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
1052
                    case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
1053
                    case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
1054
                    case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
1055
                    case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
1056
                    case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
1057
                    case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
1058
                    case 8: URL = get_string(infile,1);
1059
                            /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
1060
                            if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
1061
                                canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
1062
                            }
1063
                            int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
1064
                            int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
1065
                            int_data[6] = abs(int_data[6] - int_data[4]);/* width */
1066
                            int_data[7] = abs(int_data[7] - int_data[5]);/* height */
1067
                            if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
1068
                            int_data[9] = click_cnt;
1069
                            if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
14038 schaersvoo 1070
                                // if( reply_format == 0 ){ reply_format = 20; }
11806 schaersvoo 1071
                                 int_data[8] = 2;/* drag & drop */
1072
                            }
1073
                            else
1074
                            {
1075
                                if( onclick == 1  ){
14038 schaersvoo 1076
                                //    reply_format = 20;
11806 schaersvoo 1077
                                    int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
1078
                                    click_cnt++; /* will also be used in dragstuff ! */
1079
                                }
1080
                                else
1081
                                {
1082
                                    int_data[8] = 0; /* just static image */
1083
                                }
1084
                            }
14038 schaersvoo 1085
                            if( include_special_OEF_reply == FALSE){
1086
                             if( int_data[8] == 1 || int_data[8] == 2 ){
1087
                              include_special_OEF_reply = TRUE;
1088
                              fprintf(js_include_file,"\
1089
                              \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
1090
                              read_canvas_images = function(){\
1091
                               var prec = %d;\
1092
                               var len  = ext_drag_images.length;\
1093
                               var reply = new Array(len);\
1094
                               for(var p = 0 ; p < len ; p++){\
1095
                                var img = ext_drag_images[p];\
1096
                                reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
1097
                               };\
1098
                               return reply;\
1099
                              };\n\
1100
                              /* end function 20 read_canvas_images() */",reply_precision);
1101
                             }
1102
                            }
1103
 
11806 schaersvoo 1104
/*
1105
(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
1106
URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
1107
*/
14044 schaersvoo 1108
                            string_length = snprintf(NULL,0,  "draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
11806 schaersvoo 1109
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
14044 schaersvoo 1110
                            snprintf(tmp_buffer,string_length,"draw_external_image(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,1,%d,%d,%d,%d);\n",URL,int_data[0],int_data[1],int_data[2],int_data[3],int_data[4],int_data[5],int_data[6],int_data[7],ext_img_cnt,int_data[8],int_data[9],use_offset,use_snap);
14038 schaersvoo 1111
                            add_to_buffer(tmp_buffer);
11806 schaersvoo 1112
                            drag_type = -1; /* reset the drag_type indicator */
1113
                            ext_img_cnt++;
1114
                            onclick=0;
14038 schaersvoo 1115
                            use_offset=0;
1116
                            reset();
11806 schaersvoo 1117
                            break;
1118
                    default: break;
1119
                }
1120
            }
14038 schaersvoo 1121
            reset();
11806 schaersvoo 1122
            break;
8386 schaersvoo 1123
 
11806 schaersvoo 1124
        case CROSSHAIR:
8386 schaersvoo 1125
        /*
11806 schaersvoo 1126
        @ crosshair x,y,color
1127
        @ draw a single crosshair point at (x;y) in color 'color'
1128
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
1129
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 1130
        @%crosshair%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshair 0,0,red%linewidth 1%onclick%crosshair 1,1,blue%linewidth 3%onclick%crosshair 3,3,green%linewidth 4%xrosshair 4,4,orange
11806 schaersvoo 1131
        */
1132
            for(i=0;i<3;i++){
1133
                switch(i){
1134
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
1135
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
1136
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
1137
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 1138
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 1139
                        if(onclick > 0){click_cnt++;}
1140
                        /* click_cnt++ */
1141
                        reset();
1142
                        break;
1143
                    default:break;
1144
                }
1145
            }
1146
            break;
1147
 
1148
        case CROSSHAIRS:
1149
        /*
1150
        @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
1151
        @ draw multiple crosshair points at given coordinates in color 'color'
1152
        @ use command 'crosshairsize int' and / or 'linewidth int'  to adust
9406 schaersvoo 1153
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12107 schaersvoo 1154
        @%crosshairs_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 2%drag xy%crosshairs red,0,0,1,1,2,2,3,3%drag x%crosshairs blue,0,1,1,2,2,3,3,4
1155
        @%crosshairs_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 2%onclick%crosshairs red,0,0,1,1,2,2,3,3%onclick%crosshairs blue,0,1,1,2,2,3,3,4
1156
*/
8386 schaersvoo 1157
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1158
            fill_color = stroke_color;
1159
            i=0;
1160
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 1161
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8386 schaersvoo 1162
                if(i%2 == 0 ){
1163
                    double_data[i] = get_real(infile,0); /* x */
1164
                }
1165
                else
1166
                {
1167
                    double_data[i] = get_real(infile,1); /* y */
1168
                }
1169
                i++;
1170
            }
1171
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1172
            for(c=0 ; c < i-1 ; c = c+2){
14045 schaersvoo 1173
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8386 schaersvoo 1174
                if(onclick > 0){click_cnt++;}
11806 schaersvoo 1175
                /* click_cnt++; */
8386 schaersvoo 1176
            }
1177
            reset();
1178
            break;
1179
 
11806 schaersvoo 1180
        case CROSSHAIRSIZE:
7614 schaersvoo 1181
        /*
11806 schaersvoo 1182
        @ crosshairsize int
1183
        @ default 8 (px)
7614 schaersvoo 1184
        */
11806 schaersvoo 1185
            crosshair_size = (int) (get_real(infile,1));
1186
            break;
1187
 
1188
        case CURSOR:
1189
        /*
1190
        @ cursor 'some CSS cursor_style'
1191
        @ alternative : pointer
13956 schaersvoo 1192
        @ style can be any valid CSS property value
1193
        @ choose from these types:<br />alias,all-scroll,auto,cell,context-menu,col-resize,copy,crosshair,default,e-resize,<br />ew-resize,grab,grabbing,help,move,n-resize,ne-resize,nesw-resize,ns-resize,nw-resize,<br />nwse-resize,no-drop,none,not-allowed,pointer,progress,row-resize,s-resize,se-resize,<br />sw-resize,text,url(myBall.cur),auto,vertical-text,w-resize,wait,zoom-in,zoom-out,initial
1194
        @ note: wims will not check the validity of your cursor declaration
1195
        @%cursor_css%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 3%drag xy%opacity 200,75%fcircles blue,-5,5,3,-4,-2,6,0,0,5,3,4,2,4,-5,4
11806 schaersvoo 1196
        */
1197
            fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
1198
            break;
1199
 
1200
        case CURVE:
1201
        /*
1202
         @ curve color,formula(x)
1203
         @ alernative : plot color,formula(x)
1204
         @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot  (trange -pi,pi)<br />curve color,formula1(t),formula2(t)
1205
         @ use command <a href="#precision">"precision" </a>to ncrease the number of digits of the plotted points
1206
         @ use command <a href="#plotsteps">"plotsteps"</a> to increase / decrease the amount of plotted points (default 150)
1207
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1208
         @ if you need a plot beyond xrange / yrange, use <a href="#jsplot">"jsplot"'</a><br />(command "curve" will only calculate points within the xrange)
12107 schaersvoo 1209
         @%curve%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 1%grid 2,2,grey,2,2,6,grey%precision 1000%curve red,4*sqrt(x)%curve green,2*sqrt(abs(x)%curve blue,3*1/sqrt(x)%curve orange,4*sin(4/x)%dashed%curve red,4*cos(x)
11806 schaersvoo 1210
        */
1211
            if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
1212
                use_parametric = FALSE;
1213
                stroke_color = get_color(infile,0);
1214
                char *fun1 = get_string_argument(infile,0);
1215
                char *fun2 = get_string_argument(infile,1);
1216
                if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
14045 schaersvoo 1217
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 1218
            }
1219
            else
1220
            {
1221
                stroke_color = get_color(infile,0);
1222
                char *fun1 = get_string_argument(infile,1);
1223
                if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
14045 schaersvoo 1224
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,9,%s,[%d],[%d],%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d,%d,%d,%d,%.1f,\"%s\",%d,\"%s\",%d,%s,%d,%d,%s,%d,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 1225
            }
1226
            if(onclick > 0){click_cnt++;}
1227
            /* click_cnt++; */
1228
            reset();
1229
            break;
14038 schaersvoo 1230
    case CURVEDARROW:
1231
    /*
1232
    @ curvedarrow x1,y1,xc,yc,x2,y2,color
1233
    @ draw a single headed  curved arrow from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b>  point (xc:yc)
1234
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
1235
    @ use command 'linewidth int' to adjust thickness of the arrow
1236
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1237
    @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow -5,0,0,10,5,0,blue
1238
    @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green
11806 schaersvoo 1239
 
14029 schaersvoo 1240
h[0] = arrowhead
1241
h[1] = type : 1 = single 2=double arrow
1242
function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1243
    */
1244
            for(i=0;i<7;i++){
1245
            switch(i){
1246
                case 0: double_data[0] = get_real(infile,0);break; /* x1 */
1247
                case 1: double_data[1] = get_real(infile,0);break; /* y1 */
1248
                case 2: double_data[2] = get_real(infile,0);break; /* xc */
1249
                case 3: double_data[3] = get_real(infile,0);break; /* yc */
1250
                case 4: double_data[4] = get_real(infile,0);break; /* y3 */
1251
                case 5: double_data[5] = get_real(infile,0);break; /* y3 */
1252
                case 6: stroke_color = get_color(infile,1);/* name or hex color */
1253
                decimals = find_number_of_digits(precision);
14045 schaersvoo 1254
            fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*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,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,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,use_pattern);
14038 schaersvoo 1255
            if(onclick > 0){click_cnt++;}
1256
            /* click_cnt++;*/
1257
            reset();
1258
            break;
1259
            }
1260
            }
1261
            break;
14029 schaersvoo 1262
 
14038 schaersvoo 1263
    case CURVEDARROW2:
1264
    /*
1265
    @ curvedarrow2 x1,y1,xc,yc,x2,y2,color
1266
    @ draw a double headed  curved arrow from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b>  point (xc:yc)
1267
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
1268
    @ use command 'linewidth int' to adjust thickness of the arrow
1269
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1270
    @%curvedarrow_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrow2 -5,0,0,10,5,0,blue
1271
    @%curvedarrow_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%cuvedarrow2 -5,0,0,-10,5,0,blue%onclick%curvedarrow -8,0,0,5,8,3,green
14029 schaersvoo 1272
 
1273
h[0] = arrowhead
1274
h[1] = type : 1 = single 2=double arrow
1275
function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1276
    */
1277
            for(i=0;i<7;i++){
1278
            switch(i){
1279
                case 0: double_data[0] = get_real(infile,0);break; /* x1 */
1280
                case 1: double_data[1] = get_real(infile,0);break; /* y1 */
1281
                case 2: double_data[2] = get_real(infile,0);break; /* xc */
1282
                case 3: double_data[3] = get_real(infile,0);break; /* yc */
1283
                case 4: double_data[4] = get_real(infile,0);break; /* y3 */
1284
                case 5: double_data[5] = get_real(infile,0);break; /* y3 */
1285
                case 6: stroke_color = get_color(infile,1);/* name or hex color */
1286
                decimals = find_number_of_digits(precision);
14045 schaersvoo 1287
            fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*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,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,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,use_pattern);
14038 schaersvoo 1288
            if(onclick > 0){click_cnt++;}
1289
            /* click_cnt++;*/
1290
            reset();
1291
            break;
1292
            }
1293
            }
1294
            break;
1295
    case CURVEDARROWS:
1296
    /*
1297
    @ curvedarrow color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
1298
    @ draw a single headed  curved arrows from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b>  point (xc:yc)
1299
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
1300
    @ use command 'linewidth int' to adjust thickness of the arrow
1301
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1302
    @%curvedarrows_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3
1303
    @%curvedarrows_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrows red,-8,0,0,8,8,0,-5,5,0,-10,6,3
14029 schaersvoo 1304
 
14030 schaersvoo 1305
h[0] = arrowhead
1306
h[1] = type : 1 = single 2=double arrow
1307
function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1308
    */
1309
        stroke_color = get_color(infile,0);/* name or hex color */
1310
        i = 0;
1311
        decimals = find_number_of_digits(precision);
1312
        while( ! done ){
1313
        if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
1314
        double_data[0] = get_real(infile,0); /* x1 */
1315
        double_data[1] = get_real(infile,0); /* y1 */
1316
        double_data[2] = get_real(infile,0); /* xc */
1317
        double_data[3] = get_real(infile,0); /* yc */
1318
        double_data[4] = get_real(infile,0); /* x3 */
1319
        double_data[5] = get_real(infile,1); /* y3 */
14045 schaersvoo 1320
        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*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,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,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,use_pattern);
14038 schaersvoo 1321
        if(onclick > 0){click_cnt++;}
1322
        i = i + 6;
1323
            }
1324
            reset();
1325
            break;
14030 schaersvoo 1326
 
14038 schaersvoo 1327
    case CURVEDARROWS2:
1328
    /*
1329
    @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
1330
    @ draw a double headed  curved arrows from (x1:y1) in direction of (xc:yc) to point (x3:y3)<br /> note: the curve will <b>not go through</b>  point (xc:yc)
1331
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
1332
    @ use command 'linewidth int' to adjust thickness of the arrow
1333
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1334
    @%curvedarrows2_drag%size 400,400%xrange -10,10%yrange -10,10%cursor move%linewidth 2%drag xy%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3
1335
    @%curvedarrows2_click%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%%onclick%curvedarrow -5,0,0,-10,5,0,blue%onclick%curvedarrows2 red,-8,0,0,8,8,0,-5,5,0,-10,6,3
14030 schaersvoo 1336
 
1337
h[0] = arrowhead
1338
h[1] = type : 1 = single 2=double arrow
1339
function Shape(click_cnt,onclick,direction,type,x,y,w,h,line_width,stroke_color,stroke_opacity,fill_color,fill_opacity,use_filled,use_dashed,dashtype0,dashtype1,use_rotate,angle,text,font_size,font_family,use_affine,affine_matrix,slider,slider_cnt,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1340
    */
1341
        stroke_color = get_color(infile,0);/* name or hex color */
1342
        i = 0;
1343
        decimals = find_number_of_digits(precision);
1344
        while( ! done ){
1345
        if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
1346
        double_data[0] = get_real(infile,0); /* x1 */
1347
        double_data[1] = get_real(infile,0); /* y1 */
1348
        double_data[2] = get_real(infile,0); /* xc */
1349
        double_data[3] = get_real(infile,0); /* yc */
1350
        double_data[4] = get_real(infile,0); /* x3 */
1351
        double_data[5] = get_real(infile,1); /* y3 */
14045 schaersvoo 1352
        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%d,%d,%d,21,[%.*f,%.*f,%.*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,%d));\n",drag_type,click_cnt,onclick,use_snap,decimals,double_data[0],decimals,double_data[2],decimals,double_data[4],decimals,double_data[1],decimals,double_data[3],decimals,double_data[5],arrow_head,arrow_head,arrow_head,2,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,use_pattern);
14038 schaersvoo 1353
        if(onclick > 0){click_cnt++;}
1354
        i = i + 6;
1355
            }
1356
            reset();
1357
            break;
11806 schaersvoo 1358
        case DASHED:
1359
        /*
1360
        @ dashed
1361
        @ keyword (no arguments required)
1362
        @ next object will be drawn with a dashed line
1363
        @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
12107 schaersvoo 1364
        @%dashed%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%line -5,-5,-5,5,red%dashtype 1,1%dline -4,-5,-4,5,green%dashtype 2,2%dline -3,-5,-3,5,blue%dashtype 3,3%dline 0,-5,0,5,orange%dashtype 4,4%dline 3,-5,3,5,brown
11806 schaersvoo 1365
        */
1366
            use_dashed = TRUE;
1367
            break;
1368
 
1369
        case DASHTYPE:
1370
        /*
1371
        @ dashtype line_width_px,space_width_px
1372
        @ every indiviual object may have its own dashtype, if needed...
1373
        @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
1374
        @ default value "dashtype 2,2" e.g. 2px line and 2px space
13957 schaersvoo 1375
        @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
13949 schaersvoo 1376
        @%dashtype%size 400,400%xrange -10,10%yrange -10,10%dashtype 1,1%dhline 0,9,red%dashtype 2,2%dhline 0,8,red%dashtype 4,4%dhline 0,7,red%dashtype 6,6%dhline 0,6,red%dashtype 8,8%dhline 0,5,red%dashtype 10,10%dhline 0,4,red%dashtype 1,2%dhline 0,3,red%dashtype 2,4%dhline 0,2,red%dashtype 3,6%dhline 0,1,red%dashtype 4,8%dhline 0,0,red%linewidth 2%dashtype 1,1%dhline 0,-9,red%dashtype 2,2%dhline 0,-8,red%dashtype 4,4%dhline 0,-7,red%dashtype 6,6%dhline 0,-6,red%dashtype 8,8%dhline 0,-5,red%dashtype 10,10%dhline 0,-4,red%dashtype 1,2%dhline 0,-3,red%dashtype 2,4%dhline 0,-2,red%dashtype 4,8%dhline 0,-1,red
11806 schaersvoo 1377
        */
1378
            for(i=0;i<2;i++){
1379
                switch(i){
1380
                    case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
1381
                    case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
1382
                }
1383
            }
1384
        break;
1385
 
1386
        case DIAMONDFILL:
1387
        /*
1388
        @ diamondfill x0,y0,dx,dy,color
1389
        @ x0,y0 in xrange / yrange
1390
        @ distances dx,dy in pixels
13936 bpr 1391
        @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a>
12110 schaersvoo 1392
        @%diamondfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%linewidth 1%diamondfill 0,0,5,8,blue%diamondfill 0,7,8,8,lightgreen
11806 schaersvoo 1393
        */
1394
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
11820 schaersvoo 1395
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1396
             js_function[DRAW_FILLTOBORDER] = 1;
1397
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1398
            }
1399
            decimals = find_number_of_digits(precision);
7614 schaersvoo 1400
            for(i=0;i<5;i++){
1401
                switch(i){
11820 schaersvoo 1402
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
14032 schaersvoo 1403
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
11820 schaersvoo 1404
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1405
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1406
                    case 4: stroke_color = get_color(infile,1);
1407
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
14032 schaersvoo 1408
                    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 1409
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11820 schaersvoo 1410
                    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 1411
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1412
                    fill_cnt++;
11806 schaersvoo 1413
                    break;
1414
                    default:break;
1415
                }
1416
            }
1417
            reset();
1418
        break;
8224 bpr 1419
 
11806 schaersvoo 1420
        case DOTFILL:
1421
        /*
1422
        @ dotfill x0,y0,dx,dy,color
1423
        @ x0,y0 in xrange / yrange
1424
        @ distances dx,dy in pixels
1425
        @ radius of dots is linewidth
13936 bpr 1426
        @ there is also a command <a href="#userdraw">userdraw dotfill,color</a>
12110 schaersvoo 1427
        @%dotfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%circles red,-4,0,6,4,0,6%dotfill 0,0,5,8,blue%dotfill 0,7,8,8,lightgreen
11806 schaersvoo 1428
        */
1429
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
11817 schaersvoo 1430
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1431
             js_function[DRAW_FILLTOBORDER] = 1;
1432
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1433
            }
1434
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1435
            for(i=0;i<5;i++){
1436
                switch(i){
11817 schaersvoo 1437
                    case 0: double_data[0] = get_real(infile,0); break; /* x in px */
1438
                    case 1: double_data[1] = get_real(infile,0); break; /* y in py */
1439
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1440
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1441
                    case 4: stroke_color = get_color(infile,1);
1442
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
14032 schaersvoo 1443
                    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 1444
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11817 schaersvoo 1445
                    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 1446
                    add_to_buffer(tmp_buffer);
11817 schaersvoo 1447
                    fill_cnt++;
7614 schaersvoo 1448
                    break;
11806 schaersvoo 1449
                    default:break;
7614 schaersvoo 1450
                }
1451
            }
11806 schaersvoo 1452
            reset();
1453
        break;
1454
 
1455
        case DRAG:
1456
        /*
1457
         @ drag [x][y][xy]
1458
         @ the next object will be draggable in x / y / xy direction
1459
         @ the displacement can be read by 'javascript:read_dragdrop();'
1460
         @ 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' !
13956 schaersvoo 1461
         @ <a href='#onclick'>'onclick'</a> and 'drag x|y|xy' may be combined (for different objects: a single object can either be onclick or drag , not both )
11806 schaersvoo 1462
         @ '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)
1463
         @ <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
14032 schaersvoo 1464
         @ 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)
13956 schaersvoo 1465
         @ use keyword <a href='#snaptogrid'>'snaptogrid'<a/> , <a href='#xsnaptogrid'>'xsnaptogrid'</a> , <a href='#ysnaptogrid'>'ysnaptogrid'</a> or command <a href='#snaptopoints'>'snaptopoints x1,y1,x2,y2,...'</a> to switch from free to discrete movement
11806 schaersvoo 1466
         @ 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.
1467
         @ 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 !!
13829 bpr 1468
         @%drag_x%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag x%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4
1469
         @%drag_y%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag y%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4
1470
         @%drag_xy%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 200,40%drag xy%linewidth 2%circles blue,-5,0,3,0,0,2,5,0,4,0,4,3,0,-3,4
11806 schaersvoo 1471
        */
1472
            temp = get_string(infile,1);
1473
            if(strstr(temp,"xy") != NULL ){
1474
                drag_type = 0;
1475
            }
1476
            else
1477
            {
1478
                if(strstr(temp,"x") != NULL ){
1479
                    drag_type = 1;
1480
                }
1481
                else
1482
                {
1483
                    drag_type = 2;
1484
                }
1485
            }
1486
            /* assuming all drag&drop coordinates the same precision: so set only once */
1487
            if( print_drag_params_only_once == FALSE ){
1488
             fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
1489
             print_drag_params_only_once = TRUE;
1490
            }
1491
            onclick = 2;
1492
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
7614 schaersvoo 1493
            break;
8386 schaersvoo 1494
 
11806 schaersvoo 1495
        case ELLIPSE:
8351 schaersvoo 1496
        /*
11806 schaersvoo 1497
        @ ellipse xc,yc,radius_x,radius_y,color
1498
        @ a ellipse with center xc/yc in x/y-range
1499
        @ radius_x and radius_y are in pixels
9406 schaersvoo 1500
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
11806 schaersvoo 1501
        @ will shrink / expand on zoom out / zoom in
13949 schaersvoo 1502
        @%ellipse%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%drag xy%ellipse 0,0,6,4,green%zoom blue
8351 schaersvoo 1503
        */
11806 schaersvoo 1504
            for(i=0;i<5;i++){
1505
                switch(i){
1506
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
1507
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
14032 schaersvoo 1508
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px  */
1509
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px  */
11806 schaersvoo 1510
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
1511
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 1512
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 1513
                        if(onclick > 0){click_cnt++;}
1514
                        /* click_cnt++; */
1515
                        reset();
1516
                    break;
1517
                }
1518
            }
1519
            break;
13829 bpr 1520
 
12110 schaersvoo 1521
        case ELLIPSES:
1522
        /*
1523
        @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,...
1524
        @ a ellipses with center xc/yc in x/y-range
1525
        @ radius_x and radius_y are in pixels
1526
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1527
        @ will shrink / expand on zoom out / zoom in
13949 schaersvoo 1528
        @%ellipses%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%opacity 200,40%linewidth 3%onclick%ellipses red,-3,0,2,4,0,0,4,2,3,0,6,2
12110 schaersvoo 1529
        */
13829 bpr 1530
 
12110 schaersvoo 1531
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1532
            fill_color = stroke_color;
1533
            i=1;
1534
            while( ! done ){     /* get next item until EOL*/
1535
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
1536
                switch (i%4){
1537
                 case 1:double_data[i-1] = get_real(infile,0);break; /* x */
1538
                 case 2:double_data[i-1] = get_real(infile,0);break; /* y */
1539
                 case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
1540
                 case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
1541
                 default: break;
1542
                }
1543
                i++;
1544
            }
1545
            decimals = find_number_of_digits(precision);
1546
            for(c = 0 ; c < i-1 ; c = c+4){
14045 schaersvoo 1547
             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n", drag_type,click_cnt,onclick,use_snap,decimals,double_data[c],decimals,double_data[c+1],decimals,double_data[c+2],decimals,double_data[c+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,use_pattern);
12110 schaersvoo 1548
             if(onclick > 0){click_cnt++;} /* click_cnt++; */
1549
            }
1550
            reset();
1551
            break;
1552
 
11806 schaersvoo 1553
        case FILLALL:
1554
        /*
1555
        @ fillall color,x1,y1,x2,y2...x_n,y_n
1556
        @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
1557
        @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill
14032 schaersvoo 1558
        @ use this command  after all boundary objects are declared.
11806 schaersvoo 1559
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1560
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1561
        @ 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..
12110 schaersvoo 1562
        @%fillall%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%vlines black,-5,0,-5,0,-4,0,-4,0,3,0,3,0%hlines black,-5,0,-5,0,-5,4,-5,4,-5,-2,-5,-2%circles green,0,0,2,3,3,5,-5,-5,3%opacity 240,50%fillall blue,1,1,8,8,-8,-8
11806 schaersvoo 1563
        */
1564
            decimals = find_number_of_digits(precision);
1565
            fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
8351 schaersvoo 1566
            i=0;
11806 schaersvoo 1567
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1568
             js_function[DRAW_FILLTOBORDER] = 1;
1569
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1570
            }
8351 schaersvoo 1571
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 1572
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8351 schaersvoo 1573
                if(i%2 == 0 ){
1574
                    double_data[i] = get_real(infile,0); /* x */
1575
                }
1576
                else
1577
                {
1578
                    double_data[i] = get_real(infile,1); /* y */
14032 schaersvoo 1579
                    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 1580
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1581
                    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 1582
                    add_to_buffer(tmp_buffer);
1583
                    fill_cnt++;
8351 schaersvoo 1584
                }
1585
                i++;
1586
            }
11806 schaersvoo 1587
        break;
1588
 
1589
        case FILLED:
1590
        /*
1591
        @ filled
1592
        @ keyword (no arguments required)
11839 schaersvoo 1593
        @ the next 'fillable' object (only the next !) will be filled
13936 bpr 1594
        @ use command <a href="#fillcolor">"fillcolor color"</a> to set fillcolor
11839 schaersvoo 1595
        @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
11806 schaersvoo 1596
        @ use command "opacity 0-255,0-255" to set stroke and fill-opacity
13956 schaersvoo 1597
        @ use command <a href='#fill'>"fill x,y,color"</a> or <a href="#floodfill">"floodfill x,y,color"</a> to fill the space around (x;y) with color <br />pixel operation implemented in javascript: use with care !
11806 schaersvoo 1598
        */
11839 schaersvoo 1599
            use_filled = 1;
11859 schaersvoo 1600
            use_pattern = 0;
11806 schaersvoo 1601
            break;
1602
 
1603
        case FILLCOLOR:
1604
        /*
1605
        @ fillcolor colorname or #hex
11839 schaersvoo 1606
        @ set the color : mainly used for command 'userdraw obj,stroke_color'
11806 schaersvoo 1607
        @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
11839 schaersvoo 1608
        @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
11806 schaersvoo 1609
        */
1610
            fill_color = get_color(infile,1);
11874 schaersvoo 1611
            use_pattern = 0;
11806 schaersvoo 1612
            break;
1613
 
11837 schaersvoo 1614
        case FILLPATTERN:
1615
        /*
11854 schaersvoo 1616
        @ fillpattern grid | hatch | diamond | dot | image-url
11837 schaersvoo 1617
        @ use a pattern as fillstyle
11874 schaersvoo 1618
        @ suitable for all fillable object including the <a href="#userdraw">'userdraw objects' family</a>
13829 bpr 1619
        @ noy -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex)
11837 schaersvoo 1620
        @ the fillcolor is set by the object command, for example:<br />size 370,370<br />xrange -5,5<br />yrange -5,5<br />opacity 165,150<br />fillpattern grid<br />fcircle -6,3,160,blue<br />fillpattern dot<br />fcircle -3,-3,160,red<br />fillpattern hatch<br />fcircle 0,3,160,green<br />filpattern diamond<br />fcircle 3,-3,160,cyan<br />userdraw dotfill,blue<br />zoom red<br />
1621
        @ the pattern dimensions are hardcoded (linewidth ,radius,dx,dy are fixed)
1622
        @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
11839 schaersvoo 1623
        @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
11854 schaersvoo 1624
        @ when using an image-url , make sure it contains an '/' in the filename...'fillpattern $$module_dir/gifs/test.jpg' will fill the next fillable object with this image.|<br />the argument to html5 canvas routine 'createPattern(img,argument)' is set to 'repeat'<br />e.g. if the image is smaller then the canvas, multiple copies will be used to fill the area ( e.g. ctx.fillStyle() = pattern)<br />for example:<br />size 150,150<br />xrange -5,5<br />yrange -5,5<br />drag xy<br />fillpattern gifs/en.gif<br />fcircle 0,0,100,red<br />fillpattern gifs/nl.gif<br />drag xy<br />fcircle -3,2,100,green<br />fillpattern gifs/cn.gif<br />drag xy<br />fcircle 3,2,100,green<br />
13829 bpr 1625
        @ fillpattern is also active for <a href="#userdraw">userdraw object,color"</a>...<br />the userdraw family a has also 'clickfill type' (e.g. an object gets filled between boundaries, when clicked) commands like:<br />'userdraw dotfill,color'<br />'userdraw hatchfill,color' etc
13948 schaersvoo 1626
        @%fillpattern_1%size 400,400%xrange -5,5%yrange -5,5%opacity 165,150%fillpattern grid%fcircle -6,3,160,blue%fillpattern dot%fcircle -3,-3,160,red%fillpattern hatch%fcircle 0,3,160,green%filpattern diamond%fcircle 3,-3,160,cyan%zoom red
1627
        @%fillpattern_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%fillcolor green%fillpattern hatch%#fillpattern dot,diamond,grid,imageurl%userdraw fcircle,red
11837 schaersvoo 1628
        */
1629
            temp = get_string(infile,1);
11875 schaersvoo 1630
            if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */
11837 schaersvoo 1631
            else
11875 schaersvoo 1632
            if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;}
11837 schaersvoo 1633
            else
11875 schaersvoo 1634
            if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;}
11837 schaersvoo 1635
            else
11875 schaersvoo 1636
            if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;}
11837 schaersvoo 1637
            else
11875 schaersvoo 1638
            if( strstr(temp,"/") != 0 ){ use_pattern = 6;use_filled = 0;if( js_function[ADD_LOAD_IMAGE] != 1 ){ js_function[ADD_LOAD_IMAGE] = 1; add_js_load_image(js_include_file,canvas_root_id);} fprintf(js_include_file,"get_image_from_url(\"%s\"); ",temp); }
11854 schaersvoo 1639
            else
13829 bpr 1640
            canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");
11837 schaersvoo 1641
            break;
11806 schaersvoo 1642
        case FILLTOBORDER:
1643
        /*
1644
        @ filltoborder x,y,bordercolor,color
14032 schaersvoo 1645
        @ fill the region  of point (x:y)  with color 'color'
11806 schaersvoo 1646
        @ any other color will not act as border to the bucket fill
14032 schaersvoo 1647
        @ use this command  after all boundary objects are declared.
11806 schaersvoo 1648
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1649
        @ 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..
1650
        @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
12110 schaersvoo 1651
        @%filltoborder%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%filltoborder 6,6,blue,blue%filltoborder 6,-6,blue,red
11806 schaersvoo 1652
        */
1653
            for(i=0 ;i < 4 ; i++){
1654
                switch(i){
1655
                    case 0:double_data[0] = get_real(infile,0);break;
1656
                    case 1:double_data[1] = get_real(infile,0);break;
1657
                    case 2:bgcolor = get_color(infile,0);break;
1658
                    case 3:fill_color = get_color(infile,1);
1659
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1660
                                js_function[DRAW_FILLTOBORDER] = 1;
1661
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1662
                           }
1663
                           decimals = find_number_of_digits(precision);
1664
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
11818 schaersvoo 1665
                           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 1666
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1667
                           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 1668
                           add_to_buffer(tmp_buffer);
1669
                           fill_cnt++;
1670
                           break;
1671
                    default:break;
8351 schaersvoo 1672
                }
11806 schaersvoo 1673
            }
1674
            reset();
1675
        break;
1676
        case FLOODFILL:
1677
        /*
1678
        @ floodfill x,y,color
1679
        @ alternative : fill x,y,color
1680
        @ fill the region of point (x:y) with color 'color'
1681
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
14032 schaersvoo 1682
        @ use this command  after all boundary objects are declared.
11806 schaersvoo 1683
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1684
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
1685
        @ 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..
12110 schaersvoo 1686
        @%floodfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%floodfill 6,6,blue%floodfill 6,-6,red
11806 schaersvoo 1687
        */
1688
            for(i=0 ;i < 4 ; i++){
1689
                switch(i){
1690
                    case 0:double_data[0] = get_real(infile,0);break;
1691
                    case 1:double_data[1] = get_real(infile,0);break;
1692
                    case 2:fill_color = get_color(infile,1);
1693
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1694
                                js_function[DRAW_FILLTOBORDER] = 1;
1695
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1696
                           }
1697
                           decimals = find_number_of_digits(precision);
1698
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
11818 schaersvoo 1699
                           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 1700
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11818 schaersvoo 1701
                           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 1702
                           add_to_buffer(tmp_buffer);
1703
                           fill_cnt++;
1704
                           break;
1705
                    default:break;
1706
                }
1707
            }
1708
            reset();
1709
        break;
1710
 
1711
        case FONTCOLOR:
1712
        /*
1713
         @ fontcolor color
1714
         @ color: hexcolor or colorname
1715
         @ default: black
13956 schaersvoo 1716
         @ use command <a href="#fontfamily'>fontfamily</a> to deviate from default font type
1717
         @%fontcolor%size 400,400%xrange -10,10%yrange -10,10%fontcolor red%#note: use command fontfamily to change size and shape%axis%axisnumbering%grid 2,2,grey,2,2,4,grey
11806 schaersvoo 1718
        */
1719
            font_color = get_color(infile,1);
1720
            break;
1721
 
1722
        case FONTFAMILY:
1723
        /*
1724
         @ fontfamily font_description
1725
         @ set the font family; for browsers that support it
1726
         @ font_description: Ariel ,Courier, Helvetica etc
12063 schaersvoo 1727
         @ 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 34pt Ariel
1728
         @ use correct syntax : 'font style' 'font size'pt 'fontfamily'
13959 bpr 1729
         @%fontfamily%size 400,400%xrange -10,10%yrange -10,10  %fontfamily Bold 10pt Ariel%string blue,-9,9,10 pt Ariel%fontfamily Italic 20pt Ariel%string blue,0,9,20 pt Ariel%fontfamily Bold 10pt Helvetica%string blue,-9,5,10 pt Helvetica%fontfamily Italic 20pt Helvetica%string blue,0,5,20 pt Helvetica %fontfamily Bold 10pt Courier%string blue,-9,0,10 pt Courier%fontfamily Italic 20pt Courier%string blue,0,0,20 pt Courier%fontfamily Bold 10pt Fixed%string blue,-9,-5,10 pt Fixed%fontfamily Italic 20pt Fixed%string blue,0,-5,20 pt Fixed %fontfamily Bold 10pt Times%string blue,-9,-9,10 pt Times%fontfamily Italic 20pt Times%string blue,0,-9,20 pt Times
1730
 
11806 schaersvoo 1731
        */
1732
            font_family = get_string(infile,1);
1733
            break;
1734
 
1735
        case FONTSIZE:
1736
        /*
1737
         @ fontsize font_size
1738
         @ default value 12
1739
         @ 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
1740
        */
1741
            font_size = (int) (get_real(infile,1));
1742
            break;
1743
 
1744
        case FUNCTION_LABEL:
1745
        /*
1746
         @ functionlabel 'some string'
1747
         @ default value "f(x)="
1748
         @ no mathml allowed (just ascii string)
13956 schaersvoo 1749
         @ use command <a href='#fontsize'>fontsize int</a> to adjust the size
1750
         @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed)
1751
         @ if needed, use before every command <a href='#userinput'>'userinput function | inputfield | textarea'</a>
1752
         @ no limit in amount of inputfields for userbased function plotting
11806 schaersvoo 1753
        */
1754
            function_label = get_string_argument(infile,1);
1755
            break;
1756
 
1757
        case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px) ,axis/tickscolor]*/
1758
        /*
1759
         @ grid step_x,step_y,gridcolor
1760
         @ 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
1761
         @ 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
1762
         @ 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)
1763
         @ can <b>not</b> be set <a href="#onclick">"onclick"</a> or <a href="#drag">"drag xy"</a>
1764
         @ 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' !
13987 bpr 1765
         @ see commands <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')
14038 schaersvoo 1766
         @ 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')
12110 schaersvoo 1767
         @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
1768
         @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
1769
         @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
1770
         @%grid_axis_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
11806 schaersvoo 1771
        */
1772
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
1773
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
1774
            for(i=0;i<4;i++){
1775
                switch(i){
1776
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
1777
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
1778
                    case 2:
1779
                    if( use_axis == TRUE ){
1780
                        stroke_color = get_color(infile,0);
1781
                        done = FALSE;
1782
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
1783
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
1784
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
1785
                        fill_color = get_color(infile,1); /* used as axis_color*/
8351 schaersvoo 1786
                    }
1787
                    else
1788
                    {
11806 schaersvoo 1789
                        int_data[0] = 1;
1790
                        int_data[1] = 1;
1791
                        stroke_color = get_color(infile,1);
1792
                        fill_color = stroke_color;
8351 schaersvoo 1793
                    }
11806 schaersvoo 1794
                    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 !");}
1795
                    /* set snap_x snap_y values in pixels */
1796
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
1797
                    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);
1798
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
1799
                    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);
1800
                    add_to_buffer(tmp_buffer);
1801
                    break;
8351 schaersvoo 1802
                }
1803
            }
1804
            reset();
1805
            break;
11806 schaersvoo 1806
        case GRIDFILL:
1807
        /*
1808
        @ gridfill x0,y0,dx,dy,color
1809
        @ x0,y0 in xrange / yrange
1810
        @ distances dx,dy in pixels
13936 bpr 1811
        @ there is also a command <a href="#userdraw">userdraw gridfill,color</a>
12110 schaersvoo 1812
        @%gridfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%gridfill 6,6,10,10,blue%gridfill 6,-6,6,6,red
1813
 
11806 schaersvoo 1814
        */
1815
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
11820 schaersvoo 1816
            decimals = find_number_of_digits(precision);
1817
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1818
             js_function[DRAW_FILLTOBORDER] = 1;
1819
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1820
            }
11806 schaersvoo 1821
            for(i=0;i<5;i++){
1822
                switch(i){
11820 schaersvoo 1823
                    case 0: double_data[0] = get_real(infile,0); break; /* x  */
1824
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
1825
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1826
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1827
                    case 4: stroke_color = get_color(infile,1);
11820 schaersvoo 1828
                    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 1829
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11820 schaersvoo 1830
                    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 1831
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1832
                    fill_cnt++;
11806 schaersvoo 1833
                    break;
1834
                    default:break;
1835
                }
1836
            }
1837
            reset();
1838
        break;
8386 schaersvoo 1839
 
8244 schaersvoo 1840
        case HALFLINE:
1841
        /*
1842
        @ demiline x1,y1,x2,y2,color
1843
        @ alternative : halfline
1844
        @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
9406 schaersvoo 1845
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12110 schaersvoo 1846
        @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
8244 schaersvoo 1847
        */
1848
            for(i=0;i<5;i++){
1849
                switch(i){
1850
                    case 0: double_data[0]= get_real(infile,0);break; /* x-values */
1851
                    case 1: double_data[1]= get_real(infile,0);break; /* y-values */
1852
                    case 2: double_data[10]= get_real(infile,0);break; /* x-values */
1853
                    case 3: double_data[11]= get_real(infile,0);break; /* y-values */
1854
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
1855
                    if(double_data[0] == double_data[10]){ /* vertical halfline */
1856
                        if(double_data[1] < double_data[11]){
1857
                         double_data[3] = ymax + 1000;
1858
                        }
1859
                        else
1860
                        {
1861
                         double_data[3] = ymin - 1000;
1862
                        }
10953 bpr 1863
                        double_data[2] = double_data[0];
8244 schaersvoo 1864
                    }
1865
                    else
1866
                    { /* horizontal halfline*/
1867
                     if( double_data[1] == double_data[11] ){
1868
                      if( double_data[0] < double_data[10] ){
1869
                        double_data[2] = xmax + 1000; /* halfline to the right */
1870
                      }
1871
                      else
1872
                      {
1873
                        double_data[2] = xmin - 1000; /* halfline to the left */
1874
                      }
1875
                      double_data[3] = double_data[1];
1876
                     }
1877
                     else
1878
                     {
1879
                      /* any other halfline */
1880
                      /* slope */
1881
                      double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
1882
                      /* const */
1883
                      double_data[13] = double_data[1] - double_data[12]*double_data[0];
1884
                      if( double_data[0] < double_data[10] ){
1885
                       double_data[2] = double_data[2] + 1000;
1886
                      }
1887
                      else
1888
                      {
1889
                       double_data[2] = double_data[2] - 1000;
1890
                      }
1891
                      double_data[3] = double_data[12]*double_data[2] + double_data[13];
1892
                     }
10953 bpr 1893
                    }
14045 schaersvoo 1894
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 1895
                    if(onclick > 0){click_cnt++;}
1896
                    /* click_cnt++; */
1897
                    reset();
8244 schaersvoo 1898
                    break;
1899
                }
1900
            }
1901
            break;
8386 schaersvoo 1902
 
8365 schaersvoo 1903
        case HALFLINES:
1904
        /*
1905
        @ demilines color,x1,y1,x2,y2,....
1906
        @ alternative : halflines
1907
        @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc etc
9406 schaersvoo 1908
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
12110 schaersvoo 1909
        @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
8365 schaersvoo 1910
        */
1911
            stroke_color=get_color(infile,0);
1912
            fill_color = stroke_color;
1913
            i=0;
1914
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 1915
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8365 schaersvoo 1916
                if(i%2 == 0 ){
1917
                    double_data[i] = get_real(infile,0); /* x */
1918
                }
1919
                else
1920
                {
1921
                    double_data[i] = get_real(infile,1); /* y */
1922
                }
1923
                i++;
1924
            }
1925
            decimals = find_number_of_digits(precision);
1926
            for(c = 0 ; c < i-1 ; c = c+4){
1927
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
1928
                    if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
1929
                        double_data[c+3] = ymax + 1000;
1930
                    }
1931
                    else
1932
                    {
1933
                     double_data[c+3] = ymin - 1000;/* descending halfline */
1934
                    }
1935
                }
1936
                else
1937
                {
1938
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
1939
                        if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
1940
                            double_data[c+2] = xmax+100;
1941
                        }
1942
                        else
1943
                        {
1944
                            double_data[c+2] = xmin-1000; /* halfline to the right */
1945
                        }
1946
                    }
1947
                    else
1948
                    {
1949
                        /* m */
1950
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
1951
                        /* q */
1952
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
1953
                        if(double_data[c] < double_data[c+2]){ /* to the right */
1954
                            double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it's just segment */
1955
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1956
                        }
1957
                        else
1958
                        { /* to the left */
1959
                            double_data[c+2] = xmin - 1000;
1960
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1961
                        }
1962
                    }
1963
                }
14045 schaersvoo 1964
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 1965
                if(onclick > 0){click_cnt++;}
1966
                /* click_cnt++; */
8365 schaersvoo 1967
            }
1968
            reset();
1969
            break;
11806 schaersvoo 1970
        case HATCHFILL:
1971
        /*
1972
        @ hatchfill x0,y0,dx,dy,color
1973
        @ x0,y0 in xrange / yrange
1974
        @ distances dx,dy in pixels
13936 bpr 1975
        @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a>
12110 schaersvoo 1976
        @%hatchfill%size 400,400%xrange -10,10%yrange -10,10%canvastype 100%linewidth 2%precision 1000%jsplot blue,5*sin(x)%opacity 200,50%hatchfill 6,6,10,10,blue%hatchfill 6,-6,6,6,red
11806 schaersvoo 1977
        */
1978
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
11820 schaersvoo 1979
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1980
             js_function[DRAW_FILLTOBORDER] = 1;
1981
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1982
            }
1983
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1984
            for(i=0;i<5;i++){
1985
                switch(i){
11820 schaersvoo 1986
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
1987
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
1988
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1989
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1990
                    case 4: stroke_color = get_color(infile,1);
1991
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
11820 schaersvoo 1992
                    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 1993
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11820 schaersvoo 1994
                    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 1995
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1996
                    fill_cnt++;
11806 schaersvoo 1997
                    break;
1998
                    default:break;
1999
                }
2000
            }
2001
            reset();
2002
        break;
8386 schaersvoo 2003
 
8224 bpr 2004
        case HLINE:
7614 schaersvoo 2005
        /*
2006
        @ hline x,y,color
9383 schaersvoo 2007
        @ alternative : horizontalline
7614 schaersvoo 2008
        @ draw a horizontal line through point (x:y) in color 'color'
13987 bpr 2009
        @ or use command <a href='#curve'>'curve color,formula'</a> to draw the line (uses more points to draw the line; is however better draggable)
9406 schaersvoo 2010
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12110 schaersvoo 2011
        @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
7614 schaersvoo 2012
        */
2013
            for(i=0;i<3;i++) {
2014
                switch(i){
2015
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
2016
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
2017
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
2018
                    double_data[3] = double_data[1];
2019
                    decimals = find_number_of_digits(precision);
14045 schaersvoo 2020
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 2021
                    if(onclick > 0){click_cnt++;}
2022
                    /* click_cnt++; */
2023
                    reset();
7614 schaersvoo 2024
                    break;
2025
                }
2026
            }
2027
            break;
8366 schaersvoo 2028
 
2029
        case HLINES:
2030
        /*
2031
        @ hlines color,x1,y1,x2,y2,...
9383 schaersvoo 2032
        @ alternative : horizontallines
8366 schaersvoo 2033
        @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
9406 schaersvoo 2034
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
12110 schaersvoo 2035
        @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
8366 schaersvoo 2036
        */
2037
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2038
            fill_color = stroke_color;
2039
            i=0;
2040
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 2041
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8366 schaersvoo 2042
                if(i%2 == 0 ){
2043
                    double_data[i] = get_real(infile,0); /* x */
2044
                }
2045
                else
2046
                {
2047
                    double_data[i] = get_real(infile,1); /* y */
2048
                }
2049
                i++;
2050
            }
2051
            decimals = find_number_of_digits(precision);
2052
            for(c = 0 ; c < i-1 ; c = c+2){
14045 schaersvoo 2053
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 2054
                if(onclick > 0){click_cnt++;}
2055
                /* click_cnt++; */
8366 schaersvoo 2056
            }
2057
            reset();
2058
            break;
11806 schaersvoo 2059
        case HTTP:
7614 schaersvoo 2060
        /*
11806 schaersvoo 2061
         @ http x1,y1,x2,y2,http://some_adress.com
2062
         @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1) , right bottom (x2:y2)
2063
         @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
2064
         @ can <b>not</b> be 'set onclick' or 'drag xy'
12110 schaersvoo 2065
         @%http%size 400,400%xrange -10,10%yrange -10,10%http 0,10,10,0,http://wims.unice.fr%opacity 200,50%drag xy%fcircle 0,0,100,green
7614 schaersvoo 2066
        */
11806 schaersvoo 2067
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
2068
            for(i=0;i<5;i++){
7614 schaersvoo 2069
                switch(i){
11806 schaersvoo 2070
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
14032 schaersvoo 2071
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
11806 schaersvoo 2072
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
2073
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
2074
                    case 4: decimals = find_number_of_digits(precision);
2075
                            temp = get_string(infile,1);
2076
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
2077
                            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);
2078
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
2079
                            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);
2080
                            add_to_buffer(tmp_buffer);
7614 schaersvoo 2081
                    break;
2082
                }
2083
            }
11806 schaersvoo 2084
            reset();
7614 schaersvoo 2085
            break;
11806 schaersvoo 2086
        case HTML:
8366 schaersvoo 2087
        /*
11806 schaersvoo 2088
         @ html x1,y1,x2,y2,html_string
2089
         @ 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.
2090
         @ can be set onclick <br />(however dragging not supported)
14038 schaersvoo 2091
         @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1)
12110 schaersvoo 2092
         @%html%size 400,400%xrange -10,10%yrange -10,10%html 0,10,10,0,<table style="border:solid 2px;background-color:yellow"><tr><th>qwerty</th><th>qwerty</th></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr><tr><td>qwerty</td><td>qwerty</td></tr></table> %opacity 200,50%drag xy%fcircle 0,0,100,green
8366 schaersvoo 2093
        */
11806 schaersvoo 2094
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
2095
            for(i=0;i<5;i++){
2096
                switch(i){
2097
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
14032 schaersvoo 2098
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
13829 bpr 2099
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
11806 schaersvoo 2100
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
2101
                    case 4: decimals = find_number_of_digits(precision);
2102
                            temp = get_string(infile,1);
2103
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
14044 schaersvoo 2104
                            string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
11806 schaersvoo 2105
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
14044 schaersvoo 2106
                            snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
11806 schaersvoo 2107
                            add_to_buffer(tmp_buffer);
2108
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
14038 schaersvoo 2109
                            use_offset = 0;
11806 schaersvoo 2110
                            break;
2111
                    default:break;
8366 schaersvoo 2112
                }
2113
            }
2114
            break;
8386 schaersvoo 2115
 
11806 schaersvoo 2116
        case IMAGEFILL:
7614 schaersvoo 2117
        /*
11996 schaersvoo 2118
        @ imagefill x,y,scaling to xsize &times; ysize?,image_url
11874 schaersvoo 2119
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
2120
        @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
2121
        @ After pattern filling ,the fill-color should be reset !
2122
        @ wims getins / image from class directory : imagefill 80,80,my_image.gif
2123
        @ normal url : imagefill 80,80,0,$module_dir/gifs/my_image.gif
2124
        @ normal url : imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
2125
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
13967 schaersvoo 2126
        @%imagefill_tile%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,0,gifs/en.gif%imagefill -5,5,0,gifs/logo/wimsedu.png
2127
        @%imagefill_scale%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,5,3,2,5%imagefill 1.5,1.5,1,gifs/en.gif%imagefill -5,5,1,gifs/logo/wimsedu.png
7614 schaersvoo 2128
        */
11806 schaersvoo 2129
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
11854 schaersvoo 2130
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
2131
             js_function[DRAW_FILLTOBORDER] = 1;
2132
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
2133
            }
11874 schaersvoo 2134
            for(i=0 ;i < 4 ; i++){
7614 schaersvoo 2135
                switch(i){
11806 schaersvoo 2136
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
2137
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
11874 schaersvoo 2138
                    case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
2139
                    case 3: URL = get_string_argument(infile,1);
2140
                            string_length = snprintf(NULL,0,  "draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]);
11806 schaersvoo 2141
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11874 schaersvoo 2142
                            snprintf(tmp_buffer,string_length,"draw_imagefill(%d,%d,%d,\"%s\",%d,%d,%d,%d);\n",STATIC_CANVAS+fill_cnt,int_data[0],int_data[1],URL,xsize,ysize,use_userdraw,int_data[2]);
11806 schaersvoo 2143
                            add_to_buffer(tmp_buffer);
11874 schaersvoo 2144
                            fill_cnt++;
11806 schaersvoo 2145
                    break;
7614 schaersvoo 2146
                }
2147
            }
11806 schaersvoo 2148
            reset();
2149
        break;
14038 schaersvoo 2150
 
2151
        case IMAGEPALETTE:
2152
        /*
2153
         @ imagepalette image1,image2,image3,...
2154
         @ if used before & together with command <a href='#multidraw'>'mmultidraw images,..,...,etc'</a> the imag as will be presented in a small table in the 'control panel'
2155
         @%imagepalette%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Ariel%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%inputstyle color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %#  \u222D ---> u222D at least will sometimes work%#  otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images
2156
         */
2157
           temp = get_string(infile,1);
2158
           temp = str_replace(temp,",","\",\"");
2159
            if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");}
2160
            fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp);
2161
        break;
2162
 
11806 schaersvoo 2163
        case INPUTSTYLE:
2164
        /*
2165
        @ inputstyle style_description
2166
        @ 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
12107 schaersvoo 2167
        @%inputstyle%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:blue;font-weight:bold;font-style:italic;font-size:16pt;text-align:center%input 0,0,10,1,Hello
11806 schaersvoo 2168
        */
2169
            input_style = get_string(infile,1);
7614 schaersvoo 2170
            break;
11806 schaersvoo 2171
        case INPUT:
2172
        /*
2173
         @ input x,y,size,editable,value
2174
         @ to set inputfield "readonly", use editable = 0
2175
         @ only active inputfields (editable = 1) will be read with read_canvas();
13948 schaersvoo 2176
         @ if "&#36;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>
11806 schaersvoo 2177
         @ may be further controlled by <a href="#inputstyle">"inputstyle"</a> (inputcss is not yet implemented...)
2178
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
2179
         @ 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)
13953 schaersvoo 2180
         @ if the student must place an inputfield(s) somewhere on the canvas, use command <a href="#userdraw">userdraw input,color</a> or make use of a command like <a href="#userdraw">userdraw text,color</a>
2181
         @%input%size 400,400%xrange -10,10%yrange -10,10%linewidth 6%point 1,2,red%input 1,2,5,1, ?%point -5,5,red%input -5,5,5,1, ?%point 6,-5,red%input 6,-5,5,1, ?%point -5,-8,red%input -5,-8,5,1, ?
11806 schaersvoo 2182
        */
2183
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
2184
            for(i = 0 ; i<5;i++){
2185
                switch(i){
2186
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
2187
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
2188
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
2189
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
2190
                    case 4:
2191
                            temp = get_string_argument(infile,1);
2192
                            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);
2193
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
2194
                            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);
2195
                            add_to_buffer(tmp_buffer);
2196
                            input_cnt++;break;
2197
                    default: break;
2198
                }
2199
            }
2200
            if(reply_format == 0 ){reply_format = 15;}
2201
            reset();
2202
            break;
8386 schaersvoo 2203
 
11806 schaersvoo 2204
        case INTOOLTIP:
2205
            /*
2206
            @ intooltip link_text
2207
            @ link_text is a single line (span-element)
2208
            @ link_text may also be an image URL 'http://some_server/images/my_image.png' or '$module_dir/gifs/my_image.jpg'
2209
            @ link_text may contain HTML markup
2210
            @ the canvas will be displayed in a tooltip on 'link_text'
2211
            @ 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'.
2212
            @ 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...
13953 schaersvoo 2213
            @%intooltip%size 400,400%xrange -10,10%yrange -10,10%fontfamily Bold 42pt Courier%string black,0,0,Hello World%intooltip <span style="background-color:black;color:white;font-style:bold;font-size:48pt;">   CLICK   <br />  HERE              </span>
11806 schaersvoo 2214
            */
2215
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
2216
            if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
2217
            tooltip_text = get_string(infile,1);
2218
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
2219
            use_tooltip = 1;
2220
            break;
2221
 
2222
        case JSCURVE:
7614 schaersvoo 2223
        /*
11893 schaersvoo 2224
         @ jscurve color,formula1(x),formula2(x),formula3(x),...
11806 schaersvoo 2225
         @ alternative : jsplot color,formula(x)
11893 schaersvoo 2226
         @ your function will be plotted by the javascript engine of the client browser
2227
         @ if <a href='trange'>trange</a> is defined, the two functions will be plotted parametric<br /><b>note</b>: use <i>x</i> as variable...and not <i>t</i>. Use keyword <a href='#animate'>animate</a> to animate a point on the curve
11806 schaersvoo 2228
         @ use only basic math in your curve:<br /> sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e
2229
         @ use parenthesis and rawmath : use 2*x instead of 2x ; use 2^(sin(x))...etc etc<br />use error console to debug any errors...
2230
         @ <b>attention</b> : last "precision" command in the canvasdraw script determines the calculation precision of the javascript curve plot !
2231
         @ no validity check is done by wims.
2232
         @ 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
2233
         @ 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
11893 schaersvoo 2234
         @ use keyword <a href='animate'>animate</a> for animating a point on the curve
11806 schaersvoo 2235
         @ use command 'trace_jscurve formula(x)` for tracing
14032 schaersvoo 2236
         @ use command 'jsmath  formula(x)` for calculating and displaying indiviual points on the curve
11806 schaersvoo 2237
         @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
2238
         @ commands plotjump / plotstep are not active for 'jscurve'
2239
         @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
13936 bpr 2240
         @ 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 must specify individual multistrokecolors &amp; multistrokeopacity &amp; multilinewidth for these multiple js-curves to use different colors.<br />otherwise all curves will be the same color...<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...)
12107 schaersvoo 2241
         @%jscurve%size 400,400%xrange -10,10%yrange -10,10%multicolors red,green,blue,orange%multilinewidth 1,1,1%multistrokeopacity 0.5,0.8,1.0%jscurve red,sin(x),1/sin(x),sin(x^2)
11806 schaersvoo 2242
        */
2243
            stroke_color = get_color(infile,0);
2244
            if( use_js_math == FALSE){/* add this stuff only once...*/
2245
                add_to_js_math(js_include_file);
2246
                use_js_math = TRUE;
2247
            }
2248
            if( use_js_plot == FALSE){
2249
                use_js_plot = TRUE;
2250
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
2251
            }
11893 schaersvoo 2252
            int use_paramteric = 0;
2253
            if( tmin != 0 && tmax !=0){use_parametric = 1;}
11806 schaersvoo 2254
            temp = get_string(infile,1);
2255
            temp = str_replace(temp,",","\",\"");
14032 schaersvoo 2256
            string_length = snprintf(NULL,0,  "jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate);
11806 schaersvoo 2257
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11893 schaersvoo 2258
            snprintf(tmp_buffer,string_length,"jsplot(%d,[\"%s\"],[%d],[\"%s\"],[%.2f],[%d],%d,%d,[%f,%f],%d,%d,%d); ",JSPLOT_CANVAS+jsplot_cnt,temp,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],tmin,tmax,plot_steps,use_parametric,use_animate);
11806 schaersvoo 2259
            add_to_buffer(tmp_buffer);
2260
            jsplot_cnt++;
2261
             /* we need to create multiple canvasses, so we may zoom and pan ?? */
2262
        break;
2263
 
2264
        case JSMATH:
2265
        /*
2266
            @ jsmath some_math_function
2267
            @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
2268
            @ 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
2269
            @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels 'x' and 'y'
2270
            @ 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...
2271
            @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
12111 schaersvoo 2272
            @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
11806 schaersvoo 2273
        */
2274
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
2275
            if( use_js_math == FALSE){
2276
                add_to_js_math(js_include_file);
2277
                use_js_math = TRUE;
2278
            }
2279
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
2280
            break;
2281
        case KILLAFFINE:
2282
        /*
2283
        @ killaffine
2284
        @ keyword : resets the transformation matrix to 1,0,0,1,0,0
2285
        */
2286
            use_affine = FALSE;
2287
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
2288
            break;
2289
 
2290
        case KILLROTATE:
2291
        /*
2292
         @ killrotate will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
2293
         @ a following rotate command will have the first object point as rotation center
2294
         @ if not set, the rotation center will remain unchanged
2295
        */
2296
            rotation_center= my_newmem(6);
2297
            snprintf(rotation_center,5,"null");
2298
         break;
2299
 
2300
        case KILLSLIDER:
2301
        /*
2302
         @ killslider
2303
         @ keyword (no arguments required)
2304
         @ ends grouping of object under a previously defined slider
2305
        */
2306
            slider = 0;
2307
            break;
2308
 
2309
        case KILLTRANSLATION:
2310
        /*
2311
         @ killtranslation
2312
         @ alternative : killtranslate
2313
         @ resets the translation matrix to 1,0,0,1,0,0
2314
        */
2315
            use_affine = FALSE;
2316
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
2317
            break;
2318
 
2319
        case LINE:
2320
        /*
2321
        @ line x1,y1,x2,y2,color
2322
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
2323
        @ or use command 'curve color,formula' to draw the line <br />(uses more points to draw the line; is however better draggable)
9406 schaersvoo 2324
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 2325
        @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
7614 schaersvoo 2326
        */
8386 schaersvoo 2327
            for(i=0;i<5;i++){
7614 schaersvoo 2328
                switch(i){
11806 schaersvoo 2329
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
2330
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
2331
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
2332
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
2333
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
2334
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
2335
                        double_data[1] = xmin;
2336
                        double_data[3] = ymax;
2337
                        double_data[0] = double_data[10];
2338
                        double_data[2] = double_data[10];
2339
                    }
2340
                    else
2341
                    {
2342
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
2343
                            double_data[1] = double_data[11];
2344
                            double_data[3] = double_data[11];
2345
                            double_data[0] = ymin;
2346
                            double_data[2] = xmax;
2347
                        }
2348
                        else
2349
                        {
2350
                        /* m */
2351
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
2352
                        /* q */
2353
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
2354
 
2355
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
2356
 
2357
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
2358
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
2359
                            double_data[0] = xmin;
2360
                            double_data[2] = xmax;
2361
                        }
2362
                    }
2363
                    decimals = find_number_of_digits(precision);
14045 schaersvoo 2364
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 2365
                    if(onclick > 0){click_cnt++;}
2366
                    /* click_cnt++;*/
2367
                    reset();
2368
                    break;
7614 schaersvoo 2369
                }
2370
            }
2371
            break;
8386 schaersvoo 2372
 
11806 schaersvoo 2373
        case LINES:
8370 schaersvoo 2374
        /*
11806 schaersvoo 2375
        @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
2376
        @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
2377
        @ 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)
2378
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
2379
        @ <b>attention</b>: the flydraw command "lines" is equivalent to canvasdraw command <a href="#polyline">"polyline"</a>
12107 schaersvoo 2380
        @%lines%size 400,400%xrange -10,10%yrange -10,10%lines green,0,1,1,3,0,0,1,3,0,0,-2,1
8370 schaersvoo 2381
        */
2382
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2383
            fill_color = stroke_color;
2384
            i=0;
2385
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 2386
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8370 schaersvoo 2387
                if(i%2 == 0 ){
2388
                    double_data[i] = get_real(infile,0); /* x */
2389
                }
2390
                else
2391
                {
2392
                    double_data[i] = get_real(infile,1); /* y */
2393
                }
2394
                i++;
2395
            }
2396
            decimals = find_number_of_digits(precision);
2397
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 2398
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
2399
                    double_data[c+1] = xmin;
2400
                    double_data[c+3] = ymax;
2401
                    double_data[c+2] = double_data[c];
2402
                }
2403
                else
2404
                {
2405
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
2406
                        double_data[c+3] = double_data[c+1];
2407
                        double_data[c] = ymin;
2408
                        double_data[c+2] = xmax;
2409
                    }
2410
                    else
2411
                    {
2412
                        /* m */
2413
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
2414
                        /* q */
2415
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
2416
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
2417
                        double_data[c+1] = (m)*(xmin)+(q);
2418
                        double_data[c+3] = (m)*(xmax)+(q);
2419
                        double_data[c] = xmin;
2420
                        double_data[c+2] = xmax;
2421
                    }
2422
                }
14045 schaersvoo 2423
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 2424
                if(onclick > 0){click_cnt++;}
2425
                /* click_cnt++; */
8370 schaersvoo 2426
            }
2427
            reset();
2428
            break;
8386 schaersvoo 2429
 
11806 schaersvoo 2430
 
2431
        case LINEWIDTH:
7614 schaersvoo 2432
        /*
11806 schaersvoo 2433
        @ linewidth int
2434
        @ default 1
12107 schaersvoo 2435
        @%linewidth%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%line -5,-5,-5,5,red%linewidth 2%line -4,-5,-4,5,green%linewidth 3%line -3,-5,-3,5,blue%linewidth 4%line -2,-5,-2,5,orange%linewidth 1%line -1,-5,-1,5,brown%linewidth 5%line 1,-5,1,5,cyan%linewidth 6%line 3,-5,3,5,purple%linewidth 7%line 5,-5,5,5,black
7614 schaersvoo 2436
        */
11806 schaersvoo 2437
            line_width = (int) (get_real(infile,1));
2438
            break;
2439
 
2440
        case LATTICE:
2441
        /*
2442
         @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
2443
         @ can <b>not</b> be set "onclick" or "drag xy"
12107 schaersvoo 2444
         @%lattice%size 400,400%xrange -10,10%yrange -10,10%fillcolor red%linewidth 2%lattice -10,-10,0,1,1,1,10,10,red%fillcolor blue%lattice 10,-10,0,1,-1,1,10,10,blue
11806 schaersvoo 2445
        */
2446
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
2447
            for( i = 0; i<9; i++){
7614 schaersvoo 2448
                switch(i){
14032 schaersvoo 2449
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
2450
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
2451
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
2452
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
2453
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
2454
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
11806 schaersvoo 2455
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
2456
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
2457
                    case 8: stroke_color=get_color(infile,1);
7614 schaersvoo 2458
                        decimals = find_number_of_digits(precision);
11996 schaersvoo 2459
                        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,%d); ",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,use_filled);
11806 schaersvoo 2460
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11996 schaersvoo 2461
                        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,%d); ",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,use_filled);
11806 schaersvoo 2462
                        add_to_buffer(tmp_buffer);break;
2463
                    default:break;
7614 schaersvoo 2464
                }
2465
            }
11806 schaersvoo 2466
            reset();
7614 schaersvoo 2467
            break;
8363 schaersvoo 2468
 
11806 schaersvoo 2469
        case LEVELCURVE:
8363 schaersvoo 2470
        /*
11806 schaersvoo 2471
        @ levelcurve color,expression in x/y,l1,l2,...
2472
        @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
2473
        @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
2474
        @ 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
2475
        @ note : the arrays for holding the javascript data are limited in size
2476
        @ note : reduce image size if javascript data arrays get overloaded<br />(command 'plotsteps int' will not control the data size of the plot...)
12107 schaersvoo 2477
        @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
8363 schaersvoo 2478
        */
11806 schaersvoo 2479
            fill_color = get_color(infile,0);
2480
            char *fun1 = get_string_argument(infile,0);
2481
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
2482
            i = 0;
2483
            done = FALSE;
2484
            while( !done ){
2485
             double_data[i] = get_real(infile,1);
2486
             i++;
2487
            }
2488
            for(c = 0 ; c < i; c++){
14045 schaersvoo 2489
             fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 2490
             if(onclick > 0){click_cnt++;}
2491
             /* click_cnt++; */
2492
            }
2493
            reset();
2494
            break;
8386 schaersvoo 2495
 
11806 schaersvoo 2496
        case LEGEND:
2497
        /*
2498
        @ legend string1:string2:string3....string_n
2499
        @ will be used to create a legend for a graph
2500
        @ also see command <a href='#piechart'>'piechart'</a>
2501
        @ will use the same colors per default as used in the graphs : use command <a href='#legendcolors'>'legendcolors'</a> to override the default
2502
        @ use command <a href="#fontsize">fontsize</a> to adjust. (command "fontfamily" is not active for command "legend")
13951 schaersvoo 2503
        @%legend%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%fontsize 16%legend legend 1:legend 2:legend 3:legend 4:this is legend 5:legend 6:another legend abc%legendcolors red:green:blue%grid 1,1,white%# note : command "grid" is mandatory%# just set grid invisible if not wanted
11806 schaersvoo 2504
        */
2505
            temp = get_string(infile,1);
2506
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2507
            legend_cnt++; /* attention :starts with -1 : it will be used in piechart etc */
2508
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
2509
            break;
2510
 
2511
        case LEGENDCOLORS:
2512
        /*
2513
        @ legendcolors color1:color2:color3:...:color_n
2514
        @ 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
2515
        @ make sure the number of colours match the number of legend items
2516
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
13960 bpr 2517
        @%legendcolors%size 400,400%xrange -10,10%yrange -10,10%fontsize 18%legend legend 1:legend 2:legend 3%legendcolors red:green:blue%grid 1,1,grey
11806 schaersvoo 2518
        */
2519
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
2520
            temp = get_string(infile,1);
2521
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2522
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
2523
            break;
2524
 
2525
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed' ,'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
2526
        /*
2527
        @ linegraph x1:y1:x2:y2...x_n:y_n
2528
        @ will plot your data in a graph
2529
        @ may <b>only</b> to be used together with command <a href='#grid'>'grid'</a>
2530
        @ 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>
2531
        @ use command <a href='#legend'>'legend'</a> to provide an optional legend in right-top-corner
2532
        @ also see command <a href='#piechart'>'piechart'</a>
2533
        @ multiple linegraphs may be used in a single plot
2534
        @ note: your arguments are not checked by canvasdraw : use your javascript console in case of trouble...
2535
        @ <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>
12107 schaersvoo 2536
        @%linegraph%size 400,400%xrange -10,10%yrange -10,10%strokecolor red%linegraph -10:1:-5:-1:3:3:10:-5%strokecolor blue%linegraph -10:-1:-5:1:3:-3:10:5%dashed%strokecolor green%linegraph -10:2:-5:-2:3:4:10:2%grid 1,1,grey
11806 schaersvoo 2537
        */
2538
            temp = get_string(infile,1);
2539
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2540
            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);
2541
            linegraph_cnt++;
2542
            reset();
2543
            break;
2544
 
2545
        case MATHML:
2546
        /*
2547
        @ mathml x1,y1,x2,y2,mathml_string
14038 schaersvoo 2548
        @ the mathml object is centered at (x1:y1)
13952 schaersvoo 2549
        @ the 'mathml_string' can be produced using WIMS commands like 'texmath' followed by 'mathmlmath'... or write correct TeX and use only 'mathmlmath'
13829 bpr 2550
        @ 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.
11806 schaersvoo 2551
        @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor  of the mathml object
13988 bpr 2552
        @ can be set onclick <br />javascript:read_dragdrop(); will return click numbers of mathml-objects<br />if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
11806 schaersvoo 2553
        @ 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...
2554
        @ 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
13829 bpr 2555
        @ 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
11806 schaersvoo 2556
        @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
2557
        @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick  mathml
2558
        @ other drag objects (circles/rects etc) are supported , but read_dragdrop() will probably be difficult to interpret...
2559
        @ 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();"
2560
        @ 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....
14038 schaersvoo 2561
        @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1)
13829 bpr 2562
        @%mathml_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%strokecolor red%mathml -5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>&sdot;</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%onclick%strokecolor blue%mathml 5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>
13952 schaersvoo 2563
        @%mathml_drag%size 400,400%xrange -10,10%yrange -10,10%drag xy%strokecolor red%mathml -5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml366290"><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mn>2</mn></mfrac></mstyle><mo>&sdot;</mo><msup><mi>x</mi> <mn>2</mn></msup></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><msup><mi>x</mi> <mn>2</mn></msup></mrow></mfrac></mstyle></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%drag xy%strokecolor blue%mathml 5,5,0,0,<span style="font-size:1em;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mstyle id="wims_mathml580175" ><mrow><mo stretchy="true">[</mo><mtable rowspacing="0.5ex"  columnalign=" left "  columnlines=" none "  rowlines=" none "  ><mtr><mtd><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mstyle displaystyle="true"><mfrac><mn>1</mn><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></mfrac></mstyle></mtd></mtr> <mtr><mtd><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msqrt><mrow><mi>sin</mi><mrow><mo stretchy="true">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="true">)</mo></mrow></mrow></msqrt></mtd></mtr></mtable><mo stretchy="true">]</mo></mrow></mstyle></math></span>%#click left top corner...then drag...
11806 schaersvoo 2564
        */
14044 schaersvoo 2565
            if(use_offset == 0){use_offset = 4;}
11806 schaersvoo 2566
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
2567
            for(i=0;i<5;i++){
2568
                switch(i){
2569
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
14032 schaersvoo 2570
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
2571
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed : overflow  */
11806 schaersvoo 2572
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed : overflow */
2573
                    case 4: decimals = find_number_of_digits(precision);
2574
                            temp = get_string(infile,1);
2575
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
14044 schaersvoo 2576
                            string_length = snprintf(NULL,0,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
11806 schaersvoo 2577
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
14044 schaersvoo 2578
                            snprintf(tmp_buffer,string_length,"draw_xml(%d,%d,%d,\"%s\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
11806 schaersvoo 2579
                            add_to_buffer(tmp_buffer);
2580
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
14038 schaersvoo 2581
                            use_offset=0;
11806 schaersvoo 2582
                            /*
2583
                             in case inputs are present , trigger adding the read_mathml()
2584
                             if no other reply_format is defined
2585
                             note: all other reply types will include a reading of elements with id='mathml'+p)
2586
                             */
2587
                            if(strstr(temp,"mathml0") != NULL){
2588
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
2589
                            }
2590
                            break;
2591
                    default:break;
2592
                }
2593
            }
2594
            break;
2595
 
2596
        case MOUSE:
2597
        /*
2598
         @ mouse color,fontsize
2599
         @ will display the cursor (x:y) coordinates  in 'color' and 'font size'<br /> using default fontfamily Ariel
2600
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
12107 schaersvoo 2601
         @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
11806 schaersvoo 2602
        */
2603
            stroke_color = get_color(infile,0);
2604
            font_size = (int) (get_real(infile,1));
2605
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2606
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2607
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
2608
            break;
2609
 
2610
 
2611
        case MOUSE_DEGREE:
2612
        /*
2613
         @ mouse_degree color,fontsize
2614
         @ 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
2615
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
2616
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
12107 schaersvoo 2617
         @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
11806 schaersvoo 2618
        */
2619
            stroke_color = get_color(infile,0);
2620
            font_size = (int) (get_real(infile,1));
2621
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2622
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2623
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2624
            js_function[JS_FIND_ANGLE] = 1;
2625
            break;
2626
        case MOUSE_DISPLAY:
2627
        /*
2628
         @ display TYPE,color,fontsize
2629
         @ TYPE may be x | y | xy | degree | radian | radius
2630
         @ 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)
2631
         @ use commands 'xunit' and / or 'yunit' to add the units to the mouse values.<br />The "degree | radian" will always have the appropriate symbol)
2632
         @ just like commands 'mouse','mousex','mousey','mouse_degree'...only other name)
12111 schaersvoo 2633
         @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
12107 schaersvoo 2634
         @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
13936 bpr 2635
         @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue
12107 schaersvoo 2636
         @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
2637
         @%display_rad%size 400,400%xrange -10,10%yrange -10,10%display radian,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
12111 schaersvoo 2638
         @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
11806 schaersvoo 2639
        */
2640
        temp = get_string_argument(infile,0);
2641
        if( strstr(temp,"xy") != NULL ){
2642
            int_data[0] = 2;
2643
        }else{
2644
            if( strstr(temp,"y") != NULL ){
2645
                int_data[0] = 1;
2646
            }else{
2647
                if( strstr(temp,"x") != NULL ){
2648
                    int_data[0] = 0;
2649
                }else{
2650
                    if(strstr(temp,"degree") != NULL){
2651
                        int_data[0] = 3;
2652
                        js_function[JS_FIND_ANGLE] = 1;
2653
                    }else{
2654
                        if(strstr(temp,"radian") != NULL){
2655
                            int_data[0] = 4;
2656
                            js_function[JS_FIND_ANGLE] = 1;
2657
                        }else{
2658
                            if(strstr(temp,"radius") != NULL){
2659
                                int_data[0] = 5;
2660
                            }else{
2661
                                int_data[0] = 2;
2662
                            }
2663
                        }
2664
                    }
2665
                }
2666
            }
2667
        }
2668
        stroke_color = get_color(infile,0);
2669
        font_size = (int) (get_real(infile,1));
2670
        tmp_buffer = my_newmem(26);
13371 schaersvoo 2671
        snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2672
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2673
        break;
2674
 
2675
        case MOUSE_PRECISION:
2676
        /*
2677
            @ precision int
2678
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
2679
            @ may be used / changed before every object
2680
            @ In case of user interaction (like 'userdraw' or 'multidraw') this value will be used to determine the amount of decimals in the reply / answer
13936 bpr 2681
            @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red
11806 schaersvoo 2682
        */
2683
            precision = (int) (get_real(infile,1));
2684
            if(precision < 1 ){precision = 1;};
2685
            break;
2686
 
2687
        case MOUSEX:
2688
        /*
2689
         @ mousex color,fontsize
2690
         @ will display the cursor x-coordinate in 'color' and 'font size'<br /> using the fontfamily Ariel
2691
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2692
 
2693
        */
2694
            stroke_color = get_color(infile,0);
2695
            font_size = (int) (get_real(infile,1));
2696
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2697
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2698
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2699
            break;
2700
        case MOUSEY:
2701
        /*
2702
         @ mousey color,fontsize
2703
         @ will display the cursor y-coordinate in 'color' and 'font size'<br /> using default fontfamily Ariel
2704
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
2705
 
2706
        */
2707
            stroke_color = get_color(infile,0);
2708
            font_size = (int) (get_real(infile,1));
2709
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2710
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2711
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2712
            break;
2713
 
2714
        case MULTIDASH:
2715
        /*
2716
         @ multidash 0,1,1
2717
         @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <em>'multifill points,circle,segments'</em>, are dashed
2718
         @ use before command <a href='#multidraw'>'multidraw'</a>
2719
         @ 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>
2720
         @ 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)
2721
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2722
         @ always use the same sequence as is used for 'multidraw'
2723
        */
2724
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2725
            temp = get_string(infile,1);
2726
            temp = str_replace(temp,",","\",\"");
2727
            fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
2728
            reset();/* if command 'dashed' was given...reset to not-dashed */
2729
            break;
2730
 
2731
        case MULTIDRAW:
2732
        /*
2733
         @ multidraw obj_type_1,obj_type_2...obj_type_11
2734
         @ for simple single object user drawings you could also use command <a href="#userdraw">'userdraw'</a>
14038 schaersvoo 2735
         @ 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><li>images</li></ul>
11875 schaersvoo 2736
         @ 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
11806 schaersvoo 2737
         @ 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...
13948 schaersvoo 2738
         @ note: mouselisteners are only active if "&#36;status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required)
11806 schaersvoo 2739
         @ 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'
2740
         @ 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)
2741
         @ multidraw is incompatible with command 'tooltip' (the reserved div_area is used for the multidraw control buttons)
2742
         @ all 'multidraw' drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">'userdraw'</a>.
2743
         @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's )
14044 schaersvoo 2744
         @ a local function read_canvas%d will read all userbased drawings.<br />The output is always a 16 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 />line 12 = image_x+";"+image_y+";"+image_idline 13 = curvedarrows_x  +";"+ curved_arrows_y +"\\n"<br />line 14 = curvedarrows2_x  +";"+ curved_arrows_y +"\\n"<br />line 15 = userdraw_x +";"+userdraw_y + "\\n" note: this is for single 'userdraw object,color' and 'replyformat 29'<br/>line 16 = userdraw_x +";"+userdraw_y +";"+userdraw_radius + "\\n" note: this is for single 'userdraw object,color' and 'replyformat 29'<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>
11806 schaersvoo 2745
         @ 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 />
2746
         @ <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.
11997 schaersvoo 2747
         @ <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 too many very slow do-it-all HTML5 canvas javascript libraries.<br />The mouselisteners are attached to the canvas-div element.</em>
14053 schaersvoo 2748
         @ a special object type is 'images'.<br />if used together with <a href='#imagepalette'>imagepalette</a> a image table will be integrated in the 'control section' of multidraw.(set 'multiuserinput 1' for 'images')<br />if not used with <a href='#imagepalette'>imagepalette</a>, provide the images (&lt;img&gt; tag with bitmap or SVG) somewhere on the html exercise page, with an onclick handler like:<br />&lt;img src='gifs/images/dog.svg' onclick='javascript:place_image_on_canvas(this.id);' id="ext_image_1" /&gt;<br />&lt;img src='gifs/fish.png' onclick='javascript:place_image_on_canvas(this.id);' id="another" /&gt;<br />etc,etc...when activating the multidraw 'image' button, the images can be selected<br /> (left mouse button/onclick) and placed on the canvas...left mouse click
14054 schaersvoo 2749
         @ When you are not content with the default 'multidraw control panel', you can create your own interface, using a few javascript functions to call the drawprimitives, delete things and 'stop drawing' in case you also want to drag&drop stuff...</br>To activate this feature, use <a href='#multilabel'>multilabel NOCONTROLS</a><br />The object types are internally represented by the following numbers (makeing typo's will render your exercise null and void)<br/>point = 0<br />points =1<br />circle = 2<br />circles = 3<br />line = 4<br />lines = 5<br />segment = 6<br />segments = 7<br />arrow = 8<br />arrows = 9<br />triangle = 10<br />triangles = 11<br />closedspoly = 12<br />text = 13<br />rect = 14<br />rects = 15<br />poly[3-9] = 16<br />polys[3-9] = 17<br />parallelogram = 18<br />parallelograms = 19<br />images = 20<br />curvedarrow = 21<br />curvedarrows = 22<br />curvedarrow2 = 23<br />curvedarrows2 = 24<br />controls for example:<br />&lt;input type='button' onclick='javascript:userdraw_primitive=null' value='STOP DRAWING' /&gt;<br />&lt;input type='button' onclick='javascript:userdraw_primitive=24;multidraw_click_cnt = 0;' value='start drawing curvedarrows2' /&gt; <br />&lt;input type='button' onclick='javascript:var fun=eval("clear_draw_area"+canvas_scripts[0]);fun(24,0);' value='REMOVE LAST CURVEDARROW ' /&gt; <br/> If using multiple canvas scripts in a single page, loop through the canvas_scripts[n]   
12107 schaersvoo 2750
         @%multidraw%size 400,400%xrange -10,10%yrange -10,10%multidash 1,0%multilinewidth 1,2%multistrokecolors red,blue%multisnaptogrid 1,1%multilabel LINES,CIRCLES,STOP DRAWING%multidraw lines,circles
14038 schaersvoo 2751
         @%multidraw_images%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%drag xy%# use special function to read the drag coordinates%copy 0,0,-1,-1,-1,-1,gifs/images/skull_and_crossbones50.png%fontcolor green%fontfamily Bold 42pt Ariel%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multiuserinput 0,0,1%inputstyle color:blue;%multisnaptogrid 1,1,1%multilinewidth 0,4,0%# attention: use unicode text input without the slash %#  \u222D ---> u222D at least will sometimes work%#  otherwise cut&past unicode symbols into inputfield...%multilabel TEXT,REACTION ARROW,FLAGS,STOP DRAWING%multidraw text,arrow,images
14044 schaersvoo 2752
         @%multidraw_demo%size 800,800%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%inputstyle color:blue;%fontfamily Italic 42pt Ariel%precision 1%opacity 200,50%snaptogrid%linewidth 3%filled%multistrokecolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,green,purple,black,cyan%multifillcolors red,green,blue,orange,yellow,purple,black,cyan,red,green,blue,orange,brown,purple%imagepalette gifs/ca.gif,gifs/en.gif,gifs/nl.gif,gifs/fr.gif,gifs/cn.gif,gifs/de.gif,gifs/kh.gif,gifs/it.gif%multidraw closedpoly,segments,rect,parallelogram,triangles,poly5,points,lines,arrows,circles,text,curvedarrows,curvedarrows2,images
11806 schaersvoo 2753
        */
14038 schaersvoo 2754
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
11806 schaersvoo 2755
            if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
2756
            use_userdraw = TRUE;
2757
            /* LET OP max 6 DRAW PRIMITIVES + TEXT */
2758
            temp = get_string(infile,1);
2759
            temp = str_replace(temp,",","\",\"");
14044 schaersvoo 2760
            /* if these are not set, set the default values for the 18 (more than enough !)  draw_primitives + draw_text */
2761
                /* int use_snap = 0;  0 = none 1=grid : 2=x-grid : 3=y-grid : 4=snap to points */
2762
 
11806 schaersvoo 2763
            fprintf(js_include_file,"\
14044 schaersvoo 2764
            if( typeof(multisnaptogrid) == 'undefined' && multisnaptogrid == null){var multisnaptogrid = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];}\
14038 schaersvoo 2765
            if( typeof(multistrokecolors) === 'undefined' && multistrokecolors == null  ){ var multistrokecolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
2766
            if( typeof(multifillcolors) === 'undefined' && multifillcolors == null ){ var multifillcolors = ['%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'];};\
2767
            if( typeof(multistrokeopacity) === 'undefined' && multistrokeopacity == null ){ var multistrokeopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
2768
            if( typeof(multifillopacity) === 'undefined' &&  multifillopacity == null ){ var multifillopacity = ['%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f','%.2f','%.2f','%.2f','%.2f','%.2f','%.2f','%2.f','%2.f','%2.f'];};\
2769
            if( typeof(multilinewidth) === 'undefined' && multilinewidth == null ){ var multilinewidth = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2770
            if( typeof(multifill) === 'undefined' && multifill == null ){ var multifill = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
2771
            if( typeof(multidash) === 'undefined' && multidash == null ){ var multidash = ['%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d'];};\
11806 schaersvoo 2772
            if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
14044 schaersvoo 2773
            if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput = ['0','0','0','0','0','0','0','0'];};\
11806 schaersvoo 2774
            var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
14044 schaersvoo 2775
            use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,use_snap,
14038 schaersvoo 2776
            stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,stroke_color,
2777
            fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,fill_color,
2778
            stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,stroke_opacity,
2779
            fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,fill_opacity,
2780
            line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,line_width,
2781
            use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,use_filled,
2782
            use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,use_dashed,
11806 schaersvoo 2783
            temp,arrow_head,font_color,font_family);
2784
 
2785
            if(strstr(temp,"text") != NULL){
2786
             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2787
            }
2788
 
2789
            /* the canvasses range from 1000 ... 1008 */
14038 schaersvoo 2790
            add_js_multidraw(js_include_file,canvas_root_id,temp,input_style,use_offset);
11806 schaersvoo 2791
            reply_precision = precision;
2792
            if( reply_format == 0){reply_format = 29;}
2793
            reset();/* if command 'filled' / 'dashed' was given...reset all */
2794
            break;
2795
        case MULTILABEL:
2796
        /*
2797
         @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
2798
         @ use before command <a href='#multidraw'>'multidraw'</a>
2799
         @ 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'...)
2800
         @ 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>
2801
         @ 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>
2802
         @ wims will not check the amount or validity of your input
2803
         @ always use the same sequence as is used for 'multidraw'
14053 schaersvoo 2804
         @ if you don't want the controls, and want to write your own interface, set 'multilabel NOCONTROLS'
11806 schaersvoo 2805
        */
2806
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2807
            temp = get_string(infile,1);
2808
            temp = str_replace(temp,",","\",\"");
2809
            fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
2810
            break;
2811
        case MULTILINEWIDTH:
2812
        /*
2813
         @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
2814
         @ use before command <a href='#multidraw'>'multidraw'</a>
2815
         @ if not set all line width will be set by a previous command <em>'linewidth int'</em>
2816
         @ 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>
2817
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2818
         @ always use the same sequence as is used for 'multidraw'
2819
        */
2820
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2821
            temp = get_string(infile,1);
2822
            temp = str_replace(temp,",","\",\"");
2823
            fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
2824
            break;
2825
        case MULTIFILL:
2826
        /*
2827
         @ multifill 0,0,1,0,1,0,0
2828
         @ 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...)
2829
         @ use before command <a href='#multidraw'>'multidraw'</a>
14032 schaersvoo 2830
         @ if not set all objects -except point|points-  will be set 'not filled'...<br />unless a command 'filled' was given before command 'multifill'
11806 schaersvoo 2831
         @ only suitable for draw_primitives like 'circle | circles' , 'triangle | triangles' and 'polygon'
2832
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2833
         @ always use the same sequence as is used for 'multidraw'
2834
        */
2835
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2836
            temp = get_string(infile,1);
2837
            temp = str_replace(temp,",","\",\"");
2838
            fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
2839
            break;
2840
 
2841
        case MULTIFILLCOLORS:
2842
        /*
2843
         @ multifillcolors color_name_1,color_name_2,...,color_name_8
2844
         @ use before command <a href='#multidraw'>'multidraw'</a>
2845
         @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be 'stroke_color' , 'fill_opacity'
2846
         @ use these up to 6 colors for the draw primitives used by command 'multidraw obj_type_1,obj_type_2...obj_type_n
2847
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
2848
         @ always use the same sequence as is used for 'multidraw'
2849
         @ 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>
2850
        */
2851
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2852
            fprintf(js_include_file,"var multifillcolors = [");
2853
            while( ! done ){
2854
                temp = get_color(infile,1);
2855
                fprintf(js_include_file,"\"%s\",",temp);
2856
            }
2857
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2858
            break;
2859
 
2860
        case MULTIFILLOPACITY:
2861
        /*
2862
         @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
2863
         @ float values 0 - 1 or integer values 0 - 255
2864
         @ use before command <a href='#multidraw'>'multidraw'</a>
2865
         @ if not set all fill opacity_ will be set by previous command <em>'opacity int,int'</em> and keyword <em>'filled'</em>
2866
         @ 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>
2867
         @ wims will not check the amount or validity of your input
2868
         @ always use the same sequence as is used for 'multidraw'
2869
        */
2870
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2871
            temp = get_string(infile,1);
2872
            temp = str_replace(temp,",","\",\"");
2873
            fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
2874
            break;
2875
        case MULTISNAPTOGRID:
2876
        /*
2877
         @ multisnaptogrid 0,1,1
14038 schaersvoo 2878
         @ alternative : multisnap
11806 schaersvoo 2879
         @ 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>)
14038 schaersvoo 2880
         @ freehand drawing...specify precision for reply: all objects snap to grid<em>multisnaptogrid 1,1,1,...</em>
2881
         @ only the xy-values snap_to_grid: all objects snap to grid  <em>multisnaptogrid 1,1,1,...</em>
2882
         @ only the x-values snap_to_grid: all objects snap to x-grid <em>multisnaptogrid 2,2,2,...</em>
2883
         @ only the y-values snap_to_grid: all objects snap to y-grid <em>multisnaptogrid 3,3,3,...</em>
2884
         @ if <a href='#snaptopoints'>snaptopoints</a> is defined: all objects snap to points <em>multisnaptogrid 4,4,4,...</em> <br /><b>make sure to define the points to snap on...</b> use command <a href='#snaptopoints'>snaptopoints</a>
2885
         @ <em>multisnaptogrid 0,1,2,3,4</em><br />multidraw text,arrow,line,circle,image<br />'text' is free hand <br /> 'arrow' is snap to grid<br /> 'line' is snap to x-grid<br /> 'circle' is snap to y-grid<br /> 'image' is snap to points defined by command <a href='#snaptopoints'>snaptopoints</a>
11806 schaersvoo 2886
         @ use before command <a href='#multidraw'>'multidraw'</a>
14038 schaersvoo 2887
         @ attention: if not set all objects will be set 'no snap'...<br />unless a generic command 'snaptogrid' was given before command 'multidraw'
2888
         @ commands <a href='#xsnaptogrid'>'xsnaptogrid'</a>, <a href='#ysnaptogrid'>'ysnaptogrid'</a>, <a href='#snaptofunction'>'snaptofunction'</a> are <b>not</b> supported amd only functional for <a href='#userdraw'>command userdraw</a>
11806 schaersvoo 2889
         @ always use the same sequence as is used for 'multidraw'
2890
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2891
        */
2892
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2893
            temp = get_string(infile,1);
14038 schaersvoo 2894
            fprintf(js_include_file,"var multisnaptogrid = [%s];",temp);
11806 schaersvoo 2895
            reset();/* if command 'dashed' was given...reset to not-dashed */
2896
            break;
2897
        case MULTISTROKECOLORS:
2898
        /*
2899
         @ multistrokecolors color_name_1,color_name_2,...,color_name_8
2900
         @ use before command <a href='#multidraw'>'multidraw'</a>
2901
         @ if not set all colors will be 'stroke_color' , 'stroke_opacity'
2902
         @ 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>
2903
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
2904
         @ always use the same sequence as is used for 'multidraw'
2905
        */
2906
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2907
            fprintf(js_include_file,"var multistrokecolors = [");
2908
            while( ! done ){
2909
                temp = get_color(infile,1);
2910
                fprintf(js_include_file,"\"%s\",",temp);
2911
            }
2912
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2913
            break;
2914
        case MULTISTROKEOPACITY:
2915
        /*
2916
         @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
2917
         @ float values 0 - 1 or integer values 0 - 255
2918
         @ use before command <a href='#multidraw'>'multidraw'</a>
2919
         @ if not set all stroke opacity_ will be set by previous command <em>'opacity int,int'</em>
2920
         @ 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>
2921
         @ wims will not check the amount or validity of your input
2922
         @ always use the same sequence as is used for 'multidraw'
2923
        */
2924
            if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2925
            temp = get_string(infile,1);
2926
            temp = str_replace(temp,",","\",\"");
2927
            fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
2928
            break;
2929
 
2930
        case MULTIUSERINPUT:
2931
        /*
2932
        @ multiuserinput 0,1,1,0
14038 schaersvoo 2933
        @ alternative multiinput
11806 schaersvoo 2934
        @ 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
2935
        @ 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
2936
        @ 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...
2937
        @ in case of a triangle | poly3, three inputfields are provided.
2938
        @ in case of 'text' and multiuserinput=1 , 3 inputfields will be shown : x,y,text
2939
        @ in case of 'text' and multiuserinput=0 , 1 inputfield will be shown : text ... a mouse click will place the text on the canvas.
2940
        @ may be styled using command <a href="#inputstyle">"inputstyle"</a>
2941
        @ an additional button 'stop drawing' may be used to combine userbased drawings with 'drag&amp;drop' or 'onclick' elements
2942
        @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword 'status'
2943
        @ use before command <a href='#multidraw'>'multidraw'</a>
2944
        @ always use the same sequence as is used for 'multidraw'
2945
        */
2946
            /* simple rawmath and input check */
2947
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2948
            temp = get_string(infile,1);
2949
            temp = str_replace(temp,",","\",\"");
2950
            fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
2951
            break;
2952
 
2953
        case NOXAXIS:
2954
        /*
13829 bpr 2955
        @ noaxis
11806 schaersvoo 2956
        @ keyword
2957
        @ if set, the automatic x-axis numbering will be ignored
13936 bpr 2958
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>
11806 schaersvoo 2959
        @ to be used before command grid (see <a href="#grid">command grid</a>)
2960
        */
11891 schaersvoo 2961
            fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
2962
            use_axis_numbering = -1;
11806 schaersvoo 2963
            break;
2964
        case NOYAXIS:
2965
        /*
13829 bpr 2966
        @ noayis
11806 schaersvoo 2967
        @ keyword
2968
        @ if set, the automatic y-axis numbering will be ignored
13936 bpr 2969
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>
11806 schaersvoo 2970
        @ to be used before command grid (see <a href="#grid">command grid</a>)
2971
        */
11891 schaersvoo 2972
            fprintf(js_include_file,"y_strings = {};\n");
11806 schaersvoo 2973
            break;
11890 schaersvoo 2974
        case NUMBERLINE:
2975
        /*
2976
        @ numberline x0,x1,xmajor,xminor,y0,y1
2977
        @ numberline is using xrange/yrange system for all dimensions
11996 schaersvoo 2978
        @ multiple numberlines are allowed ; combinations with command <a href='#grid'>grid</a> is allowed; multiple commands <a href='#xaxis'>xaxis numbering</a> are allowed
11890 schaersvoo 2979
        @ x0 is start x-value in xrange
2980
        @ x1 is end x-value in xrange
2981
        @ xmajor is step for major division
2982
        @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is 'hardcoded'
2983
        @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline : this behaviour is 'hardcoded'
2984
        @ y0 is bottom of numberline; y1 endpoint of major tics
13829 bpr 2985
        @ use command <a href="#linewidth">linewidth</a> to control appearance
11890 schaersvoo 2986
        @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
2987
        @ for all ticks linewidth and color / opacity are identical.
2988
        @ if command <a href="#xaxis">xaxis</a> or <a href="#xaxisup">xaxisup</a> is not defined, the labeling will be on major ticks: x0...x1
13829 bpr 2989
        @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
11890 schaersvoo 2990
        @ may be used together with <a href="#userdraw">userdraw</a> , <a href="#multidraw">multidraw</a> and <a href="#drag">user drag</a> command family for the extra object drawn onto the numberline
2991
        @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
2992
        @ onclick and dragging of the numberline are not -yet- supported
11997 schaersvoo 2993
        @ note: incase of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
13829 bpr 2994
        @%numberline%size 400,400%xrange -10,10%yrange -10,10%precision 1%strokecolor black%numberline -8,8,1,6,-4,-3.5%strokecolor red%xaxis -4:AA:-2:BB:2:CC:4:DD%numberline -8,8,1,2,4,4.5%strokecolor green%xaxisup -4:AAA:-2:BBB:2:CCC:4:DDD%numberline -8,8,1,3,2,2.5%strokecolor blue%xaxis -4:AAAA:-2:BBBB:2:CCCC:4:DDDD%numberline -8,8,1,4,0,0.5%strokecolor brown%xaxis -4:AAAAA:-2:BBBBB:2:CCCCC:4:DDDDD%numberline -8,8,1,5,-2,-1.5%zoom red
11890 schaersvoo 2995
        */
2996
            if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;}
2997
            for(i=0;i<6;i++){
2998
                switch(i){
2999
                    case 0: double_data[0] = get_real(infile,0);break;/* xmin */
3000
                    case 1: double_data[1] = get_real(infile,0);break;/* xmax */
3001
                    case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
3002
                    case 3: double_data[3] = get_real(infile,0);break;/* xminor */
3003
                    case 4: double_data[4] = get_real(infile,0);break;/* ymin */
3004
                    case 5: double_data[5] = get_real(infile,1);/* ymax */
3005
                            /*
3006
                            var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
3007
                            */
3008
                            fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
11996 schaersvoo 3009
                            string_length = snprintf(NULL,0,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d);   ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision);
11890 schaersvoo 3010
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11996 schaersvoo 3011
                            snprintf(tmp_buffer,string_length,"\ndraw_numberline(%d,%d,%f,%f,%f,%f,%f,%f,%d,\"%s\",%f,\"%s\",\"%s\",%d);  ",NUMBERLINE_CANVAS+numberline_cnt,use_axis_numbering,double_data[0],double_data[1],double_data[2],double_data[3],double_data[4],double_data[5],line_width,stroke_color,stroke_opacity,font_family,font_color,precision);
11890 schaersvoo 3012
                            add_to_buffer(tmp_buffer);
3013
                            numberline_cnt++;
3014
                            break;
3015
                    default:break;
3016
                }
3017
            }
3018
            reset();
3019
            break;
3020
 
3021
            break;
11806 schaersvoo 3022
        case OPACITY:
3023
        /*
13951 schaersvoo 3024
        @ opacity [0-255],[0-255]
3025
        @ opacity [0.0 - 1.0],[0.0 - 1.0]
11806 schaersvoo 3026
        @ alternative : transparent
3027
        @ first item is stroke opacity, second is fill opacity
13951 schaersvoo 3028
        @%opacity%size 400,400%xrange -10,10%yrange -10,10%opacity 255,0%fcircle -10,0,100,blue%opacity 250,50%fcircle -5,0,100,blue%opacity 200,100%fcircle 0,0,100,blue%opacity 150,150%fcircle 5,0,100,blue%opacity 100,200%fcircle 10,0,100,blue
11806 schaersvoo 3029
        */
3030
            for(i = 0 ; i<2;i++){
3031
                switch(i){
3032
                    case 0: double_data[0]= get_real(infile,0);break;
3033
                    case 1: double_data[1]= get_real(infile,1);break;
3034
                    default: break;
3035
                }
3036
            }
13951 schaersvoo 3037
            if( double_data[0] > 255 ||  double_data[1] > 255  || double_data[0] < 0 || double_data[1] < 0 ){ canvas_error("opacity [0 - 255] , [0 - 255] ");}/* typo or non-RGB ? */
11997 schaersvoo 3038
            if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
3039
            if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
11806 schaersvoo 3040
            break;
3041
 
3042
        case ONCLICK:
3043
        /*
3044
         @ onclick
3045
         @ keyword (no arguments required)
3046
         @ if the next object is clicked, its 'object onclick_or_drag sequence number' in fly script is returned <br /> by javascript:read_canvas();
3047
         @ 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'
3048
         @ line based objects will show an increase in line width<br />font based objects will show the text in 'bold' when clicked.
3049
         @ the click zone (accuracy) is determined by 2&times; the line width of the object
3050
         @ 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...)
3051
         @ note: not all objects may be set onclick
12107 schaersvoo 3052
         @%onclick%size 400,400%xrange -10,10%yrange -10,10%opacity 255,60%linewidth 3%onclick%fcircles blue,-3,3,1,1,2,2,3,1,1%onclick%ftriangles red,-4,-4,-4,0,-3,-2,0,0,4,0,2,-4%onclick%frects green,-4,4,-2,2,1,-1,3,-4
11806 schaersvoo 3053
        */
3054
            fprintf(js_include_file,"use_dragdrop_reply = true;");
3055
            onclick = 1;
3056
 
3057
            break;
3058
 
3059
        case PARALLEL:
3060
        /*
3061
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
3062
         @ can <b>not</b> be set "onclick" or "drag xy"
12107 schaersvoo 3063
         @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
11806 schaersvoo 3064
        */
3065
            for( i = 0;i < 8; i++ ){
3066
                switch(i){
14032 schaersvoo 3067
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
3068
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
3069
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
3070
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
11806 schaersvoo 3071
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
3072
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
14032 schaersvoo 3073
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
11806 schaersvoo 3074
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
3075
                    decimals = find_number_of_digits(precision);
14045 schaersvoo 3076
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3077
                    if(onclick > 0){click_cnt++;}
3078
                    /* click_cnt++*/;
3079
                    reset();
3080
                    break;
3081
                    default: break;
3082
                }
3083
            }
3084
            break;
3085
 
3086
 
3087
        case PLOTSTEPS:
3088
            /*
3089
             @ plotsteps a_number
3090
             @ default 150
14032 schaersvoo 3091
             @ only used for commands <a href="#curve">"curve / plot"</a> and  <a href="#levelcurve">"levelcurve"</a>
11806 schaersvoo 3092
             @ use with care !
3093
            */
3094
            plot_steps = (int) (get_real(infile,1));
3095
            break;
13829 bpr 3096
 
11806 schaersvoo 3097
        case POINT:
3098
        /*
3099
        @ point x,y,color
3100
        @ draw a single point at (x;y) in color 'color'
14038 schaersvoo 3101
        @ use command 'linewidth int'  to adust size
11806 schaersvoo 3102
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
3103
        @ will not resize on zooming <br />(command 'circle x,y,r,color' will resize on zooming)
3104
        @ attention: in case of command <a href="#rotate">'rotate angle'</a> a point has rotation center (0:0) in x/y-range
12107 schaersvoo 3105
        @%point%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%point 0,0,red%linewidth 2%onclick%point 1,1,blue%linewidth 3%onclick%point 3,3,green%linewidth 4%point 4,4,orange
11806 schaersvoo 3106
        */
3107
            for(i=0;i<3;i++){
3108
                switch(i){
3109
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
3110
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
3111
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
3112
                    decimals = find_number_of_digits(precision);
14045 schaersvoo 3113
                    fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3114
                    /* click_cnt++; */
3115
                    if(onclick > 0){click_cnt++;}
3116
                    break;
3117
                    default: break;
3118
                }
3119
            }
3120
            reset();
3121
            break;
3122
 
3123
        case POINTS:
3124
        /*
3125
        @ points color,x1,y1,x2,y2,...,x_n,y_n
3126
        @ draw multiple points at given coordinates in color 'color'
14032 schaersvoo 3127
        @ use command 'linewidth int'  to adust size
11806 schaersvoo 3128
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
3129
        @ attention: in case of command <a href="#rotate">'rotate angle'</a> the points have rotation center (0:0) in x/y-range
12107 schaersvoo 3130
        @%points_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%snaptogrid%linewidth 1%drag xy%points red,0,0,1,1,2,2,3,3%drag x%points blue,0,1,1,2,2,3,3,4
3131
        @%points_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,255%linewidth 1%onclick%points red,0,0,1,1,2,2,3,3%onclick%points blue,0,1,1,2,2,3,3,4
11806 schaersvoo 3132
        */
8363 schaersvoo 3133
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3134
            fill_color = stroke_color;
3135
            i=0;
3136
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3137
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8363 schaersvoo 3138
                if(i%2 == 0 ){
3139
                    double_data[i] = get_real(infile,0); /* x */
3140
                }
3141
                else
3142
                {
3143
                    double_data[i] = get_real(infile,1); /* y */
3144
                }
3145
                i++;
3146
            }
3147
            decimals = find_number_of_digits(precision);
11806 schaersvoo 3148
            for(c = 0 ; c < i-1 ; c = c+2){
14045 schaersvoo 3149
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 3150
                /* click_cnt++; */
11806 schaersvoo 3151
                if(onclick > 0){click_cnt++;}
8363 schaersvoo 3152
            }
3153
            reset();
3154
            break;
11806 schaersvoo 3155
 
3156
        case POLY:
3157
        /*
3158
        @ poly color,x1,y1,x2,y2...x_n,y_n
3159
        @ polygon color,x1,y1,x2,y2...x_n,y_n
3160
        @ draw closed polygon
3161
        @ use command 'fpoly' to fill it or use keyword <a href='#filled'>'filled'</a>
3162
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 3163
        @%polygon_1%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 2%drag xy%snaptogrid%poly blue,0,0,1,3,3,1,2,4,-1,3
3164
        @%polygon_2%size 400,400%xrange -10,10%yrange -10,10%opacity 255,25%fillcolor orange%filled%linewidth 1%onclick%poly green,0,0,1,3,3,1,2,4,-1,3
11806 schaersvoo 3165
        */
3166
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3167
            i=0;
3168
            c=0;
3169
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3170
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 3171
                for( c = 0 ; c < 2; c++){
3172
                    if(c == 0 ){
3173
                        double_data[i] = get_real(infile,0);
3174
                        i++;
3175
                    }
3176
                    else
3177
                    {
3178
                        double_data[i] = get_real(infile,1);
3179
                        i++;
3180
                    }
3181
                }
3182
            }
14032 schaersvoo 3183
            /* draw path :  closed & optional filled */
11806 schaersvoo 3184
                decimals = find_number_of_digits(precision);
14045 schaersvoo 3185
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3186
                if(onclick > 0){click_cnt++;}
3187
                /* click_cnt++; */
3188
                reset();
3189
            break;
3190
 
7614 schaersvoo 3191
        case POLYLINE:
3192
        /*
3193
        @ polyline color,x1,y1,x2,y2...x_n,y_n
10975 schaersvoo 3194
        @ brokenline color,x1,y1,x2,y2...x_n,y_n
3195
        @ path color,x1,y1,x2,y2...x_n,y_n
3196
        @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands "polyline ,x1,y1,x2,y2...x_n,y_n"
3197
        @ 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
3198
        @ 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)
3199
        @ use command <a href='#segments'>'segments'</a> for a series of segments.<br />these may be clicked/dragged individually
9406 schaersvoo 3200
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 3201
        @%polyline_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%snaptogrid%polyline blue,0,0,1,3,3,1,2,4,-1,3
3202
        @%polyline_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%onclick%polyline green,0,0,1,3,3,1,2,4,-1,3
7614 schaersvoo 3203
        */
13829 bpr 3204
 
7614 schaersvoo 3205
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3206
            i=0;
3207
            c=0;
3208
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3209
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 3210
                for( c = 0 ; c < 2; c++){
3211
                    if(c == 0 ){
3212
                        double_data[i] = get_real(infile,0);
3213
                        i++;
3214
                    }
3215
                    else
3216
                    {
3217
                        double_data[i] = get_real(infile,1);
3218
                        i++;
3219
                    }
3220
                }
3221
            }
3222
            /* draw path : not closed & not filled */
3223
            decimals = find_number_of_digits(precision);
14045 schaersvoo 3224
            fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 3225
            if(onclick > 0){click_cnt++;}
3226
            /* click_cnt++;*/
3227
            reset();
7614 schaersvoo 3228
            break;
11806 schaersvoo 3229
 
3230
        case POPUP:
3231
            /*
3232
            @ popup
3233
            @ keyword (no arguments)
3234
            @ if fly-script starts with keyword 'popup', the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
3235
            @ 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'
3236
            @ the popup window will be embedded into the page as a 'normal' image , when 'status=done' ; override with keyword <a href="#status"> 'nostatus'</a>
14032 schaersvoo 3237
            @ 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>
11806 schaersvoo 3238
            @ 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
12107 schaersvoo 3239
            @%popup%popup%size 400,400%xrange -2*pi,2*pi%yrange -5,5%precision 0%axis%axisnumbering%opacity 100,190%grid 1,1,grey,2,2,5,black%linewidth 4%fillcolor blue%trange -pi,pi%animate%linewidth 1%precision 1000%jsplot red,4*cos(2*x),2*sin(3*x-pi/6)%strokecolor green%functionlabel f(x)=%userinput function
11806 schaersvoo 3240
            */
3241
            use_tooltip = 2;
3242
            break;
3243
 
3244
        case PROTRACTOR:
7614 schaersvoo 3245
        /*
11806 schaersvoo 3246
         @ protractor x,y,x_width,type,mode,use_a_scale
3247
         @ x,y are the initial location
3248
         @ x_width : give the width in x-coordinate system (e.g. not in pixels !)
14032 schaersvoo 3249
         @ type = 1 : a triangle range  0 - 180<br />type = 2 : a circle shape 0 - 360
11806 schaersvoo 3250
         @ 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
3251
         @ 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>
3252
         @ use_scale = 1 : the protractor will have some scale values printed; use_scale=0 to disable
3253
         @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
3254
         @ commands <em>stroke_color | fill_color | linewidth | opacity | font_family</em> will determine the looks of the protractor.
3255
         @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command 'precision' to set the reply precision.
3256
         @ if combined with a ruler, use replyformat = 32
3257
         @ command <em>snap_to_grid</em> may be used to assist the pupil at placing the protractor
14032 schaersvoo 3258
         @ 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>
11806 schaersvoo 3259
         @ only one protractor allowed (for the time being)
3260
         @ 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...
12107 schaersvoo 3261
         @%protractor%size 400,400%xrange -5,10%yrange -5,10%hline 0,0,black%vline 0,0,black%fillcolor orange%opacity 255,40%protractor 2,-2,6,0,-1,1,1
7614 schaersvoo 3262
        */
11806 schaersvoo 3263
            for( i = 0;i < 6; i++ ){
3264
                switch(i){
3265
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
3266
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
3267
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
3268
                    case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
3269
                    case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
3270
                    case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
3271
                    decimals = find_number_of_digits(precision);
11821 schaersvoo 3272
                    if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
14057 schaersvoo 3273
                    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],use_snap);
11806 schaersvoo 3274
 
3275
                    string_length = snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
3276
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3277
                    snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
3278
                    add_to_buffer(tmp_buffer);
3279
                    reply_precision = precision;
3280
                    /* no reply from protractor if non-interactive */
3281
                    if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
3282
                    break;
3283
                    default: break;
3284
                }
3285
            }
3286
            break;
3287
 
3288
        case PIXELS:
3289
        /*
3290
        @ pixels color,x1,y1,x2,y2,x3,y3...
3291
        @ draw rectangular "points" with diameter 1 pixel
3292
        @ pixels can <b>not</b> be dragged or clicked
3293
        @ "pixelsize = 1" may be changed by command "pixelsize int"
12111 schaersvoo 3294
        @%pixels%size 400,400%opacity 255,255%pixelsize 5%pixels red,1,1,2,2,3,3,4,4,5,5,10,10,20,20,30,30,40,40,50,50,60,60,70,70,80,80,90,90,100,100,120,120,140,140,160,160,180,180,200,200,240,240,280,280,320,320,360,360,400,400%#NOTE pixelsize=5...otherwise you will not see them clearly...
11806 schaersvoo 3295
        */
3296
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
3297
            stroke_color=get_color(infile,0);
7614 schaersvoo 3298
            i=0;
3299
            c=0;
3300
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3301
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 3302
                for( c = 0 ; c < 2; c++){
3303
                    if(c == 0 ){
3304
                        double_data[i] = get_real(infile,0);
3305
                        i++;
3306
                    }
3307
                    else
3308
                    {
3309
                        double_data[i] = get_real(infile,1);
3310
                        i++;
3311
                    }
3312
                }
3313
            }
11806 schaersvoo 3314
            decimals = find_number_of_digits(precision);
3315
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
3316
            string_length = snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
3317
            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3318
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
3319
            add_to_buffer(tmp_buffer);
3320
            reset();
7614 schaersvoo 3321
            break;
11806 schaersvoo 3322
 
3323
        case PIXELSIZE:
7614 schaersvoo 3324
        /*
11806 schaersvoo 3325
        @ pixelsize int
3326
        @ in case you want to deviate from default pixelsize = 1(...)
12111 schaersvoo 3327
        @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
7614 schaersvoo 3328
        */
11806 schaersvoo 3329
            pixelsize = (int) get_real(infile,1);
3330
        break;
8105 schaersvoo 3331
 
11806 schaersvoo 3332
        case PIECHART:
7614 schaersvoo 3333
        /*
11806 schaersvoo 3334
        @ piechart xc,yc,radius,'data+colorlist'
3335
        @ (xc : yc) center of circle diagram in xrange/yrange
3336
        @ radius in pixels
3337
        @ 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
11875 schaersvoo 3338
        @ example data+colorlist : 32:red:65:green:23:black:43:orange:43:yellow:14:white
11806 schaersvoo 3339
        @ the number of colors must match the number of data.
11875 schaersvoo 3340
        @ if defined <a href='#fillpattern'>'fillpattern some_pattern'</a> then the pie pieces will be filled with the respective color and a fill pattern...<br />the pattern is cycled from the 4 pattern primitives: grid,hatch,diamond,dot,grid,hatch,diamond,dot,...
11806 schaersvoo 3341
        @ use command "<a href='#opacity'>'opacity'</a> to adjust fill_opacity of colours
3342
        @ 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.
13829 bpr 3343
        @ use command <a href='centered'>'centered'</a> to place <a href='#legend'>'legend'</a> text inside the piechart. The text is using the same color as the pie segment: use (fill) opacity to enhance visibility.
12538 schaersvoo 3344
        @%piechart_1%size 300,200%xrange -10,10%yrange -10,10%legend cars:motorcycles:bicycles:trikes%opacity 255,120%piechart -5,0,75,22:red:8:blue:63:green:7:purple%
3345
        @%piechart_2%size 200,200%xrange -10,10%yrange -10,10%fontfamily 16px Ariel%centered%legend cars:motorcycles:bicycles:trikes%opacity 255,60%piechart 0,0,100,22:red:8:blue:63:green:7:purple
7614 schaersvoo 3346
        */
11806 schaersvoo 3347
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
7614 schaersvoo 3348
            for(i=0;i<5;i++){
3349
                switch(i){
11806 schaersvoo 3350
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
14032 schaersvoo 3351
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
11806 schaersvoo 3352
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
3353
                    case 3: temp = get_string(infile,1);
3354
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
12538 schaersvoo 3355
                            string_length = snprintf(NULL,0,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset);
11806 schaersvoo 3356
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
12538 schaersvoo 3357
                            snprintf(tmp_buffer,string_length,"draw_piechart(%d,%d,%d,%d,[\"%s\"],%.2f,%d,\"%s\",%d,%d);\n",PIECHART,int_data[0],int_data[1],int_data[2],temp,fill_opacity,legend_cnt,font_family,use_filled,use_offset);
11806 schaersvoo 3358
                            add_to_buffer(tmp_buffer);
3359
                           break;
3360
                    default:break;
7614 schaersvoo 3361
                }
3362
            }
11806 schaersvoo 3363
            reset();
7614 schaersvoo 3364
        break;
8304 schaersvoo 3365
 
7614 schaersvoo 3366
        case RAYS:
3367
        /*
3368
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
3369
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 3370
         @ may be set draggable or onclick (every individual ray)
12111 schaersvoo 3371
         @%rays_onclick%size 400,400%xrange -10,10%yrange -10,10%onclick%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9
3372
         @%rays_drag_xy%size 400,400%xrange -10,10%yrange -10,10%drag xy%rays blue,0,0,3,9,-3,5,-4,0,4,-9,7,9,-8,1,-1,-9
7614 schaersvoo 3373
        */
3374
            stroke_color=get_color(infile,0);
7786 schaersvoo 3375
            fill_color = stroke_color;
3376
            double_data[0] = get_real(infile,0);/* xc */
3377
            double_data[1] = get_real(infile,0);/* yc */
3378
            i=2;
3379
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3380
                if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
7786 schaersvoo 3381
                if(i%2 == 0 ){
3382
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 3383
                }
7786 schaersvoo 3384
                else
3385
                {
3386
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 3387
                }
7786 schaersvoo 3388
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
3389
                i++;
7614 schaersvoo 3390
            }
8224 bpr 3391
 
3392
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
3393
            decimals = find_number_of_digits(precision);
7786 schaersvoo 3394
            for(c=2; c<i;c = c+2){
14045 schaersvoo 3395
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 3396
                /* click_cnt++; */
3397
                if(onclick > 0){click_cnt++;}
7614 schaersvoo 3398
            }
3399
            reset();
3400
            break;
8304 schaersvoo 3401
 
11806 schaersvoo 3402
        case RECT:
8386 schaersvoo 3403
        /*
11806 schaersvoo 3404
        @ rect x1,y1,x2,y2,color
3405
        @ use command 'frect x1,y1,x2,y2,color' for a filled rectangle
14038 schaersvoo 3406
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rect x1,y1,x2,y2,color'
9406 schaersvoo 3407
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12111 schaersvoo 3408
        @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
8386 schaersvoo 3409
        */
11806 schaersvoo 3410
            for(i=0;i<5;i++){
3411
                switch(i){
3412
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
3413
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
3414
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
3415
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
3416
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
8386 schaersvoo 3417
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 3418
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3419
                        if(onclick > 0){click_cnt++;}
3420
                        /* click_cnt++; */
8386 schaersvoo 3421
                        reset();
3422
                        break;
11806 schaersvoo 3423
                }
3424
            }
3425
            break;
8386 schaersvoo 3426
 
11806 schaersvoo 3427
        case RECTS:
8304 schaersvoo 3428
        /*
11806 schaersvoo 3429
        @ rects color,x1,y1,x2,y2,.....
3430
        @ use command 'frect color,x1,y1,x2,y2,.....' for a filled rectangle
3431
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'rects color,x1,y1,x2,y2,....'
3432
        @ use command 'fillcolor color' before 'frects' to set the fill colour.
9406 schaersvoo 3433
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
12111 schaersvoo 3434
        @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
8304 schaersvoo 3435
        */
3436
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3437
            fill_color = stroke_color;
3438
            i=0;
3439
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3440
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8304 schaersvoo 3441
                if(i%2 == 0 ){
3442
                    double_data[i] = get_real(infile,0); /* x */
3443
                }
3444
                else
3445
                {
3446
                    double_data[i] = get_real(infile,1); /* y */
3447
                }
3448
                i++;
3449
            }
3450
            decimals = find_number_of_digits(precision);
3451
            for(c = 0 ; c < i-1 ; c = c+4){
14045 schaersvoo 3452
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3453
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 3454
                /* click_cnt++; */
8304 schaersvoo 3455
            }
3456
            reset();
3457
            break;
8386 schaersvoo 3458
 
11806 schaersvoo 3459
        case REPLYFORMAT:
7614 schaersvoo 3460
        /*
11806 schaersvoo 3461
        @ replyformat number
3462
        @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
3463
        @ default values should be fine !
3464
        @ use command 'precision [0,1,10,100,1000,10000...]' before command 'replyformat' to set the desired number of decimals in the student reply / drawing
3465
        @ the last value for 'precision int' will be used to calculate  the reply coordinates, if needed (read_canvas();)
14032 schaersvoo 3466
        @ 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>
14038 schaersvoo 3467
        @ replyformat 34 : a special for OEF and dragging external images -included via commands <a href='#copy'>copy</a> or <a href='#copyresized'>copyresized</a> there will be an extra function 'read_canvas_images()' for reading the coordinates of the images.<br />for now this is a unique function, e.g. there is no 'canvas id' linked to it. (TO DO !!! 18/5/2019)
11806 schaersvoo 3468
        */
3469
         reply_format = (int) get_real(infile,1);
3470
         reply_precision = precision;
3471
        break;
3472
 
3473
        case ROUNDRECT:
3474
        /*
3475
        @ roundrect x1,y1,x2,y2,radius in px,color
3476
        @ use command 'froundrect x1,y1,x2,y2,radius,color' for a filled rectangle
14032 schaersvoo 3477
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'roundrect x1,y1,x2,y2,radius,color'
11806 schaersvoo 3478
        @ fillcolor will be identical to 'color'
9406 schaersvoo 3479
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12111 schaersvoo 3480
        @%roundrect%size 400,400%xrange -10,10%yrange -10,10%roundrect 0,0,4,-4,20,green%roundrect 0,5,4,1,10,red
7614 schaersvoo 3481
        */
11806 schaersvoo 3482
            for(i=0;i<6;i++){
3483
                switch(i){
3484
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
3485
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
3486
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
3487
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
3488
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
3489
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
3490
                        /* ensure no inverted roundrect is produced... */
3491
                        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];}
3492
                        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 3493
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 3494
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
8379 schaersvoo 3495
                        if(onclick > 0){click_cnt++;}
3496
                        /* click_cnt++;*/
3497
                        reset();
11806 schaersvoo 3498
                    break;
3499
                }
3500
            }
3501
            break;
8386 schaersvoo 3502
 
11806 schaersvoo 3503
        case ROUNDRECTS:
8347 schaersvoo 3504
        /*
11806 schaersvoo 3505
        @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
3506
        @ for filled roundrects use command/keyword <a href='#filled'>'filled'</a> before command
9406 schaersvoo 3507
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
13935 bpr 3508
        @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2
8347 schaersvoo 3509
        */
11806 schaersvoo 3510
 
8347 schaersvoo 3511
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
11806 schaersvoo 3512
            int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
8347 schaersvoo 3513
            fill_color = stroke_color;
3514
            i=0;
3515
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3516
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8347 schaersvoo 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
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 3528
                /* ensure no inverted roundrect is produced... */
3529
                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];}
3530
                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];}
14045 schaersvoo 3531
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3532
                if(onclick > 0){click_cnt++;}
8379 schaersvoo 3533
                /* click_cnt++; */
8347 schaersvoo 3534
            }
3535
            reset();
3536
            break;
8386 schaersvoo 3537
 
11806 schaersvoo 3538
        case RULER:
7614 schaersvoo 3539
        /*
11806 schaersvoo 3540
        @ ruler x,y,x-width ,y-height,mode
3541
        @ x,y are the initial location
3542
        @ x-width , y-height are the ruler dimensions width &amp; height in xy-coordinate system
3543
        @ 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
3544
        @ 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
3545
        @ if combined with a protractor, use replyformat = 32
3546
        @ only one ruler allowed (for the time being)
3547
        @ 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>
3548
        @ 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...
12111 schaersvoo 3549
        @%ruler_interactive%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler -9,0,10,2,-1%display degree,blue,22%zoom red
3550
        @%ruler_set_degree_45%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,45%zoom red
3551
        @%ruler_set_degree_125%size 800,400%xrange -10,10%yrange -10,10%strokecolor blue%opacity 200,50%filled%fillcolor lightgrey%ruler 0,0,10,2,125%zoom red
7614 schaersvoo 3552
        */
11806 schaersvoo 3553
            for( i = 0;i < 5; i++ ){
7614 schaersvoo 3554
                switch(i){
11806 schaersvoo 3555
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
3556
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
3557
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
3558
                    case 3: double_data[3] = get_real(infile,0);break; /* y-width */
3559
                    case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
3560
                    decimals = find_number_of_digits(precision);
3561
                    if( int_data[0] < 0 ){
14032 schaersvoo 3562
                      if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
11806 schaersvoo 3563
                    }
14057 schaersvoo 3564
                    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],use_snap);
11806 schaersvoo 3565
                    string_length = snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
3566
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3567
                    snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
3568
                    add_to_buffer(tmp_buffer);
3569
                    reply_precision = precision;
3570
                    /* no reply from ruler if non-interactive */
3571
                    if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
7614 schaersvoo 3572
                    break;
3573
                    default: break;
3574
                }
3575
            }
3576
            break;
8386 schaersvoo 3577
 
11806 schaersvoo 3578
        case RESETOFFSET:
7614 schaersvoo 3579
        /*
11806 schaersvoo 3580
         @ resetoffset
3581
         @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
3582
         @ 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 3583
        */
11806 schaersvoo 3584
         use_offset = 0;
3585
         break;
3586
 
3587
        case ROTATE:
3588
        /*
3589
         @ rotate rotation_angle
3590
         @ angle in degrees
3591
         @ (only) the next object will be rotated is given angle
3592
         @ positive values rotate counter clockwise
3593
         @ 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)
13936 bpr 3594
         @ 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>
3595
         @ 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
13939 bpr 3596
         @%rotate_1%size 400,400%xrange -10,10%yrange -10,10%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%killrotate%rotate 90%fpoly violet,0,0,4,3,2,5%
11806 schaersvoo 3597
        */
3598
            use_rotate = TRUE;
3599
            angle = -1*(get_real(infile,1));/* -1 : to be compatible with Flydraw... */
7614 schaersvoo 3600
            break;
11806 schaersvoo 3601
        case ROTATION_CENTER:
9306 schaersvoo 3602
        /*
11806 schaersvoo 3603
        @ rotationcenter x_center,y_center
3604
        @ define an rotation center in your x/y-coordinate system
3605
        @ wims will not check the validity of your input; use javascript console to debug any erors
3606
        @ if not defined a rotation will be around the first point of an object
3607
        @ to be used before command <a href="#rotate">rotate</a>
3608
        @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
13956 schaersvoo 3609
        @%rotationcenter%size 400,400%xrange -5,10%yrange -5,10%circles green,3,3,4.25%rotationcenter 3,3%opacity 255,80%fpoly yellow,0,0,4,3,2,5%rotate 45%fpoly violet,0,0,4,3,2,5%rotate 90%fpoly lightblue,0,0,4,3,2,5%rotate 135%fpoly blue,0,0,4,3,2,5%rotate 180%fpoly orange,0,0,4,3,2,5%rotate 225%fpoly green,0,0,4,3,2,5%rotate 270%fpoly cyan,0,0,4,3,2,5%rotate 315%fpoly purple,0,0,4,3,2,5%linewidth 3%point 3,3,red%mouse red,22
13969 schaersvoo 3610
        @%rotationcenter_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%slider 0,2*pi,400,30,angle degrees,rotate...%plot red,5*sin(x)%filled%linewidth 1%opacity 150,50%fillcolor orange%angle 0,0,pi,0,0,blue
9306 schaersvoo 3611
        */
11806 schaersvoo 3612
            temp = get_string(infile,1);
3613
            string_length = snprintf(NULL,0,"[ %s ]",temp);
3614
            check_string_length(string_length);
3615
            rotation_center = my_newmem(string_length+1);
3616
            snprintf(rotation_center,string_length,"[%s]",temp);
9306 schaersvoo 3617
            break;
11806 schaersvoo 3618
 
3619
        case SIZE:
3620
            /*
3621
            @ size width,height
3622
            @ set canvas size in pixels
3623
            @ mandatory first command (can only be preceded by keyword <a href="#popup">'popup'</a>)
3624
            @ 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
3625
            */
3626
            found_size_command = 1;
3627
            /* using fabs : however "xsize == int" : so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
3628
            xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
3629
            ysize = (int)(fabs(round(get_real(infile,1))));
3630
            /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
3631
            xmin = 0;xmax = xsize;
3632
            ymin = 0;ymax = ysize;
3633
 
3634
/*
3635
 The sequence in which stuff is finally printed is important !!
3636
*/
3637
fprintf(stdout,"\n\
13970 obado 3638
<script>\n\
11806 schaersvoo 3639
/*<![CDATA[*/\n\
3640
if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
3641
if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
3642
if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
3643
canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
3644
",canvas_root_id);
3645
 
3646
/* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
3647
if( use_tooltip != 2){
3648
 fprintf(stdout,"<!-- canvasdraw div  -->\n\
3649
<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\
3650
<!-- tooltip and input placeholder  -->\n\
3651
<div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
3652
<!-- include actual object code via include file -->\n\
13970 obado 3653
<script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
11806 schaersvoo 3654
}
3655
else
3656
{
3657
/*
3658
set canvas_div invisible and do not include placeholder in main html page :
3659
the js-include will also be in a popup window...to be shown when wims $status = done
3660
*/
3661
 fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
3662
<div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
3663
<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>\
3664
<!-- include actual object code via include file -->\n\
13970 obado 3665
<script id=\"canvas_script%d\" src=\"%s\"></script>\n",canvas_root_id,xsize,ysize,canvas_root_id,canvas_root_id,canvas_root_id,getfile_cmd);
11806 schaersvoo 3666
}
3667
 
3668
/* these must be global...it's all really very poor javascript :( */
13970 obado 3669
fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\
11806 schaersvoo 3670
\"use strict\";\n\
13970 obado 3671
/* these variables and functions must be global */\n\
11806 schaersvoo 3672
var read_dragdrop%d;\
14038 schaersvoo 3673
var read_canvas_images;\
11806 schaersvoo 3674
var read_canvas%d;\
3675
var set_clock;\
3676
var clear_draw_area%d;\
3677
var update_draw_area%d;\
14038 schaersvoo 3678
var place_image_on_canvas;\
11806 schaersvoo 3679
var draw_boxplot;\
3680
var redraw_all%d;\
3681
var userdraw_primitive;\n\
13970 obado 3682
var wims_canvas_function%d = function(){\n/* common used stuff */\n\
11806 schaersvoo 3683
var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
3684
var xsize = %d;\
3685
var ysize = %d;\
3686
var precision = 100;\
3687
var canvas_div = document.getElementById(\"canvas_div%d\");\
3688
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;};\
3689
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;};\
3690
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);};};\
3691
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);};};\
3692
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);};};\
3693
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);};};\
3694
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
3695
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
3696
function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
3697
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) ));};\
3698
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;};\
3699
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;};\
14044 schaersvoo 3700
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));var snap_x = 1;var snap_y = 1;\
11806 schaersvoo 3701
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
11890 schaersvoo 3702
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
14044 schaersvoo 3703
function multisnap_check(x,y,snap){switch(snap){case 1:return [snap_to_x(x),snap_to_y(y)];break;case 2:return [snap_to_x(x),y];break;case 3:return [x,snap_to_y(y)];break;case 4:return snap_to_points(x,y);break;default: return [x,y];break;};};\
11806 schaersvoo 3704
var xlogbase = 10;\
3705
var ylogbase = 10;\
3706
var use_xlogscale = 0;\
3707
var use_ylogscale = 0;\
11891 schaersvoo 3708
var x_strings = {};var x_strings_up = [];\
11806 schaersvoo 3709
var y_strings = null;\
3710
var use_pan_and_zoom = 0;\
3711
var use_jsmath = 0;\
3712
var xstart = 0;\
3713
var ystart = 0;\
3714
var unit_x=\" \";\
3715
var unit_y=\" \";\
14038 schaersvoo 3716
var external_canvas = create_canvas%d(%d,xsize,ysize);",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);
11806 schaersvoo 3717
/* default add the drag code : nearly always used ...*/
3718
  add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
3719
 
3720
            break;
3721
 
3722
 
3723
        case SEGMENT:
7614 schaersvoo 3724
        /*
11806 schaersvoo 3725
        @ segment x1,y1,x2,y2,color
3726
        @ alternative : seg
3727
        @ draw a line segment between points (x1:y1)--(x2:y2) in color 'color'
3728
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
14061 schaersvoo 3729
        @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green
3730
        @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green
7614 schaersvoo 3731
        */
11806 schaersvoo 3732
            for(i=0;i<5;i++) {
7614 schaersvoo 3733
                switch(i){
11806 schaersvoo 3734
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
3735
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
3736
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
3737
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
3738
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
3739
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 3740
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3741
                        if(onclick > 0){click_cnt++;}
3742
                        /* click_cnt++; */
3743
                        reset();
3744
                        break;
3745
                    default: break;
7614 schaersvoo 3746
                }
3747
            }
3748
            break;
10953 bpr 3749
 
11806 schaersvoo 3750
        case SEGMENTS:
9213 schaersvoo 3751
        /*
11806 schaersvoo 3752
        @ segments color,x1,y1,x2,y2,...,x_n,y_n
3753
        @ alternative : segs
3754
        @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color 'color'
14038 schaersvoo 3755
        @ use command 'linewidth int'  to adust size
11806 schaersvoo 3756
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12111 schaersvoo 3757
        @%segments_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1
3758
        @%segments_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segments green,1,1,3,3,0,0,-3,3,1,1,4,-1,-5,5,-3,-1
9213 schaersvoo 3759
        */
11806 schaersvoo 3760
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3761
            fill_color = stroke_color;
3762
            i=0;
3763
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3764
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 3765
                if(i%2 == 0 ){
3766
                    double_data[i] = get_real(infile,0); /* x */
3767
                }
3768
                else
3769
                {
3770
                    double_data[i] = get_real(infile,1); /* y */
3771
                }
3772
                i++;
3773
            }
3774
            decimals = find_number_of_digits(precision);
3775
            for(c = 0 ; c < i-1 ; c = c+4){
14045 schaersvoo 3776
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 3777
                if(onclick > 0){click_cnt++;}
3778
                /* click_cnt++;*/
3779
            }
3780
            reset();
9213 schaersvoo 3781
            break;
11806 schaersvoo 3782
 
3783
        case SETLIMITS:
9213 schaersvoo 3784
        /*
11806 schaersvoo 3785
            @ setlimits
3786
            @ keyword : if set, it will produce 4 inputfields for 'xmin,xmax,ymin,ymax' and an 'ok' button
3787
            @ may be used for inputfield based zooming / panning
3788
            @ may be styled using command <a href="#inputstyle">inputstyle</a>
3789
            @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to 'xlabel' etc
3790
            @ note:the input value will not be checked on validity
12107 schaersvoo 3791
            @%setlimits%size 400,400%xrange -10,10%yrange -10,10%precision 1%xlabel T%ylabel H%axis%axisnumbering%grid 2,2,grey,2,2,5,grey%precision 100%multistrokecolors red,green,blue,orange%multilinewidth 1,1,2,2%multistrokeopacity 0.6,0.7,0.8,0.9%jsplot red,1/x,-1,x,1/(x-3),1/(x+3)%setlimits
9213 schaersvoo 3792
        */
11806 schaersvoo 3793
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
3794
            add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
3795
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
3796
            use_pan_and_zoom = TRUE;
3797
            done = TRUE;
9213 schaersvoo 3798
            break;
11806 schaersvoo 3799
 
3800
        case SETPIXEL:
9213 schaersvoo 3801
        /*
11806 schaersvoo 3802
        @ setpixel x,y,color
3803
        @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
3804
        @ pixels can <b>not</b> be dragged or clicked
3805
        @ "pixelsize = 1" may be changed by command "pixelsize int"
12107 schaersvoo 3806
        @%setpixel%size 400,400%xrange -10,10%yrange -10,10%setpixel 1,1,red%pixelsize 2%setpixel 2,2,green%pixelsize 3%setpixel 3,3,blue%
9213 schaersvoo 3807
        */
11806 schaersvoo 3808
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
3809
            for(i=0;i<3;i++){
3810
                switch(i){
3811
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
14032 schaersvoo 3812
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
11806 schaersvoo 3813
                    case 2: stroke_color = get_color(infile,1);
3814
                           string_length = snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3815
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3816
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3817
                           add_to_buffer(tmp_buffer);
3818
                           break;
3819
                    default:break;
3820
                }
3821
            }
3822
            reset();
3823
        break;
3824
 
3825
 
3826
        case SLIDER:
9213 schaersvoo 3827
        /*
11806 schaersvoo 3828
        @ slider start_value,end_value,width px,height px,<em>type</em>,label
3829
        @ <em>type</em> may be : xy,x,y,angle
3830
        @ 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
3831
        @ if a unit (or something like that...) for x/y-value display is needed, use commands 'xunit' and / or 'yunit'
3832
        @ 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
3833
        @ use command 'slider' before draggable/clickable objects.
3834
        @ 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>
3835
        @ no slider for a math function, these can be traced using command 'trace_jscurve some_function_in_x'
3836
        @ 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'
3837
        @ amount of sliders is not limited.
3838
        @ javascript:read_dragdrop(); will return an array with 'object_number:slider_value'
3839
        @ type=xy: will produce a 2D 'slider' [rectangle width x heigh px] in your web page
3840
        @ every draggable object may have its own slider (no limit in amount of sliders)
3841
        @ label: some slider text
3842
        @ use fillcolor for slider ball
3843
        @ use strokecolor for slider bar
3844
        @ use fontfamily / fontcolor to set used fonts
3845
        @ use opacity (only fill opacity will be used) to set transparency
3846
        @ the slider canvas will be added to the 'tooltip div' : so incompatible with command tooltip ; setlimits etc
13950 schaersvoo 3847
        @%slider_angle%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue
3848
        @%slider_x%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,x,move arrow%arrow 0,0,4.5,0,8,red%opacity 200,100%frect -4,4,1,-1,blue%killslider%frect -4,4,1,-1,blue%display x,red,12
13951 schaersvoo 3849
        @%slider_x_y_angle%size 300,300%xrange -5,5%yrange -5,5%grid 1,1,grey%linewidth 3%fillcolor orange%strokecolor blue%slider 0,2*pi,300,30,angle degrees,Rotate arrow%arrow 0,0,4.5,0,8,red%killslider%opacity 200,100%slider -2,2,300,30,x,move blue rectangle%frect -4,4,1,-1,blue%killslider%slider -2,2,300,30,y,move green rectangle%frect -4,4,1,-1,green
9213 schaersvoo 3850
        */
11806 schaersvoo 3851
            slider_cnt++;/* slider starts at 1 */
3852
            for(i=0; i<6 ; i++){
3853
                switch(i){
3854
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
3855
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
3856
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
3857
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
3858
                    case 4: temp = get_string_argument(infile,0); /* type : xy,x,y,angle */
3859
                            if(strstr(temp,"xy")!= 0){
3860
                                slider = 4;
3861
                            }
3862
                            else
3863
                            {
3864
                                if(strstr(temp,"x") != 0){
3865
                                    slider = 1;
3866
                                }
3867
                                else
3868
                                {
3869
                                    if(strstr(temp,"y") != 0){
3870
                                        slider = 2;
3871
                                    }
3872
                                    else
3873
                                    {
3874
                                        if(strstr(temp,"angle") != 0){ /* angle diplay radian */
3875
                                            slider = 3;
3876
                                        }
3877
                                        else
3878
                                        {
3879
                                            canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
3880
                                        }
3881
                                    }
3882
                                }
3883
                            }
3884
                            if(strstr(temp,"display")!=0){
3885
                                if( slider == 4 ){ /* show x:y */
3886
                                    use_slider_display = 1; /* show x xy values in canvas window */
3887
                                }
3888
                                else
3889
                                {
3890
                                    if( slider == 1 ){ /* show only x -values */
3891
                                     use_slider_display = 10;
3892
                                    }
3893
                                    else
3894
                                    {
3895
                                     use_slider_display = 11; /* show only y -values*/
3896
                                    }
3897
                                }
3898
                            }
3899
                            else
3900
                            {
3901
                                if(strstr(temp,"degree")!= 0){
3902
                                    use_slider_display = 2; /* show angle values in canvas window */
3903
                                }
3904
                                else
3905
                                {
3906
                                    if(strstr(temp,"radian")!=0){
3907
                                        use_slider_display = 3; /* show radian values in canvas window */
3908
                                    }
3909
                                }
3910
                            }
3911
                            if(use_slider_display != 0 && slider_cnt == 1){ /*add just once the display js-code */
3912
                                add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
3913
                            }
3914
                            if(strstr(temp,"fun")!= 0){
3915
                                if( use_js_math == FALSE){/* add this stuff only once...*/
3916
                                    add_to_js_math(js_include_file); use_js_math = TRUE;
3917
                                }
3918
                                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);
3919
                                slider_function_x = "x";slider_function_y = "y";/* reset the functions for next slider...*/
3920
                            }
3921
                            else
3922
                            {
3923
                                fprintf(js_include_file,"var slider_function%d = {x:'x',y:'y'};",slider_cnt);
3924
                                /* we must define these, otherwise 'use stict' will cause an error */
3925
                            }
3926
                    break;
3927
                    case 5: /* some string used for slider description  */
3928
                            if(slider == 4){
3929
                                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);
3930
                            }
3931
                            else
3932
                            {
3933
                                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);
3934
                            }
3935
                    break;
3936
                }
3937
             }
9213 schaersvoo 3938
            break;
11806 schaersvoo 3939
        case SLIDER_X:
9213 schaersvoo 3940
        /*
11806 schaersvoo 3941
         @ sliderfunction_x some_function_in_x
3942
         @ default value "x"
3943
         @ the x-value of the slider object(s) will be calculated with this function.
3944
         @ default is the x-slider value itself
3945
         @ only used by command 'slider'
3946
         @ define before a slider command !
9213 schaersvoo 3947
        */
11806 schaersvoo 3948
         slider_function_x = get_string(infile,1);
3949
        break;
3950
        case SLIDER_Y:
3951
         slider_function_y = get_string(infile,1);
3952
         /*
3953
         @ sliderfunction_y some_function_in_y
3954
         @ default value "y"
3955
         @ the y-value of the slider object(s) will be calculated with this function.
3956
         @ only used by command 'slider'
3957
         @ define before a slider command !
3958
         */
3959
        break;
3960
        case SGRAPH:
3961
        /*
3962
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
3963
         @ primitive implementation of a 'broken scale' graph...
3964
         @ 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 />
12111 schaersvoo 3965
         @%sgraph%size 400,400%xrange 0,10000%yrange 0,100%sgraph 9000,50,100,10,4,4,grey,blue%userinput_xy%linewidth 2%userdraw segments,red%precision 0%mouse blue,22
11806 schaersvoo 3966
        */
3967
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
3968
            for(i = 0 ; i < 8 ;i++){
3969
                switch(i){
3970
                    case 0:double_data[0] = get_real(infile,0);break;
3971
                    case 1:double_data[1] = get_real(infile,0);break;
3972
                    case 2:double_data[2] = get_real(infile,0);break;
3973
                    case 3:double_data[3] = get_real(infile,0);break;
3974
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
3975
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
3976
                    case 6:stroke_color = get_color(infile,0);break;
3977
                    case 7:font_color = get_color(infile,1);
3978
                    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);
3979
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
3980
                    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);
3981
                    add_to_buffer(tmp_buffer);
3982
                    break;
3983
                    default:break;
3984
                }
3985
            }
3986
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
9213 schaersvoo 3987
            break;
11806 schaersvoo 3988
 
3989
        case SNAPTOFUNCTION:
9213 schaersvoo 3990
        /*
11806 schaersvoo 3991
        @ snaptofunction some_function_in_x,some_funtion_in_y
3992
        @ alternative : snaptofun some_function_in_x,some_funtion_in_y
3993
        @ the next object will snap to the calculated values
13987 bpr 3994
        @ note: snaptopfun is probably not really useful feature...
11806 schaersvoo 3995
        @ if you want only modification of y-values,just use: snaptofunction x,5*sin(1/y)
3996
        @ if you want only modification of x-values,just use: snaptofunction 5*sin(1/x),y
3997
        @ for now only one instance of 'snaptofunction' is allowed
3998
        @ use rawmath on your functions: no validity checking is done by wims !
11997 schaersvoo 3999
        @ note: switching x and y coordinates?<br />snaptofunction y,x
13960 bpr 4000
        @%snaptofunction_1%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction x,5*sin(x)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,5*sin(x)%xunit = x-value%display x,blue,22
4001
        @%snaptofunction_2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 100%snaptofunction y^2-9,y%#snaptofunction y^2-9,abs(y)%linewidth 3%crosshairsize 6%userdraw crosshairs,red%linewidth 2%curve blue,sqrt(x+9)%curve blue,-1*sqrt(x+9)%yunit = y-value%display y,blue,22
9213 schaersvoo 4002
        */
11806 schaersvoo 4003
        temp = get_string_argument(infile,0);
14038 schaersvoo 4004
        use_snap = 2;
11806 schaersvoo 4005
        if( use_js_math == FALSE){/* add this stuff only once...*/
4006
            add_to_js_math(js_include_file); use_js_math = TRUE;
4007
        }
4008
        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));
4009
        break;
4010
        case SNAPTOPOINTS:
4011
        /*
4012
        @ snaptopoints x1,y1,x2,y2,x3,y3....
4013
        @ a userdraw object will snap to these points.
4014
        @ the array size (e.g. the number of points) of command 'snaptopoints' is limited by constant MAX_INT (canvasdraw.h)
13982 bpr 4015
        @ a draggable object (use command "drag  x|y|xy") will snap to the closed of these points when dragged (mouseup)
11806 schaersvoo 4016
        @ other options: use keyword "snaptogrid", "xsnaptogrid" or "ysnaptogrid"
13950 schaersvoo 4017
        @%snaptopoints%size 400,400%xrange -5,5%yrange -5,5%snaptopoints -1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%linewidth 2%points red,-1,-3,-1,-2,-1,0,-1,1,-1,2,-1,3,1,-3,1,-2,1,-1,1,0,1,1,1,2,1,3%userdraw arrows,red
11806 schaersvoo 4018
        */
4019
            i = 0;
14038 schaersvoo 4020
            use_snap = 4;
11806 schaersvoo 4021
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 4022
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 4023
                if(i%2 == 0 ){
4024
                    double_data[i] = get_real(infile,0); /* x */
4025
                }
4026
                else
4027
                {
4028
                    double_data[i] = get_real(infile,1); /* y */
4029
                }
4030
                i++;
4031
            }
4032
            decimals = find_number_of_digits(precision);
14044 schaersvoo 4033
            fprintf(js_include_file,"function 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;};function 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)];};",(int) (0.5*i),double_xy2js_array(double_data,i,decimals));
11806 schaersvoo 4034
        break;
4035
 
4036
        case SNAPTOGRID:
4037
        /*
4038
         @ snaptogrid
4039
         @ keyword (no arguments required)
14038 schaersvoo 4040
         @ a draggable object (use command "drag  x|y|xy") will snap to the given grid when dragged (mouseup)
11806 schaersvoo 4041
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
4042
         @ if no grid is defined ,points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
4043
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
4044
         @ 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 />
12311 schaersvoo 4045
         @%snaptogrid_1%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,2,2,6,grey%linewidth 2%snaptogrid%userdraw crosshairs,blue%mouse red,22
4046
         @%snaptogrid_2%size 400,400%xrange -5,5%yrange -5,5%axis%axisnumbering%precision 1%grid 1,1,grey,4,1,6,grey%linewidth 1%snaptogrid%userdraw crosshairs,blue%mouse red,22
11806 schaersvoo 4047
        */
14038 schaersvoo 4048
        use_snap = 1;
11806 schaersvoo 4049
        break;
4050
 
4051
        case SQUARE:
4052
        /*
4053
        @ square x,y,side (px) ,color
4054
        @ draw a square with left top corner (x:y) with side 'side' in color 'color'
4055
        @ use command 'fsquare x,y,side,color' for a filled square
14038 schaersvoo 4056
        @ use command/keyword  <a href='#filled'>'filled'</a> before command 'square x,y,side,color'
11806 schaersvoo 4057
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 4058
        @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
11806 schaersvoo 4059
        */
11991 schaersvoo 4060
            for(i=0;i<4;i++){
11806 schaersvoo 4061
                switch(i){
4062
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
4063
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
11991 schaersvoo 4064
                    case 2:double_data[2] = get_real(infile,0);break; /* width in px */
4065
                    case 3:stroke_color = get_color(infile,1);/* name or hex color */
4066
                           decimals = find_number_of_digits(precision);
4067
                           double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
4068
                           double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
14045 schaersvoo 4069
                           fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11991 schaersvoo 4070
                           if(onclick > 0){click_cnt++;}/* click_cnt++; */
4071
                           reset();break;
4072
                    default: break;
11806 schaersvoo 4073
                }
4074
            }
9213 schaersvoo 4075
            break;
13829 bpr 4076
 
11806 schaersvoo 4077
        case STATUS:
9213 schaersvoo 4078
        /*
11806 schaersvoo 4079
        @ status
4080
        @ keyword
4081
        @ alernative : nostatus
4082
        @ used to override the effects of "status=done" in wims (answer.phtml)
4083
        @ affects 'readonly' in inputfields / textarea's in canvasimage and all userdraw based commands
13948 schaersvoo 4084
        @ e.g.: if keyword 'status' is set, the pupil will be able to modify the canvas when the 'wims &#36;status variable' is set to 'done'
9213 schaersvoo 4085
        */
11806 schaersvoo 4086
 
4087
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
9213 schaersvoo 4088
            break;
11806 schaersvoo 4089
 
4090
        case STRING:
9213 schaersvoo 4091
        /*
11806 schaersvoo 4092
         @ string color,x,y,the text string
4093
         @ may be set "onclick" or "drag xy"
4094
         @ unicode supported: string red,0,0,\\u2232
4095
         @ use a command like 'fontfamily italic 24px Ariel' <br />to set fonts on browser that support font change
12311 schaersvoo 4096
         @%string%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,-3,red%crosshair 3,3,blue%string red,-3,-3,Hello World%fontfamily Italic 18px Ariel%string red,3,3,Hello World%fontfamily 22pt STIX%string black,-10,8,\\u03B1 \\u03B2 \\u03B3 \\u03B4 \\u03B5 \\u03B6 \\u03B7 \\u03B8 \\u03B9 \\u03BA \\u03BB \\u03BC \\u03BD \\u03BE \\u03BF
9213 schaersvoo 4097
        */
11806 schaersvoo 4098
            for(i=0;i<5;i++){
4099
                switch(i){
4100
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
4101
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
4102
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
4103
                    case 3: decimals = find_number_of_digits(precision);
4104
                        temp = get_string_argument(infile,1);
4105
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 4106
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 4107
                        if(onclick > 0){click_cnt++;}
14038 schaersvoo 4108
                        onclick = 0;
4109
                        use_offset = 0;
4110
                        reset();;
11806 schaersvoo 4111
                        break;
4112
                    default:break;
4113
                }
9213 schaersvoo 4114
            }
4115
            break;
11806 schaersvoo 4116
 
4117
        case STRINGUP:
9213 schaersvoo 4118
        /*
11806 schaersvoo 4119
         @ stringup color,x,y,rotation_degrees,the text string
12000 schaersvoo 4120
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translation matrix...mouse incompatible)
11806 schaersvoo 4121
         @ unicode supported: stringup red,0,0,45,\\u2232
4122
         @ use a command like 'fontfamily bold 34px Courier' <br />to set fonts on browser that support font change
12000 schaersvoo 4123
         @ you could use keyword <a href='#yoffset'>yoffset</a> to -sometimes- do a small correction of text placement under/above a point<br />(e.g. text &amp; point have thesame coordinates)
12311 schaersvoo 4124
         @%stringup%size 400,400%xrange -10,10%yrange -10,10%fontfamily 14px Ariel%crosshair -3,0,red%crosshair 3,0,blue%stringup red,-3,0,-90,Hello World%stringup red,-3,0,-45,Hello World%stringup red,-3,0,45,Hello World%stringup red,-3,0,90,Hello World%stringup blue,3,0,-90,Hello World%stringup blue,3,0,-45,Hello World%stringup blue,3,0,45,Hello World%stringup blue,3,0,90,Hello World
11806 schaersvoo 4125
 
9213 schaersvoo 4126
        */
11806 schaersvoo 4127
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library : rotate / mouse issues */
4128
            for(i=0;i<6;i++){
4129
                switch(i){
4130
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
4131
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
4132
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
4133
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
4134
                    case 4: decimals = find_number_of_digits(precision);
4135
                            temp = get_string_argument(infile,1);
11811 schaersvoo 4136
                            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 4137
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11811 schaersvoo 4138
                            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 4139
                            add_to_buffer(tmp_buffer);
14038 schaersvoo 4140
                            use_offset=0;
4141
                            reset();
11806 schaersvoo 4142
                            break;
4143
                    default:break;
4144
                }
9213 schaersvoo 4145
            }
4146
            break;
11767 schaersvoo 4147
 
11806 schaersvoo 4148
        case STYLE:
11767 schaersvoo 4149
        /*
11806 schaersvoo 4150
         @ highlight color,opacity,linewidth
4151
         @ NOT IMPLEMENTED
4152
         @ use command "onclick" : when the object receives a userclick it will increase its linewidth
11767 schaersvoo 4153
        */
4154
            break;
11806 schaersvoo 4155
 
4156
 
4157
        case STROKECOLOR:
9213 schaersvoo 4158
        /*
11806 schaersvoo 4159
        @ strokecolor colorname or #hex
4160
        @ to be used for commands that do not supply a color argument (like command 'linegraph')
9213 schaersvoo 4161
        */
11806 schaersvoo 4162
            stroke_color = get_color(infile,1);
9213 schaersvoo 4163
            break;
11806 schaersvoo 4164
 
4165
        case FLY_TEXT:
9213 schaersvoo 4166
        /*
11806 schaersvoo 4167
        @ text fontcolor,x,y,font,text_string
4168
        @ font may be described by keywords : giant,huge,normal,small,tiny
4169
        @ use command 'fontsize' to increase base fontsize for these keywords
4170
        @ may be set "onclick" or "drag xy"
4171
        @ backwards compatible with flydraw
4172
        @ unicode supported: text red,0,0,huge,\\u2232
4173
        @ use command 'string' combined with 'fontfamily' for a more fine grained control over html5 canvas text element
14038 schaersvoo 4174
        @ 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.
12311 schaersvoo 4175
        @%text%size 400,400%xrange -10,10%yrange -10,10%fontsize 14%onclick%drag xy%text green,-4,-4,small,Hello World%drag xy%text red,-4,-2,large,Hello World%drag xy%text blue,-4,0,huge,Hello World%drag xy%text green,-4,3,giant,Hello World%drag xy
9213 schaersvoo 4176
        */
11806 schaersvoo 4177
            for(i = 0; i < 5 ;i++){
4178
                switch(i){
4179
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
4180
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
4181
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
4182
                    case 3: fly_font = get_string_argument(infile,0);
4183
                            if(strcmp(fly_font,"giant") == 0){
4184
                                fly_font_size = (int)(font_size + 24);
4185
                            }
4186
                            else
4187
                            {
4188
                                if(strcmp(fly_font,"huge") == 0){
4189
                                    fly_font_size = (int)(font_size + 14);
4190
                                }
4191
                                else
4192
                                {
4193
                                    if(strcmp(fly_font,"large") == 0){
4194
                                        fly_font_size = (int)(font_size + 6);
4195
                                        }
4196
                                        else
4197
                                        {
4198
                                            if(strcmp(fly_font,"small") == 0){
4199
                                                fly_font_size = (int)(font_size - 4);
4200
                                                if(fly_font_size<0){fly_font_size = 8;}
4201
                                        }
4202
                                    }
4203
                                }
4204
                            }
4205
                            break;
4206
                    case 4:
4207
                        temp = get_string_argument(infile,1);
4208
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 4209
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 4210
                        if(onclick > 0){click_cnt++;}
14038 schaersvoo 4211
                        onclick=0;
4212
                        use_offset = 0;
11806 schaersvoo 4213
                        reset();
4214
                        break;
4215
                    default:break;
4216
                }
10953 bpr 4217
            }
9213 schaersvoo 4218
            break;
11806 schaersvoo 4219
        case TEXTAREA:
9289 schaersvoo 4220
        /*
11806 schaersvoo 4221
         @ textarea x,y,cols,rows,readonly,value
4222
         @ may be further controlled by <a href="#inputstyle">"inputstyle"</a>
14038 schaersvoo 4223
         @ if "&#36;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>
11806 schaersvoo 4224
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
4225
         @ keyword 'xoffset | centered' is not active for commande 'textarea'
12107 schaersvoo 4226
         @%textarea%size 400,400%xrange -10,10%yrange -10,10%inputstyle color:red;background-color:lightblue;font-size:14px;text-align:center%textarea -3,-2,6,3,1,?%inputstyle color:blue;background-color:yellow;font-size:14px;text-align:center%textarea 0,-2,8,2,1,?
9289 schaersvoo 4227
        */
11806 schaersvoo 4228
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
4229
            for(i = 0 ; i<6;i++){
9289 schaersvoo 4230
                switch(i){
11806 schaersvoo 4231
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
4232
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
4233
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
4234
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
4235
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
4236
                    case 5: temp = get_string_argument(infile,1);
4237
                            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);
4238
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
4239
                            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);
4240
                            add_to_buffer(tmp_buffer);
4241
                            input_cnt++;break;
9289 schaersvoo 4242
                    default: break;
4243
                }
4244
            }
11806 schaersvoo 4245
            if(reply_format == 0 ){reply_format = 15;}
4246
            reset();
9289 schaersvoo 4247
            break;
11806 schaersvoo 4248
 
11830 schaersvoo 4249
        case TEXTFILL:
4250
        /*
4251
        @ textfill x0,y0,color,some_text
4252
        @ x0,y0 in xrange / yrange
4253
        @ color will be used for the font color
4254
        @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
13829 bpr 4255
        @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
13951 schaersvoo 4256
        @%textfill%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%fontfamily 24pt Ariel%circles red,0,0,3,3,3,6%textfill 4,4,blue,HELLO WORLD
11830 schaersvoo 4257
        */
4258
 
4259
            js_function[DRAW_TEXTFILL] = 1;
4260
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
4261
             js_function[DRAW_FILLTOBORDER] = 1;
4262
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
4263
            }
4264
            decimals = find_number_of_digits(precision);
4265
            for(i=0;i<4;i++){
4266
                switch(i){
4267
                    case 0: double_data[0] = get_real(infile,0); break; /* x in px */
4268
                    case 1: double_data[1] = get_real(infile,0); break; /* y in py */
13829 bpr 4269
                    case 2: font_color = get_color(infile,0); break;
11830 schaersvoo 4270
                    case 3: temp = get_string(infile,1);
4271
                    string_length = snprintf(NULL,0,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp);
4272
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
4273
                    snprintf(tmp_buffer,string_length,"draw_textfill(%d,%*.f,%*.f,'%s','%s',%d,%d,'%s',false); ",FILL_CANVAS+fill_cnt,decimals,double_data[0],decimals,double_data[1],font_color,font_family,xsize,ysize,temp);
4274
                    add_to_buffer(tmp_buffer);
4275
                    fill_cnt++;
4276
                    break;
4277
                    default:break;
4278
                }
4279
            }
4280
            reset();
4281
        break;
4282
 
4283
 
11806 schaersvoo 4284
        case FLY_TEXTUP:
9289 schaersvoo 4285
        /*
11806 schaersvoo 4286
         @ textup fontcolor,x,y,font,text_string
4287
         @ can <b>not</b> be set "onclick" or "drag xy" (because of translaton matrix...mouse incompatible)
4288
         @ font may be described by keywords : giant,huge,normal,small,tiny
4289
         @ use command 'fontsize' to increase base fontsize for the keywords
4290
         @ backwards compatible with flydraw
4291
         @ unicode supported: textup red,0,0,huge,\\u2232
4292
         @ use command 'stringup' and 'fontfamily' for a more fine grained control over html5 canvas text element
14038 schaersvoo 4293
         @ 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 4294
        */
11806 schaersvoo 4295
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
4296
            for(i = 0; i<5 ;i++){
9289 schaersvoo 4297
                switch(i){
11806 schaersvoo 4298
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
4299
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
4300
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
4301
                    case 3: fly_font = get_string_argument(infile,0);
4302
                            if(strcmp(fly_font,"giant") == 0){
4303
                                fly_font_size = (int)(font_size + 24);
4304
                            }
4305
                            else
4306
                            {
4307
                                if(strcmp(fly_font,"huge") == 0){
4308
                                    fly_font_size = (int)(font_size + 14);
4309
                                }
4310
                                else
4311
                                {
4312
                                    if(strcmp(fly_font,"large") == 0){
4313
                                        fly_font_size = (int)(font_size + 6);
4314
                                        }
4315
                                        else
4316
                                        {
4317
                                            if(strcmp(fly_font,"small") == 0){
4318
                                                fly_font_size = (int)(font_size - 4);
4319
                                                if(fly_font_size<0){fly_font_size = 8;}
4320
                                        }
4321
                                    }
4322
                                }
4323
                            }
4324
                            break;
4325
                    case 4:
9289 schaersvoo 4326
                    decimals = find_number_of_digits(precision);
11806 schaersvoo 4327
                    temp = get_string_argument(infile,1);
11811 schaersvoo 4328
                    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 4329
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11811 schaersvoo 4330
                    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 4331
                    add_to_buffer(tmp_buffer);
14038 schaersvoo 4332
                    reset();use_offset = 0;
9289 schaersvoo 4333
                    break;
11806 schaersvoo 4334
                    default:break;
4335
                }
4336
            }
4337
            break;
4338
 
4339
 
4340
        case TRACE_JSCURVE:
4341
        /*
4342
         @ trace_jscurve some_math_function
4343
         @ will use a crosshair to trace the jsmath curve
4344
         @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
4345
         @ 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
4346
         @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
4347
         @ use commands linewidth,strokecolor,crosshairsize to adjust the corsshair.
4348
         @ 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...
13948 schaersvoo 4349
         @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
13959 bpr 4350
         @%trace_jscurve%size 400,400%xrange -10,10%yrange -10,10%precision 0%axis%axisnumbering%grid 2,2,grey,2,2,5,gray%recision 100%inputstyle color:blue;%linewidth 4%crosshairsize 8%trace_jscurve 5*sin(0.1*x^2)%linewidth 1%jsplot red,5*sin(0.1*x^2)%#only one curve can be traced
11806 schaersvoo 4351
        */
4352
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
4353
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4354
            if( use_js_math == FALSE){
4355
                add_to_js_math(js_include_file);
4356
                use_js_math = TRUE;
4357
            }
4358
            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);
4359
            break;
4360
 
4361
 
4362
        case TRANGE:
4363
        /*
4364
        @ trange tmin,tmax
4365
        @ alternative : ranget
4366
        @ default -2,2
4367
        */
4368
            use_parametric = TRUE;
4369
            for(i = 0 ; i<2; i++){
4370
                switch(i){
4371
                    case 0: tmin = get_real(infile,0);break;
4372
                    case 1: tmax = get_real(infile,1);break;
9289 schaersvoo 4373
                    default: break;
4374
                }
4375
            }
11806 schaersvoo 4376
            if(tmin >= tmax ){canvas_error(" trange is not OK : tmin &lt; tmax!\n");}
9289 schaersvoo 4377
            break;
11806 schaersvoo 4378
        case TRANSLATION:
4379
        /*
4380
         @ translation tx,ty
4381
         @ alternative : translate
4382
         @ will translate the next objects tx in xrange and ty in yrange
4383
         @ use command 'killtranstation' to end the command
13958 schaersvoo 4384
         @%translation%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%fillpattern grid%ftriangle -6,6,8,6,5,1,blue%translation 2,2%ftriangle -6,6,8,6,5,1,red
11806 schaersvoo 4385
        */
4386
            for(i = 0 ; i<2;i++){
4387
                switch(i){
4388
                    case 0: double_data[0] = get_real(infile,0);break;
4389
                    case 1: double_data[1] = get_real(infile,1);
4390
                        use_affine = TRUE;
4391
                        decimals = find_number_of_digits(precision);
4392
                        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));
4393
                        check_string_length(string_length);affine_matrix = my_newmem(string_length+1);
4394
                        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));
4395
                        break;
4396
                    default: break;
4397
                }
4398
            }
4399
        break;
4400
 
4401
        case TRIANGLE:
4402
        /*
4403
         @ triangle x1,y1,x2,y2,x3,y3,color
4404
         @ use ftriangle or keyword <a href='#filled'>'filled'</a> for a solid triangle
4405
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
13948 schaersvoo 4406
         @%triangle%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%opacity 250,150%drag xy%triangle 0,0,-4,4,6,8,red%drag xy%ftriangle 0,0,-4,-4,6,-8,red%fillpattern grid%drag xy%ftriangle -6,6,8,6,5,1,blue
11806 schaersvoo 4407
        */
4408
            for(i=0;i<7;i++){
4409
                switch(i){
4410
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
4411
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
4412
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
4413
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
4414
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
4415
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
4416
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
4417
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 4418
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 4419
                        if(onclick > 0){click_cnt++;}
4420
                        /* click_cnt++;*/
4421
                        reset();
4422
                        break;
4423
                    default: break;
4424
                }
4425
            }
4426
            break;
4427
        case TRIANGLES:
4428
        /*
4429
         @ triangles color,x1,y1,x2,y2,x3,y3,...
4430
         @ use ftriangles or keyword <a href='#filled'>'filled'</a> for solid triangles
4431
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
13948 schaersvoo 4432
         @%triangles%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%onclick%triangles red,0,0,-4,4,6,8,0,0,-4,-4,6,-8,-6,6,8,6,5,1%# the same as 3 calls to command triangle
11806 schaersvoo 4433
        */
4434
            stroke_color = get_color(infile,0);/* name or hex color */
4435
            i = 0;
4436
            decimals = find_number_of_digits(precision);
4437
            while( ! done ){
11997 schaersvoo 4438
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 4439
                double_data[0] = get_real(infile,0); /* x1 */
4440
                double_data[1] = get_real(infile,0); /* y1 */
4441
                double_data[2] = get_real(infile,0); /* x2 */
4442
                double_data[3] = get_real(infile,0); /* y2 */
4443
                double_data[4] = get_real(infile,0); /* x3 */
4444
                double_data[5] = get_real(infile,1); /* y3 */
14045 schaersvoo 4445
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 4446
                if(onclick > 0){click_cnt++;}
4447
                i = i + 6;
4448
            }
4449
            reset();
4450
            break;
4451
        case USERBOXPLOT:
4452
        /*
4453
         @ userboxplot
4454
         @ keyword, no arguments
4455
         @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
4456
         @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the 'draw_boxplot' function
4457
         @ 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)
4458
        */
4459
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
4460
            fprintf(js_include_file,"var boxplot_source = 3;\n");
4461
            js_function[DRAW_JSBOXPLOT] = 2;
4462
        break;
4463
 
4464
        case USERBOXPLOTDATA:
4465
        /*
4466
         @ userboxplotdata
4467
         @ keyword, no arguments
4468
         @ use before command <a href="#boxplot">'boxplot x_or_y,box-height_or_box-width,x_or_y-position'</a>
4469
         @ if set, the student will have to generate some statistical data. These data should be put in a named array "student_boxplot_data"
4470
         @ "min,Q1,median,Q3,max" are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
4471
         @ see command <a href="#userboxplot">'userboxplot'</a> for calling 'draw_boxplot()'
4472
        */
4473
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
4474
            fprintf(js_include_file,"var boxplot_source = 2;\n");
4475
            js_function[DRAW_JSBOXPLOT] = 1;
4476
 
4477
        break;
4478
 
7614 schaersvoo 4479
        case USERDRAW:
4480
        /*
4481
        @ userdraw object_type,color
9213 schaersvoo 4482
        @ only a single object_type is allowed.
14044 schaersvoo 4483
        @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">'multidraw'</a>
14038 schaersvoo 4484
        @ 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>curvedarrow</li><li>curvedarrows</li><li>curvedarrow2</li><li>curvedarrows2</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 color<br />multiple areas may be selected <br />multiple colors may be provided using commands <a href='#colorpalette'>colorpalette color1,color2,color3,...</a> or <a href='#multifillcolors'>multifillcolors color1,color2,color_3,...</a> use <a href='#replyformat'>replyformat 10</a> for checking the user click color ... reply=x1:y1:color1,x2:y2:color2...<br/>attention: this will <b>not</b> work for pattern filling, because the pattern image is only generated once and after creation can not be changed !<br />the opacity of this image on a separate canvas is set to 0.01 and not 0 (!!)...in the 'fill algorithm' the opacity of the matching pixels is set to 1</li><li>dotfill : fill the clicked area with a dot pattern; use command linewidth to change dot size</li><li>diamondfill : fill the clicked area with a diamond pattern</li><li>hatchfill : fill the clicked area with a hatch pattern</li><li>gridfill : fill the clicked area with a grid pattern</li><li>textfill: fill the clicked area with a repeating string<br />userdraw textfill,blue,some_text<br />use command <a href="#fontfamily">fontfamily</a> to adjust text style and size</li><li>'clickfill | pattern filling' in general:<br />the clicks may be set <a href="#snaptogrid">'snaptogrid'</a><br />can be used together with command <a href="#floodfill">'floodfill' or 'fill'</a><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_canvas() 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)</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>
13948 schaersvoo 4485
        @ note: mouselisteners are only active if "&#36;status != done " (eg only drawing in an active/non-finished exercise) <br /> to overrule use command/keyword "status" (no arguments required)
13951 schaersvoo 4486
        @ 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 on 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" , 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 4487
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
4488
        @ 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)
13956 schaersvoo 4489
        @ use a prefix <a href='#filled'>'filled'</a> or 'f' to set fillable objects filled. (fcircles,filledcircles etc)
11839 schaersvoo 4490
        @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
14038 schaersvoo 4491
        @ use <a href='#opacity'>"opacity int,int"</a>  and <a href='#fillcolor'>"fillcolor color"</a> to trigger coloured filling of fillable objects
8224 bpr 4492
        @ use command "dashed" and/or "dashtype int,int" to trigger dashing
13951 schaersvoo 4493
        @ use command "replyformat int" to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...)
14038 schaersvoo 4494
        @ may be combined with onclick or drag xy  of other components of flyscript objects (although not very useful...)
13956 schaersvoo 4495
        @ may be combined with keyword <a href='#userinput_xy'>'userinput_xy'</a>
14044 schaersvoo 4496
        @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply
13956 schaersvoo 4497
        @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a>
11088 schaersvoo 4498
        @ 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...
14044 schaersvoo 4499
        @ note:the default replyformat for 'userdraw input(s),color' used format x1;y1;text1 \n x2;y2;test2 \n x_n;y_n;text_n (e.g. it is not a comma separated array...use 'direct exec' to test)
14038 schaersvoo 4500
        @ note: a special case is  'userdraw images,boguscolor'.<br />Images (bitmap or svg) present in the exercise page and the img-tag with an unique 'id' and onclick='javascript:place_image_on_canvas(this.id)' can be placed onto the canvas.<br />The 'id' and (x;y) coordinates will be returned using read_canvas();<br /> On Gecko browsers there is an option to include MathML from the page onto the canvas, when the MathML code is embedded in a foreignObject,a div and an svg with size 1px , like in:<br /> &lt;svg xmlns="http://www.w3.org/2000/svg" width="1px" height="1px" onclick="javascript:place_image_on_canvas(this.id);" id='my_id'&gt;<br />&lt;foreignObject width="100%" height="100%"&gt;<br />&lt;div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;width:auto;text-align: center;" &gt; MATHML &lt;/div&gt;<br />&lt;/foreignObject&gt;<br />&lt;/svg&gt;<br />To resize and used the svg element, a small piece of javascript is needed...<br />function resize_svg_mathml( mythings ){<br /> var len = mythings.length;<br />for(var p=0; p&lt; len; p=p+2){<br /> var svg = document.getElementById(mythings[p]);<br />var div = document.getElementById(mythings[p+1]);<br />var w = parseInt(getComputedStyle(div).width);<br />var h = parseInt(getComputedStyle(div).height);<br />svg.setAttribute("height", h+'px');<br />svg.setAttribute("width",  w+'px');<br />};<br />};<br /><br /> var mythings = [ array_with_image_id's ];<br />resize_svg_mathml(mythings);
12107 schaersvoo 4501
        @%userdraw_canvastype_a%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%snaptogrid%replyformat 10%colorpalette orange,yellow,red,green,lightgreen,blue,lightblue,cyan%canvastype 4%userdraw clickfill,blue%clearbutton REMOVE LAST RECTANGLE
4502
        @%userdraw_canvastype_b%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%canvastype 4%snaptogrid%replyformat 10%userdraw dotfill,blue%clearbutton REMOVE LAST RECTANGLE
4503
        @%userdraw_rect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rect,green
4504
        @%userdraw_rects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw rects,green
4505
        @%userdraw_frect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frect,green
4506
        @%userdraw_frects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw frects,green
4507
        @%userdraw_roundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrect,green
4508
        @%userdraw_roundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw roundrects,green
4509
        @%userdraw_froundrect%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrect,green
4510
        @%userdraw_froundrects%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw froundrects,green
4511
        @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
4512
        @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
4513
        @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
4514
        @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
4515
        @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
4516
        @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
4517
        @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
4518
        @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
4519
        @%userdraw_arc%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arc,green
4520
        @%userdraw_arcs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw arcs,green
4521
        @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
4522
        @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
4523
        @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
4524
        @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
4525
        @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
4526
        @%userdraw_arrows2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows2,green
14025 schaersvoo 4527
        @%userdraw_curvedarrow%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow,red%clearbutton REMOVE ALL ARROWS
4528
        @%userdraw_curvedarrows%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows,red%clearbutton REMOVE ALL ARROWS
14038 schaersvoo 4529
        @%userdraw_curvedarrow2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrow2,red%clearbutton REMOVE ALL ARROWS
4530
        @%userdraw_curvedarrows2%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 1%grid 2,2,grey,2,2,5,grey%precision 1%linewidth 3%userdraw curvedarrows2,red%clearbutton REMOVE ALL ARROWS     
12107 schaersvoo 4531
        @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
4532
        @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
4533
        @%userdraw_circle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circle,green
4534
        @%userdraw_circles%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw circles,green
4535
        @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
4536
        @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
4537
        @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
4538
        @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
4539
        @%userdraw_triangle%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw triangle,green
4540
        @%userdraw_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly5,green
4541
        @%userdraw_filled_poly5%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly5,green
4542
        @%userdraw_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw poly7,green
4543
        @%userdraw_filled_poly7%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw poly7,green
4544
        @%userdraw_polyline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%userdraw polyline,green
4545
        @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
4546
        @%userdraw_filled_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%fillcolor orange%opacity 200,50%filled%userdraw freehandline,green
4547
        @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
4548
        @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
4549
        @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
4550
        @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
14044 schaersvoo 4551
        @%userdraw_clickfill_colorpalette%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%colorpalette red,green,yellow,blue%userdraw clickfill,green
13948 schaersvoo 4552
        @%userdraw_clickfill_1%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%circles blue,0,0,4,1,1,6,3,3,3,-3,-3,5%opacity 255,120%userdraw clickfill,green
4553
        @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%linewidth 1%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw hatchfill,red%#userdraw dotfill,red%#userdraw diamonefill,red%#userdraw gridfill,red
4554
        @%userdraw_clickfill_2%size 400,400%xrange -10,10%yrange -10,10%bgcolor white%# to get nice click coordinates take invisible'grid' and use 'snaptogrid'%grid 1,1,white%snaptogrid%circles blue,0,0,2,1,1,5,5,5,4,-5,5,6,5,-5,6%userdraw gridfill,red
7614 schaersvoo 4555
        */
4556
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
14038 schaersvoo 4557
                canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
7614 schaersvoo 4558
            }
8074 schaersvoo 4559
            reply_precision = precision;
7614 schaersvoo 4560
            use_userdraw = TRUE;
13970 obado 4561
            fprintf(js_include_file,"\n/* begin userdraw mouse events */\n\
11839 schaersvoo 4562
            userdraw_x = new Array();userdraw_y = new Array();\
11041 schaersvoo 4563
            userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
11001 schaersvoo 4564
            var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
4565
            if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
4566
            if(wims_status != \"done\"){\
14038 schaersvoo 4567
             canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
4568
             canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
4569
             canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
4570
             canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
4571
             canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
14044 schaersvoo 4572
            }\n/* end userdraw mouse & touch events */",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
7614 schaersvoo 4573
            draw_type = get_string_argument(infile,0);
4574
            stroke_color = get_color(infile,1);
4575
            if( strcmp(draw_type,"point") == 0 ){
4576
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4577
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 4578
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
12006 schaersvoo 4579
/*
13829 bpr 4580
type = 0 : a point ...radius is fixed
4581
type = 1 : a circle ... read inputfield userinput_r
4582
num = 1 : a single point / circle
12006 schaersvoo 4583
num = 2 : multiple points / circles
4584
*/
8071 schaersvoo 4585
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4586
                if(use_input_xy == 1){
12006 schaersvoo 4587
                    add_input_circle(js_include_file,0,1);
8815 schaersvoo 4588
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4589
                }
14044 schaersvoo 4590
                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,use_snap);
7614 schaersvoo 4591
            }
4592
            else
4593
            if( strcmp(draw_type,"points") == 0 ){
4594
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4595
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 4596
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 4597
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4598
                if(use_input_xy == 1){
12006 schaersvoo 4599
                    add_input_circle(js_include_file,0,2);
8815 schaersvoo 4600
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4601
                }
14044 schaersvoo 4602
                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,use_snap);
7614 schaersvoo 4603
            }
4604
            else
4605
            if( strcmp(draw_type,"segment") == 0 ){
4606
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4607
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 4608
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 4609
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4610
                if(use_input_xy == 1){
7652 schaersvoo 4611
                    add_input_segment(js_include_file,1);
8815 schaersvoo 4612
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4613
                }
14044 schaersvoo 4614
                add_js_segments(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
7614 schaersvoo 4615
            }
4616
            else
10975 schaersvoo 4617
            if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
7663 schaersvoo 4618
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 4619
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 4620
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 4621
                if( use_input_xy == 1 ){
4622
                    add_input_polyline(js_include_file);
8815 schaersvoo 4623
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7663 schaersvoo 4624
                }
14044 schaersvoo 4625
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
7663 schaersvoo 4626
            }
4627
            else
7614 schaersvoo 4628
            if( strcmp(draw_type,"segments") == 0 ){
4629
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4630
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 4631
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 4632
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4633
                if(use_input_xy == 1){
7652 schaersvoo 4634
                    add_input_segment(js_include_file,2);
8815 schaersvoo 4635
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4636
                }
14044 schaersvoo 4637
                add_js_segments(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
7614 schaersvoo 4638
            }
4639
            else
11839 schaersvoo 4640
            if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0  || strcmp(draw_type,"filledcircle") == 0 ){
7614 schaersvoo 4641
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4642
                if(reply_format == 0){reply_format = 10;}
11875 schaersvoo 4643
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
7614 schaersvoo 4644
                /* 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 4645
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4646
                if(use_input_xy == 1){
12006 schaersvoo 4647
/*
13829 bpr 4648
type = 0 : a point ...radius is fixed
4649
type = 1 : a circle ... read inputfield userinput_r
4650
num = 1 : a single point / circle
12006 schaersvoo 4651
num = 2 : multiple points / circles
4652
*/
4653
                    add_input_circle(js_include_file,1,1);
8815 schaersvoo 4654
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4655
                }
14044 schaersvoo 4656
                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],use_snap);
7614 schaersvoo 4657
            }
4658
            else
11839 schaersvoo 4659
            if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){
7614 schaersvoo 4660
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4661
                if(reply_format == 0){reply_format = 10;}
11839 schaersvoo 4662
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7614 schaersvoo 4663
                /* 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n in x/y-range */
14044 schaersvoo 4664
                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],use_snap);
8071 schaersvoo 4665
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4666
                if(use_input_xy == 1){
12006 schaersvoo 4667
                    add_input_circle(js_include_file,1,2);
8815 schaersvoo 4668
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4669
                }
7614 schaersvoo 4670
            }
4671
            else
4672
            if(strcmp(draw_type,"crosshair") == 0 ){
4673
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4674
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4675
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
14044 schaersvoo 4676
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
8071 schaersvoo 4677
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4678
                if(use_input_xy == 1){
7654 schaersvoo 4679
                    add_input_crosshair(js_include_file,1);
8815 schaersvoo 4680
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4681
                }
7614 schaersvoo 4682
            }
4683
            else
4684
            if(strcmp(draw_type,"crosshairs") == 0 ){
4685
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4686
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4687
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
14044 schaersvoo 4688
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
8071 schaersvoo 4689
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4690
                if(use_input_xy == 1){
7654 schaersvoo 4691
                    add_input_crosshair(js_include_file,2);
8815 schaersvoo 4692
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4693
                }
7614 schaersvoo 4694
            }
4695
            else
4696
            if(strcmp(draw_type,"freehandline") == 0 ){
4697
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4698
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4699
                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],use_snap);
7652 schaersvoo 4700
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4701
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4702
            }
4703
            else
4704
            if(strcmp(draw_type,"freehandlines") == 0 ){
4705
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4706
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4707
                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],use_snap);
7652 schaersvoo 4708
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4709
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4710
            }
4711
            else
11839 schaersvoo 4712
            if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){
7614 schaersvoo 4713
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
13829 bpr 4714
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4715
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4716
                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],use_snap);
7652 schaersvoo 4717
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4718
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4719
            }
4720
            else
11839 schaersvoo 4721
            if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0  || strcmp(draw_type,"filledpaths") == 0 ){
7614 schaersvoo 4722
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
13829 bpr 4723
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4724
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4725
                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],use_snap);
7652 schaersvoo 4726
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4727
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4728
            }
4729
            else
4730
            if(strcmp(draw_type,"arrows") == 0 ){
4731
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4732
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4733
                add_js_arrows(js_include_file,2,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
8224 bpr 4734
                if(use_input_xy == 1){
7654 schaersvoo 4735
                    add_input_arrow(js_include_file,2);
8815 schaersvoo 4736
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4737
                }
8071 schaersvoo 4738
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4739
            }
4740
            else
7874 schaersvoo 4741
            if(strcmp(draw_type,"arrows2") == 0 ){
4742
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4743
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4744
                add_js_arrows(js_include_file,2,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
8224 bpr 4745
                if(use_input_xy == 1){
7874 schaersvoo 4746
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4747
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4748
                }
8071 schaersvoo 4749
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4750
            }
4751
            else
4752
            if(strcmp(draw_type,"arrow2") == 0 ){
4753
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4754
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4755
                add_js_arrows(js_include_file,1,draw_type,line_width,2,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
8224 bpr 4756
                if(use_input_xy == 1){
7874 schaersvoo 4757
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4758
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4759
                }
8071 schaersvoo 4760
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4761
            }
4762
            else
7614 schaersvoo 4763
            if(strcmp(draw_type,"arrow") == 0 ){
4764
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4765
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4766
                add_js_arrows(js_include_file,1,draw_type,line_width,1,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],arrow_head,use_snap);
8224 bpr 4767
                if(use_input_xy == 1){
7654 schaersvoo 4768
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4769
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4770
                }
8071 schaersvoo 4771
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4772
            }
4773
            else
14027 schaersvoo 4774
            if( strcmp(draw_type,"curvedarrow2") == 0 ){
14035 schaersvoo 4775
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4776
                add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap);
14027 schaersvoo 4777
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4778
            }
4779
            else
4780
            if( strcmp(draw_type,"curvedarrows2") == 0 ){
14035 schaersvoo 4781
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4782
                add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,2,use_snap);
14027 schaersvoo 4783
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4784
            }
4785
            else
4786
            if( strcmp(draw_type,"curvedarrows") == 0 ){
14035 schaersvoo 4787
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4788
                add_js_curvedarrow(js_include_file,canvas_root_id,2,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap);
14027 schaersvoo 4789
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4790
            }
4791
            else
4792
            if( strcmp(draw_type,"curvedarrow") == 0 ){
14035 schaersvoo 4793
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4794
                add_js_curvedarrow(js_include_file,canvas_root_id,1,line_width,stroke_color,stroke_opacity,use_dashed,arrow_head,1,use_snap);
14027 schaersvoo 4795
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4796
            }
14025 schaersvoo 4797
            else
11839 schaersvoo 4798
            if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){
7614 schaersvoo 4799
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
11839 schaersvoo 4800
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4801
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4802
                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],use_snap);
8071 schaersvoo 4803
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4804
                if(use_input_xy == 2){
7780 schaersvoo 4805
                  add_textarea_polygon(js_include_file);
8815 schaersvoo 4806
                  add_textarea_xy(js_include_file,canvas_root_id,input_style);
7746 schaersvoo 4807
                }
7614 schaersvoo 4808
            }
8224 bpr 4809
            else
7614 schaersvoo 4810
            if(strncmp(draw_type,"poly",4) == 0){
4811
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
4812
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4813
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4814
                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],use_snap);
7652 schaersvoo 4815
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4816
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4817
            }
8224 bpr 4818
            else
11839 schaersvoo 4819
            if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){
7614 schaersvoo 4820
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
11839 schaersvoo 4821
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4822
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4823
                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],use_snap);
7652 schaersvoo 4824
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4825
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4826
            }
8224 bpr 4827
            else
7989 schaersvoo 4828
            if( strcmp(draw_type,"hline") == 0 ){
4829
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4830
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4831
                add_js_hlines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
8071 schaersvoo 4832
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4833
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4834
            }
4835
            else
4836
            if( strcmp(draw_type,"hlines") == 0 ){
4837
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4838
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4839
                add_js_hlines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
8071 schaersvoo 4840
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4841
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4842
            }
4843
            else
4844
            if( strcmp(draw_type,"vline") == 0 ){
4845
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4846
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4847
                add_js_hlines(js_include_file,3,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
8071 schaersvoo 4848
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4849
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4850
            }
4851
            else
4852
            if( strcmp(draw_type,"vlines") == 0 ){
4853
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4854
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4855
                add_js_hlines(js_include_file,4,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
8071 schaersvoo 4856
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4857
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4858
            }
4859
            else
7614 schaersvoo 4860
            if( strcmp(draw_type,"line") == 0 ){
4861
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4862
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4863
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4864
                add_js_lines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
7747 schaersvoo 4865
                if( use_input_xy == 1 ){
7780 schaersvoo 4866
                    add_input_line(js_include_file,1);
8815 schaersvoo 4867
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7747 schaersvoo 4868
                }
8071 schaersvoo 4869
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4870
            }
4871
            else
4872
            if( strcmp(draw_type,"lines") == 0 ){
4873
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4874
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4875
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4876
                add_js_lines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
7747 schaersvoo 4877
                if( use_input_xy == 1 ){
7780 schaersvoo 4878
                    add_input_line(js_include_file,2);
8815 schaersvoo 4879
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7746 schaersvoo 4880
                }
8071 schaersvoo 4881
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4882
            }
4883
            else
8362 schaersvoo 4884
            if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
8244 schaersvoo 4885
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4886
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4887
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4888
                add_js_demilines(js_include_file,2,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
8244 schaersvoo 4889
                if( use_input_xy == 1 ){
4890
                    add_input_demiline(js_include_file,2);
8815 schaersvoo 4891
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4892
                }
4893
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4894
            }
4895
            else
8362 schaersvoo 4896
            if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
8244 schaersvoo 4897
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4898
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4899
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4900
                add_js_demilines(js_include_file,1,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
8244 schaersvoo 4901
                if( use_input_xy == 1 ){
4902
                    add_input_demiline(js_include_file,1);
8815 schaersvoo 4903
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4904
                }
4905
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4906
            }
4907
            else
11839 schaersvoo 4908
            if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0  || strcmp(draw_type,"filledrects") == 0 ){
7614 schaersvoo 4909
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
12008 schaersvoo 4910
                if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4911
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4912
                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],use_snap);
7652 schaersvoo 4913
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4914
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4915
            }
8224 bpr 4916
            else
11839 schaersvoo 4917
            if( strcmp(draw_type,"roundrects") == 0 ||  strcmp(draw_type,"froundrects") == 0  ||  strcmp(draw_type,"filledroundrects") == 0){
7614 schaersvoo 4918
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
11839 schaersvoo 4919
                if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4920
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4921
                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],use_snap);
7652 schaersvoo 4922
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4923
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4924
            }
8224 bpr 4925
            else
11839 schaersvoo 4926
            if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){
7614 schaersvoo 4927
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
13829 bpr 4928
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4929
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4930
                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],use_snap);
7652 schaersvoo 4931
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4932
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4933
            }
8224 bpr 4934
            else
11839 schaersvoo 4935
            if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0  || strcmp(draw_type,"filledroundrect") == 0){
7614 schaersvoo 4936
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
11839 schaersvoo 4937
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
7876 schaersvoo 4938
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4939
                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],use_snap);
7652 schaersvoo 4940
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4941
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4942
            }
4943
            else
11839 schaersvoo 4944
            if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0  || strcmp(draw_type,"filledarcs") == 0 ){
8083 schaersvoo 4945
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
11839 schaersvoo 4946
                if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
4947
                if( strstr(draw_type,"f") != NULL ){use_filled =1;}
8083 schaersvoo 4948
                if(reply_format == 0){reply_format = 25;}
14044 schaersvoo 4949
                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],use_filled,use_snap);
8083 schaersvoo 4950
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4951
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4952
            }
4953
            else
11839 schaersvoo 4954
            if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){
8071 schaersvoo 4955
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
11017 schaersvoo 4956
                if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
11839 schaersvoo 4957
                if( strstr(draw_type,"f") != NULL ){use_filled =1;}
8083 schaersvoo 4958
                if(reply_format == 0){reply_format = 25;}
14044 schaersvoo 4959
                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],use_filled,use_snap);
8071 schaersvoo 4960
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4961
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4962
            }
4963
            else
7614 schaersvoo 4964
            if( strcmp(draw_type,"text") == 0){
7876 schaersvoo 4965
                if(reply_format == 0){reply_format = 17;}
14044 schaersvoo 4966
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity,use_snap);
7652 schaersvoo 4967
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4968
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4969
            }
8116 schaersvoo 4970
            else
14038 schaersvoo 4971
            if( strcmp(draw_type,"images") == 0){
4972
                if(reply_format == 0){reply_format = 29;}
4973
                add_js_images(js_include_file,canvas_root_id,use_offset,use_snap);
4974
            }
4975
            else
8116 schaersvoo 4976
            if( strcmp(draw_type,"inputs") == 0){
8224 bpr 4977
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 4978
                if(reply_format == 0){reply_format = 27;}
14044 schaersvoo 4979
                add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset,use_snap);
8116 schaersvoo 4980
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4981
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4982
            }
4983
            else
4984
            if( strcmp(draw_type,"input") == 0){
8224 bpr 4985
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 4986
                if(reply_format == 0){reply_format = 27;}
14044 schaersvoo 4987
                add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset,use_snap);
8116 schaersvoo 4988
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4989
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4990
            }
11839 schaersvoo 4991
            else /* attention: THIS NEEDS TO BE LAST ! */
11825 schaersvoo 4992
            if( strstr(draw_type,"fill") != NULL ){
11005 schaersvoo 4993
                decimals = find_number_of_digits(precision);
14044 schaersvoo 4994
                add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215),use_snap);
4995
                if( reply_format == 0){reply_format = 10;}
11825 schaersvoo 4996
                if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);}
11830 schaersvoo 4997
                if( strcmp(draw_type,"gridfill") == 0){js_function[DRAW_GRIDFILL] = 1;string_length = snprintf(NULL,0,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_gridfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
4998
                if( strcmp(draw_type,"diamondfill") == 0){js_function[DRAW_DIAMONDFILL] = 1;string_length = snprintf(NULL,0,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_diamondfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
4999
                if( strcmp(draw_type,"dotfill") == 0){js_function[DRAW_DOTFILL] = 1;string_length = snprintf(NULL,0,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_dotfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
5000
                if( strcmp(draw_type,"hatchfill") == 0){js_function[DRAW_HATCHFILL] = 1;string_length = snprintf(NULL,0,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);  ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_hatchfill(%d,%d,%d,4,4,%d,'%s','0.01',%d,%d,true);",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),line_width,stroke_color,xsize,ysize);add_to_buffer(tmp_buffer);fill_cnt++;}
5001
                if( strcmp(draw_type,"textfill") == 0){js_function[DRAW_TEXTFILL] = 1;temp = get_string(infile,1);string_length = snprintf(NULL,0,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);snprintf(tmp_buffer,string_length,"draw_textfill(%d,%d,%d,'%s','%s',%d,%d,'%s',true); ",FILL_CANVAS+fill_cnt,(int) (xmax),(int) (ymax),stroke_color,font_family,xsize,ysize,temp);add_to_buffer(tmp_buffer);fill_cnt++;}
11005 schaersvoo 5002
            }
5003
            else
7614 schaersvoo 5004
            {
5005
                canvas_error("unknown drawtype or typo? ");
5006
            }
5007
            reset();
5008
        break;
8386 schaersvoo 5009
 
5010
        case USERINPUT:
5011
        /*
13955 schaersvoo 5012
         @ userinput function inputfield
9382 schaersvoo 5013
         @ alternative : userinput_function
5014
         @ alternative : userinput_xy
8386 schaersvoo 5015
         @ textarea and inputfield are only usable in combination with some 'userdraw draw_ type'
5016
         @ function may be used any time (e.g. without userdraw)
8815 schaersvoo 5017
         @ multiple 'userinput function' commands may be used.
8386 schaersvoo 5018
         @ use command "functionlabel some_string" to define the inputfield text : default value "f(x)="
5019
         @ use command 'strokecolor some_color' to adjust the plot / functionlabel color
8815 schaersvoo 5020
         @ use command 'inputstyle some_css' to adjust the inputfields
5021
         @ use command 'fontsize int' to adjust the label fonts. (default 12px)
5022
         @ 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
13959 bpr 5023
         @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%grid 2,2,grey,3,3,5,grey%inputstyle color:blue;text-align:center%userinput function%# note: number of function inputs not limited
13955 schaersvoo 5024
         @%userinput_points%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%# adding 2 inputfields for x and y%userinput inputfield%userdraw points,blue
5025
         @%userinput_arrows%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%#adding 4 inputfields for (x1;y1)---(x2;y2)%userinput inputfieldd%userdraw arrows,blue
5026
         @%userinput_combined%size 400,400%xrange -10,10%yrange -10,10%functionlabel your function g(x)=%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,3,3,5,grey%inputstyle color:blue;text-align:center%precision 1000%strokecolor red%opacity 255,255%userinput function%# note: number of function inputs not limited%userdraw line,blue
8386 schaersvoo 5027
        */
5028
            temp = get_string_argument(infile,1);
5029
            if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
5030
             if( js_function[DRAW_JSFUNCTION] != 1 ){
5031
              add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
5032
              js_function[DRAW_JSFUNCTION] = 1;
5033
              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 5034
              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 5035
              input_cnt++;
5036
             }
10953 bpr 5037
             else
8386 schaersvoo 5038
             {
5039
              /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
8815 schaersvoo 5040
              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 5041
              input_cnt++;
5042
             }
5043
             if( use_js_math == FALSE){/* add this stuff only once...*/
5044
              add_to_js_math(js_include_file);
5045
              use_js_math = TRUE;
5046
             }
5047
             if( use_js_plot == FALSE){
5048
              use_js_plot = TRUE;
5049
              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
5050
             }
5051
            }
5052
            else
5053
            {
5054
             if(strstr(temp,"inputfield") != 0 ){
5055
              if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
5056
              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5057
              use_input_xy = 1;
5058
             }
5059
             else
5060
             {
5061
              if(strstr(temp,"textarea") != 0 ){
5062
               if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
5063
               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5064
               use_input_xy = 2;
5065
              }
5066
              else
5067
              {
5068
                canvas_error("userinput argument may be \"function,inputfield,textarea\"");
5069
              }
5070
             }
5071
            }
5072
            break;
5073
        case USERINPUT_XY:
5074
        /*
5075
        @ userinput_xy
9372 schaersvoo 5076
        @ keyword (no arguments required)
8386 schaersvoo 5077
        @ to be used in combination with command "userdraw object_type,color"
5078
        @ 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)
5079
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
5080
        @ 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 5081
        @ can <b>not</b> be combined with command "intooltip tiptext" <br />note: the 'tooltip div element' is used for placing inputfields
8386 schaersvoo 5082
        @ user drawings will not zoom on zooming (or pan on panning)
8815 schaersvoo 5083
        @ use command 'inputstyle some_css' to adjust the inputarea.
5084
        @ use command 'fontsize int' to adjust the text labels (if needed)
13950 schaersvoo 5085
        @%userinput_xy%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%precision 0%grid 2,2,grey,3,3,6,black%# provides inputfields for (x1:y1)---(x2:y2)%userinput_xy%linewidth 2%precision 1000%userdraw lines,blue
8386 schaersvoo 5086
        */
5087
            /* add simple eval check to avoid code injection with unprotected eval(string) */
5088
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
5089
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5090
            use_input_xy = 1;
5091
            break;
5092
 
5093
        case USERINPUT_FUNCTION:
5094
        /*
5095
        @ userinput_function
9372 schaersvoo 5096
        @ keyword (no arguments required)
8386 schaersvoo 5097
        @ if set , a inputfield will be added to the page
5098
        @ repeat keyword for more function input fields
5099
        @ the userinput value will be plotted in the canvas
10953 bpr 5100
        @ 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 5101
        @ 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 5102
        @ fontsize can be set using command 'fontsize int'
8386 schaersvoo 5103
        @ incompatible with command 'intooltip link_text_or_image' : it uses the tooltip div for adding the inputfield
13950 schaersvoo 5104
        @%userinput_function%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel x-axis%ylabel y-axis%precision 0%grid 2,2,grey,2,2,5,grey%precision 1000%linewidth 2%# first inputfield%inputstyle color:blue;text-align:center;font-family:Italic;%strokecolor blue%functionlabel g(x)=%userinput function%# second inputfield%inputstyle color:green;text-align:center;font-family:Italic;%strokecolor green%functionlabel h(x)=%userinput function%# third inputfield%inputstyle color:purple;text-align:center;font-family:Italic;%strokecolor purple%functionlabel k(x)=%userinput function%# no limit in number of function inputfields
8386 schaersvoo 5105
        */
5106
            if( js_function[DRAW_JSFUNCTION] != 1 ){
5107
             js_function[DRAW_JSFUNCTION] = 1;
5108
             add_rawmath(js_include_file);
5109
             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 5110
             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 5111
             input_cnt++;
5112
            }
10953 bpr 5113
            else
8386 schaersvoo 5114
            {
5115
              /* no need to add DRAW_JSFUNCTION , just call it with the parameters */
8815 schaersvoo 5116
             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 5117
             input_cnt++;
5118
            }
5119
            if( use_js_math == FALSE){/* add this stuff only once...*/
5120
             add_to_js_math(js_include_file);
5121
             use_js_math = TRUE;
5122
            }
5123
            if( use_js_plot == FALSE){
5124
             use_js_plot = TRUE;
5125
             add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
5126
            }
5127
            break;
5128
 
5129
 
5130
 
11806 schaersvoo 5131
        case USERTEXTAREA_XY:
7788 schaersvoo 5132
        /*
11806 schaersvoo 5133
        @ usertextarea_xy
13955 schaersvoo 5134
        @ NOT IMPLEMENTED !!
11806 schaersvoo 5135
        @ keyword (no arguments required)
5136
        @ to be used in combination with command "userdraw object_type,color" wherein object_type is only segment / polyline for the time being...
5137
        @ if set two textareas are added to the document<br />(one for x-values , one for y-values)
5138
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
5139
        @ user drawings will not zoom on zooming (or pan on panning)
5140
        @ use command 'inputstyle some_css' to adjust the inputarea.
5141
        @ use command 'fontsize int' to adjust the text labels (if needed)
7788 schaersvoo 5142
        */
11806 schaersvoo 5143
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
5144
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5145
            use_input_xy = 2;
7788 schaersvoo 5146
            break;
8386 schaersvoo 5147
 
11806 schaersvoo 5148
        case VLINE:
8386 schaersvoo 5149
        /*
11806 schaersvoo 5150
        @ vline x,y,color
5151
        @ alternative : verticalline
5152
        @ draw a vertical line through point (x:y) in color 'color'
5153
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 5154
        @%vline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vline 0,0,red%onclick%vline 1,0,orange%onclick%vline 2,0,blue%onclick%vline 3,0,green
8386 schaersvoo 5155
        */
11806 schaersvoo 5156
            for(i=0;i<3;i++) {
7614 schaersvoo 5157
                switch(i){
11806 schaersvoo 5158
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
5159
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
5160
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
5161
                        double_data[2] = double_data[0];
7614 schaersvoo 5162
                        decimals = find_number_of_digits(precision);
14045 schaersvoo 5163
                        fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 5164
                        if(onclick > 0){click_cnt++;}
5165
                        /* click_cnt++; */
8379 schaersvoo 5166
                        reset();
7614 schaersvoo 5167
                    break;
5168
                }
5169
            }
5170
            break;
5171
 
11806 schaersvoo 5172
        case VLINES:
11802 schaersvoo 5173
        /*
11806 schaersvoo 5174
        @ vlines color,x1,y1,x2,y2....
5175
        @ alternative : verticallines
5176
        @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
5177
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
13939 bpr 5178
        @%vlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%vlines red,1,0,2,0,3,0,4,0
11802 schaersvoo 5179
        */
11806 schaersvoo 5180
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5181
            fill_color = stroke_color;
5182
            i=0;
5183
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 5184
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 5185
                if(i%2 == 0 ){
5186
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 5187
                }
11806 schaersvoo 5188
                else
5189
                {
5190
                    double_data[i] = get_real(infile,1); /* y */
7983 schaersvoo 5191
                }
11806 schaersvoo 5192
                i++;
7983 schaersvoo 5193
            }
11806 schaersvoo 5194
            decimals = find_number_of_digits(precision);
5195
            for(c = 0 ; c < i-1 ; c = c+2){
14045 schaersvoo 5196
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 5197
                if(onclick > 0){click_cnt++;}
5198
                /* click_cnt++; */
5199
            }
5200
            reset();
7983 schaersvoo 5201
            break;
11806 schaersvoo 5202
 
5203
        case VIDEO:
7614 schaersvoo 5204
        /*
11806 schaersvoo 5205
        @ video x,y,w,h,videofile location
5206
        @ x,y : left top corner of audio element (in xrange / yrange)
5207
        @ w,y : width and height in pixels
5208
        @ video format may be in *.mp4 (todo:other formats)
13950 schaersvoo 5209
        @%video%size 400,400%xrange -10,10%yrange -10,10%opacity 200,100%frect -9,9,6,-6,green%video -5,5,200,200,http://techslides.com/demos/sample-videos/small.mp4
7614 schaersvoo 5210
        */
11806 schaersvoo 5211
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
7614 schaersvoo 5212
            for(i=0;i<5;i++){
5213
                switch(i){
11806 schaersvoo 5214
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
5215
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
5216
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
5217
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
5218
                    case 4: temp = get_string(infile,1);
5219
                            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 5220
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+1);
11806 schaersvoo 5221
                            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 5222
                            add_to_buffer(tmp_buffer);
5223
                            break;
5224
                    default:break;
5225
                }
5226
            }
5227
            reset();
5228
            break;
11806 schaersvoo 5229
 
7614 schaersvoo 5230
        case X_AXIS_STRINGS:
5231
        /*
5232
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9385 schaersvoo 5233
         @ alternative : xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
13936 bpr 5234
         @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof
9346 schaersvoo 5235
         @ use these x-axis num1...num_n values instead of default xmin...xmax
11891 schaersvoo 5236
         @ in case of command 'grid' . there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
13936 bpr 5237
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
11088 schaersvoo 5238
         @ 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 5239
         @ a javascript error message will flag non-matching value:name pairs
9341 schaersvoo 5240
         @ if the 'x-axis words' are too big and will overlap, a simple alternating offset will be applied
11044 schaersvoo 5241
         @ to be used before command grid (see <a href="#grid">command grid</a>)
13937 schaersvoo 5242
         @'xmajor' steps should be synchronised with numbers eg. "1" in the next example "grid 1,100,grey,1,4,6,grey"
5243
         @%xaxistext%size 800,200%xrange -1,13%yrange -5,10%axis%xaxistext 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red
7614 schaersvoo 5244
        */
11891 schaersvoo 5245
            use_axis_numbering++;
7614 schaersvoo 5246
            temp = get_string(infile,1);
5247
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
5248
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
11891 schaersvoo 5249
            fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
7614 schaersvoo 5250
            break;
9341 schaersvoo 5251
        case X_AXIS_STRINGS_UP:
5252
        /*
5253
         @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9385 schaersvoo 5254
         @ alternative : xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
9341 schaersvoo 5255
         @ the text will be rotated 90&deg; up
11044 schaersvoo 5256
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
13936 bpr 5257
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
9346 schaersvoo 5258
         @ use these x-axis num1...num_n values instead of default xmin...xmax
13937 schaersvoo 5259
         @ use command "fontcolor",<a href="#fontfamily">fontfamily</a> 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 5260
         @ a javascript error message will flag non-matching value:name pairs
9341 schaersvoo 5261
         @ 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 5262
         @ to be used before command grid (see <a href="#grid">command grid</a>)
13937 schaersvoo 5263
         @'xmajor' steps should be synchronised with numbers eg. "1" in the next example "grid 1,100,grey,1,4,6,grey"
5264
         @%xaxistextup%size 800,300%xrange -1,13%yrange -10,10%fontfamily Italic 18pt Courier%axis%xaxistextup 1:january:2:february:3:march:4:april:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%grid 1,4,grey,1,2,10,red
9341 schaersvoo 5265
        */
11891 schaersvoo 5266
            use_axis_numbering++;
9341 schaersvoo 5267
            temp = get_string(infile,1);
5268
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
5269
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
11891 schaersvoo 5270
            fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
9341 schaersvoo 5271
            break;
8224 bpr 5272
 
11806 schaersvoo 5273
        case XERRORBARS:
7614 schaersvoo 5274
        /*
11806 schaersvoo 5275
        @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
5276
        @ 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'
5277
        @ the errors E1 and E2 values are in xrange.
5278
        @ use command 'linewidth int' to adust size
5279
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12107 schaersvoo 5280
        @%xerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%xerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1
12006 schaersvoo 5281
 
7614 schaersvoo 5282
        */
11806 schaersvoo 5283
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5284
            fill_color = stroke_color;
5285
            i=0;
5286
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 5287
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 5288
                if(i%2 == 0 ){
5289
                    double_data[i] = get_real(infile,0); /* x */
8071 schaersvoo 5290
                }
11806 schaersvoo 5291
                else
5292
                {
5293
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 5294
                }
11806 schaersvoo 5295
                i++;
7614 schaersvoo 5296
            }
11806 schaersvoo 5297
            decimals = find_number_of_digits(precision);
5298
            for(c = 2 ; c < i-1 ; c = c+2){
14045 schaersvoo 5299
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 5300
                /* click_cnt++; */
5301
                if(onclick > 0){click_cnt++;}
5302
            }
7614 schaersvoo 5303
            reset();
5304
            break;
11806 schaersvoo 5305
 
5306
        case XRANGE:
7614 schaersvoo 5307
        /*
11806 schaersvoo 5308
        @ xrange xmin,xmax
5309
        @ alternative : rangex
5310
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 5311
        */
11806 schaersvoo 5312
            for(i = 0 ; i<2; i++){
7614 schaersvoo 5313
                switch(i){
11806 schaersvoo 5314
                    case 0: xmin = get_real(infile,0);break;
5315
                    case 1: xmax = get_real(infile,1);break;
7614 schaersvoo 5316
                    default: break;
5317
                }
5318
            }
11806 schaersvoo 5319
            if(xmin >= xmax){canvas_error(" xrange is not OK : xmin &lt; xmax !\n");}
5320
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
5321
            found_size_command++;
7614 schaersvoo 5322
            break;
8386 schaersvoo 5323
 
5324
 
5325
 
11806 schaersvoo 5326
        case XSNAPTOGRID:
7614 schaersvoo 5327
        /*
11806 schaersvoo 5328
         @ xsnaptogrid
5329
         @ keyword (no arguments required)
5330
         @ a draggable object (use command "drag  x|y|xy") will snap to the given x-grid values when dragged (mouseup)
5331
         @ in case of userdraw the drawn points will snap to xmajor grid
5332
         @ if no grid is defined ,points will snap to every integer xrange value. (eg snap_x=1)
5333
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
5334
         @ 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 />
13939 bpr 5335
         @%xsnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%xsnaptogrid%userdraw segments,red%precision 1%display x,red,12
5336
         @%xsnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 3%drag x%points red,0,0,0,0,0,0,0,0,0,0
12007 schaersvoo 5337
 
7614 schaersvoo 5338
        */
14038 schaersvoo 5339
        use_snap = 2;
11806 schaersvoo 5340
        break;
8386 schaersvoo 5341
 
11806 schaersvoo 5342
        case XOFFSET:
7614 schaersvoo 5343
        /*
12063 schaersvoo 5344
         @ xoffset
13829 bpr 5345
         @ keyword ; to place the text centered above the text coordinates(x:y) ...
5346
         @ may be used for points or other things requiring centered labels
12063 schaersvoo 5347
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
11811 schaersvoo 5348
         @ 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)
12107 schaersvoo 5349
        @%xoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
7614 schaersvoo 5350
        */
12063 schaersvoo 5351
         use_offset = 2;
11806 schaersvoo 5352
         break;
8386 schaersvoo 5353
 
11806 schaersvoo 5354
        case XYOFFSET:
7614 schaersvoo 5355
        /*
11806 schaersvoo 5356
         @ xyoffset
5357
         @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
13829 bpr 5358
         @ may be used for points or other things requiring labels
12063 schaersvoo 5359
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
11806 schaersvoo 5360
         @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
13829 bpr 5361
         @ 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>
12107 schaersvoo 5362
         @%xyoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
7614 schaersvoo 5363
        */
12063 schaersvoo 5364
         use_offset = 3;
11806 schaersvoo 5365
         break;
8386 schaersvoo 5366
 
7996 schaersvoo 5367
        case XUNIT:
5368
        /*
5369
         @ xunit some_unit_for_x-values
5370
         @ unicode allowed (no html code)
12007 schaersvoo 5371
         @ use together with command <a href='#display'>display or mouse</a>
9372 schaersvoo 5372
         @ will display the cursor x-coordinate in 'unit'
12107 schaersvoo 5373
         @%xunit%size 400,400%xrange -10,10%yrange -10,10%xunit cm \\u00B2%grid 2,2,grey%linewidth 2%userdraw segments,blue%display x,blue,18
7996 schaersvoo 5374
        */
5375
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
5376
            break;
11806 schaersvoo 5377
 
5378
        case XLABEL:
7996 schaersvoo 5379
        /*
11806 schaersvoo 5380
        @ xlabel some_string
5381
        @ will be used to create a label for the x-axis (label is in quadrant I)
5382
        @ can only be used together with command 'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
5383
        @ 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)
12007 schaersvoo 5384
        @ see <a href='#ylabel'>ylabel</a>
12107 schaersvoo 5385
        @%xlabel%size 400,400%xrange -10,10%yrange -10,10%axis%axisnumbering%xlabel cm\u00B2 %ylabel v\u00B2 %precision 1%grid 2,2,grey,2,2,5,grey
7996 schaersvoo 5386
        */
11806 schaersvoo 5387
            temp = get_string(infile,1);
5388
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7996 schaersvoo 5389
            break;
8071 schaersvoo 5390
 
11806 schaersvoo 5391
        case XLOGBASE:
7991 schaersvoo 5392
        /*
11806 schaersvoo 5393
        @ xlogbase number
5394
        @ sets the logbase number for the x-axis
5395
        @ default value 10
5396
        @ use together with commands xlogscale / xylogscale
7991 schaersvoo 5397
        */
11806 schaersvoo 5398
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7991 schaersvoo 5399
            break;
5400
 
11806 schaersvoo 5401
        case XLOGSCALE:
7614 schaersvoo 5402
        /*
11806 schaersvoo 5403
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
5404
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
5405
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
5406
         @ the linewidth is set using command 'linewidth int'
5407
         @ the opacity of major / minor grid lines is set by command <a href='#opacity'>'opacity</a>'
5408
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number'
5409
         @ 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>
5410
         @ note: the complete canvas will be used for the 'log paper'
5411
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
5412
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
5413
         @ 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
5414
         @ note: in case of userdraw , the use of keyword <a href='#userinput_xy'>'userinput_xy'</a> may be handy !
5415
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
12107 schaersvoo 5416
         @%xlogscale%size 400,400%xrange 10,50000%yrange -5,5%xlabel x-axis%ylabel y-axis%xlogscale 10,1,black,grey%display x,red,22
7614 schaersvoo 5417
        */
11972 schaersvoo 5418
            use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
11806 schaersvoo 5419
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
5420
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
5421
            for(i=0;i<4;i++){
7614 schaersvoo 5422
                switch(i){
11806 schaersvoo 5423
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
5424
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
5425
                    case 2: stroke_color = get_color(infile,0); break;
5426
                    case 3: fill_color = get_color(infile,1);
5427
                        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);
5428
                        tmp_buffer = my_newmem(string_length+1);
5429
                        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);
5430
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
5431
                        add_to_buffer(tmp_buffer);
5432
                        break;
7614 schaersvoo 5433
                    default:break;
5434
                }
5435
            }
5436
            break;
11806 schaersvoo 5437
 
5438
        case XYLOGSCALE:
7614 schaersvoo 5439
        /*
11806 schaersvoo 5440
         @ xylogscale majorcolor,minorcolor
5441
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
5442
         @ the linewidth is set using command 'linewidth int'
5443
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
5444
         @ default logbase number = 10 ... when needed , set the logbase number with command 'xlogbase number' and/or 'ylogbase number'
5445
         @ 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>
5446
         @ note: the complete canvas will be used for the 'log paper'
5447
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
5448
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
5449
         @ 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')
5450
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
5451
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
13829 bpr 5452
         @%xylogscale%size 400,400%xrange 10,50000%yrange 10,50000%xlabel x-axis%ylabel y-axis%xylogscale black,grey%display xy,red,22
7614 schaersvoo 5453
        */
11972 schaersvoo 5454
            use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
11806 schaersvoo 5455
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
5456
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
5457
            for(i=0;i<2;i++){
7614 schaersvoo 5458
                switch(i){
11806 schaersvoo 5459
                    case 0: stroke_color = get_color(infile,0); break;
5460
                    case 1: fill_color = get_color(infile,1);
5461
                        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);
5462
                        tmp_buffer = my_newmem(string_length+1);
5463
                        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);
5464
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
5465
                        add_to_buffer(tmp_buffer);
5466
                        break;
7614 schaersvoo 5467
                    default:break;
5468
                }
5469
            }
5470
        break;
11806 schaersvoo 5471
 
5472
 
5473
        case Y_AXIS_STRINGS:
7647 schaersvoo 5474
        /*
11806 schaersvoo 5475
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
5476
         @ alternativ : yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
5477
         @ 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>)
5478
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
13936 bpr 5479
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
11806 schaersvoo 5480
         @ use these y-axis num1...num_n  values instead of default ymin...ymax
5481
         @ a javascript error message will flag non-matching value:name pairs
5482
         @ to be used before command grid (see <a href="#grid">command grid</a>)
12107 schaersvoo 5483
         @%yaxistext%size 400,400%yrange 0,13%xrange -100,500%axis%yaxis 1:january:2:february:3:march:5:may:6:june:7:july:8:august:9:september:10:october:11:november:12:december%#'ymajor' steps should be synchronised with numbers eg. "1" in this example%grid 100,1,grey,4,1,6,grey
7647 schaersvoo 5484
        */
11806 schaersvoo 5485
            temp = get_string(infile,1);
5486
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
5487
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
5488
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
11891 schaersvoo 5489
            use_axis_numbering++;
11806 schaersvoo 5490
            break;
5491
 
5492
 
5493
        case YERRORBARS:
7614 schaersvoo 5494
        /*
11806 schaersvoo 5495
        @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
5496
        @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
5497
        @ the errors E1 and E2 values are in yrange.
5498
        @ use command 'linewidth int' to adust size
5499
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12107 schaersvoo 5500
        @%yerrorbars%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%yerrorbars red,0.8,1.3,0,0,1,1,2,3,3,2,4,5,5,2,6,1,-1,-2,-2,0,-3,2,-4,4,-5,-1
7614 schaersvoo 5501
        */
11806 schaersvoo 5502
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5503
            fill_color = stroke_color;
11772 schaersvoo 5504
            i=0;
5505
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 5506
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11772 schaersvoo 5507
                if(i%2 == 0 ){
5508
                    double_data[i] = get_real(infile,0); /* x */
5509
                }
5510
                else
5511
                {
5512
                    double_data[i] = get_real(infile,1); /* y */
5513
                }
5514
                i++;
5515
            }
11806 schaersvoo 5516
            for(c = 2 ; c < i-1 ; c = c+2){
14045 schaersvoo 5517
                fprintf(js_include_file,"dragstuff.addShape(new Shape(%d,%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,%d));\n",drag_type,click_cnt,onclick,use_snap,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,use_pattern);
11806 schaersvoo 5518
                /* click_cnt++; */
5519
                if(onclick > 0){click_cnt++;}
8083 schaersvoo 5520
            }
11806 schaersvoo 5521
            decimals = find_number_of_digits(precision);
8083 schaersvoo 5522
            reset();
11806 schaersvoo 5523
            break;
11811 schaersvoo 5524
        case YOFFSET:
5525
        /*
5526
         @ yoffset
13829 bpr 5527
         @ keyword ; to place the text centered above the text coordinates(x:y) ...
5528
         @ may be used for points or other things requiring centered labels
12063 schaersvoo 5529
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
5530
         @ 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)
12107 schaersvoo 5531
         @%yoffset%size 400,400%xrange -10,10%yrange -10,10%fontfamily 12pt Ariel%string blue,-9,-9,no offset%point -9,-9,red%centered%string blue,-6,-6,centered%point -6,-6,red%xoffset%string blue,-3,-3,xoffset%point -3,-3,red%yoffset%string blue,0,0,yoffset%point 0,0,red%xyoffset%string blue,3,3,xyoffset%point 3,3,red%resetoffset%string blue,6,6,resetoffset%point 6,6,red
11811 schaersvoo 5532
        */
12063 schaersvoo 5533
         use_offset = 1;
11811 schaersvoo 5534
         break;
5535
 
11806 schaersvoo 5536
        case YRANGE:
7614 schaersvoo 5537
        /*
11806 schaersvoo 5538
        @ yrange ymin,ymax
5539
        @ alternative : rangey
5540
        @ if not given 0,ysize (eg in pixels)
7614 schaersvoo 5541
        */
11806 schaersvoo 5542
            for(i = 0 ; i<2; i++){
7614 schaersvoo 5543
                switch(i){
11806 schaersvoo 5544
                    case 0: ymin = get_real(infile,0);break;
5545
                    case 1: ymax = get_real(infile,1);break;
5546
                    default: break;
7614 schaersvoo 5547
                }
5548
            }
11806 schaersvoo 5549
            if(ymin >= ymax){canvas_error(" yrange is not OK : ymin &lt; ymax !\n");}
5550
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
5551
            found_size_command++;
5552
            break;
5553
 
5554
        case YSNAPTOGRID:
7614 schaersvoo 5555
        /*
11806 schaersvoo 5556
         @ ysnaptogrid
5557
         @ keyword (no arguments required)
5558
         @ a draggable object (use command "drag  x|y|xy") will snap to the given y-grid values when dragged (mouseup)
5559
         @ in case of userdraw the drawn points will snap to ymajor grid
5560
         @ if no grid is defined ,points will snap to every integer yrange value. (eg snap_y=1)
5561
         @ if you do not want a visible grid, but you only want a 'snaptogrid' with some value...define this grid with opacity 0.
5562
         @ 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 />
13959 bpr 5563
         @%ysnaptogrid_1%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 2%userdraw crosshairs,blue%inputstyle font-size:8px;color:blue%clearbutton delete all crosshairs
5564
         @%ysnaptogrid_2%size 400,400%xrange -10,10%yrange -10,10%ysnaptogrid%grid 1,1,grey%linewidth 3%drag y%points red,0,0,0,0,0,0,0,0,0,0
7614 schaersvoo 5565
        */
14038 schaersvoo 5566
        use_snap = 3;
7614 schaersvoo 5567
        break;
11080 schaersvoo 5568
 
7614 schaersvoo 5569
        case YLABEL:
5570
        /*
5571
        @ ylabel some_string
8224 bpr 5572
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
9379 schaersvoo 5573
        @ can only be used together with command <a href="#grid">'grid'</a><br />not depending on keywords 'axis' and 'axisnumbering'
10953 bpr 5574
        @ 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)
12107 schaersvoo 5575
        @%ylabel%size 400,400%xrange -10,10%yrange -10,10%fontsize 8%axis%axisnumbering%precision 1%xlabel x-axis%ylabel y-axis%grid 1,1,grey,2,2,2,red
7614 schaersvoo 5576
        */
5577
            temp = get_string(infile,1);
7653 schaersvoo 5578
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 5579
            break;
7735 schaersvoo 5580
        case YLOGBASE:
5581
        /*
5582
        @ ylogbase number
5583
        @ sets the logbase number for the y-axis
5584
        @ default value 10
5585
        @ use together with commands ylogscale / xylogscale
5586
        */
5587
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
5588
            break;
7614 schaersvoo 5589
        case YLOGSCALE:
7729 schaersvoo 5590
        /*
5591
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
5592
         @ the x/y-range are set using commands 'xrange xmin,xmax' and 'yrange ymin,ymax'
5593
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
5594
         @ the linewidth is set using command 'linewidth int'
5595
         @ the opacity of major / minor grid lines is set by command 'opacity [0-255],[0-255]'
7735 schaersvoo 5596
         @ default logbase number = 10 ... when needed , set the logbase number with command 'ylogbase number'
8224 bpr 5597
         @ 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 5598
         @ note: the complete canvas will be used for the 'log paper'
5599
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
5600
         @ note: command 'mouse color,fontsize' will show the real values in the logpaper.<br />\
5601
         @ 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')
5602
         @ note: in case of userdraw , the use of keyword 'userinput_xy' may be handy !
9383 schaersvoo 5603
         @ <b>attention</b>: keyword 'snaptogrid' may not lead to the desired result...
7729 schaersvoo 5604
        */
11972 schaersvoo 5605
            use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
7729 schaersvoo 5606
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
5607
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
5608
            for(i=0;i<4;i++){
5609
                switch(i){
5610
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
5611
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
5612
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 5613
                    case 3: fill_color = get_color(infile,1);
7779 schaersvoo 5614
                        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 5615
                        tmp_buffer = my_newmem(string_length+1);
7779 schaersvoo 5616
                        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 5617
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 5618
                        add_to_buffer(tmp_buffer);
5619
                        break;
5620
                    default:break;
5621
                }
5622
            }
7614 schaersvoo 5623
            break;
11806 schaersvoo 5624
 
5625
        case YUNIT:
7735 schaersvoo 5626
        /*
11806 schaersvoo 5627
         @ yunit some_unit_for_y-values
5628
         @ unicode allowed (no html code)
5629
         @ use together with command mousey
5630
         @ will display the cursor y-coordinate in 'unit'
7735 schaersvoo 5631
        */
11806 schaersvoo 5632
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
5633
            break;
5634
 
5635
        case ZOOM:
5636
        /*
5637
         @ zoom button_color
5638
         @ introduce a very small 'controlpanel' at the lower right corner
5639
         @ 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
5640
         @ the 'x' symbol will do a 'location.reload' of the page, and thus reset all canvas drawings.
5641
         @ choose an appropriate colour, so the small 'x,arrows,-,+' are clearly visible
5642
         @ command 'opacity' may be used to set stroke_opacity of 'buttons
5643
         @ note: use command 'zoom' at the end of your script code (the same is true for command 'mouse')
5644
         @ note: only objects that may be set draggable / clickable will be zoomed / panned
5645
         @ 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 !!
5646
        */
5647
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
5648
            use_pan_and_zoom = TRUE;
5649
            stroke_color = get_color(infile,1);
5650
            /* we use BG_CANVAS (0) */
5651
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
5652
            done = TRUE;
5653
            break;
5654
 
5655
/* ready */
7614 schaersvoo 5656
        default:sync_input(infile);
5657
        break;
5658
    }
8224 bpr 5659
  }
7614 schaersvoo 5660
  /* we are done parsing script file */
7983 schaersvoo 5661
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize : Quadrant I */
5662
  if( found_size_command == 1 ){
5663
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
5664
  }
5665
  else
5666
  {
5667
    if( found_size_command != 3 ){
8222 schaersvoo 5668
     canvas_error("Please specify both xrange and yrange ...");
7983 schaersvoo 5669
    }
5670
  }
8257 schaersvoo 5671
 
8222 schaersvoo 5672
  /* if needed, add generic draw functions (grid / xml etc) to buffer : these are no draggable/clickable shapes / objects  ! */
11021 schaersvoo 5673
  add_javascript_function(js_function,canvas_root_id);
7614 schaersvoo 5674
   /* add read_canvas() etc functions if needed */
8257 schaersvoo 5675
  if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
7797 schaersvoo 5676
  if( use_pan_and_zoom == TRUE ){
5677
  /* in case of zooming ... */
13970 obado 5678
  fprintf(js_include_file,"\n/* some extra global stuff : need to rethink panning and zooming !!! */\n\
7797 schaersvoo 5679
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 5680
  var ymin_start=ymin;var ymax_start=xmax;\
5681
  var zoom_x_increment=0;var zoom_y_increment=0;\
5682
  var pan_x_increment=0;var pan_y_increment=0;\
5683
  if(use_ylogscale == 0 ){\
7956 schaersvoo 5684
   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 5685
  }else{\
5686
   zoom_x_increment = (xmax - xmin)/20;\
5687
   pan_x_increment = (xmax - xmin)/20;\
5688
  };\
9406 schaersvoo 5689
  var zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 5690
  function start_canvas%d(type){\
9406 schaersvoo 5691
   zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 5692
   switch(type){\
7729 schaersvoo 5693
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
5694
    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 5695
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
5696
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
5697
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
5698
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
11004 schaersvoo 5699
    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
7653 schaersvoo 5700
    default:break;\
5701
   };\
5702
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
5703
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
9406 schaersvoo 5704
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
11088 schaersvoo 5705
   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
9406 schaersvoo 5706
   %s ;\
7653 schaersvoo 5707
  };\
7797 schaersvoo 5708
  start_canvas%d(333);\
9438 schaersvoo 5709
 };\
13970 obado 5710
\n/* end wims_canvas_function */\n\
9406 schaersvoo 5711
wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
7797 schaersvoo 5712
  }
5713
  else
5714
  {
5715
  /* no zoom, just add buffer */
13970 obado 5716
  fprintf(js_include_file,"\n/* add buffer */\n\
7797 schaersvoo 5717
  %s\
5718
 };\n\
13970 obado 5719
/* end wims_canvas_function */\n\
7797 schaersvoo 5720
wims_canvas_function%d();\n",buffer,canvas_root_id);
5721
  }
7614 schaersvoo 5722
/* done writing the javascript include file */
5723
fclose(js_include_file);
5724
 
5725
}
5726
 
5727
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
9329 schaersvoo 5728
 if( use_tooltip > 0 ){
5729
  if( use_tooltip == 1 ){
5730
   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
5731
  }
5732
  else
5733
  {
5734
   if( use_tooltip == 2 ){
5735
    add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
5736
   }
5737
  }
5738
 }
7614 schaersvoo 5739
exit(EXIT_SUCCESS);
5740
}
5741
/* end main() */
5742
 
5743
/******************************************************************************
5744
**
5745
**  sync_input
5746
**
5747
**  synchronises input line - reads to end of line, leaving file pointer
5748
**  at first character of next line.
5749
**
5750
**  Used by:
5751
**  main program - error handling.
5752
**
5753
******************************************************************************/
5754
void sync_input(FILE *infile)
5755
{
5756
        int c = 0;
5757
 
7658 schaersvoo 5758
        if( c == '\n' || c == ';' ) return;
5759
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 5760
        if( c == EOF ) finished = 1;
7658 schaersvoo 5761
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 5762
        return;
5763
}
5764
 
5765
/******************************************************************************/
5766
 
5767
char *str_replace(const char *str, const char *old, const char *new){
5768
/* http://creativeandcritical.net/str-replace-c/ */
5769
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
5770
    char *ret, *r;
5771
    const char *p, *q;
5772
    size_t oldlen = strlen(old);
5773
    size_t count = 0;
5774
    size_t retlen = 0;
5775
    size_t newlen = strlen(new);
5776
    if (oldlen != newlen){
5777
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
5778
            count++;
5779
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
5780
        }
8224 bpr 5781
    }
7614 schaersvoo 5782
    else
5783
    {
5784
        retlen = strlen(str);
5785
    }
8224 bpr 5786
 
7614 schaersvoo 5787
    if ((ret = malloc(retlen + 1)) == NULL){
5788
        ret = NULL;
5789
        canvas_error("string argument is NULL");
5790
    }
5791
    else
5792
    {
5793
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
5794
            size_t l = q - p;
5795
            memcpy(r, p, l);
5796
            r += l;
5797
            memcpy(r, new, newlen);
5798
            r += newlen;
5799
        }
5800
        strcpy(r, p);
5801
    }
5802
    return ret;
5803
}
5804
 
5805
/******************************************************************************/
7848 bpr 5806
 
7614 schaersvoo 5807
char *get_color(FILE *infile , int last){
5808
    int c,i = 0,is_hex = 0;
5809
    char temp[MAX_COLOR_STRING], *string;
8305 schaersvoo 5810
    const char *not_allowed = "0123456789";
10891 schaersvoo 5811
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
7614 schaersvoo 5812
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
5813
        if( c == '#' ){
5814
            is_hex = 1;
5815
        }
5816
        if( c != ' '){
8304 schaersvoo 5817
            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 5818
            temp[i]=tolower(c);
5819
            i++;
5820
        }
5821
    }
10891 schaersvoo 5822
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5823
    if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5824
    if( c == EOF ){finished = 1;}
5825
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
5826
    temp[i]='\0';
5827
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
5828
    if( is_hex == 1 ){
5829
        char red[3], green[3], blue[3];
5830
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
5831
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
5832
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
5833
        int r = (int) strtol(red,   NULL, 16);
5834
        int g = (int) strtol(green, NULL, 16);
5835
        int b = (int) strtol(blue,  NULL, 16);
5836
        string = (char *)my_newmem(12);
5837
        snprintf(string,11,"%d,%d,%d",r,g,b);
5838
        return string;
5839
    }
5840
    else
5841
    {
5842
        string = (char *)my_newmem(sizeof(temp));
5843
        snprintf(string,sizeof(temp),"%s",temp);
8304 schaersvoo 5844
        for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
7614 schaersvoo 5845
            if( strcmp( colors[i].name , string ) == 0 ){
5846
                return colors[i].rgb;
5847
            }
5848
        }
8304 schaersvoo 5849
        canvas_error("I was expecting a color name or hexnumber...but found nothing.");
7614 schaersvoo 5850
    }
8304 schaersvoo 5851
    return "0,0,255";
7614 schaersvoo 5852
}
5853
 
5854
char *get_string(FILE *infile,int last){ /* last = 0 : more arguments ; last=1 final argument */
5855
    int c,i=0;
5856
    char  temp[MAX_BUFFER], *string;
10891 schaersvoo 5857
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
7614 schaersvoo 5858
        temp[i]=c;
5859
        i++;
5860
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
5861
    }
10891 schaersvoo 5862
    if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
5863
    if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
11022 schaersvoo 5864
    if( c == EOF ) {finished = 1;}
7614 schaersvoo 5865
    temp[i]='\0';
11022 schaersvoo 5866
    if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
7614 schaersvoo 5867
    string=(char *)my_newmem(strlen(temp));
5868
    snprintf(string,sizeof(temp),"%s",temp);
5869
    return string;
5870
}
5871
 
5872
char *get_string_argument(FILE *infile,int last){  /* last = 0 : more arguments ; last=1 final argument */
5873
    int c,i=0;
5874
    char temp[MAX_BUFFER], *string;
10891 schaersvoo 5875
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
7614 schaersvoo 5876
        temp[i]=c;
5877
        i++;
5878
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
5879
    }
8224 bpr 5880
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
10891 schaersvoo 5881
    if( c == '\n' || c == '\t' ) { line_number++; }
7614 schaersvoo 5882
    if( c == EOF ) {finished = 1;}
9478 schaersvoo 5883
    if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
7614 schaersvoo 5884
    temp[i]='\0';
10953 bpr 5885
/*
8322 schaersvoo 5886
    17.10.2014 removed (question Perrin)
5887
    may cause some unwanted effects...
7614 schaersvoo 5888
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma) , but found nothing !!");}
8322 schaersvoo 5889
*/
7614 schaersvoo 5890
    string=(char *)my_newmem(sizeof(temp));
5891
    snprintf(string,sizeof(temp),"%s",temp);
5892
    done = TRUE;
5893
    return string;
5894
}
5895
 
5896
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0 : more arguments ; last=1 final argument */
5897
    int c,i=0,found_calc = 0;
5898
    double y;
5899
    char tmp[MAX_INT];
10953 bpr 5900
    /*
5901
     these things are 'allowed functions' : *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
8383 schaersvoo 5902
     but there should be a better way to avoid segfaults !
8348 schaersvoo 5903
    */
5904
    const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
5905
    const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
10891 schaersvoo 5906
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
7614 schaersvoo 5907
     if( c != ' ' ){
8224 bpr 5908
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 5909
       continue;
8224 bpr 5910
      }
7614 schaersvoo 5911
      else
5912
      {
8304 schaersvoo 5913
       c = tolower(c);
5914
       if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
5915
       if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
7614 schaersvoo 5916
       tmp[i] = c;
5917
       i++;
5918
      }
5919
     }
5920
     if( i > MAX_INT - 1){canvas_error("number too large");}
5921
    }
10891 schaersvoo 5922
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5923
    if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5924
    if( c == EOF ){done = TRUE ; finished = 1;}
5925
    tmp[i]='\0';
5926
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
8304 schaersvoo 5927
    if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
7848 bpr 5928
     void *f = eval_create(tmp);
7614 schaersvoo 5929
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 5930
     y = eval_x(f, 1);
7614 schaersvoo 5931
     /* if function is bogus; y = 1 : so no core dumps */
7848 bpr 5932
     eval_destroy(f);
7614 schaersvoo 5933
    }
5934
    else
5935
    {
5936
     y = atof(tmp);
5937
    }
5938
    return y;
5939
}
8304 schaersvoo 5940
 
13829 bpr 5941
 
7614 schaersvoo 5942
void canvas_error(char *msg){
8383 schaersvoo 5943
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d : %s</span><hr />",line_number,msg);
7614 schaersvoo 5944
    finished = 1;
5945
    exit(EXIT_SUCCESS);
5946
}
5947
 
5948
 
5949
/* convert x/y coordinates to pixel */
5950
int x2px(double x){
5951
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
5952
}
5953
 
5954
int y2px(double y){
5955
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
5956
}
5957
 
5958
double px2x(int x){
5959
 return (x*(xmax - xmin)/xsize + xmin);
5960
}
5961
double px2y(int y){
5962
 return (y*(ymax - ymin)/ysize + ymin);
5963
}
5964
 
5965
void add_to_buffer(char *tmp){
5966
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
5967
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
5968
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
5969
 if( space_left > strlen(tmp)){
5970
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
5971
 }
5972
 else
5973
 {
5974
  canvas_error("buffer is too big\n");
5975
 }
5976
 tmp = NULL;free(tmp);
5977
 return;
5978
}
5979
 
5980
void reset(){
14038 schaersvoo 5981
 use_filled = FALSE;
5982
 use_dashed = FALSE;
5983
 use_rotate = FALSE;
8379 schaersvoo 5984
 onclick = 0;
7614 schaersvoo 5985
}
5986
 
5987
 
5988
 
5989
/* What reply format in read_canvas();
5990
 
5991
note:if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
5992
1 = x1,x2,x3,x4....x_n
5993
    y1,y2,y3,y4....y_n
5994
 
5995
    x/y in pixels
5996
 
5997
2 = x1,x2,x3,x4....x_n
5998
    y1,y2,y3,y4....y_n
5999
    x/y in  xrange / yrange coordinate system
6000
 
6001
3 = x1,x2,x3,x4....x_n
6002
    y1,y2,y3,y4....y_n
6003
    r1,r2,r3,r4....r_n
6004
 
8224 bpr 6005
    x/y in pixels
7614 schaersvoo 6006
    r in pixels
6007
 
6008
4 = x1,x2,x3,x4....x_n
6009
    y1,y2,y3,y4....y_n
6010
    r1,r2,r3,r4....r_n
6011
 
6012
    x/y in  xrange / yrange coordinate system
6013
    r in pixels
6014
 
6015
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
6016
    Ay1,Ay2,Ay3,Ay4....Ay_n
6017
    Bx1,Bx2,Bx3,Bx4....Bx_n
6018
    By1,By2,By3,By4....By_n
6019
    Cx1,Cx2,Cx3,Cx4....Cx_n
6020
    Cy1,Cy2,Cy3,Cy4....Cy_n
6021
    ....
6022
    Zx1,Zx2,Zx3,Zx4....Zx_n
6023
    Zy1,Zy2,Zy3,Zy4....Zy_n
8224 bpr 6024
 
7614 schaersvoo 6025
    x/y in pixels
6026
 
6027
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
6028
    Ay1,Ay2,Ay3,Ay4....Ay_n
6029
    Bx1,Bx2,Bx3,Bx4....Bx_n
6030
    By1,By2,By3,By4....By_n
6031
    Cx1,Cx2,Cx3,Cx4....Cx_n
6032
    Cy1,Cy2,Cy3,Cy4....Cy_n
6033
    ....
6034
    Zx1,Zx2,Zx3,Zx4....Zx_n
6035
    Zy1,Zy2,Zy3,Zy4....Zy_n
6036
 
6037
    x/y in  xrange / yrange coordinate system
8224 bpr 6038
 
7614 schaersvoo 6039
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 6040
 
7614 schaersvoo 6041
    x/y in pixels
6042
 
6043
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 6044
 
7614 schaersvoo 6045
    x/y in  xrange / yrange coordinate system
6046
 
8224 bpr 6047
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 6048
 
6049
    x/y in pixels
6050
 
14044 schaersvoo 6051
10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n
7614 schaersvoo 6052
 
6053
    x/y in  xrange / yrange coordinate system
14044 schaersvoo 6054
    r is userdraw_radius
7614 schaersvoo 6055
 
6056
11 = Ax1,Ay1,Ax2,Ay2
6057
     Bx1,By1,Bx2,By2
6058
     Cx1,Cy1,Cx2,Cy2
6059
     Dx1,Dy1,Dx2,Dy2
6060
     ......
6061
     Zx1,Zy1,Zx2,Zy2
8224 bpr 6062
 
7614 schaersvoo 6063
    x/y in  xrange / yrange coordinate system
6064
 
6065
12 = Ax1,Ay1,Ax2,Ay2
6066
     Bx1,By1,Bx2,By2
6067
     Cx1,Cy1,Cx2,Cy2
6068
     Dx1,Dy1,Dx2,Dy2
6069
     ......
6070
     Zx1,Zy1,Zx2,Zy2
8224 bpr 6071
 
7614 schaersvoo 6072
    x/y in pixels
6073
 
6074
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2
6075
 
6076
    x/y in  xrange / yrange coordinate system
6077
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
6078
    x/y in pixels
6079
15 = reply from inputfields,textareas
6080
    reply1,reply2,reply3,...,reply_n
7984 schaersvoo 6081
    only fields set write (a.g. will not read 'readonly' inputfield values'
7614 schaersvoo 6082
 
6083
16 = read mathml inputfields only
6084
 
11080 schaersvoo 6085
17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
7614 schaersvoo 6086
 when ready : calculate size_t of string via snprintf(NULL,0,"blah blah...");
6087
 
6088
18 = read clock(s) : H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
6089
19 = return clicked object number (analogue to shape-library onclick)
6090
20 = return x/y-data in x-range/y-range of all 'draggable' images
6091
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
6092
22 = array : x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
6093
    x/y in  xrange / yrange coordinate system
8224 bpr 6094
23 = answertype for a polyline : remove multiple occurences  due to reclick on a point to create next polyline segment
7984 schaersvoo 6095
24 = read all inputfield values: even those set 'readonly'
8224 bpr 6096
25 = return all userdrawn arcs in degrees:
6097
26 = return all userdrawn arcs in radians:
11080 schaersvoo 6098
27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
8322 schaersvoo 6099
28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
10953 bpr 6100
    x/y/r in  xrange / yrange coordinate system: may be used to reinput into command
8322 schaersvoo 6101
    'circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n'
6102
    will not return anything else (e.g. no inputfields , text etc)
10953 bpr 6103
29 = mulidraw read :
6104
 
7614 schaersvoo 6105
*/
6106
 
14044 schaersvoo 6107
/*
6108
SCHAERSVOORDE : replyformat 2,7,8,21,22,23,24
6109
USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31
6110
OEF : 22,23,28
6111
*/
8257 schaersvoo 6112
void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
14038 schaersvoo 6113
/* just 1 reply type allowed...except for format 34 !!!  */
8074 schaersvoo 6114
fprintf(js_include_file,"\
13970 obado 6115
\n/* begin set_reply_precision() */\n\
8074 schaersvoo 6116
function set_reply_precision(){\
6117
 var len = userdraw_x.length;\
6118
 var prec = %d;\
6119
 for(var p = 0 ; p < len ; p++ ){\
6120
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
6121
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
6122
 };\
6123
 len = userdraw_radius.length;\
6124
 if( len > 0 ){\
6125
  for(var p = 0 ; p < len ; p++ ){\
6126
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
6127
  };\
6128
 };\
6129
};",reply_precision);
7963 schaersvoo 6130
 
7614 schaersvoo 6131
switch(type_reply){
8224 bpr 6132
/*
7614 schaersvoo 6133
answers may have:
6134
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
6135
*/
6136
    case 1: fprintf(js_include_file,"\
13970 obado 6137
\n/* begin function 1 read_canvas%d() */\n\
8257 schaersvoo 6138
read_canvas%d = function(){\
7614 schaersvoo 6139
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 6140
 set_reply_precision();\
7614 schaersvoo 6141
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6142
  var p = 0;var input_reply = new Array();\
6143
  if( document.getElementById(\"canvas_input0\")){\
6144
   var t = 0;\
6145
   while(document.getElementById(\"canvas_input\"+t)){\
6146
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6147
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6148
     p++;\
6149
    };\
6150
    t++;\
6151
   };\
6152
  };\
11088 schaersvoo 6153
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6154
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
6155
  }\
6156
  else\
6157
  {\
6158
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
6159
  }\
6160
 }\
6161
 else\
6162
 {\
11088 schaersvoo 6163
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6164
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
6165
  }\
6166
  else\
6167
  {\
6168
   return userdraw_x+\"\\n\"+userdraw_y;\
6169
  }\
6170
 };\
8108 schaersvoo 6171
};\n\
13970 obado 6172
/* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6173
    break;
6174
    case 2: fprintf(js_include_file,"\
13970 obado 6175
\n/* begin function 2 read_canvas%d() */\n\
8257 schaersvoo 6176
read_canvas%d = function(){\
7614 schaersvoo 6177
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 6178
 set_reply_precision();\
7614 schaersvoo 6179
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 6180
 var prec = %d;\
7614 schaersvoo 6181
 while(userdraw_x[p]){\
8074 schaersvoo 6182
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
6183
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 6184
  p++;\
6185
 };\
11806 schaersvoo 6186
 if(p == 0){return;};\
7614 schaersvoo 6187
 if( document.getElementById(\"canvas_input0\")){\
6188
  var p = 0;var input_reply = new Array();\
6189
  if( document.getElementById(\"canvas_input0\")){\
6190
   var t = 0;\
6191
   while(document.getElementById(\"canvas_input\"+t)){\
6192
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6193
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6194
     p++;\
6195
    };\
6196
    t++;\
6197
   };\
6198
  };\
11088 schaersvoo 6199
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6200
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6201
  }\
6202
  else\
6203
  {\
6204
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
6205
  }\
6206
 }\
6207
 else\
6208
 {\
11088 schaersvoo 6209
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6210
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
6211
  }\
6212
  else\
6213
  {\
6214
   return reply_x+\"\\n\"+reply_y;\
6215
  };\
6216
 };\
8108 schaersvoo 6217
};\n\
13970 obado 6218
/* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6219
    break;
6220
    case 3: fprintf(js_include_file,"\
13970 obado 6221
\n/* begin function 3 read_canvas%d() */\n\
8257 schaersvoo 6222
read_canvas%d = function(){\
7614 schaersvoo 6223
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 6224
 set_reply_precision();\
7614 schaersvoo 6225
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6226
  var p = 0;var input_reply = new Array();\
6227
  if( document.getElementById(\"canvas_input0\")){\
6228
   var t = 0;\
6229
   while(document.getElementById(\"canvas_input\"+t)){\
6230
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6231
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6232
     p++;\
6233
    };\
6234
    t++;\
6235
   };\
6236
  };\
11088 schaersvoo 6237
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6238
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6239
  }\
6240
  else\
6241
  {\
6242
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
6243
  }\
6244
 }\
6245
 else\
6246
 {\
11088 schaersvoo 6247
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6248
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
6249
  }\
6250
  else\
6251
  {\
6252
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
6253
  }\
6254
 }\
8108 schaersvoo 6255
};\n\
13970 obado 6256
/* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6257
    break;
6258
    case 4: fprintf(js_include_file,"\
13970 obado 6259
\n/* begin function 4 read_canvas%d() */\n\
8257 schaersvoo 6260
read_canvas%d = function(){\
8074 schaersvoo 6261
 var prec = %d;\
7614 schaersvoo 6262
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
6263
 while(userdraw_x[p]){\
8074 schaersvoo 6264
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
6265
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 6266
  p++;\
6267
 };\
11806 schaersvoo 6268
 if(p == 0){return;};\
7614 schaersvoo 6269
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6270
  var p = 0;var input_reply = new Array();\
6271
  if( document.getElementById(\"canvas_input0\")){\
6272
   var t = 0;\
6273
   while(document.getElementById(\"canvas_input\"+t)){\
6274
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6275
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6276
     p++;\
6277
    };\
6278
    t++;\
6279
   };\
6280
  };\
11088 schaersvoo 6281
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6282
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6283
  }\
6284
  else\
6285
  {\
6286
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
6287
  }\
6288
 }\
6289
 else\
6290
 {\
11088 schaersvoo 6291
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6292
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
6293
  }\
6294
  else\
6295
  {\
6296
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
6297
  }\
6298
 };\
8108 schaersvoo 6299
};\n\
13970 obado 6300
/* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6301
    break;
8224 bpr 6302
    /*
6303
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
6304
        used for userdraw multiple paths
7614 schaersvoo 6305
    */
6306
    case 5: fprintf(js_include_file,"\
13970 obado 6307
\n/* begin function 5 read_canvas%d() */\n\
8257 schaersvoo 6308
read_canvas%d = function(){\
8074 schaersvoo 6309
 set_reply_precision();\
7614 schaersvoo 6310
 var p = 0;\
6311
 var reply = \"\";\
6312
 for(p = 0; p < userdraw_x.length;p++){\
6313
  if(userdraw_x[p] != null ){\
6314
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
6315
  };\
6316
 };\
11806 schaersvoo 6317
 if(p == 0){return;};\
7614 schaersvoo 6318
 userdraw_x = [];userdraw_y = [];\
6319
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6320
  var p = 0;var input_reply = new Array();\
6321
  if( document.getElementById(\"canvas_input0\")){\
6322
   var t = 0;\
6323
   while(document.getElementById(\"canvas_input\"+t)){\
6324
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6325
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6326
     p++;\
6327
    };\
6328
    t++;\
6329
   };\
6330
  };\
11088 schaersvoo 6331
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6332
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6333
  }\
6334
  else\
6335
  {\
6336
   return reply +\"\\n\"+input_reply;\
6337
  }\
6338
 }\
6339
 else\
6340
 {\
11088 schaersvoo 6341
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6342
   return reply+\"\\n\"+userdraw_text;\
6343
  }\
6344
  else\
6345
  {\
6346
   return reply;\
6347
  }\
6348
 };\
8108 schaersvoo 6349
};\n\
13970 obado 6350
/* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6351
    break;
8224 bpr 6352
    /*
6353
        attention: we reset userdraw_x / userdraw_y  : because  userdraw_x = [][] userdraw_y = [][]
6354
        used for userdraw multiple paths
7614 schaersvoo 6355
    */
6356
    case 6: fprintf(js_include_file,"\
13970 obado 6357
\n/* begin function 6 read_canvas%d() */\n\
8257 schaersvoo 6358
read_canvas%d = function(){\
7614 schaersvoo 6359
 var p = 0;\
6360
 var reply = \"\";\
6361
 var tmp_x = new Array();\
6362
 var tmp_y = new Array();\
8074 schaersvoo 6363
 var prec = %d;\
7614 schaersvoo 6364
 for(p = 0 ; p < userdraw_x.length; p++){\
6365
  tmp_x = userdraw_x[p];\
6366
  tmp_y = userdraw_y[p];\
6367
  if(tmp_x != null){\
6368
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 6369
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
6370
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 6371
   };\
6372
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
6373
  };\
6374
 };\
11806 schaersvoo 6375
 if(p == 0){return;};\
7614 schaersvoo 6376
 userdraw_x = [];userdraw_y = [];\
6377
 if( document.getElementById(\"canvas_input0\") ){\
6378
  var p = 0;var input_reply = new Array();\
6379
  if( document.getElementById(\"canvas_input0\")){\
6380
   var t = 0;\
6381
   while(document.getElementById(\"canvas_input\"+t)){\
6382
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6383
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6384
     p++;\
6385
    };\
6386
    t++;\
6387
   };\
6388
  };\
11088 schaersvoo 6389
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6390
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6391
  }\
6392
  else\
6393
  {\
6394
   return reply +\"\\n\"+input_reply;\
6395
  }\
6396
 }\
6397
 else\
6398
 {\
11088 schaersvoo 6399
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6400
   return reply +\"\\n\"+userdraw_text;\
6401
  }\
6402
  else\
6403
  {\
6404
   return reply;\
6405
  }\
6406
 };\
8108 schaersvoo 6407
};\n\
13970 obado 6408
/* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6409
    break;
6410
    case 7: fprintf(js_include_file,"\
13970 obado 6411
\n/* begin function 7 read_canvas%d() */\n\
8257 schaersvoo 6412
read_canvas%d = function(){\
8074 schaersvoo 6413
 set_reply_precision();\
7614 schaersvoo 6414
 var reply = new Array();\
6415
 var p = 0;\
6416
 while(userdraw_x[p]){\
6417
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
6418
  p++;\
6419
 };\
11806 schaersvoo 6420
 if(p == 0){return;};\
7614 schaersvoo 6421
 if( document.getElementById(\"canvas_input0\") ){\
6422
  var p = 0;var input_reply = new Array();\
6423
  if( document.getElementById(\"canvas_input0\")){\
6424
   var t = 0;\
6425
   while(document.getElementById(\"canvas_input\"+t)){\
6426
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6427
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6428
     p++;\
6429
    };\
6430
    t++;\
6431
   };\
6432
  };\
11088 schaersvoo 6433
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6434
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6435
  }\
6436
  else\
6437
  {\
6438
   return reply+\"\\n\"+input_reply;\
6439
  }\
7862 schaersvoo 6440
 }\
7614 schaersvoo 6441
 else\
6442
 {\
11088 schaersvoo 6443
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6444
   return reply+\"\\n\"+userdraw_text;\
6445
  }\
6446
  else\
6447
  {\
6448
   return reply;\
6449
  }\
6450
 };\
8108 schaersvoo 6451
};\n\
13970 obado 6452
/* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6453
    break;
6454
    case 8: fprintf(js_include_file,"\
13970 obado 6455
\n/* begin function 8 read_canvas%d() */\n\
8257 schaersvoo 6456
read_canvas%d = function(){\
7614 schaersvoo 6457
 var reply = new Array();\
6458
 var p = 0;\
8074 schaersvoo 6459
 var prec = %d;\
7614 schaersvoo 6460
 while(userdraw_x[p]){\
8074 schaersvoo 6461
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 6462
  p++;\
6463
 };\
11806 schaersvoo 6464
 if(p == 0){return;};\
7614 schaersvoo 6465
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6466
  var p = 0;var input_reply = new Array();\
6467
  if( document.getElementById(\"canvas_input0\")){\
6468
   var t = 0;\
6469
   while(document.getElementById(\"canvas_input\"+t)){\
6470
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6471
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6472
     p++;\
6473
    };\
6474
    t++;\
6475
   };\
6476
  };\
11088 schaersvoo 6477
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6478
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6479
  }\
6480
  else\
6481
  {\
6482
   return reply +\"\\n\"+input_reply;\
6483
  }\
6484
 }\
6485
 else\
6486
 {\
11088 schaersvoo 6487
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6488
   return reply +\"\\n\"+userdraw_text;\
6489
  }\
6490
  else\
6491
  {\
6492
   return reply;\
6493
  }\
6494
 };\
8108 schaersvoo 6495
};\n\
13970 obado 6496
/* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6497
    break;
6498
    case 9: fprintf(js_include_file,"\
13970 obado 6499
\n/* begin function 9 read_canvas%d() */\n\
8257 schaersvoo 6500
read_canvas%d = function(){\
8074 schaersvoo 6501
 set_reply_precision();\
7614 schaersvoo 6502
 var reply = new Array();\
6503
 var p = 0;\
6504
 while(userdraw_x[p]){\
6505
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
6506
  p++;\
6507
 };\
11806 schaersvoo 6508
 if(p == 0){return;};\
7614 schaersvoo 6509
 if( document.getElementById(\"canvas_input0\") ){\
6510
  var p = 0;var input_reply = new Array();\
6511
  if( document.getElementById(\"canvas_input0\")){\
6512
   var t = 0;\
6513
   while(document.getElementById(\"canvas_input\"+t)){\
6514
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6515
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6516
     p++;\
6517
    };\
6518
    t++;\
6519
   };\
6520
  };\
11088 schaersvoo 6521
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6522
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6523
  }\
6524
  else\
6525
  {\
6526
   return reply +\"\\n\"+input_reply;\
6527
  }\
6528
 }\
6529
 else\
6530
 {\
11088 schaersvoo 6531
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6532
   return reply +\"\\n\"+userdraw_text;\
6533
  }\
6534
  else\
6535
  {\
6536
   return reply;\
6537
  }\
6538
 };\
8108 schaersvoo 6539
};\n\
13970 obado 6540
/* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6541
    break;
6542
    case 10: fprintf(js_include_file,"\
13970 obado 6543
\n/* begin function 10 read_canvas%d() */\n\
8257 schaersvoo 6544
read_canvas%d = function(){\
7614 schaersvoo 6545
 var reply = new Array();\
6546
 var p = 0;\
8074 schaersvoo 6547
 var prec = %d;\
14044 schaersvoo 6548
 var reply = \"\";\
7614 schaersvoo 6549
 while(userdraw_x[p]){\
14044 schaersvoo 6550
  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\";\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec + \";\" + (Math.round(prec*userdraw_radius[p]))/prec + \"\\n\";\
7614 schaersvoo 6551
  p++;\
6552
 };\
11806 schaersvoo 6553
 if(p == 0){return;};\
14044 schaersvoo 6554
 return reply;\
8108 schaersvoo 6555
};\n\
13970 obado 6556
/* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6557
    break;
6558
    case 11: fprintf(js_include_file,"\
13970 obado 6559
\n/* begin function 11 read_canvas%d() */\n\
8257 schaersvoo 6560
read_canvas%d = function(){\
7614 schaersvoo 6561
 var reply = \"\";\
6562
 var p = 0;\
8074 schaersvoo 6563
 var prec = %d;\
13521 schaersvoo 6564
 while(userdraw_x[p+1]){\
8074 schaersvoo 6565
  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 6566
  p = p+2;\
6567
 };\
11806 schaersvoo 6568
 if(p == 0){return;};\
7614 schaersvoo 6569
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6570
  var p = 0;var input_reply = new Array();\
6571
  if( document.getElementById(\"canvas_input0\")){\
6572
   var t = 0;\
6573
   while(document.getElementById(\"canvas_input\"+t)){\
6574
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6575
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6576
     p++;\
6577
    };\
6578
    t++;\
6579
   };\
6580
  };\
11088 schaersvoo 6581
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6582
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6583
  }\
6584
  else\
6585
  {\
6586
   return reply +\"\\n\"+input_reply;\
6587
  }\
6588
 }\
6589
 else\
6590
 {\
11088 schaersvoo 6591
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6592
   return reply +\"\\n\"+userdraw_text;\
6593
  }\
6594
  else\
6595
  {\
6596
   return reply;\
6597
  }\
6598
 };\
8108 schaersvoo 6599
};\n\
13970 obado 6600
/* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6601
    break;
6602
    case 12: fprintf(js_include_file,"\
13970 obado 6603
\n/* begin function 12 read_canvas%d() */\n\
8257 schaersvoo 6604
read_canvas%d = function(){\
8074 schaersvoo 6605
 set_reply_precision();\
7614 schaersvoo 6606
 var reply = \"\";\
6607
 var p = 0;\
13522 schaersvoo 6608
 while(userdraw_x[p+1]){\
6609
 reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
6610
 p=p+2;\
7614 schaersvoo 6611
 };\
13522 schaersvoo 6612
 };\
11806 schaersvoo 6613
 if(p == 0){return;};\
7614 schaersvoo 6614
 if( document.getElementById(\"canvas_input0\") ){\
6615
  var p = 0;var input_reply = new Array();\
6616
  if( document.getElementById(\"canvas_input0\")){\
6617
   var t = 0;\
6618
   while(document.getElementById(\"canvas_input\"+t)){\
6619
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6620
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6621
     p++;\
6622
    };\
6623
    t++;\
6624
   };\
6625
  };\
11088 schaersvoo 6626
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6627
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6628
  }\
6629
  else\
6630
  {\
6631
   return reply +\"\\n\"+input_reply;\
6632
  }\
6633
 }\
6634
 else\
6635
 {\
11088 schaersvoo 6636
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6637
   return reply +\"\\n\"+userdraw_text\
6638
  }\
6639
  else\
6640
  {\
6641
   return reply;\
6642
  }\
6643
 };\
8108 schaersvoo 6644
};\n\
13970 obado 6645
/* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6646
    break;
6647
    case 13: fprintf(js_include_file,"\
13970 obado 6648
\n/* begin function 13 read_canvas%d() */\n\
8257 schaersvoo 6649
read_canvas%d = function(){\
7614 schaersvoo 6650
 var reply = new Array();\
6651
 var p = 0;var i = 0;\
8074 schaersvoo 6652
 var prec = %d;\
13521 schaersvoo 6653
 while(userdraw_x[p+1]){\
8074 schaersvoo 6654
  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 6655
  p = p+2;i++;\
6656
 };\
11806 schaersvoo 6657
 if(p == 0){return;};\
7614 schaersvoo 6658
 if( document.getElementById(\"canvas_input0\") ){\
6659
  var p = 0;var input_reply = new Array();\
6660
  if( document.getElementById(\"canvas_input0\")){\
6661
   var t = 0;\
6662
   while(document.getElementById(\"canvas_input\"+t)){\
6663
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6664
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6665
     p++;\
6666
    };\
6667
    t++;\
6668
   };\
6669
  };\
11088 schaersvoo 6670
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6671
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6672
  }\
6673
  else\
6674
  {\
6675
   return reply +\"\\n\"+input_reply;\
6676
  }\
6677
 }\
6678
 else\
6679
 {\
11088 schaersvoo 6680
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6681
   return reply +\"\\n\"+userdraw_text\
6682
  }\
6683
  else\
6684
  {\
6685
   return reply;\
6686
  }\
6687
 };\
8108 schaersvoo 6688
};\n\
13970 obado 6689
/* end function 13 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6690
    break;
6691
    case 14: fprintf(js_include_file,"\
13970 obado 6692
\n/* begin function 14 read_canvas%d() */\n\
8257 schaersvoo 6693
read_canvas%d = function(){\
8074 schaersvoo 6694
 set_reply_precision();\
7614 schaersvoo 6695
 var reply = new Array();\
6696
 var p = 0;var i = 0;\
13521 schaersvoo 6697
 while(userdraw_x[p+1]){\
7614 schaersvoo 6698
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
6699
  p = p+2;i++;\
6700
 };\
11806 schaersvoo 6701
 if(p == 0){return;};\
7614 schaersvoo 6702
 if( document.getElementById(\"canvas_input0\") ){\
6703
  var p = 0;var input_reply = new Array();\
6704
  if( document.getElementById(\"canvas_input0\")){\
6705
   var t = 0;\
6706
   while(document.getElementById(\"canvas_input\"+t)){\
6707
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6708
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6709
     p++;\
6710
    };\
6711
    t++;\
6712
   };\
6713
  };\
11088 schaersvoo 6714
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6715
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6716
  }\
6717
  else\
6718
  {\
6719
   return reply +\"\\n\"+input_reply;\
6720
  }\
6721
 }\
6722
 else\
6723
 {\
11088 schaersvoo 6724
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6725
   return reply +\"\\n\"+userdraw_text;\
6726
  }\
6727
  else\
6728
  {\
6729
   return reply;\
6730
  }\
6731
 };\
8108 schaersvoo 6732
};\n\
13970 obado 6733
/* end function 14 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6734
    break;
6735
    case 15: fprintf(js_include_file,"\
13970 obado 6736
\n/* begin function 15  read_canvas%d() */\n\
8257 schaersvoo 6737
read_canvas%d = function(){\
7614 schaersvoo 6738
 var input_reply = new Array();\
6739
 var p = 0;\
6740
 if( document.getElementById(\"canvas_input0\")){\
6741
  var t = 0;\
6742
  while(document.getElementById(\"canvas_input\"+t)){\
6743
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6744
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6745
    p++;\
6746
   };\
6747
   t++;\
6748
  };\
6749
 };\
11088 schaersvoo 6750
 if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6751
   return input_reply +\"\\n\"+userdraw_text;\
6752
 }\
6753
 else\
6754
 {\
6755
  return input_reply;\
6756
 };\
8108 schaersvoo 6757
};\n\
13970 obado 6758
/* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6759
    break;
6760
    case 16: fprintf(js_include_file,"\
13970 obado 6761
\n/* begin function 16 read_mathml() */\n\
7614 schaersvoo 6762
function read_mathml(){\
6763
 var reply = new Array();\
6764
 var p = 0;\
6765
 if( document.getElementById(\"mathml0\")){\
6766
  while(document.getElementById(\"mathml\"+p)){\
6767
   reply[p] = document.getElementById(\"mathml\"+p).value;\
6768
   p++;\
6769
  };\
6770
 };\
6771
return reply;\
6772
};\
6773
this.read_mathml = read_mathml;\n\
13970 obado 6774
/* end function 16 read_mathml() */");
7614 schaersvoo 6775
    break;
6776
    case 17:  fprintf(js_include_file,"\
13970 obado 6777
\n/* begin function 17 read_canvas%d() */\n\
8257 schaersvoo 6778
read_canvas%d = function(){\
11080 schaersvoo 6779
 var len = userdraw_x.length;\
6780
 if( len == 0){alert(\"no text typed...\");return;}\
6781
 var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
6782
 for(var p = 1 ; p < len ; p++){\
6783
  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
6784
 };\
6785
 return rep;\
8108 schaersvoo 6786
};\n\
13970 obado 6787
/* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6788
    break;
6789
    case 18: fprintf(js_include_file,"\
13970 obado 6790
\n/* javascript has no real modulo function */\n\
10956 schaersvoo 6791
function mod(n, m){\
6792
 var m = parseInt(((n %% m) + m) %% m);\
6793
 return m;\
6794
};\
13970 obado 6795
\n/* begin function 18 read_canvas%d() */\n\
8257 schaersvoo 6796
read_canvas%d = function(){\
7614 schaersvoo 6797
 var p = 0;\
6798
 var reply = new Array();\
6799
 var name;\
6800
 var t = true;\
8000 schaersvoo 6801
 var h;var m;var s;\
7614 schaersvoo 6802
 while(t){\
8000 schaersvoo 6803
  try{\
6804
   name = eval('clocks'+p);\
6805
   h = name.H;m = name.M;s = name.S;\
10956 schaersvoo 6806
   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
8000 schaersvoo 6807
   reply[p] = h+\":\"+m+\":\"+s;\
6808
   p++;\
6809
  }catch(e){t=false;};\
7614 schaersvoo 6810
 };\
8000 schaersvoo 6811
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 6812
 return reply;\
8108 schaersvoo 6813
};\n\
13970 obado 6814
/* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6815
    break;
6816
    case 19: fprintf(js_include_file,"\
13970 obado 6817
\n/* begin function 19 read_canvas%d() */\n\
8257 schaersvoo 6818
read_canvas%d = function(){\
7614 schaersvoo 6819
 return reply[0];\
8108 schaersvoo 6820
};\n\
13970 obado 6821
/* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
8130 schaersvoo 6822
    break;
7614 schaersvoo 6823
    case 20: fprintf(js_include_file,"\
13970 obado 6824
\n/* begin function 20 read_canvas%d() */\n\
8257 schaersvoo 6825
read_canvas%d = function(){\
8074 schaersvoo 6826
 var prec = %d;\
7614 schaersvoo 6827
 var len  = ext_drag_images.length;\
6828
 var reply = new Array(len);\
6829
 for(var p = 0 ; p < len ; p++){\
6830
    var img = ext_drag_images[p];\
8556 schaersvoo 6831
    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 6832
 };\
6833
 return reply;\
8108 schaersvoo 6834
};\n\
13970 obado 6835
/* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6836
    break;
6837
    case 21: fprintf(js_include_file,"\
13970 obado 6838
\n/* begin function 21 read_canvas%d() */\n\
8257 schaersvoo 6839
read_canvas%d = function(){\
7614 schaersvoo 6840
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
6841
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 6842
 var prec = %d;\
7614 schaersvoo 6843
 while(userdraw_x[p]){\
8074 schaersvoo 6844
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 6845
  p++;\
6846
 };\
11806 schaersvoo 6847
 if(p == 0){return;};\
7614 schaersvoo 6848
 if( document.getElementById(\"canvas_input0\") ){\
6849
  var p = 0;var input_reply = new Array();\
6850
  if( document.getElementById(\"canvas_input0\")){\
6851
   var t = 0;\
6852
   while(document.getElementById(\"canvas_input\"+t)){\
6853
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6854
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6855
     p++;\
6856
    };\
6857
    t++;\
6858
   };\
6859
  };\
11088 schaersvoo 6860
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6861
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6862
  }\
6863
  else\
6864
  {\
6865
   return reply_coord+\"\\n\"+input_reply;\
6866
  }\
6867
 }\
6868
 else\
6869
 {\
11088 schaersvoo 6870
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6871
   return reply_coord+\"\\n\"+userdraw_text;\
6872
  }\
6873
  else\
6874
  {\
6875
   return reply_coord;\
6876
  };\
6877
 };\
8108 schaersvoo 6878
};\n\
13970 obado 6879
/* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6880
    break;
6881
    case 22: fprintf(js_include_file,"\
13970 obado 6882
\n/* begin function 22 read_canvas%d() */\n\
8257 schaersvoo 6883
read_canvas%d = function(){\
7614 schaersvoo 6884
 var reply = new Array();\
7963 schaersvoo 6885
 var lu = userdraw_x.length;\
11806 schaersvoo 6886
 if(lu == 0){return;};\
7614 schaersvoo 6887
 var idx = 0;\
8074 schaersvoo 6888
 var prec = %d;\
7963 schaersvoo 6889
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 6890
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
6891
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 6892
 };\
6893
 if( document.getElementById(\"canvas_input0\") ){\
6894
  var p = 0;var input_reply = new Array();\
6895
  if( document.getElementById(\"canvas_input0\")){\
6896
   var t = 0;\
6897
   while(document.getElementById(\"canvas_input\"+t)){\
6898
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6899
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6900
     p++;\
6901
    };\
6902
    t++;\
6903
   };\
6904
  };\
11088 schaersvoo 6905
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6906
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6907
  }\
6908
  else\
6909
  {\
6910
   return reply +\"\\n\"+input_reply;\
6911
  }\
6912
 }\
6913
 else\
6914
 {\
11088 schaersvoo 6915
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6916
   return reply +\"\\n\"+userdraw_text;\
6917
  }\
6918
  else\
6919
  {\
6920
   return reply;\
6921
  }\
6922
 };\
8108 schaersvoo 6923
};\n\
13970 obado 6924
/* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6925
    break;
7782 schaersvoo 6926
    case 23: fprintf(js_include_file,"\
13970 obado 6927
\n/* begin function 23 read_canvas%d() default 5 px marge */\n\
8257 schaersvoo 6928
read_canvas%d = function(){\
7782 schaersvoo 6929
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
6930
 var lu = userdraw_x.length;\
6931
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 6932
 var reply_x = new Array();var reply_y = new Array();\
6933
 var marge = 5;var p = 0;\
8074 schaersvoo 6934
 var prec = %d;\
7782 schaersvoo 6935
 for(var i = 0; i < lu - 1 ; i++ ){\
10987 schaersvoo 6936
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
8074 schaersvoo 6937
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 6938
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
6939
   p++;\
7782 schaersvoo 6940
  };\
8074 schaersvoo 6941
  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 6942
 };\
6943
 if( document.getElementById(\"canvas_input0\")){\
6944
  var p = 0;var input_reply = new Array();\
6945
  if( document.getElementById(\"canvas_input0\")){\
6946
   var t = 0;\
6947
   while(document.getElementById(\"canvas_input\"+t)){\
6948
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6949
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6950
     p++;\
6951
    };\
6952
    t++;\
6953
   };\
6954
  };\
11088 schaersvoo 6955
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6956
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6957
  }\
6958
  else\
6959
  {\
6960
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
6961
  }\
6962
 }\
6963
 else\
6964
 {\
11088 schaersvoo 6965
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6966
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
6967
  }\
6968
  else\
6969
  {\
6970
   return reply_x+\"\\n\"+reply_y;\
6971
  };\
6972
 };\
8108 schaersvoo 6973
};\n\
13970 obado 6974
/* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7782 schaersvoo 6975
    break;
7984 schaersvoo 6976
    case 24: fprintf(js_include_file,"\n\
13970 obado 6977
/* begin function 24  read_canvas%d() */\n\
8257 schaersvoo 6978
read_canvas%d = function(){\
7984 schaersvoo 6979
 var input_reply = new Array();\
6980
 var p = 0;\
6981
 if( document.getElementById(\"canvas_input0\")){\
6982
  while(document.getElementById(\"canvas_input\"+p)){\
6983
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
6984
    p++;\
6985
  };\
6986
  return input_reply;\
6987
 };\
8108 schaersvoo 6988
};\n\
13970 obado 6989
/* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7984 schaersvoo 6990
    break;
8083 schaersvoo 6991
    case 25:
13970 obado 6992
    fprintf(js_include_file,"\n/* begin function 25 read_canvas%d() : angle(s) in degrees */\n\
8257 schaersvoo 6993
read_canvas%d = function(){\
8083 schaersvoo 6994
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
6995
 var lu = userdraw_radius.length;\
6996
 var prec = %d;\
6997
 var angle_reply = new Array(lu);\
6998
 for(var p = 0 ; p < lu ; p++){\
6999
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
7000
 };\
7001
 return angle_reply;\
8108 schaersvoo 7002
};\n\
13970 obado 7003
/* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 7004
    break;
7005
    case 26:
13970 obado 7006
    fprintf(js_include_file,"\n/* begin function 26 read_canvas%d() : angle(s) in radians */\n\
8257 schaersvoo 7007
read_canvas%d = function(){\
8083 schaersvoo 7008
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
7009
 var lu = userdraw_radius.length;\
7010
 var prec = %d;\
7011
 var angle_reply = new Array(lu);\
7012
 for(var p = 0 ; p < lu ; p++){\
7013
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
7014
 };\
7015
 return angle_reply;\
8108 schaersvoo 7016
};\n\
13970 obado 7017
/* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 7018
    break;
8127 schaersvoo 7019
    case 27:
13970 obado 7020
    fprintf(js_include_file,"\n/* begin function 27 read_canvas%d()  : inputfield(s) location and their values : */\n\
8257 schaersvoo 7021
read_canvas%d = function(){\
8127 schaersvoo 7022
 var lu = userdraw_x.length;\
14044 schaersvoo 7023
 if( lu < 1){alert(\"nothing drawn...\");return;};\
8127 schaersvoo 7024
 set_reply_precision();\
14044 schaersvoo 7025
 var prec = %d;var rep = \"\";\
8127 schaersvoo 7026
 for(var p = 0 ; p < lu ; p++){\
14044 schaersvoo 7027
   rep = rep + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\";\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\";\"+ document.getElementById(\"canvas_input\"+p).value + \"\\n\";\
8127 schaersvoo 7028
 };\
11080 schaersvoo 7029
 return rep;\
8127 schaersvoo 7030
};\n\
13970 obado 7031
/* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8127 schaersvoo 7032
    break;
8322 schaersvoo 7033
    case 28:
13970 obado 7034
    fprintf(js_include_file,"\n/* begin function 28 read_canvas%d() */\n\
8322 schaersvoo 7035
read_canvas%d = function(){\
7036
 var prec = %d;\
7037
 var reply = new Array();var p = 0;\
7038
 var idx = 0;\
7039
 while(userdraw_x[p]){\
7040
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
7041
  idx++;\
7042
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7043
  idx++;\
7044
  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
7045
  idx++;\
7046
  p++;\
7047
 };\
7048
 if( p == 0){alert(\"nothing drawn...\");return;}\
7049
 return reply;\
7050
};\n\
13970 obado 7051
/* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8322 schaersvoo 7052
    break;
9213 schaersvoo 7053
    case 29:
13970 obado 7054
    fprintf(js_include_file,"\n/* begin function 29 read_canvas%d() */\n\
14038 schaersvoo 7055
function x_precision(array_x){\
9213 schaersvoo 7056
 var len = array_x.length;\
7057
 var x_array = new Array(len);\
14038 schaersvoo 7058
 var prec = %d;\
7059
 for(var p = 0 ; p < len ; p++ ){\
7060
  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
7061
 };\
7062
 return x_array;\
7063
};\
7064
function y_precision(array_y){\
7065
 var len = array_y.length;\
9213 schaersvoo 7066
 var y_array = new Array(len);\
7067
 var prec = %d;\
7068
 for(var p = 0 ; p < len ; p++ ){\
7069
  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
7070
 };\
14038 schaersvoo 7071
 return y_array;\
7072
};\
9213 schaersvoo 7073
function round_to_pixel(array_r){\
7074
var len = array_r.length;\
7075
 for(var p = 0 ; p < len ; p++ ){\
7076
  array_r[p] = Math.round(array_r[p]);\
7077
 };\
7078
 return array_r;\
7079
};\
7080
read_canvas%d = function(){\
14038 schaersvoo 7081
 function uniq_fast(arr){\
7082
  var seen = {};\
7083
  var out = [];\
7084
  var len = arr.length;\
7085
  var j = 0;\
7086
  for(var i = 0; i < len; i++){\
7087
   var item = arr[i];\
7088
   if(seen[item] !== 1) {\
7089
    seen[item] = 1;out[j++] = item;\
7090
   };\
7091
  };\
7092
  return out;\
7093
 };\
7094
 function list_unique(arr1,arr2,arr3){\
7095
  var len1 = arr1.length;\
7096
  if(len1 != arr2.length){alert('mismatch in number of x and y values...');return;};\
7097
  var sum = [];var R1=[];var R2=[];\
7098
  arr1 = x_precision(arr1);\
7099
  arr2 = y_precision(arr2);\
7100
  if(arr3 == null){\
7101
   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\
7102
   sum = uniq_fast(sum);var len2=sum.length;\
7103
   for(var p=0;p<len2;p++){\
7104
    var tmp = (sum[p]).split('#');\
7105
    R1[p] = tmp[0];\
7106
    R2[p] = tmp[1];\
7107
   };\
7108
   return [R1,R2];\
7109
  }else{\
7110
   var R3 = [];\
7111
   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\
7112
   sum = uniq_fast(sum);var len2=sum.length;\
7113
   for(var p=0;p<len2;p++){\
7114
    var tmp = (sum[p]).split('#');\
7115
    R1[p] = tmp[0];\
7116
    R2[p] = tmp[1];\
7117
    R3[p] = tmp[2];\
7118
   };\
7119
   return [R1,R2,R3];\
7120
  };\
7121
 };\
9300 schaersvoo 7122
 var reply=\" \";\
14038 schaersvoo 7123
 if(  typeof(points_x) === 'object' && points_x.length > 0 ){var xyz = list_unique(points_x,points_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
7124
 if(  typeof(circles_x) === 'object' && circles_x.length > 0 ){var xyz = list_unique(circles_x,circles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7125
 if(  typeof(segments_x) === 'object' && segments_x.length > 0 ){ var xyz = list_unique(segments_x,segments_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
7126
 if(  typeof(arrows_x) === 'object' && arrows_x.length > 0 ){var xyz = list_unique(arrows_x,arrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7127
 if(  typeof(lines_x) === 'object' && lines_x.length > 0 ){ var xyz = list_unique(lines_x,lines_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7128
 if(  typeof(triangles_x) === 'object' && triangles_x.length > 0){var xyz = list_unique(triangles_x,triangles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7129
 if(  typeof(polys_x) === 'object' && polys_x.length > 0){ var xyz = list_unique(polys_x,polys_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7130
 if(  typeof(rects_x) === 'object' && rects_x.length > 0 ){var xyz = list_unique(rects_x,rects_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7131
 if(  typeof(closedpoly_x) === 'object' && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();var xyz = list_unique(closedpoly_x,closedpoly_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
7132
 if(  typeof(parallelogram_x) === 'object' && parallelogram_x.length > 0){var xyz = list_unique(parallelogram_x,parallelogram_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
7133
 if(  typeof(text_x) === 'object' && text_x.length > 0){var xyz = list_unique(text_x,text_y,text_abc);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
7134
 if(  typeof(images_x) === 'object' && images_x.length > 0){var xyz = list_unique(images_x,images_y,images_id);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
7135
 if(  typeof(curvedarrows_x) === 'object' && curvedarrows_x.length > 0){var xyz = list_unique(curvedarrows_x,curvedarrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\
7136
 if(  typeof(curvedarrows2_x) === 'object' && curvedarrows2_x.length > 0){var xyz = list_unique(curvedarrows2_x,curvedarrows2_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\
7137
 if(  typeof(userdraw_x) === 'object' && userdraw_radius.x> 0){var xyz = list_unique(userdraw_x,userdraw_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; return reply;;};\
7138
 if(  typeof(userdraw_radius) === 'object' && userdraw_radius.length > 0){var xyz = list_unique(userdraw_x,userdraw_y,userdraw_radius);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\"; return reply;;};\
9213 schaersvoo 7139
 return reply;\
14038 schaersvoo 7140
};\
14044 schaersvoo 7141
/* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,canvas_root_id,canvas_root_id);
9213 schaersvoo 7142
    break;
9289 schaersvoo 7143
    case 30:
13970 obado 7144
    fprintf(js_include_file,"\n/* begin function 30 read_canvas%d() */\n\
9289 schaersvoo 7145
read_canvas%d = function(){\
7146
 var reply = new Array(3);\
7147
 var prec = %d;\
7148
 reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
7149
 reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
7150
 reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
7151
 return reply;\
7152
};\n\
13970 obado 7153
/* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
9289 schaersvoo 7154
    break;
7155
    case 31:
13970 obado 7156
    fprintf(js_include_file,"\n/* begin function 31 read_canvas%d() */\n\
9289 schaersvoo 7157
read_canvas%d = function(){\
7158
 var reply = new Array(3);\
7159
 var prec = %d;\
7160
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
7161
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
7162
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
7163
 return reply;\
7164
};\n\
13970 obado 7165
/* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
9289 schaersvoo 7166
    break;
7167
    case 32:
13970 obado 7168
    fprintf(js_include_file,"\n/* begin function 32 read_canvas%d() */\n\
9289 schaersvoo 7169
read_canvas%d = function(){\
7170
 var reply = new Array(6);\
7171
 var prec = %d;\
7172
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
7173
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
7174
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
7175
 reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
7176
 reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
7177
 reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
7178
 return reply;\
7179
};\n\
13970 obado 7180
/* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
9289 schaersvoo 7181
    break;
14038 schaersvoo 7182
    case 33:
7183
    fprintf(js_include_file,"\n/* begin function 33 read_canvas%d() */\n\
7184
read_canvas%d = function(){\
7185
 var reply = userdraw_x+'\\n'+userdraw_y;\
7186
 return reply;\
7187
};\n\
7188
/* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7189
    break;
7190
    case 34: fprintf(js_include_file,"\
7191
\n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
7192
var read_canvas_images = function(){\
7193
 var prec = %d;\
7194
 var len  = ext_drag_images.length;\
7195
 var reply = new Array(len);\
7196
 for(var p = 0 ; p < len ; p++){\
7197
    var img = ext_drag_images[p];\
7198
    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7199
 };\
7200
 return reply;\
7201
};\n\
7202
/* end function 20 read_canvas_images() */",reply_precision);
7203
    break;
7204
 
7614 schaersvoo 7205
    default: canvas_error("hmmm unknown replyformat...");break;
7206
}
7207
 return;
7208
}
7209
 
7210
 
8224 bpr 7211
/*
7212
 add drawfunction :
7614 schaersvoo 7213
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
7214
 - things not covered by the drag&drop library (static objects like parallel, lattice ,gridfill , imagefill)
7215
 - grid / mathml
7216
 - will not scale or zoom in
7217
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
8224 bpr 7218
 - is printed directly into 'js_include_file'
7614 schaersvoo 7219
*/
7220
 
11021 schaersvoo 7221
void add_javascript_function(int js_function[],int canvas_root_id){
7614 schaersvoo 7222
int i;
7223
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
11017 schaersvoo 7224
 if( js_function[i] == 1){
7614 schaersvoo 7225
    switch(i){
11026 bpr 7226
    case JS_FIND_ANGLE:
11025 schaersvoo 7227
    fprintf(js_include_file,"\n\
13970 obado 7228
/* function find_angle() */\n\
14044 schaersvoo 7229
 function find_angle(xc,yc,x1,y1){var dx = x1 - xc;var dy = yc - y1;return Math.atan2(dx,dy);};");
11017 schaersvoo 7230
    break;
8448 schaersvoo 7231
    case DRAW_EXTERNAL_IMAGE:
14038 schaersvoo 7232
/*
13969 schaersvoo 7233
the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
7234
only drag_xy !
7235
snaptogrid | xsnaptogrid | ysnaptogrid works
7236
14/5/2019
7237
on heavy styled wims (unice.fr etc problems with mouse?
7238
now uniform method of retreiving mouse coordinates dragstuff.getMouse()
8448 schaersvoo 7239
*/
13970 obado 7240
fprintf(js_include_file,"\n/* drag external images */\n\
7653 schaersvoo 7241
var external_ctx = external_canvas.getContext(\"2d\");\
7242
var external_canvas_rect = external_canvas.getBoundingClientRect();\
7243
canvas_div.addEventListener(\"mousedown\",setxy,false);\
7244
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
7245
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
7246
var selected_image = null;\
7247
var ext_image_cnt = 0;\
7248
var ext_drag_images = new Array();\
14038 schaersvoo 7249
var ext_centered = 0;\
14044 schaersvoo 7250
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
14038 schaersvoo 7251
 ext_centered = centered;\
7653 schaersvoo 7252
 ext_image_cnt = idx;\
8448 schaersvoo 7253
 if(draggable == 1 ){\
7254
  reply[click_cnt] = 0;\
7255
 };\
7653 schaersvoo 7256
 var image = new Image();\
7257
 image.src = URL;\
7258
 image.onload = function(){\
8448 schaersvoo 7259
  if( sx < 1 ){ sx = 0; };\
7260
  if( sy < 1 ){ sy = 0; };\
7261
  if( swidth < 1 ){swidth = image.width;};\
7262
  if( sheight < 1 ){sheight = image.height;};\
7263
  if( width < 1 ){width = image.width;};\
7264
  if( height < 1 ){height = image.height;};\
7265
  if( resizable == 0 ){\
7266
   if( swidth > image.width ){ swidth = image.width; };\
7267
   if( sheight > image.height){ sheight = image.height;};\
7268
   if( width > image.width ){ width = image.width; };\
7269
   if( height > image.height){ height = image.height;};\
7270
  };\
14044 schaersvoo 7271
  var img = new Array(12);\
7653 schaersvoo 7272
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
14044 schaersvoo 7273
  img[8] = width;img[9] = height;img[10] = click_cnt;img[11] = use_snap;\
14038 schaersvoo 7274
  if(ext_centered == 4 ){img[6] = x0 - 0.5*img[8];img[7] = y0-0.5*img[9];}else{img[6] = x0;img[7] = y0;};\
7653 schaersvoo 7275
  ext_drag_images[idx] = img;\
7276
  external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
7277
 };\
7278
};\
7279
function dragstop(evt){\
7280
 selected_image = null;return;\
7281
};\
7282
function dragxy(evt){\
7283
 if( selected_image != null ){\
14044 schaersvoo 7284
  var s_img = ext_drag_images[selected_image];\
13969 schaersvoo 7285
  var mouse = dragstuff.getMouse(evt,external_canvas);\
14044 schaersvoo 7286
  var xy = multisnap_check(mouse.x,mouse.y,s_img[11]);\
7287
  var x = xy[0];var y = xy[1];\
14038 schaersvoo 7288
  if(ext_centered == 4 ){ x = x - 0.5*s_img[8] ;y = y - 0.5*s_img[9];};\
7289
  s_img[6] = x;s_img[7] = y;\
7653 schaersvoo 7290
  ext_drag_images[selected_image] = s_img;\
7291
  external_ctx.clearRect(0,0,xsize,ysize);\
7292
  for(var i = 0; i <= ext_image_cnt ; i++){\
7293
   var img = ext_drag_images[i];\
7294
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
7295
  };\
7296
 };\
7297
};\
7298
function setxy(evt){\
7299
 if( ! selected_image && evt.which == 1 ){\
13969 schaersvoo 7300
  var mouse = dragstuff.getMouse(evt,external_canvas);\
7301
  var xm = mouse.x;\
7302
  var ym = mouse.y;\
8448 schaersvoo 7303
  var img;\
7653 schaersvoo 7304
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
8448 schaersvoo 7305
   if( ext_drag_images[p] ){\
7306
    img = ext_drag_images[p];\
7307
    if( img[0] != 0 ){\
7308
     if( xm > img[6] && xm < img[6] + img[8]){\
7309
      if( ym > img[7] && ym < img[7] + img[9]){\
7310
       if( img[0] == 1){\
7311
        if( reply[img[10]] == 1 ){\
7312
         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
7313
        }\
7314
        else\
7315
        {\
7316
         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
7317
        };\
13969 schaersvoo 7318
        external_ctx.lineWidth = 4;\
8448 schaersvoo 7319
        external_ctx.beginPath();\
7320
        external_ctx.rect(img[6],img[7],img[8],img[9]);\
7321
        external_ctx.closePath();\
7322
        external_ctx.stroke();\
7323
        return;\
7324
       }\
7325
       else\
7326
       {\
7327
        img[6] = xm;\
7328
        img[7] = ym;\
7329
        ext_drag_images[p] = img;\
7330
        selected_image = p;\
7331
        dragxy(evt);\
7332
       };\
7333
      };\
7653 schaersvoo 7334
     };\
7335
    };\
7336
   };\
7337
  };\
7338
 }\
7339
 else\
7340
 {\
7341
  selected_image = null;\
7342
 };\
8448 schaersvoo 7343
};");
7614 schaersvoo 7344
    break;
8370 schaersvoo 7345
    case DRAW_BEZIER:
13970 obado 7346
fprintf(js_include_file,"\n/* draw bezier curve */\n\
11874 schaersvoo 7347
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8370 schaersvoo 7348
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){\
7349
 var obj;\
7350
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7351
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7352
 }\
7353
 else\
7354
 {\
7355
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7356
 };\
7357
 var ctx = obj.getContext(\"2d\");\
7358
 ctx.save();\
7359
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7360
 ctx.lineWidth = linewidth;\
11088 schaersvoo 7361
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8370 schaersvoo 7362
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7363
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
7364
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7365
 ctx.beginPath();\
7366
 ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
7367
 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]));\
11874 schaersvoo 7368
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 7369
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
8370 schaersvoo 7370
 ctx.stroke();\
7371
 ctx.restore();\
7372
};\n",canvas_root_id,canvas_root_id,canvas_root_id);
7373
    break;
13829 bpr 7374
 
7614 schaersvoo 7375
    case DRAW_GRIDFILL:/* not used for userdraw */
13970 obado 7376
fprintf(js_include_file,"\n/* draw gridfill */\n\
11827 schaersvoo 7377
var grid_fill_pattern;\
11823 schaersvoo 7378
var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\
11820 schaersvoo 7379
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
7380
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7381
 var fc = %d+canvas_type;\n\
7382
 fill_canvas_no.push(fc);\
7383
 var obj = create_canvas%d(fc,xsize,ysize);\n\
7384
 var ctx = obj.getContext('2d');\n\
7614 schaersvoo 7385
 var x,y;\
11820 schaersvoo 7386
 ctx.fillStyle='rgba(255,255,255,0.01)';\n\
7387
 ctx.rect(0,0,xsize,ysize);\n\
7388
 ctx.fill();\n\
7389
 ctx.lineWidth = linewidth;\
7390
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7391
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7392
 for( x = 0 ; x < xsize ; x = x + dx ){\
7393
  ctx.beginPath();\
7394
  ctx.moveTo(x,0);\
7395
  ctx.lineTo(x,ysize);\
7396
  ctx.closePath();\
7397
  ctx.stroke();\
7614 schaersvoo 7398
 };\
11820 schaersvoo 7399
 for( y = 0 ; y < ysize; y = y + dy ){\
7400
  ctx.beginPath();\
7401
  ctx.moveTo(0,y);\
7402
  ctx.lineTo(xsize,y);\
7403
  ctx.closePath();\
7404
  ctx.stroke();\
7614 schaersvoo 7405
 };\
11823 schaersvoo 7406
 if( use_userdraw ){\
7407
  grid_fill_pattern = ctx;\
7408
 }\
7409
 else\
7410
 {\
11874 schaersvoo 7411
  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\
7412
};",canvas_root_id,canvas_root_id);
7614 schaersvoo 7413
    break;
8224 bpr 7414
 
7614 schaersvoo 7415
    case DRAW_IMAGEFILL:/* not  used for userdraw */
13970 obado 7416
fprintf(js_include_file,"\n/* draw imagefill */\n\
11874 schaersvoo 7417
var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\
11854 schaersvoo 7418
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7419
 var fc = %d+canvas_type;\
7420
 fill_canvas_no.push(fc);\
7421
 var obj = create_canvas%d(fc,xsize,ysize);\
7422
 var ctx = obj.getContext('2d');\
7423
 var img = new Image();\
7424
 img.src = URL;\
11857 schaersvoo 7425
 obj.style.visibility = 'hidden';\
7426
 img.onload = function(){\
11874 schaersvoo 7427
  if( use_scaling == 1 ){\
7428
   ctx.drawImage(img,x0,y0,xsize,ysize);\
7429
  }else{\
7430
   var w0 = img.width;var h0 = img.height;var w;var h;\
7431
   for( w = x0; w < xsize ; w = w + w0 ){\
7432
    for( h = y0; h < ysize; h = h + h0){\
7433
      ctx.drawImage(img,w,h,w0,h0);\
7434
    };\
7435
   };\
7436
  };\
11857 schaersvoo 7437
  if( use_userdraw ){\
7438
   image_pattern = ctx;\
7439
  }\
7440
  else\
7441
  {\
7442
   setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\
7443
  };\
7444
 };\
11854 schaersvoo 7445
};",canvas_root_id,canvas_root_id);
7614 schaersvoo 7446
    break;
8224 bpr 7447
 
7614 schaersvoo 7448
    case DRAW_DOTFILL:/* not  used for userdraw */
13970 obado 7449
fprintf(js_include_file,"\n/* draw dotfill */\n\
11827 schaersvoo 7450
var dot_fill_pattern;\
11823 schaersvoo 7451
var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\
11820 schaersvoo 7452
if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
11818 schaersvoo 7453
if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
11820 schaersvoo 7454
var fc = %d+canvas_type;\
11818 schaersvoo 7455
fill_canvas_no.push(fc);\
11820 schaersvoo 7456
 var obj = create_canvas%d(fc,xsize,ysize);\
7457
 var ctx = obj.getContext('2d');\
7458
 var x,y;\
7459
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7460
 ctx.rect(0,0,xsize,ysize);\
7461
 ctx.fill();\
7462
 ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
7463
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7464
 for( x = 0 ; x < xsize ; x = x + dx ){\
7465
  for( y = 0 ; y < ysize ; y = y + dy ){\
7466
   ctx.beginPath();\
7467
   ctx.arc(x,y,radius,0,2*Math.PI,false);\
7468
   ctx.closePath();\
7469
   ctx.fill();\
7470
  };\
7471
 };\
11823 schaersvoo 7472
 if( use_userdraw ){\
11824 schaersvoo 7473
  dot_fill_pattern = ctx;\
11823 schaersvoo 7474
 }\
7475
 else\
7476
 {\
11874 schaersvoo 7477
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
7478
 };\
7479
return;\
7480
};",canvas_root_id,canvas_root_id);
7614 schaersvoo 7481
    break;
7645 schaersvoo 7482
 
11830 schaersvoo 7483
    case DRAW_TEXTFILL:/* not  used for userdraw */
13970 obado 7484
fprintf(js_include_file,"\n/* draw textfill */\n\
11830 schaersvoo 7485
var text_fill_pattern;\
7486
var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\
7487
if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7488
var fc = %d+canvas_type;\
7489
fill_canvas_no.push(fc);\
7490
 var obj = create_canvas%d(fc,xsize,ysize);\
7491
 var ctx = obj.getContext('2d');\
7492
 ctx.font = fontfamily;\
11832 schaersvoo 7493
 var dx = (ctx.measureText(txt)).width;\
11830 schaersvoo 7494
 var dy = parseInt(fontfamily)+2;\
7495
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7496
 ctx.rect(0,0,xsize,ysize);\
7497
 ctx.fill();\
7498
 ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
7499
 for(var x = 0 ; x < xsize ; x = x + dx ){\
7500
  for(var y = 0 ; y < ysize ; y = y + dy ){\
7501
   ctx.fillText(txt,x,y);\
7502
  };\
7503
 };\
7504
 if( use_userdraw ){\
7505
  text_fill_pattern = ctx;\
7506
 }\
7507
 else\
7508
 {\
7509
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
7510
 return;};",canvas_root_id,canvas_root_id);
7511
    break;
7512
 
7647 schaersvoo 7513
    case DRAW_DIAMONDFILL:/* not used for userdraw */
13970 obado 7514
fprintf(js_include_file,"\n/* draw hatch fill */\n\
11827 schaersvoo 7515
var diamond_fill_pattern;\
11823 schaersvoo 7516
var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
11820 schaersvoo 7517
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
7518
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7519
 var fc = %d+canvas_type;\
7520
 fill_canvas_no.push(fc);\
7521
 var obj = create_canvas%d(fc,xsize,ysize);\
7522
 var ctx = obj.getContext('2d');\
7614 schaersvoo 7523
 var x;\
7524
 var y;\
7525
 ctx.lineWidth = linewidth;\
11820 schaersvoo 7526
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7527
 ctx.rect(0,0,xsize,ysize);\
7528
 ctx.fill();\
11088 schaersvoo 7529
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
11820 schaersvoo 7530
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7614 schaersvoo 7531
 y = ysize;\
11820 schaersvoo 7532
 ctx.beginPath();\
7533
 for( x = 0 ; x < xsize ; x = x + dx ){\
7534
  ctx.moveTo(x,0);\
7614 schaersvoo 7535
  ctx.lineTo(xsize,y);\
7536
  y = y - dy;\
7537
 };\
11820 schaersvoo 7538
 y=0;\
7614 schaersvoo 7539
 for( x = xsize ; x > 0 ; x = x - dx){\
7540
  ctx.moveTo(x,ysize);\
11820 schaersvoo 7541
  ctx.lineTo(0,y);\
7614 schaersvoo 7542
  y = y + dy;\
7543
 };\
11820 schaersvoo 7544
 y = 0;\
7545
 for( x = 0 ; x < xsize ; x = x + dx ){\
7546
  ctx.moveTo(x,0);\
7547
  ctx.lineTo(0,y);\
7548
  y = y + dy;\
7549
 };\
7550
 y = 0;\
7551
 for( x = 0 ; x < xsize ; x = x + dx ){\
7614 schaersvoo 7552
  ctx.moveTo(xsize,y);\
7553
  ctx.lineTo(x,ysize);\
11820 schaersvoo 7554
  y = y + dy;\
7614 schaersvoo 7555
 };\
11820 schaersvoo 7556
 ctx.closePath();\
7614 schaersvoo 7557
 ctx.stroke();\
11823 schaersvoo 7558
 if( use_userdraw ){\
11827 schaersvoo 7559
  diamond_fill_pattern = ctx;\
11823 schaersvoo 7560
 }\
7561
 else\
7562
 {\
7563
  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
7614 schaersvoo 7564
 return;\
11820 schaersvoo 7565
 }",canvas_root_id,canvas_root_id);
7614 schaersvoo 7566
    break;
8224 bpr 7567
 
7647 schaersvoo 7568
    case DRAW_HATCHFILL:/* not used for userdraw */
13970 obado 7569
fprintf(js_include_file,"\n/* draw hatch fill */\n\
11827 schaersvoo 7570
var hatch_fill_pattern;\
11823 schaersvoo 7571
var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
11820 schaersvoo 7572
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
7573
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7574
 var fc = %d+canvas_type;\
7575
 fill_canvas_no.push(fc);\
7576
 var obj = create_canvas%d(fc,xsize,ysize);\
7577
 var ctx = obj.getContext('2d');\
7578
 var x,y;\
7579
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7580
 ctx.rect(0,0,xsize,ysize);\
7581
 ctx.fill();\
7582
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7647 schaersvoo 7583
 ctx.lineWidth = linewidth;\
11088 schaersvoo 7584
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7647 schaersvoo 7585
 y = ysize;\
11820 schaersvoo 7586
 ctx.beginPath();\
7587
 for( x = 0 ; x < xsize ; x = x + dx ){\
7588
  ctx.moveTo(x,0);\
7647 schaersvoo 7589
  ctx.lineTo(xsize,y);\
7590
  y = y - dy;\
7591
 };\
11820 schaersvoo 7592
 y = 0;\
7647 schaersvoo 7593
 for( x = xsize ; x >= dx ; x = x - dx){\
7594
  ctx.moveTo(x,ysize);\
11820 schaersvoo 7595
  ctx.lineTo(0,y);\
7647 schaersvoo 7596
  y = y + dy;\
7597
 };\
11820 schaersvoo 7598
 ctx.closePath();\
7647 schaersvoo 7599
 ctx.stroke();\
11823 schaersvoo 7600
 if( use_userdraw ){\
7601
  hatch_fill_pattern = ctx;\
7602
 }\
7603
 else\
7604
 {\
7605
  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
7647 schaersvoo 7606
 return;\
11820 schaersvoo 7607
 };",canvas_root_id,canvas_root_id);
7647 schaersvoo 7608
    break;
7614 schaersvoo 7609
    case DRAW_CIRCLES:/*  used for userdraw */
13970 obado 7610
fprintf(js_include_file,"\n/* draw circles */\n\
11874 schaersvoo 7611
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7612
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 7613
 ctx.save();\
8071 schaersvoo 7614
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7615
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7616
 ctx.lineWidth = line_width;\
11839 schaersvoo 7617
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7618
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\n\
11874 schaersvoo 7619
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 7620
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
11088 schaersvoo 7621
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7622
 for(var p = 0 ; p < x_points.length ; p++ ){\
7623
  ctx.beginPath();\
7624
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
7625
  ctx.closePath();\
11839 schaersvoo 7626
  if(use_filled != 0 ){ctx.fill();};\
7614 schaersvoo 7627
  ctx.stroke();\
7628
 }\
7629
 ctx.restore();\
7630
 return;\
7653 schaersvoo 7631
};");
7614 schaersvoo 7632
    break;
7663 schaersvoo 7633
    case DRAW_POLYLINE:/* user for userdraw : draw lines through points */
13970 obado 7634
fprintf(js_include_file,"\n/* draw polyline */\n\
11874 schaersvoo 7635
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7636
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 7637
 ctx.save();\
8071 schaersvoo 7638
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 7639
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7640
 ctx.lineWidth = line_width;\
11088 schaersvoo 7641
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7663 schaersvoo 7642
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7643
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7644
 ctx.clearRect(0,0,xsize,ysize);\
7645
 ctx.beginPath();\
7646
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
7647
  ctx.moveTo(x_points[p],y_points[p]);\
7648
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
7649
 }\
7650
 ctx.closePath();\
7651
 ctx.stroke();\
7652
 for(var p = 0 ; p < x_points.length ; p++ ){\
7653
  ctx.beginPath();\
7654
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
7655
  ctx.closePath();ctx.fill();ctx.stroke();\
7656
 };\
7657
 ctx.restore();\
7658
 return;\
7659
};");
7660
    break;
8224 bpr 7661
 
7614 schaersvoo 7662
    case DRAW_SEGMENTS:/*  used for userdraw */
13970 obado 7663
fprintf(js_include_file,"\n/* draw segments */\n\
8105 schaersvoo 7664
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 7665
 ctx.save();\
8071 schaersvoo 7666
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7667
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7668
 ctx.lineWidth = line_width;\
11088 schaersvoo 7669
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7670
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7671
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7672
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
7673
  ctx.beginPath();\
7674
  ctx.moveTo(x_points[p],y_points[p]);\
7675
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
7676
  ctx.closePath();\
7677
  ctx.stroke();\
7678
  }\
7679
  ctx.restore();\
7680
  return;\
7681
 };");
7682
    break;
8224 bpr 7683
 
7614 schaersvoo 7684
    case DRAW_LINES:/*  used for userdraw */
13970 obado 7685
fprintf(js_include_file,"\n/* draw lines */\n\
7614 schaersvoo 7686
function calc_line(x1,x2,y1,y2){\
7687
 var marge = 2;\
7688
 if(x1 < x2+marge && x1>x2-marge){\
7689
  return [x1,0,x1,ysize];\
7690
 };\
7691
 if(y1 < y2+marge && y1>y2-marge){\
7692
  return [0,y1,xsize,y1];\
7693
 };\
7694
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
7695
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
7696
 return [0,Y1,xsize,Y2];\
7697
};\
8105 schaersvoo 7698
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 7699
 ctx.save();\
7700
 var line = new Array(4);\
8071 schaersvoo 7701
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7702
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7703
 ctx.lineWidth = line_width;\
11088 schaersvoo 7704
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7705
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7706
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7707
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
7708
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
7709
  ctx.beginPath();\
7710
  ctx.moveTo(line[0],line[1]);\
7711
  ctx.lineTo(line[2],line[3]);\
7712
  ctx.closePath();\
7713
  ctx.stroke();\
7714
  }\
7715
  ctx.restore();\
7716
  return;\
7717
 };");
7718
    break;
7719
 
8244 schaersvoo 7720
    case DRAW_DEMILINES:/*  used for userdraw */
13970 obado 7721
fprintf(js_include_file,"\n/* draw demilines */\n\
8244 schaersvoo 7722
function find_inf_point(x1,y1,x2,y2){\
7723
 if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
7724
 var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
7725
 if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
7726
};\
7727
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){\
7728
 ctx.save();\
7729
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7730
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7731
 ctx.lineWidth = line_width;\
11088 schaersvoo 7732
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8244 schaersvoo 7733
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7734
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7735
 var pair = new Array(4);\
7736
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
7737
  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
7738
  ctx.beginPath();\
7739
  ctx.moveTo(pair[0],pair[1]);\
7740
  ctx.lineTo(pair[2],pair[3]);\
7741
  ctx.closePath();\
7742
  ctx.stroke();\
7743
  }\
7744
  ctx.restore();\
7745
  return;\
7746
 };");
7747
    break;
7748
 
7614 schaersvoo 7749
    case DRAW_CROSSHAIRS:/*  used for userdraw */
13970 obado 7750
fprintf(js_include_file,"\n/* draw crosshairs  */\n\
8105 schaersvoo 7751
var draw_crosshairs = function(ctx,x_points,y_points,line_width,crosshair_size,stroke_color,stroke_opacity,use_rotate,angle,use_affine,affine_matrix){\
12311 schaersvoo 7752
 ctx.save();\
8071 schaersvoo 7753
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7754
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7755
 ctx.lineWidth = line_width;\
11088 schaersvoo 7756
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7757
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7758
 var x1,x2,y1,y2;\
7759
 for(var p = 0 ; p < x_points.length ; p++ ){\
7760
  x1 = x_points[p] - crosshair_size;\
7761
  x2 = x_points[p] + crosshair_size;\
7762
  y1 = y_points[p] - crosshair_size;\
7763
  y2 = y_points[p] + crosshair_size;\
7764
  ctx.beginPath();\
7765
  ctx.moveTo(x1,y1);\
7766
  ctx.lineTo(x2,y2);\
7767
  ctx.closePath();\
7768
  ctx.stroke();\
7769
  ctx.beginPath();\
7770
  ctx.moveTo(x2,y1);\
7771
  ctx.lineTo(x1,y2);\
7772
  ctx.closePath();\
7773
  ctx.stroke();\
7774
 }\
7775
 ctx.restore();\
7776
  return;\
7653 schaersvoo 7777
};");
7614 schaersvoo 7778
    break;
7779
 
7780
    case DRAW_RECTS:/*  used for userdraw */
13970 obado 7781
fprintf(js_include_file,"\n/* draw rects */\n\
11874 schaersvoo 7782
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7783
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){\
12000 schaersvoo 7784
var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7614 schaersvoo 7785
 ctx.save();\
8071 schaersvoo 7786
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7787
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7788
 ctx.lineWidth = line_width;\
11088 schaersvoo 7789
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8448 schaersvoo 7790
 ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
7614 schaersvoo 7791
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
11875 schaersvoo 7792
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
7614 schaersvoo 7793
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
7794
  ctx.beginPath();\
7795
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
7796
  ctx.closePath();\
11839 schaersvoo 7797
  if(use_filled != 0 ){ctx.fill();}\
7614 schaersvoo 7798
  ctx.stroke();\
7799
 };\
7800
 ctx.restore();\
7801
 return;\
7653 schaersvoo 7802
};");
7614 schaersvoo 7803
    break;
7804
 
7805
    case DRAW_ROUNDRECTS:/*  used for userdraw */
13970 obado 7806
fprintf(js_include_file,"\n/* draw round rects */\n\
11874 schaersvoo 7807
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7808
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){\
12000 schaersvoo 7809
var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7614 schaersvoo 7810
 ctx.save();\
8071 schaersvoo 7811
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7812
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7813
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
9462 schaersvoo 7814
 ctx.lineWidth = line_width;\
11088 schaersvoo 7815
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
11875 schaersvoo 7816
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
7614 schaersvoo 7817
 var x,y,w,h,r;\
7818
 for(var p = 0; p < x_points.length; p = p+2){\
7819
  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);\
7820
  ctx.beginPath();ctx.moveTo(x + r, y);\
7821
  ctx.lineTo(x + w - r, y);\
7822
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
7823
  ctx.lineTo(x + w, y + h - r);\
7824
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
7825
  ctx.lineTo(x + r, y + h);\
7826
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
7827
  ctx.lineTo(x, y + r);\
7828
  ctx.quadraticCurveTo(x, y, x + r, y);\
7829
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
7830
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11839 schaersvoo 7831
  if( use_filled != 0 ){ctx.fill();};\
7614 schaersvoo 7832
  ctx.stroke();\
7833
 }\
7834
 ctx.restore();\
7653 schaersvoo 7835
};");
8224 bpr 7836
    break;
7614 schaersvoo 7837
 
7838
    case DRAW_ELLIPSES:/* not  used for userdraw */
13970 obado 7839
fprintf(js_include_file,"\n/* draw ellipses */\n\
11874 schaersvoo 7840
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7841
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 7842
 var obj;\
7843
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7844
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7845
 }\
7846
 else\
7847
 {\
7848
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7849
 };\
7850
 var ctx = obj.getContext(\"2d\");\
7851
 ctx.save();\
8071 schaersvoo 7852
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7853
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
11875 schaersvoo 7854
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
7614 schaersvoo 7855
 var cx,cy,ry,rx;\
7856
 ctx.lineWidth = line_width;\
11088 schaersvoo 7857
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7858
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7859
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7860
 for(var p=0;p< x_points.length;p = p+2){\
7861
  ctx.beginPath();\
7862
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
7863
  ctx.translate(cx - rx, cy - ry);\
7864
  ctx.scale(rx, ry);\
7865
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
11839 schaersvoo 7866
  if( use_filled != 0 ){ctx.fill();}\
7614 schaersvoo 7867
  ctx.stroke();\
7868
 };\
7869
 ctx.restore();\
7653 schaersvoo 7870
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 7871
    break;
7872
 
7873
    case DRAW_PATHS: /*  used for userdraw */
13970 obado 7874
fprintf(js_include_file,"\n/* draw paths */\n\
11874 schaersvoo 7875
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7876
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 7877
 ctx.save();\
8071 schaersvoo 7878
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7879
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7880
 ctx.lineWidth = line_width;\
11088 schaersvoo 7881
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7882
 ctx.lineJoin = \"round\";\
7883
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11874 schaersvoo 7884
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 7885
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
7614 schaersvoo 7886
 ctx.beginPath();\
7887
 ctx.moveTo(x_points[0],y_points[0]);\
7888
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
7889
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
7890
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
11839 schaersvoo 7891
 if(use_filled != 0){ctx.fill();}\
7614 schaersvoo 7892
 ctx.stroke();\
7893
 ctx.restore();\
7894
 return;\
7895
};");
8224 bpr 7896
 
7614 schaersvoo 7897
    break;
7898
    case DRAW_ARROWS:/*  used for userdraw */
13970 obado 7899
fprintf(js_include_file,"\n/* draw arrows */\n\
8105 schaersvoo 7900
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 7901
 ctx.save();\
8071 schaersvoo 7902
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7903
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7904
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7905
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7906
 ctx.lineWidth = line_width;\
11088 schaersvoo 7907
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7908
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7909
 ctx.lineCap = \"round\";\
7910
 var x1,y1,x2,y2,dx,dy,len;\
7911
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 7912
   ctx.save();\
7614 schaersvoo 7913
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
7914
   len = Math.sqrt(dx*dx+dy*dy);\
7915
   ctx.translate(x2,y2);\
7916
   ctx.rotate(Math.atan2(dy,dx));\
7917
   ctx.lineCap = \"round\";\
7918
   ctx.beginPath();\
7919
   ctx.moveTo(0,0);\
7920
   ctx.lineTo(-len,0);\
7921
   ctx.closePath();\
7922
   ctx.stroke();\
7923
   ctx.beginPath();\
7924
   ctx.moveTo(0,0);\
7925
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
7926
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
7927
   ctx.closePath();\
7928
   ctx.fill();\
7874 schaersvoo 7929
   ctx.restore();\
7614 schaersvoo 7930
   if( type == 2 ){\
7931
     ctx.save();\
7932
     ctx.translate(x1,y1);\
7933
     ctx.rotate(Math.atan2(-dy,-dx));\
7934
     ctx.beginPath();\
7935
     ctx.moveTo(0,0);\
8347 schaersvoo 7936
     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
7937
     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
7614 schaersvoo 7938
     ctx.closePath();\
7939
     ctx.stroke();\
7940
     ctx.fill();\
7874 schaersvoo 7941
     ctx.restore();\
8379 schaersvoo 7942
   };\
7943
  };\
7614 schaersvoo 7944
  ctx.restore();\
7945
  return;\
7653 schaersvoo 7946
};");
7614 schaersvoo 7947
    break;
7948
 
7949
    case DRAW_VIDEO:/* not  used for userdraw */
13970 obado 7950
fprintf(js_include_file,"\n/* draw video */\n\
8105 schaersvoo 7951
var draw_video = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 7952
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7953
 var video_div = document.createElement(\"div\");\
7954
 canvas_div.appendChild(video_div);\
7955
 video_div.style.position = \"absolute\";\
7956
 video_div.style.left = x+\"px\";\
7957
 video_div.style.top = y+\"px\";\
7958
 video_div.style.width = w+\"px\";\
7959
 video_div.style.height = h+\"px\";\
7960
 var video = document.createElement(\"video\");\
7961
 video_div.appendChild(video);\
7962
 video.style.width = w+\"px\";\
7963
 video.style.height = h+\"px\";\
7964
 video.autobuffer = true;\
7965
 video.controls = true;video.autoplay = false;\
7966
 var src = document.createElement(\"source\");\
7967
 src.type = \"video/mp4\";\
7968
 src.src = URL;\
7969
 video.appendChild(src);\
7970
 video.load();\
7971
 return;\
8224 bpr 7972
};");
7614 schaersvoo 7973
    break;
8224 bpr 7974
 
7614 schaersvoo 7975
    case DRAW_AUDIO:/* not used for userdraw */
13970 obado 7976
fprintf(js_include_file,"\n/* draw audio */\n\
8105 schaersvoo 7977
var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
7614 schaersvoo 7978
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7979
 var audio_div = document.createElement(\"div\");\
7980
 canvas_div.appendChild(audio_div);\
7981
 audio_div.style.position = \"absolute\";\
7982
 audio_div.style.left = x+\"px\";\
7983
 audio_div.style.top = y+\"px\";\
7984
 audio_div.style.width = w+\"px\";\
7985
 audio_div.style.height = h+\"px\";\
7986
 var audio = document.createElement(\"audio\");\
7987
 audio_div.appendChild(audio);\
7988
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
7989
 audio.autobuffer = true;\
8379 schaersvoo 7990
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
7991
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
7614 schaersvoo 7992
 var src1 = document.createElement(\"source\");\
7993
 src1.type = \"audio/ogg\";\
7994
 src1.src = URL1;\
7995
 audio.appendChild(src1);\
7996
 var src2 = document.createElement(\"source\");\
7997
 src2.type = \"audio/mpeg\";\
7998
 src2.src = URL2;\
7999
 audio.appendChild(src2);\
8000
 audio.load();\
8001
 return;\
7653 schaersvoo 8002
};");
7614 schaersvoo 8003
    break;
8224 bpr 8004
 
7614 schaersvoo 8005
    case DRAW_HTTP:/* not  used for userdraw */
13970 obado 8006
fprintf(js_include_file,"\n/* draw http */\n\
8105 schaersvoo 8007
var draw_http = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 8008
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
8009
 var http_div = document.createElement(\"div\");\
8010
 var iframe = document.createElement(\"iframe\");\
8011
 canvas_div.appendChild(http_div);\
8012
 http_div.appendChild(iframe);\
8013
 iframe.src = URL;\
8014
 iframe.setAttribute(\"width\",w);\
8015
 iframe.setAttribute(\"height\",h);\
8016
 return;\
7653 schaersvoo 8017
};");
7614 schaersvoo 8018
    break;
8224 bpr 8019
 
13829 bpr 8020
    case DRAW_XML: /*
8021
    onclick=1 : click
11238 schaersvoo 8022
    onclick=2 drag
8023
    xy:drag_type = 0;
8024
    x:    drag_type = 1;
8025
    y:    drag_type = 2;
8026
    */
8027
 
13970 obado 8028
fprintf(js_include_file,"\n/* draw xml */\n\
14044 schaersvoo 8029
var draw_xml = function(canvas_root_id,x,y,mathml,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,centered,use_snap){\
7614 schaersvoo 8030
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
8031
 var xml_div = document.createElement(\"div\");\
8032
 canvas_div.appendChild(xml_div);\
8033
 xml_div.innerHTML = mathml;\
14038 schaersvoo 8034
 xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
8035
 var factor = 1;\
8036
 if( centered > 0 ){ factor = 0.5;};\
8037
 var xml_div_width = factor*(parseInt(window.getComputedStyle(xml_div).width , 10));\
8038
 var xml_div_height = factor*(parseInt(window.getComputedStyle(xml_div).height ,10));\
8379 schaersvoo 8039
 xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11745 schaersvoo 8040
 var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11756 schaersvoo 8041
 var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8042
 var no_color = \"rgba(255,255,255,0)\";\
11745 schaersvoo 8043
 var dragging = false;\
11747 schaersvoo 8044
 if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
8045
 if( onclick == 1 ){reply[click_cnt] = 0;};\
8046
 if( onclick == 2 ){\
8047
  xml_div.onclick = function(){\
11756 schaersvoo 8048
   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 8049
   canvas_div.onmousemove = function(evt){\
8050
    if(!dragging){return;};\
8051
    var x1;var y1;\
8052
    var mouse = dragstuff.getMouse(evt,xml_div);\
14044 schaersvoo 8053
    var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
11747 schaersvoo 8054
    switch(drag_type){\
14044 schaersvoo 8055
     case 0: x1 = xy[0]-xml_div_width;y1=xy[1]-xml_div_height;break;\
8056
     case 1: x1 = xy[0]-xml_div_width;y1 = y;break;\
8057
     case 2: x1 = x;y1 = xy[1]-xml_div_height;break;\
8058
     default:x1 = xy[0];y1 = xy[1]; break;\
11747 schaersvoo 8059
    };\
8060
    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
8061
    reply[click_cnt] = px2x(x1)+','+px2y(y1);\
11238 schaersvoo 8062
   };\
7614 schaersvoo 8063
  };\
11238 schaersvoo 8064
 };\
8065
 if(onclick == 1){\
11747 schaersvoo 8066
  xml_div.onclick = function(){\
11756 schaersvoo 8067
  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 8068
 };\
8069
 return;\
11745 schaersvoo 8070
};");
7614 schaersvoo 8071
    break;
7654 schaersvoo 8072
    case DRAW_SGRAPH:
8224 bpr 8073
/*
7654 schaersvoo 8074
 xstart = given
8075
 ystart = given
8076
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
8077
*/
13970 obado 8078
fprintf(js_include_file,"\n/* draw sgraph */\n\
8105 schaersvoo 8079
var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
7658 schaersvoo 8080
 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);};\
8081
 var ctx = obj.getContext(\"2d\");\
8082
 ctx.font = fontfamily;\
8083
 var minor_opacity = 0.8*opacity;\
8084
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 8085
 var zero_x = 0.1*xsize;\
8086
 var zero_y = 0.9*ysize;\
8129 schaersvoo 8087
 var snor_x;var snor_y;\
7654 schaersvoo 8088
 if( xstart != xmin){\
7658 schaersvoo 8089
  snor_x = 0.1*xsize;\
8090
 }\
8091
 else\
8092
 {\
8093
  snor_x = 0;\
8094
  xstart = xmin;\
8095
 };\
8096
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8097
 ctx.lineWidth = 2;\
8098
 ctx.beginPath();\
8099
 ctx.moveTo(xsize,zero_y);\
8100
 ctx.lineTo(zero_x,zero_y);\
8101
 ctx.lineTo(zero_x,0);\
8102
 ctx.stroke();\
8103
 ctx.closePath();\
8104
 ctx.beginPath();\
8105
 ctx.moveTo(zero_x,zero_y);\
8106
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
8107
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
8108
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
8109
 ctx.lineTo(zero_x + snor_x,zero_y);\
8110
 ctx.stroke();\
8111
 ctx.closePath();\
8112
 ctx.beginPath();\
8113
 var num = xstart;\
7660 schaersvoo 8114
 var flipflop = 1;\
7658 schaersvoo 8115
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 8116
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 8117
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 8118
  txtsize = ctx.measureText(num).width;\
8119
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
8120
  if( flipflop == 1){\
8121
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
8122
  }\
8123
  else\
8124
  {\
8125
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
8379 schaersvoo 8126
  };\
7976 schaersvoo 8127
  num = num + xmajor;\
7658 schaersvoo 8128
 };\
8129
 ctx.stroke();\
8130
 ctx.closePath();\
8131
 ctx.lineWidth = 1;\
8132
 ctx.beginPath();\
8133
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
8134
   ctx.moveTo(x,zero_y);\
8135
   ctx.lineTo(x,0);\
8136
 };\
8137
 ctx.stroke();\
8138
 ctx.closePath();\
8139
 if( xminor > 1){\
8140
  ctx.lineWidth = 0.5;\
8141
  ctx.beginPath();\
8142
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
8143
  var minor_step_x = step_x / xminor;\
8144
  var nx;\
8145
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
8146
    num = 1;\
8147
    for(var p = 1 ; p < xminor ; p++){\
8148
     nx = x + num*minor_step_x;\
8149
     ctx.moveTo(nx,zero_y);\
8150
     ctx.lineTo(nx,0);\
8151
     num++;\
8152
    };\
8153
  };\
8154
  ctx.stroke();\
8155
  ctx.closePath();\
8156
  ctx.beginPath();\
8157
  ctx.lineWidth = 2;\
8158
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8159
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
8160
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
8161
  };\
8162
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
8163
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
8164
  };\
8165
  ctx.stroke();\
8166
  ctx.closePath();\
8167
  ctx.lineWidth = 0.5;\
8168
 };\
8169
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
8170
 if( ystart != ymin){\
8171
  snor_y = 0.1*ysize;\
8172
 }\
8173
 else\
8174
 {\
8175
  snor_y = 0;\
8176
  ystart = ymin;\
8177
 };\
8178
 ctx.lineWidth = 2;\
8179
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8180
 ctx.beginPath();\
8181
 ctx.moveTo(zero_x,zero_y);\
8182
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
8183
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
8184
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
8185
 ctx.lineTo(zero_x,zero_y - snor_y);\
8186
 ctx.stroke();\
8187
 ctx.closePath();\
8188
 ctx.beginPath();\
8189
 ctx.lineWidth = 1;\
8190
 num = ystart;\
8191
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
8192
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
8193
  ctx.moveTo(zero_x,y);\
8194
  ctx.lineTo(xsize,y);\
8195
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
8196
  num = num + ymajor;\
8197
 };\
8198
 ctx.stroke();\
8199
 ctx.closePath();\
8200
 if( yminor > 1){\
8201
  ctx.lineWidth = 0.5;\
8202
  ctx.beginPath();\
8203
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
8204
  var minor_step_y = step_y / yminor;\
8205
  var ny;\
8206
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
8207
   num = 1;\
8208
   for(var p = 1 ;p < yminor;p++){\
8209
     ny = y + num*minor_step_y;\
8210
     ctx.moveTo(zero_x,ny);\
8211
     ctx.lineTo(xsize,ny);\
8212
     num++;\
8213
    };\
8214
  };\
8215
  ctx.stroke();\
8216
  ctx.closePath();\
8217
  ctx.lineWidth = 2;\
8218
  ctx.beginPath();\
8219
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8220
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
8221
   ctx.moveTo(zero_x,y);\
8222
   ctx.lineTo(zero_x+12,y);\
8223
  };\
8224
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
8225
   ctx.moveTo(zero_x,y);\
8226
   ctx.lineTo(zero_x+6,y);\
8227
  };\
8228
  ctx.stroke();\
8229
  ctx.closePath();\
8230
 };\
8231
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
11088 schaersvoo 8232
 if( typeof(legend%d)  !== 'undefined' ){\
7654 schaersvoo 8233
  ctx.globalAlpha = 1.0;\
8234
  var y_offset = 2*font_size;\
8235
  var txt;var txt_size;\
8236
  var x_offset = xsize - 2*font_size;\
8237
  var l_length = legend%d.length;var barcolor = new Array();\
11088 schaersvoo 8238
  if( typeof(legendcolors%d) !== 'undefined' ){\
7654 schaersvoo 8239
   for(var p = 0 ; p < l_length ; p++){\
8240
    barcolor[p] = legendcolors%d[p];\
8241
   };\
8242
  }else{\
8243
   if( barcolor.length == 0 ){\
8244
    for(var p = 0 ; p < l_length ; p++){\
8245
     barcolor[p] = stroke_color;\
8246
    };\
8247
   };\
8248
  };\
8249
  for(var p = 0; p < l_length; p++){\
8250
   ctx.fillStyle = barcolor[p];\
8251
   txt = legend%d[p];\
8252
   txt_size = ctx.measureText(txt).width;\
8253
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
8254
   y_offset = parseInt(y_offset + 1.5*font_size);\
8255
  };\
8256
 };\
11088 schaersvoo 8257
 if( typeof(xaxislabel) !== 'undefined' ){\
7658 schaersvoo 8258
   ctx.fillStyle = \'#000000\';\
8259
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
8260
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
8261
 };\
11088 schaersvoo 8262
 if( typeof(yaxislabel) !== 'undefined'){\
7658 schaersvoo 8263
   ctx.save();\
8264
   ctx.fillStyle = \'#000000\';\
8265
   var txt_size = ctx.measureText(yaxislabel).width;\
8266
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
8267
   ctx.rotate(-0.5*Math.PI);\
8268
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 8269
   ctx.restore();\
7658 schaersvoo 8270
 };\
7654 schaersvoo 8271
};\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);
8272
    break;
11890 schaersvoo 8273
    case DRAW_NUMBERLINE:
13970 obado 8274
fprintf(js_include_file,"\n/* draw numberline */\n\
11996 schaersvoo 8275
var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\
11890 schaersvoo 8276
 var obj = create_canvas%d(canvas_type,xsize,ysize);\
8277
 var ctx = obj.getContext(\"2d\");\
8278
 ctx.lineWidth = linewidth || 1;\
8279
 ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\
8280
 ctx.font = fontfamily || 'Ariel 12px';\
8281
 var fontsize = parseInt(ctx.font);\
8282
 ctx.fillStyle =  \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\
8283
 x1 = x2px(x1);\
8284
 x0 = x2px(x0);\
8285
 y0 = y2px(y0);\
8286
 y1 = y2px(y1);\
8287
 var sub_devision = -1;\
8288
 if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\
11892 schaersvoo 8289
 var ybase1 = parseInt( y0 + fontsize + 2 );\
8290
 var ybase2 = parseInt( ybase1 + fontsize + 2 );\
11890 schaersvoo 8291
 var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\
8292
 var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\
8293
 xmajor = x2px(xmajor) - x2px(0);\
8294
 var i;var len;var p;\
8295
 xminor = xmajor / xminor;\
8296
 ctx.beginPath();\
8297
 for(p = x0 ; p < x1 ; p = p + xmajor){\
8298
  ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\
8299
  for(var s = p ; s < p + xmajor ; s = s + xminor ){\
8300
   ctx.moveTo(s,y0);\
8301
   if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\
8302
   i++;\
8303
  };\
8304
 };\
8305
 ctx.moveTo(p,y0);ctx.lineTo(p,y1);\
8306
 ctx.closePath();\
8307
 ctx.stroke();\
11996 schaersvoo 8308
 if( use_axis_numbering >-1 ){\
11891 schaersvoo 8309
  var str = x_strings[use_axis_numbering];\
8310
  len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
11892 schaersvoo 8311
  var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\
11890 schaersvoo 8312
  ctx.beginPath();\
11891 schaersvoo 8313
  if( x_strings_up[use_axis_numbering] == null){\
11890 schaersvoo 8314
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8315
    var x_nums = x2px(eval(str[p]));\
8316
    var x_text = str[p+1];\
11890 schaersvoo 8317
    corr = ctx.measureText(x_text).width;\
11892 schaersvoo 8318
    if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
11996 schaersvoo 8319
    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\
11890 schaersvoo 8320
   };\
8321
  }\
8322
  else\
8323
  {\
8324
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8325
    x_nums = x2px(eval(str[p]));\
8326
    x_text = str[p+1];\
11892 schaersvoo 8327
    corr = ctx.measureText(x_text).width + ybase1 - fontsize;\
11890 schaersvoo 8328
    ctx.save();\
8329
    ctx.translate(x_nums+0.5*fontsize, corr);\
8330
    ctx.rotate(-1.5708);\
8331
    ctx.fillText(x_text,0,0);\
8332
    ctx.restore();\
8333
   };\
8334
  }\
8335
 }\
8336
 else\
8337
 {\
11892 schaersvoo 8338
  var corr;var num;var flipflop = 0;var off = ybase1;\
8339
  var prec = parseInt(Math.log(precision)/Math.log(10));\
11890 schaersvoo 8340
  for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\
11892 schaersvoo 8341
   num = (px2x(p)).toFixed(prec);\
11996 schaersvoo 8342
   corr = ctx.measureText(num).width;\
11892 schaersvoo 8343
   if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
11996 schaersvoo 8344
   ctx.fillText(num,parseInt(p - 0.5*corr),off);\
11890 schaersvoo 8345
  };\
8346
 };\
8347
};",canvas_root_id);
8348
    break;
7614 schaersvoo 8349
    case DRAW_GRID:/* not used for userdraw */
13970 obado 8350
fprintf(js_include_file,"\n/* draw grid */\n\
8105 schaersvoo 8351
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 8352
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);};\
8353
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 8354
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
8355
ctx.save();\
8071 schaersvoo 8356
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 8357
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
8358
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8359
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
8360
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
8361
ctx.font = font_family;\
7988 schaersvoo 8362
var barcolor = new Array();\
7614 schaersvoo 8363
var xstep = xsize*xmajor/(xmax - xmin);\
8364
var ystep = ysize*ymajor/(ymax - ymin);\
8365
var x2step = xstep / xminor;\
8366
var y2step = ystep / yminor;\
7996 schaersvoo 8367
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
8368
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
8369
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
11088 schaersvoo 8370
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8371
ctx.beginPath();\
8372
ctx.lineWidth = line_width;\
8373
ctx.strokeStyle = stroke_color;\
8374
for(var p = zero_x ; p < xsize; p = p + xstep){\
8375
 ctx.moveTo(p,0);\
8376
 ctx.lineTo(p,ysize);\
8377
};\
8378
for(var p = zero_x ; p > 0; p = p - xstep){\
8379
 ctx.moveTo(p,0);\
8380
 ctx.lineTo(p,ysize);\
8381
};\
8382
for(var p = zero_y ; p < ysize; p = p + ystep){\
8383
 ctx.moveTo(0,p);\
8384
 ctx.lineTo(xsize,p);\
8385
};\
8386
for(var p = zero_y ; p > 0; p = p - ystep){\
8387
 ctx.moveTo(0,p);\
8388
 ctx.lineTo(xsize,p);\
8389
};\
11088 schaersvoo 8390
if( typeof(xaxislabel) !== 'undefined' ){\
7614 schaersvoo 8391
 ctx.save();\
8392
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
12007 schaersvoo 8393
 var corr =  parseInt(1.1*ctx.measureText(xaxislabel).width);\
8394
 ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\
7614 schaersvoo 8395
 ctx.restore();\
8396
};\
11088 schaersvoo 8397
if( typeof(yaxislabel) !== 'undefined' ){\
7614 schaersvoo 8398
 ctx.save();\
8399
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
12007 schaersvoo 8400
 var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\
8401
 ctx.translate(zero_x+tics_length + font_size,corr);\
7614 schaersvoo 8402
 ctx.rotate(-0.5*Math.PI);\
8403
 ctx.fillText(yaxislabel,0,0);\
8404
 ctx.restore();\
8405
};\
8406
ctx.stroke();\
8407
ctx.closePath();\
8408
if( use_axis == 1 ){\
7988 schaersvoo 8409
 ctx.save();\
7614 schaersvoo 8410
 ctx.beginPath();\
8411
 ctx.strokeStyle = stroke_color;\
8412
 ctx.lineWidth = 0.6*line_width;\
8413
 for(var p = zero_x ; p < xsize; p = p + x2step){\
8414
  ctx.moveTo(p,0);\
8415
  ctx.lineTo(p,ysize);\
8416
 };\
8417
 for(var p = zero_x ; p > 0; p = p - x2step){\
8418
  ctx.moveTo(p,0);\
8419
  ctx.lineTo(p,ysize);\
8420
 };\
8421
 for(var p = zero_y ; p < ysize; p = p + y2step){\
8422
  ctx.moveTo(0,p);\
8423
  ctx.lineTo(xsize,p);\
8424
 };\
8425
 for(var p = zero_y ; p > 0; p = p - y2step){\
8426
  ctx.moveTo(0,p);\
8427
  ctx.lineTo(xsize,p);\
8428
 };\
8429
 ctx.stroke();\
8430
 ctx.closePath();\
8431
 ctx.beginPath();\
8432
 ctx.lineWidth = 2*line_width;\
8433
 ctx.strokeStyle = axis_color;\
8434
 ctx.moveTo(0,zero_y);\
8435
 ctx.lineTo(xsize,zero_y);\
8436
 ctx.moveTo(zero_x,0);\
8437
 ctx.lineTo(zero_x,ysize);\
8438
 ctx.stroke();\
8439
 ctx.closePath();\
8440
 ctx.lineWidth = line_width+0.5;\
8441
 ctx.beginPath();\
8442
 for(var p = zero_x ; p < xsize; p = p + xstep){\
8443
  ctx.moveTo(p,zero_y-tics_length);\
8444
  ctx.lineTo(p,zero_y+tics_length);\
8445
 };\
8446
 for(var p = zero_x ; p > 0; p = p - xstep){\
8447
  ctx.moveTo(p,zero_y-tics_length);\
8448
  ctx.lineTo(p,zero_y+tics_length);\
8449
 };\
8450
 for(var p = zero_y ; p < ysize; p = p + ystep){\
8451
  ctx.moveTo(zero_x-tics_length,p);\
8452
  ctx.lineTo(zero_x+tics_length,p);\
8453
 };\
8454
 for(var p = zero_y ; p > 0; p = p - ystep){\
8455
  ctx.moveTo(zero_x-tics_length,p);\
8456
  ctx.lineTo(zero_x+tics_length,p);\
8457
 };\
8458
 for(var p = zero_x ; p < xsize; p = p + x2step){\
8459
  ctx.moveTo(p,zero_y-0.5*tics_length);\
8460
  ctx.lineTo(p,zero_y+0.5*tics_length);\
8461
 };\
8462
 for(var p = zero_x ; p > 0; p = p - x2step){\
8463
  ctx.moveTo(p,zero_y-0.5*tics_length);\
8464
  ctx.lineTo(p,zero_y+0.5*tics_length);\
8465
 };\
8466
 for(var p = zero_y ; p < ysize; p = p + y2step){\
8467
  ctx.moveTo(zero_x-0.5*tics_length,p);\
8468
  ctx.lineTo(zero_x+0.5*tics_length,p);\
8469
 };\
8470
 for(var p = zero_y ; p > 0; p = p - y2step){\
8471
  ctx.moveTo(zero_x-0.5*tics_length,p);\
8472
  ctx.lineTo(zero_x+0.5*tics_length,p);\
8473
 };\
8474
 ctx.stroke();\
8475
 ctx.closePath();\
7988 schaersvoo 8476
 ctx.restore();\
8477
};\
11891 schaersvoo 8478
if( use_axis_numbering != -1 ){\
7988 schaersvoo 8479
 ctx.save();\
8480
 ctx.fillColor = axis_color;\
8110 schaersvoo 8481
 ctx.strokeStyle = axis_color;\
8482
 ctx.lineWidth = 2*line_width;\
7988 schaersvoo 8483
 ctx.font = font_family;\
8484
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
11891 schaersvoo 8485
 if( x_strings[use_axis_numbering] != null ){\
8486
  var str = x_strings[use_axis_numbering];\
8487
  var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 8488
  ctx.beginPath();\
11891 schaersvoo 8489
  if( x_strings_up[use_axis_numbering] == null){\
9341 schaersvoo 8490
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8491
    var x_nums = x2px(eval(str[p]));\
8492
    var x_text = str[p+1];\
9341 schaersvoo 8493
    corr = ctx.measureText(x_text).width;\
8494
    skip = 1.2*corr/xstep;\
8495
    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
8496
    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
8497
    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
8498
    ctx.moveTo(x_nums,zero_y - tics_length);\
8499
    ctx.lineTo(x_nums,zero_y + tics_length);\
8500
   };\
8501
  }\
8502
  else\
8503
  {\
8504
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8505
    var x_nums = x2px(eval(str[p]));\
8506
    var x_text = str[p+1];\
9341 schaersvoo 8507
    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
8508
    if( corr > ysize ){corr = ysize;};\
8509
    ctx.save();\
9346 schaersvoo 8510
    ctx.translate(x_nums+0.25*font_size, corr);\
9341 schaersvoo 8511
    ctx.rotate(-1.5708);\
8512
    ctx.fillText(x_text,0,0);\
8513
    ctx.restore();\
8514
    ctx.moveTo(x_nums,zero_y - tics_length);\
8515
    ctx.lineTo(x_nums,zero_y + tics_length);\
8516
   };\
7988 schaersvoo 8517
  };\
8110 schaersvoo 8518
  ctx.closePath();\
7988 schaersvoo 8519
 }\
8520
 else\
8521
 {\
8522
  skip = 1;cnt = px2x(zero_x);\
8523
  prec = Math.log(precision)/(Math.log(10));\
8524
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
8525
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
8526
   if(skip == 0 ){\
7990 schaersvoo 8527
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8528
    corr = ctx.measureText(disp_cnt).width;\
8529
    skip = parseInt(1.2*corr/xstep);\
8530
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 8531
   }\
7988 schaersvoo 8532
   else\
8533
   {\
8534
    skip--;\
7614 schaersvoo 8535
   };\
7988 schaersvoo 8536
   cnt = cnt + xmajor;\
7614 schaersvoo 8537
  };\
7988 schaersvoo 8538
  cnt = px2x(zero_x);skip = 1;\
8539
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
8540
   if(skip == 0 ){\
7990 schaersvoo 8541
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8542
    corr = ctx.measureText(disp_cnt).width;\
8543
    skip = parseInt(1.2*corr/xstep);\
8544
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
8545
   }\
8546
   else\
8547
   {\
8548
    skip--;\
7614 schaersvoo 8549
   };\
7988 schaersvoo 8550
   cnt = cnt - xmajor;\
7614 schaersvoo 8551
  };\
8552
 };\
7988 schaersvoo 8553
 if( y_strings != null ){\
8554
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 8555
  ctx.beginPath();\
7988 schaersvoo 8556
  for(var p = 0 ; p < len ; p = p+2){\
8557
   var y_nums = y2px(eval(y_strings[p]));\
8558
   var y_text = y_strings[p+1];\
8559
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
8560
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
8110 schaersvoo 8561
   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
8562
   ctx.moveTo(zero_x - tics_length,y_nums);\
8563
   ctx.lineTo(zero_x + tics_length,y_nums);\
7614 schaersvoo 8564
  };\
8110 schaersvoo 8565
  ctx.closePath();\
7988 schaersvoo 8566
 }\
8567
 else\
8568
 {\
7991 schaersvoo 8569
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 8570
  cnt = px2y(zero_y);skip = 1;\
8571
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
8572
   if(skip == 0 ){\
8573
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 8574
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8575
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
8576
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
8577
   }\
8578
   else\
8579
   {\
8580
    skip--;\
8581
   };\
8582
   cnt = cnt - ymajor;\
7614 schaersvoo 8583
  };\
7988 schaersvoo 8584
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 8585
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 8586
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
8587
   if(skip == 0 ){\
8588
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 8589
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8590
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
8591
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
8592
   }\
8593
   else\
8594
   {\
8595
    skip--;\
8596
   };\
8597
   cnt = cnt + ymajor;\
7614 schaersvoo 8598
  };\
8599
 };\
7988 schaersvoo 8600
 ctx.stroke();\
7614 schaersvoo 8601
 ctx.restore();\
8602
};\
11088 schaersvoo 8603
if( typeof(legend0)  !== 'undefined' ){\
7988 schaersvoo 8604
 ctx.save();\
7614 schaersvoo 8605
 ctx.globalAlpha = 1.0;\
8606
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
8607
 var y_offset = 2*font_size;\
8608
 var txt;var txt_size;\
8609
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 8610
 var l_length = legend0.length;\
11088 schaersvoo 8611
 if( typeof(legendcolors0) !== 'undefined' ){\
7614 schaersvoo 8612
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 8613
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 8614
  };\
7988 schaersvoo 8615
 }\
8616
 else\
8617
 {\
7614 schaersvoo 8618
  if( barcolor.length == 0 ){\
8619
   for(var p = 0 ; p < l_length ; p++){\
8620
    barcolor[p] = stroke_color;\
8621
   };\
8622
  };\
8623
 };\
8624
 for(var p = 0; p < l_length; p++){\
8625
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 8626
  txt = legend0[p];\
7614 schaersvoo 8627
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 8628
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 8629
  y_offset = parseInt(y_offset + 1.5*font_size);\
8630
 };\
7988 schaersvoo 8631
 ctx.restore();\
7614 schaersvoo 8632
};\
11088 schaersvoo 8633
if( typeof(barchart_0)  !== 'undefined' ){\
7991 schaersvoo 8634
 ctx.save();\
8635
 var num_barcharts = 0;\
8636
 var bar_name = eval('barchart_0');\
11088 schaersvoo 8637
 while( typeof(bar_name) !== 'undefined' ){\
7991 schaersvoo 8638
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
8639
 };\
9346 schaersvoo 8640
 var bar_width = parseInt(0.8*x2step/(num_barcharts));\
7991 schaersvoo 8641
 for(var i=0 ; i< num_barcharts ; i++){\
8642
  bar_name = eval('barchart_'+i);\
8643
  var bar_x = new Array();\
8644
  var bar_y = new Array();\
8645
  var lb = bar_name.length;\
8646
  var idx = 0;\
8647
  var dx = parseInt(0.5*i*bar_width);\
8648
  for( var p = 0 ; p < lb ; p = p + 3 ){\
8649
   bar_x[idx] = x2px(bar_name[p]);\
8650
   bar_y[idx] = y2px(bar_name[p+1]);\
8651
   barcolor[idx] = bar_name[p+2];\
8652
   idx++;\
8653
  };\
8654
  ctx.globalAlpha = fill_opacity;\
8655
  for( var p = 0; p < idx ; p++ ){\
11739 schaersvoo 8656
   ctx.beginPath();\
7991 schaersvoo 8657
   ctx.strokeStyle = barcolor[p];\
8658
   ctx.fillStyle = barcolor[p];\
9346 schaersvoo 8659
   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
11739 schaersvoo 8660
   ctx.fill();\
8661
   ctx.stroke();\
8662
   ctx.closePath();\
7991 schaersvoo 8663
  };\
8664
 };\
8665
 ctx.restore();\
8666
};\
11088 schaersvoo 8667
if( typeof(linegraph_0) !== 'undefined' ){\
7996 schaersvoo 8668
 ctx.save();\
8669
 ctx.globalAlpha = 1.0;\
8670
 var i = 0;\
8671
 var line_name = eval('linegraph_'+i);\
11088 schaersvoo 8672
 while ( typeof(line_name) !== 'undefined' ){\
7996 schaersvoo 8673
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
8674
  ctx.lineWidth = parseInt(line_name[1]);\
8675
  if(line_name[2] == \"1\"){\
8676
   var d1 = parseInt(line_name[3]);\
8677
   var d2 = parseInt(line_name[4]);\
8678
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
8679
  }\
8680
  else\
8681
  {\
8682
  if(ctx.setLineDash){ctx.setLineDash = null;}\
8683
  if(ctx.mozDash){ctx.mozDash = null;}\
8684
  };\
8685
  var data_x = new Array();\
8686
  var data_y = new Array();\
8687
  var lb = line_name.length;\
8688
  var idx = 0;\
8689
  for( var p = 5 ; p < lb ; p = p + 2 ){\
8690
   data_x[idx] = x2px(line_name[p]);\
8691
   data_y[idx] = y2px(line_name[p+1]);\
8692
   idx++;\
8693
  };\
8694
  for( var p = 0; p < idx ; p++){\
8695
   ctx.beginPath();\
8696
   ctx.moveTo(data_x[p],data_y[p]);\
8697
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
8698
   ctx.stroke();\
8699
   ctx.closePath();\
8700
  };\
8701
  i++;\
8702
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
8703
 };\
8704
 ctx.restore();\
8705
};\
7614 schaersvoo 8706
return;\
7989 schaersvoo 8707
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8708
    break;
8224 bpr 8709
 
7614 schaersvoo 8710
    case DRAW_PIECHART:
13970 obado 8711
fprintf(js_include_file,"\n/* draw piecharts */\n\
11875 schaersvoo 8712
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
12538 schaersvoo 8713
function draw_piechart(canvas_type,x_center,y_center,radius, data_color_list,fill_opacity,legend_cnt,font_family,use_filled,use_offset){\
7614 schaersvoo 8714
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8715
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8716
 }\
8717
 else\
8718
 {\
8719
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8720
 };\
12538 schaersvoo 8721
 var center_text = use_offset || 0;\
7614 schaersvoo 8722
 var ld = data_color_list.length;\
8723
 var sum = 0;\
8724
 var idx = 0;\
7956 schaersvoo 8725
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 8726
 var colors = new Array();\
8727
 var data = new Array();\
8728
 for(var p = 0;p < ld; p = p + 2){\
8729
  data[idx] = parseFloat(data_color_list[p]);\
8730
  sum = sum + data[idx];\
8731
  colors[idx] = data_color_list[p+1];\
8732
  idx++;\
8733
 };\
11875 schaersvoo 8734
 if( use_filled > 1 ){\
8735
  var i = 2;\
8736
  for(var p = 0 ;  p < idx ; p++){\
8737
   if(i > 5 ){ i = 2; };\
8738
   var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\
8739
  };\
8740
 };\
7614 schaersvoo 8741
 var ctx = obj.getContext(\"2d\");\
8742
 ctx.save();\
8743
 var angle;\
8744
 var angle_end = 0;\
8745
 var offset = Math.PI / 2;\
8746
 ctx.globalAlpha = fill_opacity;\
12538 schaersvoo 8747
 var angles = [];\
7614 schaersvoo 8748
 for(var p=0; p < idx; p++){\
8749
  ctx.beginPath();\
8750
  ctx.moveTo(x_center,y_center);\
8751
  angle = Math.PI * (2 * data[p] / sum);\
8752
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
8753
  ctx.lineTo(x_center, y_center);\
11875 schaersvoo 8754
  if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\
7614 schaersvoo 8755
  ctx.fill();\
8756
  ctx.closePath();\
12538 schaersvoo 8757
  angles.push(angle_end + angle - offset);\
7614 schaersvoo 8758
  angle_end  = angle_end + angle;\
8759
 };\
11088 schaersvoo 8760
 if(typeof(legend0) !== 'undefined'){\
7956 schaersvoo 8761
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 8762
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 8763
  ctx.font = font_family;\
12538 schaersvoo 8764
  var y_offset = font_size;\
7614 schaersvoo 8765
  var x_offset = 0;\
8766
  var txt;var txt_size;\
8767
  for(var p = 0; p < idx; p++){\
8768
   ctx.fillStyle = colors[p];\
7956 schaersvoo 8769
   txt = legenda[p];\
12538 schaersvoo 8770
   txt_size = ctx.measureText(txt).width + 2;\
8771
   if(center_text == 4){\
8772
    ctx.save();\
8773
    ctx.translate(x_center, y_center);\
8774
    ctx.rotate(angles[p]);\
8775
    ctx.fillText(txt,radius-txt_size,0);\
8776
    ctx.restore();\
8777
   }\
8778
   else\
8779
   {\
8780
    if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
8781
    ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
8782
    y_offset = parseInt(y_offset + 1.5*font_size);\
8783
   };\
7614 schaersvoo 8784
  };\
8785
 };\
8786
 ctx.restore();\
7956 schaersvoo 8787
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8788
    break;
9433 schaersvoo 8789
    case DRAW_JSBOXPLOT:
13970 obado 8790
fprintf(js_include_file,"\n/* draw jsboxplots */\n\
11874 schaersvoo 8791
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
9433 schaersvoo 8792
function statistics(data){\
8793
 var len = data.length;\
8794
 var min = 10000000;\
8795
 var max = -10000000;\
8796
 var sum = 0;var d;\
8797
 for(var i=0;i<len;i++){\
8798
  d = data[i];\
8799
  if(d < min){min = d;}else{if(d > max){max = d;};};\
8800
  sum+= parseFloat(data[i]);\
8801
 };\
8802
 var mean = parseFloat(sum/len);\
8803
 var variance = 0;\
8804
 for(var i=0;i<len;i++){\
8805
  d = data[i];\
8806
  variance += (d - mean)*(d - mean);\
8807
 };\
8808
 variance = parseFloat(variance / len);\
8809
 var std = Math.sqrt(variance);\
8810
 data.sort(function(a,b){return a - b;});\
8811
 var median;var Q1;var Q3;\
8812
 var half = Math.floor(0.5*len);\
8813
 var q1 = Math.floor(0.25*len);\
8814
 var q3 = Math.floor(0.75*len);\
8815
 var half = Math.floor(0.5*len);\
8816
 if(len %%2 == 1){\
8817
  median = data[half];\
8818
  Q1 = data[q1];\
8819
  Q3 = data[q3];\
8820
 }\
8821
 else\
8822
 {\
8823
  median = (data[half - 1] + data[half] )/2;\
8824
  Q1 = (data[q1 - 1] + data[q1] )/2;\
8825
  Q3 = (data[q3 - 1] + data[q3] )/2;\
8826
 };\
8827
 return [min,Q1,median,Q3,max];\
8828
};");
8829
    break;
8830
    case DRAW_BOXPLOT:
13970 obado 8831
fprintf(js_include_file,"\n/* draw boxplots */\n\
11874 schaersvoo 8832
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
9465 schaersvoo 8833
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){\
14044 schaersvoo 8834
 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);};\
9433 schaersvoo 8835
 var ctx = obj.getContext(\"2d\");\
8836
 ctx.clearRect(0,0,xsize,ysize);\
8837
 ctx.save();\
8838
 ctx.lineWidth = line_width;\
11088 schaersvoo 8839
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
9433 schaersvoo 8840
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11875 schaersvoo 8841
 var colors = new Array(2);\
8842
 colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8843
 colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8844
 if( use_filled > 1 ){\
8845
   var pat = create_Pattern(0,0,3,colors[0]);\
8846
   all_fill_patterns[0] = pat;\
8847
   pat = create_Pattern(0,0,4,colors[1]);\
8848
   all_fill_patterns[1] = pat;\
8849
 };\
9433 schaersvoo 8850
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8851
 var hh = 0.25*hw;\
9465 schaersvoo 8852
 switch(boxplot_source){\
11088 schaersvoo 8853
  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
8854
  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
8855
  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
9465 schaersvoo 8856
  default: break;\
9433 schaersvoo 8857
 };\
8858
 var min,Q1,median,Q3,max;\
8859
 if(xy == 1 ){\
8860
  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
8861
  hh = Math.abs(y2px(hh) - y2px(ystart));\
8862
  hw = Math.abs(y2px(hw) - y2px(ystart));\
8863
  cxy = y2px(cxy);\
9465 schaersvoo 8864
  ctx.beginPath();\
9433 schaersvoo 8865
  ctx.moveTo(min,cxy);\
8866
  ctx.lineTo(Q1,cxy);\
8867
  ctx.moveTo(Q3,cxy);\
8868
  ctx.lineTo(max,cxy);\
8869
  ctx.moveTo(min,cxy+hh);\
8870
  ctx.lineTo(min,cxy-hh);\
8871
  ctx.moveTo(max,cxy+hh);\
8872
  ctx.lineTo(max,cxy-hh);\
9465 schaersvoo 8873
  ctx.closePath();\
8874
  ctx.stroke();\
8875
  ctx.beginPath();\
9433 schaersvoo 8876
  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
9465 schaersvoo 8877
  ctx.closePath();\
11839 schaersvoo 8878
  if( use_filled != 0 ){\
12024 schaersvoo 8879
   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
9465 schaersvoo 8880
   ctx.fill();\
8881
  };\
8882
  ctx.stroke();\
8883
  ctx.beginPath();\
9433 schaersvoo 8884
  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
9465 schaersvoo 8885
  ctx.closePath();\
11839 schaersvoo 8886
  if( use_filled != 0 ){\
12075 schaersvoo 8887
   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
9465 schaersvoo 8888
   ctx.fill();\
8889
  };\
8890
  ctx.stroke();\
9433 schaersvoo 8891
 }else{\
8892
  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
8893
  hh = Math.abs(x2px(hh) - x2px(xstart));\
8894
  hw = Math.abs(x2px(hw) - x2px(xstart));\
8895
  cxy = x2px(cxy);\
9465 schaersvoo 8896
  ctx.beginPath();\
9433 schaersvoo 8897
  ctx.moveTo(cxy,min);\
8898
  ctx.lineTo(cxy,Q1);\
8899
  ctx.moveTo(cxy,Q3);\
8900
  ctx.lineTo(cxy,max);\
8901
  ctx.moveTo(cxy + hh,min);\
8902
  ctx.lineTo(cxy - hh,min);\
8903
  ctx.moveTo(cxy + hh,max);\
8904
  ctx.lineTo(cxy - hh,max);\
9465 schaersvoo 8905
  ctx.closePath;\
8906
  ctx.stroke();\
8907
  ctx.beginPath();\
9433 schaersvoo 8908
  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
9465 schaersvoo 8909
  ctx.closePath();\
11839 schaersvoo 8910
  if( use_filled != 0 ){\
12075 schaersvoo 8911
   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
9465 schaersvoo 8912
   ctx.fill();\
8913
  };\
8914
  ctx.stroke();\
8915
  ctx.beginPath();\
9433 schaersvoo 8916
  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
9465 schaersvoo 8917
  ctx.closePath();\
11839 schaersvoo 8918
  if( use_filled != 0 ){\
12075 schaersvoo 8919
   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
9465 schaersvoo 8920
   ctx.fill();\
8921
  };\
8922
  ctx.stroke();\
9433 schaersvoo 8923
 };\
8924
 ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
8925
    break;
7614 schaersvoo 8926
    case DRAW_ARCS:
13970 obado 8927
fprintf(js_include_file,"\n/* draw arcs */\n\
11874 schaersvoo 8928
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 8929
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 8930
 ctx.save();\
8931
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 8932
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 8933
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
8934
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 8935
 start = 360 - start;\
8936
 end = 360 - end;\
7614 schaersvoo 8937
 ctx.lineWidth = line_width;\
11088 schaersvoo 8938
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8939
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11874 schaersvoo 8940
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 8941
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
8071 schaersvoo 8942
 ctx.beginPath();\
8943
 ctx.moveTo(xc,yc);\
8944
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
8945
 ctx.lineTo(xc,yc);\
8946
 ctx.closePath();\
11875 schaersvoo 8947
 if( use_filled != 0 ){ctx.fill();};\
8071 schaersvoo 8948
 ctx.stroke();\
7614 schaersvoo 8949
 ctx.restore();\
8071 schaersvoo 8950
};");
8224 bpr 8951
 
7614 schaersvoo 8952
    break;
7983 schaersvoo 8953
    case DRAW_CENTERSTRING:
13970 obado 8954
fprintf(js_include_file,"\n/* draw centerstring */\n\
8105 schaersvoo 8955
var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
7983 schaersvoo 8956
 var obj;\
8957
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8958
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8959
 }\
8960
 else\
8961
 {\
8962
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8963
 };\
8964
 var ctx = obj.getContext(\"2d\");\
8965
 ctx.save();\
9481 schaersvoo 8966
 ctx.clearRect(0,0,xsize,ysize);\
7983 schaersvoo 8967
 ctx.font = font_family;\
8968
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8969
 var stringwidth = ctx.measureText(text).width;\
8970
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
8971
 ctx.fillText(text,x,y2px(y));\
9481 schaersvoo 8972
 ctx.restore();\
7983 schaersvoo 8973
return;\
8974
};",canvas_root_id,canvas_root_id,canvas_root_id);
8975
    break;
7614 schaersvoo 8976
    case DRAW_TEXTS:
13970 obado 8977
fprintf(js_include_file,"\n/* draw text */\n\
11811 schaersvoo 8978
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){\
12000 schaersvoo 8979
 var obj;\
8980
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8981
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8982
 }\
8983
 else\
8984
 {\
8985
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8986
 };\
8987
 var ctx = obj.getContext(\"2d\");\
8988
 if( font_family != 'null' ){\
8989
  ctx.font = font_family;\
8990
 }\
8991
 else\
8992
 {\
8993
  ctx.font = font_size+'px Ariel';\
8994
 };\
8995
 if( use_offset == 3 ){if(angle2 < 0 ){ y = y + 0.8*font_size; x = x + (Math.cos(angle2))*font_size; }else{y = y - 0.8*font_size; x = x + (Math.sin(angle2))*font_size;};};\
8996
 if(angle2 == 0 && angle != 0){\
8997
  ctx.save();\
8998
  if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
8999
  if(use_rotate == 1 ){\
9000
  ctx.rotate(angle*Math.PI/180);};\
9001
  ctx.restore();\
9002
 };\
9003
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
9004
 if(angle2 != 0){\
9005
  ctx.save();\
9006
  ctx.translate(x,y);\
9007
  ctx.rotate((360-angle2)*(Math.PI / 180));\
9008
  ctx.fillText(text,0,0);\
9009
  ctx.restore();\
9010
 }\
9011
 else\
9012
 {\
9013
  ctx.fillText(text,x,y);\
9014
 };\
7614 schaersvoo 9015
 return;\
12000 schaersvoo 9016
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 9017
    break;
9018
    case DRAW_CURVE:
13970 obado 9019
fprintf(js_include_file,"\n/* draw curve */\n\
8105 schaersvoo 9020
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 9021
 var obj;\
9022
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9023
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9024
 }\
9025
 else\
9026
 {\
9027
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9028
 };\
9029
 var ctx = obj.getContext(\"2d\");\
9030
 ctx.save();\
8071 schaersvoo 9031
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 9032
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
9033
 ctx.beginPath();ctx.lineWidth = line_width;\
11088 schaersvoo 9034
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 9035
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
9036
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
9037
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
9038
 for(var p = 1 ; p < x_points.length ; p++){\
9039
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
9040
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
9041
  }\
9042
  else\
9043
  {\
9044
   ctx.stroke();\
9045
   ctx.beginPath();\
9046
   p++;\
9047
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
9048
  };\
9049
 };\
9050
 ctx.stroke();\
9051
 ctx.restore();\
7653 schaersvoo 9052
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 9053
    break;
8224 bpr 9054
 
7614 schaersvoo 9055
    case DRAW_INPUTS:
13970 obado 9056
fprintf(js_include_file,"\n/* draw input fields */\n\
11803 schaersvoo 9057
var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
7614 schaersvoo 9058
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
9059
var input = document.createElement(\"input\");\
9060
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
9061
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
9062
input.setAttribute(\"size\",size);\
9063
input.setAttribute(\"value\",value);\
7877 schaersvoo 9064
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
11803 schaersvoo 9065
canvas_div.appendChild(input);\
9066
if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
9067
};\
9068
function center_input(id,x,y,style){\
9069
 var inp = document.getElementById(id);\
9070
 var pos = inp.getBoundingClientRect();\
9071
 var center_x = parseInt(x - 0.5*(pos.width));\
9072
 var center_y = parseInt(y - 0.5*(pos.height));\
9073
 try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
9074
 catch(e){return;};\
9075
};");
7614 schaersvoo 9076
    break;
8224 bpr 9077
 
7614 schaersvoo 9078
    case DRAW_TEXTAREAS:
13970 obado 9079
fprintf(js_include_file,"\n/* draw text area inputfields */\n\
8105 schaersvoo 9080
var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
7614 schaersvoo 9081
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
9082
var textarea = document.createElement(\"textarea\");\
9083
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
9084
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
9085
textarea.setAttribute(\"cols\",cols);\
9086
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 9087
textarea.value = value;\
9088
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 9089
canvas_div.appendChild(textarea);};");
7614 schaersvoo 9090
    break;
8224 bpr 9091
 
7614 schaersvoo 9092
case DRAW_PIXELS:
13970 obado 9093
fprintf(js_include_file,"\n/* draw pixel */\n\
8105 schaersvoo 9094
var draw_setpixel = function(x,y,color,opacity,pixelsize){\
11997 schaersvoo 9095
 var idx = 2000+Math.ceil(1000*(Math.random()));\
9096
 var canvas = create_canvas%d(idx,xsize,ysize);\
7614 schaersvoo 9097
 var d = 0.5*pixelsize;\
9098
 var ctx = canvas.getContext(\"2d\");\
9462 schaersvoo 9099
 if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
7614 schaersvoo 9100
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
9101
 ctx.clearRect(0,0,xsize,ysize);\
9102
 for(var p=0; p<x.length;p++){\
9103
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
9104
 };\
9105
 ctx.fill();ctx.stroke();\
9106
};",canvas_root_id);
9107
break;
9108
 
9109
case DRAW_CLOCK:
13970 obado 9110
fprintf(js_include_file,"\n/* begin command clock */\n\
7614 schaersvoo 9111
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
9112
var clock_ctx = clock_canvas.getContext(\"2d\");\
9113
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
8130 schaersvoo 9114
 clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
7614 schaersvoo 9115
 clock_ctx.save();\
7997 schaersvoo 9116
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 9117
 this.type = type || 0;\
9118
 this.interaction = interaction || 0;\
7862 schaersvoo 9119
 this.H = H;\
9120
 this.M = M;\
9121
 this.S = S;\
7614 schaersvoo 9122
 this.xc = xc || xsize/2;\
9123
 this.yc = yc || ysize/2;\
9124
 this.radius = radius || xsize/4;\
9125
 var font_size = parseInt(0.2*this.radius);\
11991 schaersvoo 9126
 this.H_color = h_color || \"black\";\
9127
 this.M_color = m_color || \"black\";\
9128
 this.S_color = s_color || \"black\";\
9129
 this.fg_color = fg_color || \"black\";\
7614 schaersvoo 9130
 this.bg_color = bg_color || \"white\";\
9131
 clock_ctx.translate(this.xc,this.yc);\
9132
 clock_ctx.beginPath();\
9133
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
9134
 clock_ctx.fillStyle = this.bg_color;\
9135
 clock_ctx.fill();\
9136
 clock_ctx.closePath();\
9137
 clock_ctx.beginPath();\
9138
 clock_ctx.font = font_size+\"px Arial\";\
9139
 clock_ctx.fillStyle = this.fg_color;\
9140
 clock_ctx.textAlign = \"center\";\
9141
 clock_ctx.textBaseline = 'middle';\
9142
 var angle;var x1,y1,x2,y2;\
9143
 var angle_cos;var angle_sin;\
7997 schaersvoo 9144
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 9145
 switch(type){\
9146
 case 0:clock_ctx.beginPath();\
9147
 for(var p = 1; p <= 12 ; p++){\
9148
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
9149
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
9150
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9151
  clock_ctx.moveTo(x1,y1);\
9152
  clock_ctx.lineTo(x2,y2);\
9153
 };\
9154
 for(var p = 1; p <= 60 ; p++){\
9155
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
9156
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
9157
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9158
  clock_ctx.moveTo(x1,y1);\
9159
  clock_ctx.lineTo(x2,y2);\
9160
 };\
9161
 clock_ctx.closePath();\
9162
 clock_ctx.stroke();\
9163
 break;\
9164
 case 1:\
9165
 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 9166
 case 2:\
9167
 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 9168
 clock_ctx.beginPath();\
9169
 for(var p = 1; p <= 12 ; p++){\
9170
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
9171
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
9172
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9173
  clock_ctx.moveTo(x1,y1);\
9174
  clock_ctx.lineTo(x2,y2);\
9175
 };\
9176
 for(var p = 1; p <= 60 ; p++){\
9177
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
9178
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
9179
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9180
  clock_ctx.moveTo(x1,y1);\
9181
  clock_ctx.lineTo(x2,y2);\
9182
 };\
9183
 clock_ctx.closePath();\
9184
 clock_ctx.stroke();\
9185
 break;\
9186
 };\
9187
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
9188
 clock_ctx.rotate(angle);\
9189
 clock_ctx.beginPath();\
9190
 clock_ctx.moveTo(-3, -2);\
9191
 clock_ctx.lineTo(-3, 2);\
11026 bpr 9192
 clock_ctx.lineTo(this.radius * 0.6, 1);\
9193
 clock_ctx.lineTo(this.radius  * 0.6, -1);\
7614 schaersvoo 9194
 clock_ctx.fillStyle = this.H_color;\
9195
 clock_ctx.fill();\
9196
 clock_ctx.rotate(-angle);\
9197
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
9198
 clock_ctx.rotate(angle);\
9199
 clock_ctx.beginPath();\
9200
 clock_ctx.moveTo(-3, -2);\
9201
 clock_ctx.lineTo(-3, 2);\
9202
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
9203
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
9204
 clock_ctx.fillStyle = this.M_color;\
9205
 clock_ctx.fill();\
9206
 clock_ctx.rotate(-angle);\
9207
 angle = (this.S - 15) * 2 * Math.PI / 60;\
9208
 clock_ctx.rotate(angle);\
9209
 clock_ctx.beginPath();\
9210
 clock_ctx.moveTo(0,0);\
11026 bpr 9211
 clock_ctx.lineTo(this.radius  * 0.9, 1);\
9212
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
7614 schaersvoo 9213
 clock_ctx.strokeStyle = this.S_color;\
9214
 clock_ctx.stroke();\
9215
 clock_ctx.restore();\
7653 schaersvoo 9216
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 9217
break;
9218
 
9219
case DRAW_LATTICE:
13970 obado 9220
fprintf(js_include_file,"\n/* draw lattice */\n\
11991 schaersvoo 9221
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,use_filled){\
7614 schaersvoo 9222
 var obj;\
9223
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9224
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9225
 }\
9226
 else\
9227
 {\
9228
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9229
 };\
9230
 var ctx = obj.getContext(\"2d\");\
9231
 ctx.save();\
8071 schaersvoo 9232
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 9233
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
11874 schaersvoo 9234
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 9235
 if(use_filled > 1 ){ if(! all_fill_patterns[use_filled] ){ var pat = create_Pattern(0,0,use_filled,color); all_fill_patterns[use_filled] = pat;};ctx.fillStyle = all_fill_patterns[use_filled]; } else { ctx.fillStyle = color;};\
7614 schaersvoo 9236
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
9237
 var radius = line_width;\
9238
 var x = 0;\
9239
 var y = 0;\
9240
 var x_step_px = xsize/(xmax-xmin);\
9241
 var y_step_px = ysize/(ymax-ymin);\
9242
 var xv1 = dx1*x_step_px;\
9243
 var yv1 = dy1*y_step_px;\
9244
 var xv2 = dx2*x_step_px;\
9245
 var yv2 = dy2*y_step_px;\
9246
 for(var p = 0; p < n1 ;p++){\
9247
  x = p*xv1 + x0;\
9248
  y = p*yv1 + y0;\
9249
  for(var c = 0; c < n2 ; c++){\
9250
   ctx.beginPath();\
9251
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
9252
   ctx.fill();\
9253
   ctx.stroke();\
9254
   ctx.closePath();\
9255
  };\
9256
 };\
9257
 ctx.restore();\
9258
 return;\
7653 schaersvoo 9259
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 9260
    break;
7735 schaersvoo 9261
case DRAW_XYLOGSCALE:
13970 obado 9262
fprintf(js_include_file,"\n/* draw xylogscale */\n\
8105 schaersvoo 9263
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 9264
 var obj;\
9265
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9266
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9267
 }\
9268
 else\
9269
 {\
9270
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9271
 };\
9272
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 9273
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 9274
 ctx.save();\
7739 schaersvoo 9275
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 9276
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
9277
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
9278
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
9279
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
11972 schaersvoo 9280
 if(use_axis_numbering != -1){\
7956 schaersvoo 9281
  ctx.font = font_family;\
9282
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
9283
  ymarge = parseInt(1.5*font_size);\
9284
  ctx.save();\
9285
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
9286
  ctx.rect(0,0,xmarge,ysize);\
9287
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
9288
  ctx.fill();\
9289
  ctx.restore();\
9290
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 9291
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 9292
  ctx.save();\
9293
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9294
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9295
  corr =  ctx.measureText(xaxislabel).width;\
9296
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
9297
  ctx.restore();\
9298
 };\
11088 schaersvoo 9299
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 9300
  ctx.save();\
9301
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9302
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9303
  corr = ctx.measureText(yaxislabel).width;\
9304
  ctx.translate(xmarge+font_size,corr+font_size);\
9305
  ctx.rotate(-0.5*Math.PI);\
9306
  ctx.fillText(yaxislabel,0,0);\
9307
  ctx.restore();\
9308
 };\
9309
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9310
 ctx.lineWidth = line_width;\
9311
 for(var p = x_min; p <= x_max ; p++){\
9312
  num = Math.pow(xlogbase,p);\
9313
  for(var i = 1 ; i < xlogbase ; i++){\
9314
   x_e = x2px(i*num);\
7735 schaersvoo 9315
   if( i == 1 ){\
7956 schaersvoo 9316
    ctx.lineWidth = line_width;\
9317
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9318
    if( use_axis_numbering != -1 && p > x_min){\
7956 schaersvoo 9319
      xtxt = xlogbase+'^'+p.toFixed(0);\
9320
      corr = 0.5*(ctx.measureText(xtxt).width);\
9321
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
9322
    };\
7735 schaersvoo 9323
   }else{\
7956 schaersvoo 9324
    ctx.lineWidth = 0.2*line_width;\
9325
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9326
   };\
7738 schaersvoo 9327
   if( x_e >= xmarge ){\
7956 schaersvoo 9328
    ctx.beginPath();\
9329
    ctx.moveTo(x_e,0);\
9330
    ctx.lineTo(x_e,ysize - ymarge);\
9331
    ctx.stroke();\
9332
    ctx.closePath();\
7738 schaersvoo 9333
   };\
7956 schaersvoo 9334
  };\
9335
 };\
9336
 for(var p = y_min; p <= y_max ; p++){\
9337
  num = Math.pow(ylogbase,p);\
9338
  for(var i = 1 ; i < ylogbase ; i++){\
9339
   y_e = y2px(i*num);\
9340
   if( i == 1 ){\
9341
    ctx.lineWidth = line_width;\
7735 schaersvoo 9342
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9343
    if( use_axis_numbering != -1 && p > y_min){\
7956 schaersvoo 9344
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
9345
    };\
9346
   }else{\
9347
    ctx.lineWidth = 0.2*line_width;\
9348
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9349
   };\
9350
   ctx.beginPath();\
9351
   ctx.moveTo(xmarge,y_e);\
9352
   ctx.lineTo(xsize,y_e);\
9353
   ctx.stroke();\
9354
   ctx.closePath();\
9355
  };\
9356
 };\
7735 schaersvoo 9357
 ctx.restore();\
9358
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
9359
    break;
7614 schaersvoo 9360
 
7735 schaersvoo 9361
case DRAW_XLOGSCALE:
13970 obado 9362
fprintf(js_include_file,"\n/* draw xlogscale */\n\
8105 schaersvoo 9363
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 9364
 var obj;\
9365
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9366
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9367
 }\
9368
 else\
9369
 {\
9370
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9371
 };\
9372
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 9373
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 9374
 ctx.save();\
9375
 ctx.lineWidth = line_width;\
7739 schaersvoo 9376
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 9377
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
9378
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
9379
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 9380
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
11972 schaersvoo 9381
 if(use_axis_numbering != -1){\
7956 schaersvoo 9382
  ctx.font = font_family;\
9383
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
9384
  ymarge = parseInt(1.5*font_size);\
9385
  ctx.save();\
9386
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
9387
  ctx.rect(0,0,xmarge,ysize);\
9388
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
9389
  ctx.fill();\
9390
  ctx.restore();\
9391
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 9392
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 9393
  ctx.save();\
9394
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9395
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9396
  corr =  ctx.measureText(xaxislabel).width;\
9397
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
9398
  ctx.restore();\
9399
 };\
11088 schaersvoo 9400
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 9401
  ctx.save();\
9402
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9403
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9404
  corr = ctx.measureText(yaxislabel).width;\
9405
  ctx.translate(xmarge+font_size,corr+font_size);\
9406
  ctx.rotate(-0.5*Math.PI);\
9407
  ctx.fillText(yaxislabel,0,0);\
9408
  ctx.restore();\
9409
 };\
9410
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9411
 ctx.lineWidth = line_width;\
9412
 for(var p = x_min; p <= x_max ; p++){\
9413
  num = Math.pow(xlogbase,p);\
9414
  for(var i = 1 ; i < xlogbase ; i++){\
9415
   x_e = x2px(i*num);\
7735 schaersvoo 9416
   if( i == 1 ){\
7956 schaersvoo 9417
     ctx.lineWidth = line_width;\
7739 schaersvoo 9418
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9419
    if( use_axis_numbering != -1 && p > x_min ){\
7735 schaersvoo 9420
      xtxt = xlogbase+'^'+p.toFixed(0);\
9421
      corr = 0.5*(ctx.measureText(xtxt).width);\
9422
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
9423
    };\
9424
   }else{\
7956 schaersvoo 9425
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 9426
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9427
   };\
7739 schaersvoo 9428
   if( x_e >= xmarge ){\
7956 schaersvoo 9429
    ctx.beginPath();\
9430
    ctx.moveTo(x_e,0);\
9431
    ctx.lineTo(x_e,ysize - ymarge);\
9432
    ctx.stroke();\
9433
    ctx.closePath();\
7739 schaersvoo 9434
   };\
9435
  };\
7956 schaersvoo 9436
 };\
7735 schaersvoo 9437
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
9438
 var minor_step = stepy / yminor;\
7749 schaersvoo 9439
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 9440
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 9441
  ctx.lineWidth = line_width;\
9442
  ctx.beginPath();\
9443
  ctx.moveTo(xmarge,y);\
9444
  ctx.lineTo(xsize,y);\
9445
  ctx.stroke();\
9446
  ctx.closePath();\
11972 schaersvoo 9447
  if( use_axis_numbering != -1){\
7735 schaersvoo 9448
   ytxt = (px2y(y)).toFixed(prec);\
9449
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
9450
  };\
9451
  for(var dy = 1 ; dy < yminor ; dy++){\
9452
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 9453
   ctx.lineWidth = 0.2*line_width;\
9454
   ctx.beginPath();\
7739 schaersvoo 9455
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 9456
   ctx.lineTo(xsize,y+dy*minor_step);\
9457
   ctx.stroke();\
9458
   ctx.closePath();\
7735 schaersvoo 9459
  };\
9460
 };\
7956 schaersvoo 9461
 ctx.restore();\
9462
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 9463
    break;
7729 schaersvoo 9464
case DRAW_YLOGSCALE:
13970 obado 9465
fprintf(js_include_file,"\n/* draw ylogscale */\n\
8105 schaersvoo 9466
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 9467
 var obj;\
9468
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9469
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9470
 }\
9471
 else\
9472
 {\
9473
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9474
 };\
9475
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 9476
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 9477
 ctx.save();\
9478
 ctx.lineWidth = line_width;\
7735 schaersvoo 9479
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
9480
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
8109 schaersvoo 9481
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
11972 schaersvoo 9482
 if(use_axis_numbering != -1){\
7956 schaersvoo 9483
  ctx.font = font_family;\
9484
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
9485
  ymarge = 2*font_size;\
9486
  ctx.save();\
9487
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
9488
  ctx.rect(0,0,xmarge,ysize);\
9489
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
9490
  ctx.fill();\
9491
  ctx.restore();\
9492
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 9493
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 9494
  ctx.save();\
9495
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9496
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9497
  corr =  ctx.measureText(xaxislabel).width;\
9498
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
9499
  ctx.restore();\
9500
 };\
11088 schaersvoo 9501
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 9502
  ctx.save();\
9503
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9504
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9505
  corr = ctx.measureText(yaxislabel).width;\
9506
  ctx.translate(xmarge+font_size,corr+font_size);\
9507
  ctx.rotate(-0.5*Math.PI);\
9508
  ctx.fillText(yaxislabel,0,0);\
9509
  ctx.restore();\
9510
 };\
9511
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9512
 ctx.lineWidth = line_width;\
9513
 for(var p = y_min; p <= y_max ; p++){\
9514
  num = Math.pow(ylogbase,p);\
9515
  for(var i = 1 ; i < ylogbase ; i++){\
9516
   y_e = y2px(i*num);\
7729 schaersvoo 9517
   if( i == 1 ){\
7956 schaersvoo 9518
    ctx.lineWidth = line_width;\
7729 schaersvoo 9519
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9520
    if( use_axis_numbering != -1 && p > y_min){\
7735 schaersvoo 9521
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 9522
    };\
9523
   }else{\
7956 schaersvoo 9524
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 9525
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9526
   };\
7956 schaersvoo 9527
   ctx.beginPath();\
9528
   ctx.moveTo(xmarge,y_e);\
9529
   ctx.lineTo(xsize,y_e);\
9530
   ctx.stroke();\
9531
   ctx.closePath();\
9532
  };\
9533
 };\
7729 schaersvoo 9534
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
9535
 var minor_step = stepx / xminor;\
9536
 var prec = Math.log(precision)/Math.log(10);\
9537
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 9538
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 9539
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 9540
  ctx.lineWidth = line_width;\
9541
  ctx.beginPath();\
9542
  ctx.moveTo(x,ysize-ymarge);\
9543
  ctx.lineTo(x,0);\
9544
  ctx.stroke();\
9545
  ctx.closePath();\
11972 schaersvoo 9546
  if( use_axis_numbering != -1){\
7729 schaersvoo 9547
   xtxt = (px2x(x)).toFixed(prec);\
9548
   corr = 0.5*(ctx.measureText(xtxt).width);\
9549
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
9550
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
9551
  };\
9552
  for(var dx = 1 ; dx < xminor ; dx++){\
9553
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 9554
   ctx.lineWidth = 0.2*line_width;\
9555
   ctx.beginPath();\
7739 schaersvoo 9556
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 9557
   ctx.lineTo(x+dx*minor_step,0);\
9558
   ctx.stroke();\
9559
   ctx.closePath();\
7735 schaersvoo 9560
  };\
9561
 };\
7956 schaersvoo 9562
 ctx.restore();\
9563
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 9564
    break;
9213 schaersvoo 9565
 
7614 schaersvoo 9566
    default:break;
9567
   }
9568
  }
9569
 }
9570
  return;
9571
}
9572
 
9573
void check_string_length(int L){
9466 schaersvoo 9574
 if( L > MAX_BUFFER-1){
7614 schaersvoo 9575
  canvas_error("problem with your arguments to command...");
9576
 }
9577
 return;
9578
}
9579
 
9580
 
9581
int get_token(FILE *infile){
9582
        int     c,i=0;
9583
        char    temp[MAX_INT], *input_type;
9584
        char    *line="line",
9585
        *audio="audio",
9586
        *blink="blink",
9587
        *arrowhead="arrowhead",
9588
        *crosshairsize="crosshairsize",
9589
        *crosshair="crosshair",
9590
        *crosshairs="crosshairs",
9591
        *audioobject="audioobject",
9592
        *style="style",
9593
        *mouse="mouse",
7991 schaersvoo 9594
        *mousex="mousex",
9595
        *mousey="mousey",
8071 schaersvoo 9596
        *mouse_display="display",
9597
        *mouse_degree="mouse_degree",
7614 schaersvoo 9598
        *userdraw="userdraw",
9599
        *highlight="highlight",
9600
        *http="http",
9601
        *rays="rays",
9602
        *dashtype="dashtype",
9603
        *dashed="dashed",
9604
        *filled="filled",
9605
        *lattice="lattice",
9606
        *parallel="parallel",
9607
        *segment="segment",
8299 schaersvoo 9608
        *segments="segments",
7614 schaersvoo 9609
        *dsegment="dsegment",
9374 schaersvoo 9610
        *dsegments="dsegments",
7614 schaersvoo 9611
        *seg="seg",
9383 schaersvoo 9612
        *segs="segs",
7614 schaersvoo 9613
        *bgimage="bgimage",
9614
        *bgcolor="bgcolor",
9615
        *strokecolor="strokecolor",
9616
        *backgroundimage="backgroundimage",
9617
        *text="text",
9618
        *textup="textup",
9619
        *mouseprecision="mouseprecision",
9620
        *precision="precision",
9621
        *plotsteps="plotsteps",
9622
        *plotstep="plotstep",
9623
        *tsteps="tsteps",
9624
        *curve="curve",
9625
        *dcurve="dcurve",
14038 schaersvoo 9626
        *curvedarrow="curvedarrow",
9627
        *curvedarrows="curvedarrows",
9628
        *curvedarrow2="curvedarrow2",
9629
        *curvedarrows2="curvedarrows2",
7614 schaersvoo 9630
        *plot="plot",
9631
        *dplot="dplot",
7788 schaersvoo 9632
        *levelcurve="levelcurve",
7614 schaersvoo 9633
        *fontsize="fontsize",
9634
        *fontcolor="fontcolor",
9635
        *axis="axis",
9636
        *axisnumbering="axisnumbering",
9637
        *axisnumbers="axisnumbers",
9638
        *arrow="arrow",
9382 schaersvoo 9639
        *vector="vector",
9640
        *vectors="vectors",
7614 schaersvoo 9641
        *darrow="darrow",
9642
        *arrow2="arrow2",
9643
        *darrow2="darrow2",
8304 schaersvoo 9644
        *arrows="arrows",
8347 schaersvoo 9645
        *arrows2="arrows2",
7614 schaersvoo 9646
        *zoom="zoom",
9647
        *grid="grid",
9648
        *hline="hline",
7786 schaersvoo 9649
        *dhline="dhline",
7614 schaersvoo 9650
        *drag="drag",
9651
        *horizontalline="horizontalline",
9383 schaersvoo 9652
        *horizontallines="horizontallines",
7614 schaersvoo 9653
        *vline="vline",
7786 schaersvoo 9654
        *dvline="dvline",
7614 schaersvoo 9655
        *verticalline="verticalline",
9383 schaersvoo 9656
        *verticallines="verticallines",
7614 schaersvoo 9657
        *triangle="triangle",
9306 schaersvoo 9658
        *triangles="triangles",
7614 schaersvoo 9659
        *ftriangle="ftriangle",
9374 schaersvoo 9660
        *ftriangles="ftriangles",
7614 schaersvoo 9661
        *mathml="mathml",
9662
        *html="html",
9663
        *input="input",
8146 schaersvoo 9664
        *clearbutton="clearbutton",
9386 schaersvoo 9665
        *erase="erase",
9666
        *delete="delete",
7614 schaersvoo 9667
        *inputstyle="inputstyle",
9668
        *textarea="textarea",
9669
        *trange="trange",
9670
        *ranget="ranget",
9671
        *xrange="xrange",
9672
        *yrange="yrange",
9673
        *rangex="rangex",
9674
        *rangey="rangey",
8370 schaersvoo 9675
        *path="path",
7614 schaersvoo 9676
        *polyline="polyline",
8351 schaersvoo 9677
        *brokenline="brokenline",
7614 schaersvoo 9678
        *lines="lines",
9679
        *poly="poly",
9680
        *polygon="polygon",
9681
        *fpolygon="fpolygon",
9682
        *fpoly="fpoly",
9683
        *filledpoly="filledpoly",
9684
        *filledpolygon="filledpolygon",
9685
        *rect="rect",
9686
        *frect="frect",
9687
        *rectangle="rectangle",
9688
        *frectangle="frectangle",
9689
        *square="square",
9690
        *fsquare="fsquare",
9374 schaersvoo 9691
        *fsquares="fsquares",
8363 schaersvoo 9692
        *rects="rects",
9693
        *frects="frects",
7614 schaersvoo 9694
        *dline="dline",
9695
        *arc="arc",
9696
        *filledarc="filledarc",
9374 schaersvoo 9697
        *farc="farc",
7614 schaersvoo 9698
        *size="size",
9699
        *string="string",
9700
        *stringup="stringup",
9701
        *copy="copy",
9702
        *copyresized="copyresized",
9703
        *opacity="opacity",
9704
        *transparent="transparent",
9705
        *fill="fill",
9706
        *point="point",
9707
        *points="points",
9708
        *linewidth="linewidth",
9709
        *circle="circle",
8304 schaersvoo 9710
        *circles="circles",
7614 schaersvoo 9711
        *fcircle="fcircle",
9374 schaersvoo 9712
        *fcircles="fcircles",
7614 schaersvoo 9713
        *disk="disk",
9374 schaersvoo 9714
        *disks="disks",
7614 schaersvoo 9715
        *comment="#",
9716
        *end="end",
9717
        *ellipse="ellipse",
12110 schaersvoo 9718
        *ellipses="ellipses",
7614 schaersvoo 9719
        *fellipse="fellipse",
9720
        *rotate="rotate",
7785 schaersvoo 9721
        *affine="affine",
9907 schaersvoo 9722
        *rotationcenter="rotationcenter",
9723
        *killrotate="killrotate",
7785 schaersvoo 9724
        *killaffine="killaffine",
7614 schaersvoo 9725
        *fontfamily="fontfamily",
9726
        *fillcolor="fillcolor",
9727
        *clicktile="clicktile",
9728
        *clicktile_colors="clicktile_colors",
9729
        *translation="translation",
9730
        *translate="translate",
9731
        *killtranslation="killtranslation",
9732
        *killtranslate="killtranslate",
9733
        *onclick="onclick",
8370 schaersvoo 9734
        *roundrects="roundrects",
7614 schaersvoo 9735
        *roundrect="roundrect",
9736
        *froundrect="froundrect",
9374 schaersvoo 9737
        *froundrects="froundrects",
7614 schaersvoo 9738
        *roundrectangle="roundrectangle",
9739
        *patternfill="patternfill",
9740
        *hatchfill="hatchfill",
9741
        *diafill="diafill",
7647 schaersvoo 9742
        *diamondfill="diamondfill",
7614 schaersvoo 9743
        *dotfill="dotfill",
11830 schaersvoo 9744
        *textfill="textfill",
7614 schaersvoo 9745
        *gridfill="gridfill",
9746
        *imagefill="imagefill",
7735 schaersvoo 9747
        *xlogbase="xlogbase",
9748
        *ylogbase="ylogbase",
7614 schaersvoo 9749
        *xlogscale="xlogscale",
9750
        *ylogscale="ylogscale",
9751
        *xylogscale="xylogscale",
9752
        *intooltip="intooltip",
9329 schaersvoo 9753
        *popup="popup",
7614 schaersvoo 9754
        *replyformat="replyformat",
9755
        *floodfill="floodfill",
11772 schaersvoo 9756
        *fillall="fillall",
7614 schaersvoo 9757
        *filltoborder="filltoborder",
9758
        *setpixel="setpixel",
9759
        *pixels="pixels",
9760
        *pixelsize="pixelsize",
9761
        *xaxis="xaxis",
9341 schaersvoo 9762
        *xaxisup="xaxisup",
7614 schaersvoo 9763
        *yaxis="yaxis",
9764
        *xaxistext="xaxistext",
9341 schaersvoo 9765
        *xaxistextup="xaxistextup",
7614 schaersvoo 9766
        *yaxistext="yaxistext",
9767
        *piechart="piechart",
9433 schaersvoo 9768
        *boxplot="boxplot",
9465 schaersvoo 9769
        *boxplotdata="boxplotdata",
9770
        *userboxplot="userboxplot",
9771
        *userboxplotdata="userboxplotdata",
7614 schaersvoo 9772
        *legend="legend",
9773
        *legendcolors="legendcolors",
9774
        *xlabel="xlabel",
9775
        *ylabel="ylabel",
9776
        *barchart="barchart",
9777
        *linegraph="linegraph",
9778
        *clock="clock",
9779
        *animate="animate",
9780
        *video="video",
9781
        *status="status",
7877 schaersvoo 9782
        *nostatus="nostatus",
7652 schaersvoo 9783
        *snaptogrid="snaptogrid",
7784 schaersvoo 9784
        *xsnaptogrid="xsnaptogrid",
9785
        *ysnaptogrid="ysnaptogrid",
8379 schaersvoo 9786
        *snaptopoints="snaptopoints",
9213 schaersvoo 9787
        *snaptofunction="snaptofunction",
9788
        *snaptofun="snaptofun",
7654 schaersvoo 9789
        *userinput_xy="userinput_xy",
8193 schaersvoo 9790
        *userinput_function="userinput_function",
7663 schaersvoo 9791
        *usertextarea_xy="usertextarea_xy",
8222 schaersvoo 9792
        *userinput="userinput",
7823 schaersvoo 9793
        *jsmath="jsmath",
7858 schaersvoo 9794
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 9795
        *setlimits="setlimits",
7858 schaersvoo 9796
        *jscurve="jscurve",
9797
        *jsplot="jsplot",
7983 schaersvoo 9798
        *sgraph="sgraph",
7984 schaersvoo 9799
        *title="title",
7996 schaersvoo 9800
        *centerstring="centerstring",
9801
        *xunit="xunit",
8071 schaersvoo 9802
        *yunit="yunit",
8101 schaersvoo 9803
        *slider="slider",
8105 schaersvoo 9804
        *killslider="killslider",
8244 schaersvoo 9805
        *angle="angle",
8365 schaersvoo 9806
        *halflines="halflines",
9807
        *demilines="demilines",
8244 schaersvoo 9808
        *halfline="halfline",
8297 schaersvoo 9809
        *demiline="demiline",
8366 schaersvoo 9810
        *hlines="hlines",
9811
        *vlines="vlines",
8370 schaersvoo 9812
        *bezier="bezier",
9213 schaersvoo 9813
        *functionlabel="functionlabel",
9814
        *sliderfunction_x="sliderfunction_x",
9815
        *sliderfunction_y="sliderfunction_y",
9816
        *multidraw="multidraw",
9817
        *multilinewidth="multilinewidth",
9818
        *multistrokecolors="multistrokecolors",
9819
        *multifillcolors="multifillcolors",
9820
        *multistrokeopacity="multistrokeopacity",
9821
        *multifillopacity="multifillopacity",
9822
        *multifill="multifill",
9823
        *multidash="multidash",
9824
        *multilabel="multilabel",
9825
        *multiuserinput="multiuserinput",
14038 schaersvoo 9826
        *multiinput="multiinput",
9289 schaersvoo 9827
        *multisnaptogrid="multisnaptogrid",
14038 schaersvoo 9828
        *multisnap="multisnap",
9289 schaersvoo 9829
        *protractor="protractor",
9386 schaersvoo 9830
        *ruler="ruler",
9831
        *cursor="cursor",
9427 schaersvoo 9832
        *pointer="pointer",
9833
        *yerrorbars="yerrorbars",
11006 schaersvoo 9834
        *xerrorbars="xerrorbars",
11044 schaersvoo 9835
        *noxaxis="noxaxis",
9836
        *noyaxis="noyaxis",
11767 schaersvoo 9837
        *colorpalette="colorpalette",
14038 schaersvoo 9838
        *imagepalette="imagepalette",
12063 schaersvoo 9839
        *yoffset="yoffset",
11802 schaersvoo 9840
        *xoffset="xoffset",
9841
        *centered="centered",
9842
        *xyoffset="xyoffset",
9843
        *resetoffset="resetoffset",
11837 schaersvoo 9844
        *fillpattern="fillpattern",
11890 schaersvoo 9845
        *numberline="numberline",
11006 schaersvoo 9846
        *canvastype="canvastype";
7614 schaersvoo 9847
 
10891 schaersvoo 9848
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
9849
         if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
9850
         }else{
9851
          if( c == ' ' ){
7614 schaersvoo 9852
            break;
10891 schaersvoo 9853
          }else{
9854
           temp[i] = c;
9855
           if(i > MAX_INT - 2){canvas_error("command string too long !");}
9856
           i++;
9857
          }
9858
         }
9859
         if(temp[0] == '#'){ break; }
7614 schaersvoo 9860
        }
10891 schaersvoo 9861
        if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
9862
        if (c == EOF) {finished=1;return 0;}
7614 schaersvoo 9863
 
9864
        temp[i]='\0';
9865
        input_type=(char*)my_newmem(strlen(temp));
9866
        snprintf(input_type,sizeof(temp),"%s",temp);
10891 schaersvoo 9867
/* fprintf(stdout,"temp = %s <br/>",input_type); */
7614 schaersvoo 9868
        if( strcmp(input_type, size) == 0 ){
9869
        free(input_type);
9870
        return SIZE;
9871
        }
9872
        if( strcmp(input_type, xrange) == 0 ){
9873
        free(input_type);
9874
        return XRANGE;
9875
        }
9876
        if( strcmp(input_type, rangex) == 0 ){
9877
        free(input_type);
9878
        return XRANGE;
9879
        }
9880
        if( strcmp(input_type, trange) == 0 ){
9881
        free(input_type);
9882
        return TRANGE;
9883
        }
9884
        if( strcmp(input_type, ranget) == 0 ){
9885
        free(input_type);
9886
        return TRANGE;
9887
        }
9888
        if( strcmp(input_type, yrange) == 0 ){
9889
        free(input_type);
9890
        return YRANGE;
9891
        }
9892
        if( strcmp(input_type, rangey) == 0 ){
9893
        free(input_type);
9894
        return YRANGE;
9895
        }
9896
        if( strcmp(input_type, linewidth) == 0 ){
9897
        free(input_type);
9898
        return LINEWIDTH;
9899
        }
9900
        if( strcmp(input_type, dashed) == 0 ){
9901
        free(input_type);
9902
        return DASHED;
9903
        }
9904
        if( strcmp(input_type, dashtype) == 0 ){
9905
        free(input_type);
9906
        return DASHTYPE;
9907
        }
9908
        if( strcmp(input_type, axisnumbering) == 0 ){
9909
        free(input_type);
9910
        return AXIS_NUMBERING;
9911
        }
9912
        if( strcmp(input_type, axisnumbers) == 0 ){
9913
        free(input_type);
9914
        return AXIS_NUMBERING;
9915
        }
9916
        if( strcmp(input_type, axis) == 0 ){
9917
        free(input_type);
9918
        return AXIS;
9919
        }
9920
        if( strcmp(input_type, grid) == 0 ){
9921
        free(input_type);
9922
        return GRID;
9923
        }
9383 schaersvoo 9924
        if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
8366 schaersvoo 9925
        free(input_type);
9926
        return HLINES;
9927
        }
9383 schaersvoo 9928
        if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
8366 schaersvoo 9929
        free(input_type);
9930
        return VLINES;
9931
        }
9383 schaersvoo 9932
        if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
7614 schaersvoo 9933
        free(input_type);
9934
        return HLINE;
9935
        }
9936
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
9937
        free(input_type);
9938
        return VLINE;
9939
        }
9940
        if( strcmp(input_type, line) == 0 ){
9941
        free(input_type);
9942
        return LINE;
9943
        }
9383 schaersvoo 9944
        if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
8299 schaersvoo 9945
        free(input_type);
9946
        return SEGMENTS;
9947
        }
7614 schaersvoo 9948
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
9949
        free(input_type);
9950
        return SEGMENT;
9951
        }
9374 schaersvoo 9952
        if( strcmp(input_type, dsegments) == 0 ){
9953
        free(input_type);
9954
        use_dashed = TRUE;
9955
        return SEGMENTS;
9956
        }
7614 schaersvoo 9957
        if( strcmp(input_type, dsegment) == 0 ){
9958
        free(input_type);
9959
        use_dashed = TRUE;
9960
        return SEGMENT;
9961
        }
9962
        if( strcmp(input_type, crosshairsize) == 0 ){
9963
        free(input_type);
9964
        return CROSSHAIRSIZE;
9965
        }
9966
        if( strcmp(input_type, arrowhead) == 0 ){
9967
        free(input_type);
9968
        return ARROWHEAD;
9969
        }
9970
        if( strcmp(input_type, crosshairs) == 0 ){
9971
        free(input_type);
9972
        return CROSSHAIRS;
9973
        }
9974
        if( strcmp(input_type, crosshair) == 0 ){
9975
        free(input_type);
9976
        return CROSSHAIR;
9977
        }
9978
        if( strcmp(input_type, onclick) == 0 ){
9979
        free(input_type);
9980
        return ONCLICK;
9981
        }
9982
        if( strcmp(input_type, drag) == 0 ){
9983
        free(input_type);
9984
        return DRAG;
9985
        }
9986
        if( strcmp(input_type, userdraw) == 0 ){
9987
        free(input_type);
9988
        return USERDRAW;
9989
        }
9990
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
9991
        free(input_type);
9992
        return STYLE;
9993
        }
9994
        if( strcmp(input_type, fillcolor) == 0 ){
9995
        free(input_type);
9996
        return FILLCOLOR;
9997
        }
9998
        if( strcmp(input_type, strokecolor) == 0 ){
9999
        free(input_type);
10000
        return STROKECOLOR;
10001
        }
10002
        if( strcmp(input_type, filled) == 0  ){
10003
        free(input_type);
10004
        return FILLED;
10005
        }
10006
        if( strcmp(input_type, http) == 0 ){
10007
        free(input_type);
10008
        return HTTP;
10009
        }
10010
        if( strcmp(input_type, rays) == 0 ){
10011
        free(input_type);
10012
        return RAYS;
10013
        }
10014
        if( strcmp(input_type, lattice) == 0 ){
10015
        free(input_type);
10016
        return LATTICE;
10017
        }
10018
        if( strcmp(input_type, bgimage) == 0 ){
10019
        free(input_type);
10020
        return BGIMAGE;
10021
        }
10022
        if( strcmp(input_type, bgcolor) == 0 ){
10023
        free(input_type);
10024
        return BGCOLOR;
10025
        }
10026
        if( strcmp(input_type, backgroundimage) == 0 ){
10027
        free(input_type);
10028
        return BGIMAGE;
10029
        }
10030
        if( strcmp(input_type, text) == 0 ){
10031
        free(input_type);
10032
        return FLY_TEXT;
10033
        }
10034
        if( strcmp(input_type, textup) == 0 ){
10035
        free(input_type);
10036
        return FLY_TEXTUP;
10037
        }
10038
        if( strcmp(input_type, mouse) == 0 ){
10039
        free(input_type);
10040
        return MOUSE;
10041
        }
7991 schaersvoo 10042
        if( strcmp(input_type, mousex) == 0 ){
10043
        free(input_type);
10044
        return MOUSEX;
10045
        }
10046
        if( strcmp(input_type, mousey) == 0 ){
10047
        free(input_type);
10048
        return MOUSEY;
10049
        }
8071 schaersvoo 10050
        if( strcmp(input_type, mouse_degree) == 0 ){
10051
        free(input_type);
10052
        return MOUSE_DEGREE;
10053
        }
10054
        if( strcmp(input_type, mouse_display) == 0 ){
10055
        free(input_type);
10056
        return MOUSE_DISPLAY;
10057
        }
7614 schaersvoo 10058
        if( strcmp(input_type, mouseprecision) == 0 ){
10059
        free(input_type);
10060
        return MOUSE_PRECISION;
10061
        }
10062
        if( strcmp(input_type, precision) == 0 ){
10063
        free(input_type);
10064
        return MOUSE_PRECISION;
10065
        }
10066
        if( strcmp(input_type, curve) == 0 ){
10067
        free(input_type);
10068
        return CURVE;
10069
        }
10070
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 10071
        use_dashed = TRUE;
7614 schaersvoo 10072
        free(input_type);
10073
        return CURVE;
10074
        }
10075
        if( strcmp(input_type, plot) == 0 ){
10076
        free(input_type);
10077
        return CURVE;
10078
        }
10079
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 10080
        use_dashed = TRUE;
7614 schaersvoo 10081
        free(input_type);
10082
        return CURVE;
10083
        }
7788 schaersvoo 10084
        if( strcmp(input_type, levelcurve) == 0 ){
10085
        free(input_type);
10086
        return LEVELCURVE;
10087
        }
7614 schaersvoo 10088
        if( strcmp(input_type, plotsteps) == 0 ){
10089
        free(input_type);
10090
        return PLOTSTEPS;
10091
        }
10092
        if( strcmp(input_type, plotstep) == 0 ){
10093
        free(input_type);
10094
        return PLOTSTEPS;
10095
        }
10096
        if( strcmp(input_type, tsteps) == 0 ){
10097
        free(input_type);
10098
        return PLOTSTEPS;
10099
        }
10100
        if( strcmp(input_type, fontsize) == 0 ){
10101
        free(input_type);
10102
        return FONTSIZE;
10103
        }
10104
        if( strcmp(input_type, fontcolor) == 0 ){
10105
        free(input_type);
10106
        return FONTCOLOR;
10107
        }
10108
        if( strcmp(input_type, arrow2) == 0 ){
10109
        free(input_type);
10110
        return ARROW2;
10111
        }
10112
        if( strcmp(input_type, darrow) == 0 ){
10113
        free(input_type);
8071 schaersvoo 10114
        use_dashed = TRUE;
7614 schaersvoo 10115
        return ARROW;
10116
        }
10117
        if( strcmp(input_type, darrow2) == 0 ){
10118
        free(input_type);
10119
        use_dashed = TRUE;
10120
        return ARROW2;
10121
        }
8347 schaersvoo 10122
        if( strcmp(input_type, arrows2) == 0 ){
10123
        free(input_type);
10124
        return ARROWS2;
10125
        }
9382 schaersvoo 10126
        if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
8304 schaersvoo 10127
        free(input_type);
10128
        return ARROWS;
10129
        }
9382 schaersvoo 10130
        if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
8304 schaersvoo 10131
        free(input_type);
10132
        return ARROW;
10133
        }
7614 schaersvoo 10134
        if( strcmp(input_type, zoom) == 0 ){
10135
        free(input_type);
10136
        return ZOOM;
10137
        }
10138
        if( strcmp(input_type, triangle) == 0 ){
10139
        free(input_type);
10140
        return TRIANGLE;
10141
        }
9306 schaersvoo 10142
        if( strcmp(input_type, triangles) == 0 ){
10143
        free(input_type);
10144
        return TRIANGLES;
10145
        }
9374 schaersvoo 10146
        if( strcmp(input_type, ftriangles) == 0 ){
10147
        free(input_type);
10148
        use_filled = TRUE;
10149
        return TRIANGLES;
10150
        }
7614 schaersvoo 10151
        if( strcmp(input_type, ftriangle) == 0 ){
10152
        free(input_type);
10153
        use_filled = TRUE;
10154
        return TRIANGLE;
10155
        }
10156
        if( strcmp(input_type, input) == 0 ){
10157
        free(input_type);
10158
        return INPUT;
10159
        }
10160
        if( strcmp(input_type, inputstyle) == 0 ){
10161
        free(input_type);
10162
        return INPUTSTYLE;
10163
        }
10164
        if( strcmp(input_type, textarea) == 0 ){
10165
        free(input_type);
10166
        return TEXTAREA;
10167
        }
10168
        if( strcmp(input_type, mathml) == 0 ){
10169
        free(input_type);
10170
        return MATHML;
10171
        }
10172
        if( strcmp(input_type, html) == 0 ){
10173
        free(input_type);
10174
        return MATHML;
10175
        }
10176
        if( strcmp(input_type, fontfamily) == 0 ){
10177
        free(input_type);
10178
        return FONTFAMILY;
10179
        }
10975 schaersvoo 10180
        if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
7614 schaersvoo 10181
        free(input_type);
10182
        return POLYLINE;
10183
        }
8351 schaersvoo 10184
        if( strcmp(input_type, lines) == 0 ){
10185
        free(input_type);
10186
        return LINES;
10187
        }
9374 schaersvoo 10188
        if( strcmp(input_type, rects) == 0){
8363 schaersvoo 10189
        free(input_type);
10190
        return RECTS;
10191
        }
9383 schaersvoo 10192
        if( strcmp(input_type, frects) == 0 ){
8363 schaersvoo 10193
        free(input_type);
9374 schaersvoo 10194
        use_filled = TRUE;
8363 schaersvoo 10195
        return RECTS;
10196
        }
7614 schaersvoo 10197
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
10198
        free(input_type);
10199
        return RECT;
10200
        }
9374 schaersvoo 10201
        if( strcmp(input_type, square) == 0 ){
10202
        free(input_type);
11991 schaersvoo 10203
        return SQUARE;
9374 schaersvoo 10204
        }
10205
        if( strcmp(input_type, fsquare) == 0 ){
10206
        free(input_type);
10207
        use_filled = TRUE;
10208
        return SQUARE;
10209
        }
10210
        if( strcmp(input_type, fsquares) == 0 ){
10211
        free(input_type);
10212
        use_filled = TRUE;
10213
        return RECTS;
10214
        }
8370 schaersvoo 10215
        if( strcmp(input_type, roundrects) == 0 ){
10216
        free(input_type);
10217
        return ROUNDRECTS;
10218
        }
7614 schaersvoo 10219
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
10220
        free(input_type);
10221
        return ROUNDRECT;
10222
        }
9374 schaersvoo 10223
        if( strcmp(input_type, froundrects) == 0 ){
7614 schaersvoo 10224
        free(input_type);
10225
        use_filled = TRUE;
9374 schaersvoo 10226
        return ROUNDRECTS;
7614 schaersvoo 10227
        }
9374 schaersvoo 10228
        if( strcmp(input_type, froundrect) == 0 ){
7614 schaersvoo 10229
        free(input_type);
10230
        use_filled = TRUE;
9374 schaersvoo 10231
        return ROUNDRECT;
7614 schaersvoo 10232
        }
10233
        if( strcmp(input_type, dline) == 0 ){
10234
        use_dashed = TRUE;
10235
        free(input_type);
10236
        return LINE;
10237
        }
7786 schaersvoo 10238
        if( strcmp(input_type, dvline) == 0 ){
10239
        use_dashed = TRUE;
10240
        free(input_type);
10241
        return VLINE;
10242
        }
10243
        if( strcmp(input_type, dhline) == 0 ){
10244
        use_dashed = TRUE;
10245
        free(input_type);
10246
        return HLINE;
10247
        }
9386 schaersvoo 10248
        if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
10249
        free(input_type);
10250
        return HALFLINES;
10251
        }
10252
        if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
10253
        free(input_type);
10254
        return HALFLINE;
10255
        }
7614 schaersvoo 10256
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
10257
        use_filled = TRUE;
10258
        free(input_type);
10259
        return RECT;
10260
        }
8304 schaersvoo 10261
        if( strcmp(input_type, circles) == 0 ){
10262
        free(input_type);
10263
        return CIRCLES;
10264
        }
7614 schaersvoo 10265
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
10266
        use_filled = TRUE;
10267
        free(input_type);
10268
        return CIRCLE;
10269
        }
9374 schaersvoo 10270
        if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
10271
        use_filled = TRUE;
10272
        free(input_type);
10273
        return CIRCLES;
10274
        }
7614 schaersvoo 10275
        if( strcmp(input_type, circle) == 0 ){
10276
        free(input_type);
10277
        return CIRCLE;
10278
        }
10279
        if( strcmp(input_type, point) == 0 ){
10280
        free(input_type);
10281
        return POINT;
10282
        }
10283
        if( strcmp(input_type, points) == 0 ){
10284
        free(input_type);
10285
        return POINTS;
10286
        }
9374 schaersvoo 10287
        if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
7614 schaersvoo 10288
        use_filled = TRUE;
10289
        free(input_type);
10290
        return ARC;
10291
        }
10292
        if( strcmp(input_type, arc) == 0 ){
10293
        free(input_type);
10294
        return ARC;
10295
        }
10296
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
10297
        free(input_type);
10298
        return POLY;
10299
        }
10300
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
10301
        use_filled = TRUE;
10302
        free(input_type);
10303
        return POLY;
10304
        }
10305
        if( strcmp(input_type, ellipse) == 0){
10306
        free(input_type);
10307
        return ELLIPSE;
10308
        }
12110 schaersvoo 10309
        if( strcmp(input_type, ellipses) == 0){
10310
        free(input_type);
10311
        return ELLIPSES;
10312
        }
7614 schaersvoo 10313
        if( strcmp(input_type, string) == 0 ){
10314
        free(input_type);
10315
        return STRING;
10316
        }
10317
        if( strcmp(input_type, stringup) == 0 ){
10318
        free(input_type);
10319
        return STRINGUP;
10320
        }
9385 schaersvoo 10321
        if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
7614 schaersvoo 10322
        free(input_type);
10323
        return OPACITY;
10324
        }
10325
        if( strcmp(input_type, comment) == 0){
10326
        free(input_type);
10327
        return COMMENT;
10328
        }
10329
        if( strcmp(input_type, fellipse) == 0){
10330
        free(input_type);
10331
        use_filled = TRUE;
10332
        return ELLIPSE;
8224 bpr 10333
        }
9386 schaersvoo 10334
        if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
7614 schaersvoo 10335
        free(input_type);
8146 schaersvoo 10336
        return CLEARBUTTON;
7614 schaersvoo 10337
        }
10338
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
10339
        free(input_type);
10340
        return TRANSLATION;
10341
        }
10342
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
10343
        free(input_type);
10344
        return KILLTRANSLATION;
10345
        }
10346
        if( strcmp(input_type, rotate) == 0){
10347
        free(input_type);
10348
        return ROTATE;
10349
        }
9907 schaersvoo 10350
        if( strcmp(input_type, killrotate) == 0){
10351
        free(input_type);
10352
        return KILLROTATE;
10353
        }
10354
        if( strcmp(input_type, rotationcenter) == 0){
10355
        free(input_type);
10356
        return ROTATION_CENTER;
10357
        }
7785 schaersvoo 10358
        if( strcmp(input_type, affine) == 0){
10359
        free(input_type);
10360
        return AFFINE;
10361
        }
10362
        if( strcmp(input_type, killaffine) == 0){
10363
        free(input_type);
10364
        return KILLAFFINE;
10365
        }
7614 schaersvoo 10366
        if( strcmp(input_type, slider) == 0 ){
10367
        free(input_type);
10368
        return SLIDER;
10369
        }
8101 schaersvoo 10370
        if( strcmp(input_type, killslider) == 0 ){
10371
        free(input_type);
10372
        return KILLSLIDER;
10373
        }
7614 schaersvoo 10374
        if( strcmp(input_type, copy) == 0 ){
10375
        free(input_type);
10376
        return COPY;
10377
        }
10378
        if( strcmp(input_type, copyresized) == 0 ){
10379
        free(input_type);
10380
        return COPYRESIZED;
10381
        }
10382
        if( strcmp(input_type, xlogscale) == 0 ){
10383
        free(input_type);
10384
        return XLOGSCALE;
10385
        }
10386
        if( strcmp(input_type, ylogscale) == 0 ){
10387
        free(input_type);
10388
        return YLOGSCALE;
10389
        }
10390
        if( strcmp(input_type, xylogscale) == 0 ){
10391
        free(input_type);
10392
        return XYLOGSCALE;
10393
        }
10394
        if( strcmp(input_type, ylogscale) == 0 ){
10395
        free(input_type);
10396
        return YLOGSCALE;
10397
        }
7735 schaersvoo 10398
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 10399
        free(input_type);
7735 schaersvoo 10400
        return XLOGBASE;
7614 schaersvoo 10401
        }
7735 schaersvoo 10402
        if( strcmp(input_type, ylogbase) == 0 ){
10403
        free(input_type);
10404
        return YLOGBASE;
10405
        }
7614 schaersvoo 10406
        if( strcmp(input_type, intooltip) == 0 ){
10407
        free(input_type);
10408
        return INTOOLTIP;
10409
        }
9329 schaersvoo 10410
        if( strcmp(input_type, popup) == 0 ){
10411
        free(input_type);
10412
        return POPUP;
10413
        }
7614 schaersvoo 10414
        if( strcmp(input_type,video) == 0 ){
10415
        free(input_type);
10416
        return VIDEO;
10417
        }
11772 schaersvoo 10418
        if( strcmp(input_type,fillall) == 0 ){
10419
        free(input_type);
10420
        return FILLALL;
10421
        }
7614 schaersvoo 10422
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
10423
        free(input_type);
10424
        return FLOODFILL;
8224 bpr 10425
        }
7614 schaersvoo 10426
        if( strcmp(input_type,filltoborder) == 0 ){
10427
        free(input_type);
10428
        return FILLTOBORDER;
8224 bpr 10429
        }
14038 schaersvoo 10430
        if( strcmp(input_type, curvedarrow2) == 0 ){
10431
        free(input_type);
10432
        return CURVEDARROW2;
10433
        }
10434
        if( strcmp(input_type, curvedarrow) == 0 ){
10435
        free(input_type);
10436
        return CURVEDARROW;
10437
        }
10438
        if( strcmp(input_type, curvedarrows) == 0 ){
10439
        free(input_type);
10440
        return CURVEDARROWS;
10441
        }
10442
        if( strcmp(input_type, curvedarrows2) == 0 ){
10443
        free(input_type);
10444
        return CURVEDARROWS2;
10445
        }
7614 schaersvoo 10446
        if( strcmp(input_type, replyformat) == 0 ){
10447
        free(input_type);
10448
        return REPLYFORMAT;
10449
        }
10450
        if( strcmp(input_type, pixelsize) == 0 ){
10451
        free(input_type);
10452
        return PIXELSIZE;
10453
        }
10454
        if( strcmp(input_type, setpixel) == 0 ){
10455
        free(input_type);
10456
        return SETPIXEL;
10457
        }
10458
        if( strcmp(input_type, pixels) == 0 ){
10459
        free(input_type);
10460
        return PIXELS;
10461
        }
10462
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
10463
        free(input_type);
10464
        return X_AXIS_STRINGS;
10465
        }
9341 schaersvoo 10466
        if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
10467
        free(input_type);
10468
        return X_AXIS_STRINGS_UP;
10469
        }
7614 schaersvoo 10470
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
10471
        free(input_type);
10472
        return Y_AXIS_STRINGS;
10473
        }
10474
        if( strcmp(input_type, legend) == 0  ){
10475
        free(input_type);
10476
        return LEGEND;
10477
        }
10478
        if( strcmp(input_type, legendcolors) == 0  ){
10479
        free(input_type);
10480
        return LEGENDCOLORS;
10481
        }
10482
        if( strcmp(input_type, xlabel) == 0  ){
10483
        free(input_type);
10484
        return XLABEL;
10485
        }
10486
        if( strcmp(input_type, ylabel) == 0  ){
10487
        free(input_type);
10488
        return YLABEL;
10489
        }
8370 schaersvoo 10490
        if( strcmp(input_type, bezier) == 0  ){
10491
        free(input_type);
10492
        return BEZIER;
10493
        }
7614 schaersvoo 10494
        if( strcmp(input_type, animate) == 0  ){
10495
        free(input_type);
10496
        return ANIMATE;
10497
        }
9354 schaersvoo 10498
        /* these are bitmap related flydraw commands...must be removed. eventually */
7614 schaersvoo 10499
        if( strcmp(input_type, transparent) == 0 ){
10500
        free(input_type);
10501
        return TRANSPARENT;
10502
        }
7877 schaersvoo 10503
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 10504
        free(input_type);
10505
        return STATUS;
10506
        }
7784 schaersvoo 10507
        if( strcmp(input_type, xsnaptogrid) == 0 ){
10508
        free(input_type);
10509
        return XSNAPTOGRID;
10510
        }
10511
        if( strcmp(input_type, ysnaptogrid) == 0 ){
10512
        free(input_type);
10513
        return YSNAPTOGRID;
10514
        }
8379 schaersvoo 10515
        if( strcmp(input_type, snaptogrid) == 0 ){
10516
        free(input_type);
10517
        return SNAPTOGRID;
10518
        }
10519
        if( strcmp(input_type, snaptopoints) == 0 ){
10520
        free(input_type);
10521
        return SNAPTOPOINTS;
10522
        }
9213 schaersvoo 10523
        if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
10524
        free(input_type);
10525
        return SNAPTOFUNCTION;
10526
        }
7652 schaersvoo 10527
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 10528
        free(input_type);
7652 schaersvoo 10529
        return USERINPUT_XY;
10530
        }
8193 schaersvoo 10531
        if( strcmp(input_type, userinput_function) == 0 ){
10532
        free(input_type);
10533
        return USERINPUT_FUNCTION;
10534
        }
7663 schaersvoo 10535
        if( strcmp(input_type, usertextarea_xy) == 0 ){
10536
        free(input_type);
10537
        return USERTEXTAREA_XY;
10538
        }
8222 schaersvoo 10539
        if( strcmp(input_type, userinput) == 0 ){
10540
        free(input_type);
10541
        return USERINPUT;
10542
        }
8105 schaersvoo 10543
        if( strcmp(input_type, angle) == 0 ){
7996 schaersvoo 10544
        free(input_type);
8105 schaersvoo 10545
        return ANGLE;
10546
        }
8297 schaersvoo 10547
        if( strcmp(input_type, functionlabel) == 0 ){
8244 schaersvoo 10548
        free(input_type);
8297 schaersvoo 10549
        return FUNCTION_LABEL;
10550
        }
9213 schaersvoo 10551
        if( strcmp(input_type, sliderfunction_x) == 0 ){
8297 schaersvoo 10552
        free(input_type);
9213 schaersvoo 10553
        return SLIDER_X;
10554
        }
10555
        if( strcmp(input_type, sliderfunction_y) == 0 ){
10556
        free(input_type);
10557
        return SLIDER_Y;
10558
        }
10559
        if( strcmp(input_type, multidraw) == 0 ){
10560
        free(input_type);
10561
        return MULTIDRAW;
10562
        }
10563
        if( strcmp(input_type, multistrokeopacity) == 0 ){
10564
        free(input_type);
10565
        return MULTISTROKEOPACITY;
10566
        }
10567
        if( strcmp(input_type, multifillopacity) == 0 ){
10568
        free(input_type);
10569
        return MULTIFILLOPACITY;
10570
        }
10571
        if( strcmp(input_type, multilinewidth) == 0 ){
10572
        free(input_type);
10573
        return MULTILINEWIDTH;
10574
        }
10575
        if( strcmp(input_type, multistrokecolors) == 0 ){
10576
        free(input_type);
10577
        return MULTISTROKECOLORS;
10578
        }
10579
        if( strcmp(input_type, multifill) == 0 ){
10580
        free(input_type);
10581
        return MULTIFILL;
10582
        }
10583
        if( strcmp(input_type, multifillcolors) == 0 ){
10584
        free(input_type);
10585
        return MULTIFILLCOLORS;
10586
        }
10587
        if( strcmp(input_type, multilabel) == 0 ){
10588
        free(input_type);
10589
        return MULTILABEL;
10590
        }
10591
        if( strcmp(input_type, multidash) == 0 ){
10592
        free(input_type);
10593
        return MULTIDASH;
10594
        }
14038 schaersvoo 10595
        if( strcmp(input_type, multisnaptogrid) == 0  ||  strcmp(input_type, multisnap) == 0 ){
9213 schaersvoo 10596
        free(input_type);
10597
        return MULTISNAPTOGRID;
10598
        }
14038 schaersvoo 10599
        if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0  ){
9213 schaersvoo 10600
        free(input_type);
10601
        return MULTIUSERINPUT;
10602
        }
9386 schaersvoo 10603
        if( strcmp(input_type, parallel) == 0 ){
10604
        free(input_type);
10605
        return PARALLEL;
10606
        }
9289 schaersvoo 10607
        if( strcmp(input_type, protractor) == 0 ){
10608
        free(input_type);
10609
        return PROTRACTOR;
10610
        }
10611
        if( strcmp(input_type, ruler) == 0 ){
10612
        free(input_type);
10613
        return RULER;
10614
        }
9386 schaersvoo 10615
        if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
9213 schaersvoo 10616
        free(input_type);
9386 schaersvoo 10617
        return CURSOR;
10618
        }
10619
        if( strcmp(input_type, sgraph) == 0 ){
10620
        free(input_type);
10621
        return SGRAPH;
10622
        }
10623
        if( strcmp(input_type, jsmath) == 0 ){
10624
        free(input_type);
10625
        return JSMATH;
10626
        }
10627
        if( strcmp(input_type, trace_jscurve) == 0 ){
10628
        free(input_type);
10629
        return TRACE_JSCURVE;
10630
        }
10631
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
10632
        free(input_type);
10633
        return JSCURVE;
10634
        }
10635
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
10636
        free(input_type);
10637
        return CENTERSTRING;
10638
        }
10639
        if( strcmp(input_type, setlimits) == 0 ){
10640
        free(input_type);
10641
        return SETLIMITS;
10642
        }
10643
        if( strcmp(input_type, xunit) == 0 ){
10644
        free(input_type);
10645
        return XUNIT;
10646
        }
10647
        if( strcmp(input_type, yunit) == 0 ){
10648
        free(input_type);
10649
        return YUNIT;
10650
        }
10651
        if( strcmp(input_type, fill) == 0 ){
10652
        free(input_type);
10653
        return FLOODFILL;
10654
        }
10655
        if( strcmp(input_type, end) == 0){
10656
        free(input_type);
10657
        return END;
10658
        }
10659
        if( strcmp(input_type, blink) == 0 ){
10660
        free(input_type);
10661
        return BLINK;
10662
        }
10663
        if( strcmp(input_type, audio) == 0 ){
10664
        free(input_type);
10665
        return AUDIO;
10666
        }
10667
        if( strcmp(input_type, audioobject) == 0 ){
10668
        free(input_type);
10669
        return AUDIOOBJECT;
10670
        }
10671
        if( strcmp(input_type, patternfill) == 0 ){
10672
        free(input_type);
10673
        return PATTERNFILL;
10674
        }
10675
        if( strcmp(input_type, hatchfill) == 0 ){
10676
        free(input_type);
10677
        return HATCHFILL;
10678
        }
10679
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
10680
        free(input_type);
10681
        return DIAMONDFILL;
10682
        }
10683
        if( strcmp(input_type, dotfill) == 0 ){
10684
        free(input_type);
10685
        return DOTFILL;
10686
        }
11830 schaersvoo 10687
        if( strcmp(input_type, textfill) == 0 ){
10688
        free(input_type);
10689
        return TEXTFILL;
10690
        }
9386 schaersvoo 10691
        if( strcmp(input_type, gridfill) == 0 ){
10692
        free(input_type);
10693
        return GRIDFILL;
10694
        }
10695
        if( strcmp(input_type, imagefill) == 0 ){
10696
        free(input_type);
10697
        return IMAGEFILL;
10698
        }
10699
        if( strcmp(input_type, clicktile_colors) == 0 ){
10700
        free(input_type);
10701
        return CLICKTILE_COLORS;
10702
        }
10703
        if( strcmp(input_type, clicktile) == 0 ){
10704
        free(input_type);
10705
        return CLICKTILE;
10706
        }
10707
        if( strcmp(input_type, piechart) == 0  ){
10708
        free(input_type);
10709
        return PIECHART;
10710
        }
9433 schaersvoo 10711
        if( strcmp(input_type, boxplot) == 0  ){
10712
        free(input_type);
10713
        return BOXPLOT;
10714
        }
9465 schaersvoo 10715
        if( strcmp(input_type, boxplotdata) == 0  ){
9433 schaersvoo 10716
        free(input_type);
9465 schaersvoo 10717
        return BOXPLOTDATA;
9433 schaersvoo 10718
        }
9465 schaersvoo 10719
        if( strcmp(input_type, userboxplot) == 0  ){
10720
        free(input_type);
10721
        return USERBOXPLOT;
10722
        }
10723
        if( strcmp(input_type, userboxplotdata) == 0  ){
10724
        free(input_type);
10725
        return USERBOXPLOT;
10726
        }
9386 schaersvoo 10727
        if( strcmp(input_type, barchart) == 0  ){
10728
        free(input_type);
10729
        return BARCHART;
10730
        }
10731
        if( strcmp(input_type, linegraph) == 0  ){
10732
        free(input_type);
10733
        return LINEGRAPH;
10734
        }
10735
        if( strcmp(input_type, clock) == 0  ){
10736
        free(input_type);
10737
        return CLOCK;
10738
        }
9427 schaersvoo 10739
        if( strcmp(input_type, yerrorbars) == 0  ){
9386 schaersvoo 10740
        free(input_type);
9427 schaersvoo 10741
        return YERRORBARS;
10742
        }
10743
        if( strcmp(input_type, xerrorbars) == 0  ){
10744
        free(input_type);
10745
        return XERRORBARS;
10746
        }
11006 schaersvoo 10747
        if( strcmp(input_type, canvastype) == 0  ){
9427 schaersvoo 10748
        free(input_type);
11006 schaersvoo 10749
        return CANVASTYPE;
10750
        }
11044 schaersvoo 10751
        if( strcmp(input_type, noyaxis) == 0  ){
11006 schaersvoo 10752
        free(input_type);
11044 schaersvoo 10753
        return NOYAXIS;
10754
        }
10755
        if( strcmp(input_type, noxaxis) == 0  ){
10756
        free(input_type);
10757
        return NOXAXIS;
10758
        }
11767 schaersvoo 10759
        if( strcmp(input_type, colorpalette) == 0  ){
11044 schaersvoo 10760
        free(input_type);
11767 schaersvoo 10761
        return COLORPALETTE;
10762
        }
14038 schaersvoo 10763
        if( strcmp(input_type, imagepalette) == 0  ){
10764
        free(input_type);
10765
        return IMAGEPALETTE;
10766
        }
11802 schaersvoo 10767
        if( strcmp(input_type, resetoffset) == 0  ){
11767 schaersvoo 10768
        free(input_type);
11802 schaersvoo 10769
        return RESETOFFSET;
10770
        }
10771
        if( strcmp(input_type, xyoffset) == 0  ){
10772
        free(input_type);
10773
        return XYOFFSET;
10774
        }
12063 schaersvoo 10775
        if( strcmp(input_type, centered) == 0 ){
11802 schaersvoo 10776
        free(input_type);
12063 schaersvoo 10777
        return CENTERED;
11802 schaersvoo 10778
        }
12063 schaersvoo 10779
        if( strcmp(input_type, yoffset) == 0   ){
11802 schaersvoo 10780
        free(input_type);
11811 schaersvoo 10781
        return YOFFSET;
10782
        }
12063 schaersvoo 10783
        if( strcmp(input_type, xoffset) == 0   ){
10784
        free(input_type);
10785
        return XOFFSET;
10786
        }
11837 schaersvoo 10787
        if( strcmp(input_type, fillpattern) == 0 ){
11811 schaersvoo 10788
        free(input_type);
11837 schaersvoo 10789
        return FILLPATTERN;
10790
        }
11890 schaersvoo 10791
        if( strcmp(input_type, numberline) == 0 ){
11837 schaersvoo 10792
        free(input_type);
11890 schaersvoo 10793
        return NUMBERLINE;
10794
        }
10795
        free(input_type);
7614 schaersvoo 10796
        ungetc(c,infile);
10797
        return 0;
10798
}
14038 schaersvoo 10799
 
10800
 
10801
 
10802
 
10803
 
10804
 
10805
 
10806
 
10807
 
10808
 
10809
 
10810
 
10811