Subversion Repositories wimsdev

Rev

Rev 14247 | Rev 14251 | 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);
14078 bpr 19
void    reset();/* reset some global variables like "use_filled", "use_dashed" */
7614 schaersvoo 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*/
14208 schaersvoo 57
char *slider_type="0";
58
int slider_cnt = 0;
59
int active_sliders[MAX_SLIDERS];
60
char *current_sliders = "[-1]";
7785 schaersvoo 61
int use_affine = FALSE;
7614 schaersvoo 62
int use_rotate = FALSE;
14078 bpr 63
int use_filled = 0; /* 0:no fill, 1:fill,2=grid?,3=hatch?,4=diamond?,5=dot?,6=image? */
64
int use_dashed = FALSE; /* dashing not natively supported in firefox, for now... */
8097 schaersvoo 65
 
7614 schaersvoo 66
char buffer[MAX_BUFFER];/* contains js-functions with arguments ... all other basic code is directly printed into js-include file */
9329 schaersvoo 67
char *getfile_cmd = "";
7614 schaersvoo 68
/******************************************************************************
69
** Main Program
70
******************************************************************************/
71
int main(int argc, char *argv[]){
14066 bpr 72
    /* need unique id for every call to canvasdraw: rand(); is too slow...will result in many identical id's */
12104 schaersvoo 73
    struct timeval tv;struct timezone tz;gettimeofday(&tv, &tz);
74
    unsigned int canvas_root_id = (unsigned int) tv.tv_usec;
7614 schaersvoo 75
    infile = stdin;/* read flyscript via stdin */
76
    int i,c;
77
    double double_data[MAX_INT+1];
78
    int int_data[MAX_INT+1];
79
    for(i=0;i<MAX_INT;i++){int_data[i]=0;double_data[i]=0;}
14208 schaersvoo 80
    for(i=0;i<MAX_SLIDERS;i++){active_sliders[i]=-1;}
7614 schaersvoo 81
    int use_parametric = FALSE;/* will be reset after parametric plotting */
82
    int use_axis = FALSE;
11891 schaersvoo 83
    int use_axis_numbering = -1;
14066 bpr 84
    int use_snap = 0; /* 0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */
14038 schaersvoo 85
    int use_offset = 0;/* use_offset only for text shape objects... 0=none;1=yoffset;2=xoffset;3=xyoffset;4=centered*/
7797 schaersvoo 86
    int use_pan_and_zoom = FALSE;
14066 bpr 87
    int use_safe_eval = FALSE; /* if true, add just once: js function to evaluate userinput values for plotting etc */
7858 schaersvoo 88
    int use_js_math = FALSE; /* if true add js-function to convert math_function --> javascript math_function */
14078 bpr 89
    int use_js_plot = FALSE; /* if true, let js-engine plot the curve */
11006 schaersvoo 90
    int jsplot_cnt = 0; /* keepint track on the curve identity */
8448 schaersvoo 91
    int print_drag_params_only_once = FALSE;/* avoid multiple useless identical lines about javascript precision and use_dragdrop */
14038 schaersvoo 92
    int include_special_OEF_reply = FALSE; /* used for including extra read_canvas_images();*/
7614 schaersvoo 93
    int line_width = 1;
94
    int decimals = 2;
8365 schaersvoo 95
    int precision = 100; /* 10 = 1;100=2;1000=3 decimal display for mouse coordinates or grid coordinate.May be redefined before every object */
96
    int use_userdraw = FALSE; /* flag to indicate user interaction */
14066 bpr 97
    int drag_type = -1;/* 0,1,2: xy,x,y */
9329 schaersvoo 98
    int use_tooltip = -1; /* 1= tooltip 2= popup window*/
7614 schaersvoo 99
    char *tooltip_text = "Click here";
100
    char *temp = ""; /* */
101
    char *bgcolor = "";/* used for background of canvas_div ; default is tranparent */
102
    char *stroke_color = "255,0,0";
14208 schaersvoo 103
    char *fill_color = "255,255,255";
7614 schaersvoo 104
    char *font_family = "12px Ariel"; /* commands xaxistext,yaxistext,legend,text/textup/string/stringup may us this */
105
    char *font_color = "#00000";
106
    char *draw_type = "points";
107
    char *fly_font = "normal";
8815 schaersvoo 108
    char *input_style = "font-family:Ariel;text-align:center;color:blue;font-size:12px;background-color:orange;";
7614 schaersvoo 109
    char *flytext = "";
7785 schaersvoo 110
    char *affine_matrix = "[1,0,0,1,0,0]";
8297 schaersvoo 111
    char *function_label = "f(x)=";
14066 bpr 112
    int use_pattern = 0; /* used in drag&drop library: grid=2,hatch=3,diamond=4,dot=5*/
11006 schaersvoo 113
    int canvas_type = DRAG_CANVAS; /* to use a specific canvas  for filling etc */
7614 schaersvoo 114
    int pixelsize = 1;
115
    int reply_format = 0;
116
    int input_cnt = 0;
117
    int ext_img_cnt = 0;
11763 schaersvoo 118
    int fill_cnt = 0;
14086 bpr 119
    int font_size = 12;/* this may lead to problems when using something like <code>fontfamily Italic 24px Ariel</code> the ''fontsize`` value is not substituted into fontfamily !! */
8388 schaersvoo 120
    int fly_font_size = 12; /*fly_font_size is relative to this... */
14066 bpr 121
    int dashtype[2] = { 4 , 4 }; /* just line_px and space_px: may have more arguments...if needed in future */
122
    int js_function[MAX_JS_FUNCTIONS]; /* javascript functions include objects on demand basis: only once per object type */
7614 schaersvoo 123
    for(i=0;i<MAX_JS_FUNCTIONS;i++){js_function[i]=0;}
8365 schaersvoo 124
    int arrow_head = 8; /* size in px needed for arrow based  userdraw:  "userdraw arrow,color" */
7833 schaersvoo 125
    int crosshair_size = 5; /* size in px*/
8365 schaersvoo 126
    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  */
14066 bpr 127
    int found_size_command = 0; /* 1 = found size ; 2 = found xrange; 3 = found yrange: just to flag an error message */
8448 schaersvoo 128
    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 129
    int clock_cnt = 0; /* counts the amount of clocks used -> unique object clock%d */
130
    int linegraph_cnt = 0; /* identifier for command 'linegraph' ; multiple line graphs may be plotted in a single plot*/
7989 schaersvoo 131
    int barchart_cnt = 0; /* identifier for command 'barchart' ; multiple charts may be plotted in a single plot*/
9433 schaersvoo 132
    int boxplot_cnt = 0;
11890 schaersvoo 133
    int numberline_cnt = 0;
7956 schaersvoo 134
    int legend_cnt = -1; /* to allow multiple legends to be used, for multiple piecharts etc  */
8074 schaersvoo 135
    int reply_precision = 100; /* used for precision of student answers / drawings */
7614 schaersvoo 136
    double angle = 0.0;
10953 bpr 137
    char *rotation_center = "null";
11893 schaersvoo 138
    int use_animate = 0; /* used for jscurve / js parametric  */
7823 schaersvoo 139
    int use_input_xy = 0; /* 1= input fields 2= textarea 3=calc y value*/
10953 bpr 140
    int use_slider_display = 0; /* in case of a slider, should we display its value ?*/
8365 schaersvoo 141
    size_t string_length = 0; /* measure the size of the user input fly-string */
142
    double stroke_opacity = 0.8; /* use some opacity as default */
14208 schaersvoo 143
    double fill_opacity = 0.5;/* use some opacity as default */
7614 schaersvoo 144
    char *URL = "http://localhost/images";
9213 schaersvoo 145
    char *slider_function_x = "x";
146
    char *slider_function_y = "y";
7614 schaersvoo 147
    memset(buffer,'\0',MAX_BUFFER);
148
    void *tmp_buffer = "";
149
    /* default writing a unzipped js-include file into wims getfile directory */
150
    char *w_wims_session = getenv("w_wims_session");
12104 schaersvoo 151
    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 152
    int L0=strlen(w_wims_session) + 21;
153
    char *getfile_dir = my_newmem(L0); /* create memory to fit string precisely */
154
    snprintf(getfile_dir,L0, "../sessions/%s/getfile",w_wims_session);/* string will fit precisely  */
155
    mode_t process_mask = umask(0); /* check if file exists */
156
    int result = mkdir(getfile_dir, S_IRWXU | S_IRWXG | S_IRWXO);
157
    if( result == 0 || errno == EEXIST ){
158
     umask(process_mask); /* be sure to set correct permission */
8224 bpr 159
     char *w_session = getenv("w_session");
7614 schaersvoo 160
     int L1 = (int) (strlen(w_session)) + find_number_of_digits(canvas_root_id) + 48;
12104 schaersvoo 161
     getfile_cmd = my_newmem(L1); /* create memory to fit string precisely */
8224 bpr 162
     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 163
    /* write the include tag to html page:<script src="wims.cgi?session=%s&cmd=getfile&special_parm=11223344_js"></script> */
7614 schaersvoo 164
    /* now write file into getfile dir*/
14066 bpr 165
    char *w_wims_home = getenv("w_wims_home"); /* "/home/users/wims": we need absolute path for location */
7614 schaersvoo 166
    int L2 = (int) (strlen(w_wims_home)) + (int) (strlen(w_wims_session)) + find_number_of_digits(canvas_root_id) + 23;
167
    char *location = my_newmem(L2); /* create memory to fit string precisely */
168
    snprintf(location,L2,"%s/sessions/%s/getfile/%d.js",w_wims_home,w_wims_session,canvas_root_id);/*absolute path */
169
    js_include_file = fopen(location,"w");/* open the file location for writing */
14066 bpr 170
    /* check on opening...if nogood: mount readonly? disk full? permissions not set correctly? */
171
    if(js_include_file == NULL){ canvas_error("SHOULD NOT HAPPEN: could not write to javascript include file...check your system logfiles !" );}
14227 schaersvoo 172
    char *user_agent = getenv("HTTP_USER_AGENT");
14230 schaersvoo 173
    int browser_type = 1;/* GECKO */
14227 schaersvoo 174
    if( (strcasestr(user_agent,"khtml" ) != NULL) || (strcasestr(user_agent,"opera" ) != NULL) || (strcasestr(user_agent,"trident" ) != NULL) ){ browser_type = 0; }
7614 schaersvoo 175
 
176
/* ----------------------------------------------------- */
11997 schaersvoo 177
 
7614 schaersvoo 178
/* while more lines to process */
179
 
180
    while(!finished){
9329 schaersvoo 181
        if(line_number>1 && found_size_command == 0 && use_tooltip != 2 ){canvas_error("command \"size xsize,ysize\" needs to come first ! ");}
7614 schaersvoo 182
        type = get_token(infile);
183
        done = FALSE;
184
        /*
9385 schaersvoo 185
        @ canvasdraw
14162 bpr 186
        @ will try use the same syntax as@ 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`` (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 <code>family</code> may be combined with keywords <a href="#snaptogrid">"snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command <code>snaptopoints x1,y1,x2,y2,...</code></li><li>every draggable | onclick object may be combined with keywords <a href="#snaptogrid">snaptogrid | xsnaptogrid | ysnaptogrid | snaptofunction</a> or command <code>snaptopoints x1,y1,x2,y2,...</code></li><li>almost every command for a single object has a multiple objects counterpart:<br /><ul>general syntax rule:<li><code>single_object x1,y1,...,color</code></li><li><code>multi_object color,x1,y1,...</code></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 <code>fontfamily</code> is <b>not</b> active for these elements</li></ul>
14078 bpr 187
        @ If needed multiple interactive scripts may be used in a single webpage.<br />A function <code>read_canvas()</code> and / or <code>read_dragdrop()</code> can read all interactive userdata from these images.<br />The global array <code>canvas_scripts</code> 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 /><code>fun = eval("read_canvas"+canvas_scripts[0])</code> 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 /><code>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" 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...) ;<br />&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;};<br />&nbsp;if( found_result ){return draw_reply;}else{return null;};<br />};</code>
11006 schaersvoo 188
        @ 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>
14078 bpr 189
        @ for usage within OEF (without anstype ''draw``), something like this (a popup function plotter) will work:<br /><code>\\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 />}</code>
14071 bpr 190
        @ 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 is not wise to use older browsers...not just for canvasdraw
10827 schaersvoo 191
        @ 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.
14066 bpr 192
        @ 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 193
        */
194
        switch(type){
195
        case END:
196
        finished = 1;
197
        done = TRUE;
198
        break;
199
        case 0:
200
            sync_input(infile);
201
            break;
12063 schaersvoo 202
 
203
        case CENTERED:
204
         use_offset = 4;
205
         /*
206
         @ centered
207
         @ keyword ; to place the text centered (in width and height) on the text coordinates(x:y)
14071 bpr 208
         @ may be used for text exactly centered on its (x;y)
12063 schaersvoo 209
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
14071 bpr 210
         @ 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 211
         @%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 212
        */
213
        break;
214
 
7614 schaersvoo 215
        case COMMENT:
216
            sync_input(infile);
217
            break;
11806 schaersvoo 218
        case AFFINE:
7614 schaersvoo 219
        /*
11806 schaersvoo 220
         @ affine a,b,c,d,tx,ty
221
         @ defines a transformation matrix for subsequent objects
13957 schaersvoo 222
         @ 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" !!
14066 bpr 223
         @ use keyword <a href='#killaffine'>killaffine</a> to end the transformation...the next objects will be drawn in the original x/y-range
14071 bpr 224
         @ note 1: only ''draggable`` / ''onclick`` type of objects (e.g. objects in the ''drag/drop/onclick-library``) can be transformed.
225
         @ note 2: do not use <code>onclick</code> or <code>drag xy</code> with tranformation / rotation objects: the mouse coordinates do not get transformed (yet)
11806 schaersvoo 226
         @ note 3: no matrix operations on the transformation matrix implemented (yet)
14066 bpr 227
         @ a: Scales the drawings horizontally
228
         @ b: Skews the drawings horizontally
229
         @ c: Skews the drawings vertically
230
         @ d: Scales the drawings vertically
11806 schaersvoo 231
         @ tx: Moves the drawings horizontally in xrange coordinate system
232
         @ ty: Moves the drawings vertically in yrange coordinate system
14078 bpr 233
         @ the data precision may be set by preceding command ''precision int``
12107 schaersvoo 234
         @%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 235
        */
11806 schaersvoo 236
            for(i = 0 ; i<6;i++){
7614 schaersvoo 237
                switch(i){
11806 schaersvoo 238
                    case 0: double_data[0] = get_real(infile,0);break;
239
                    case 1: double_data[1] = get_real(infile,0);break;
240
                    case 2: double_data[2] = get_real(infile,0);break;
241
                    case 3: double_data[3] = get_real(infile,0);break;
242
                    case 4: double_data[4] = get_real(infile,0);break;
243
                    case 5: double_data[5] = get_real(infile,1);
244
                        use_affine = TRUE;
245
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 246
                        string_length = 1 + 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));
247
                        check_string_length(string_length);affine_matrix = my_newmem(string_length);
11806 schaersvoo 248
                        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));
249
                        break;
7614 schaersvoo 250
                    default: break;
251
                }
252
            }
11806 schaersvoo 253
        break;
8386 schaersvoo 254
 
11806 schaersvoo 255
        case ANGLE:
7614 schaersvoo 256
        /*
11806 schaersvoo 257
         @ angle xc,yc,width,start_angle,end_angle,color
258
         @ width is in x-range
14208 schaersvoo 259
         @ angles are in degrees
260
         @ not compatible with ''flydraw``
11806 schaersvoo 261
         @ will zoom in/out
14208 schaersvoo 262
         @ if angle size is controlled by command <a href='#slider'>slider</a>, use radians to set limits of slider
263
         @ in case of a slider, command ''angle`` is always active ,controlled by the previous slider.
12110 schaersvoo 264
         @%angle%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor orange%angle 0,0,4,10,135,blue
14208 schaersvoo 265
         @%angle_slider%size 400,400%xrange -10,10%yrange -10,10%# click on the arrow to activate slider%grid 1,1,grey%linewidth 3%fillcolor black%strokecolor yellow%rotationcenter 0,0%fontsize 24%centerstring red,8,click on the arrow to activate slider%slider -pi,pi,400,30,angle degrees,Rotate arrow%arrow 0,0,8,0,8,blue%fillpattern diamond%angle 0,0,4,0,0,red
7614 schaersvoo 266
        */
11806 schaersvoo 267
            for(i=0;i<7;i++){
7614 schaersvoo 268
                switch(i){
11806 schaersvoo 269
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
270
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
14208 schaersvoo 271
                    case 2:double_data[2] = get_real(infile,0);break; /* width x-range ! */
272
                    case 3:double_data[3] = 0.0174532925*(get_real(infile,0));break; /* start angle in degrees -> radians  */
273
                    case 4:double_data[4] = 0.0174532925*(get_real(infile,0));break; /* end angle in degrees -> radians */
11806 schaersvoo 274
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
275
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 276
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 277
                        reset();
278
                    break;
7614 schaersvoo 279
                }
280
            }
14208 schaersvoo 281
            if(onclick > 0 || slider_cnt > 0){click_cnt++;}
282
            /* click_cnt++;*/
283
 
7614 schaersvoo 284
            break;
8386 schaersvoo 285
 
11806 schaersvoo 286
        case ANIMATE:
7614 schaersvoo 287
        /*
11930 schaersvoo 288
         @ animate
11893 schaersvoo 289
         @ keyword
14071 bpr 290
         @ the animated point is a filled rectangle ; adjust colour with command <code>fillcolor colorname/hexnumber</code>
11893 schaersvoo 291
         @ use linewidth to adjust size of the points
14078 bpr 292
         @ will animate a point on -only- the next <a href='#jsplot'>jsplot/jscurve command</a>. Only a single call to <code>animate</code> is allowed...in case of multiple <code>animate</code> keywords, only the last one is valid
13957 schaersvoo 293
         @ only usable for command jsplot (normal functions or parametric)<br />no other object/thing can be animated -for now
294
         @ 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>
295
         @ 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 296
         @%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)
297
         @%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 298
        */
13512 schaersvoo 299
            use_animate++;
300
            if( use_animate == 1 ){
301
            fprintf(js_include_file,"\nvar trace_canvas  = create_canvas%d(%d,xsize,ysize);\
302
            var trace_ctx = trace_canvas.getContext('2d');\
303
            trace_ctx.fillStyle = 'rgba(%s,%f)';\
304
            trace_ctx.strokeStyle = 'rgba(%s,%f)';\
305
            trace_ctx.lineWidth = %d;var anim_pos = 0;\n\
306
            function animate_this(){\
307
             var sync;\
308
             var synchrone = Math.floor(animation_steps/animation_funs);\
309
             trace_ctx.clearRect(0,0,xsize,ysize);\
310
             for(var p=0; p<animation_funs;p++){\
311
              sync = p*synchrone;\
312
              trace_ctx.fillRect(x_anim_points[sync+anim_pos]-%d, y_anim_points[sync+anim_pos]-%d,%d,%d);\
313
             };\
314
             setTimeout(function(){\
315
              requestAnimationFrame(animate_this);  anim_pos++;}, 50\
316
             );\
317
             if(anim_pos >= animation_steps){anim_pos = 0;};\
318
             };",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);
319
            }
320
            else
321
            {
13514 schaersvoo 322
                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 323
            }
7614 schaersvoo 324
            break;
8386 schaersvoo 325
 
11806 schaersvoo 326
        case ARC:
7614 schaersvoo 327
        /*
11997 schaersvoo 328
         @ arc xc,yc,x-width,y-height,start_angle,end_angle,color
14208 schaersvoo 329
         @ can not be set ''onclick`` or ''drag xy``
330
         @ compatible with ''flydraw``
331
         @ attention: width &amp; height in x/y-range
332
         @ better use command <a href='#angle'>angle</a> for use with a <a href='#slider'>slider</a>
12110 schaersvoo 333
         @%arc%size 400,400%xrange -10,10%yrange -10,10%arc 0,0,4,4,10,135,red%zoom blue
13961 schaersvoo 334
         @%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
7614 schaersvoo 335
        */
11806 schaersvoo 336
            for(i=0;i<7;i++){
337
                switch(i){
338
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
339
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
340
                    case 2:double_data[2] = get_real(infile,0);break; /* width x-range no pixels ! */
341
                    case 3:double_data[3] = get_real(infile,0);break; /* height y-range no pixels ! */
342
                    case 4:double_data[4] = get_real(infile,0);break; /* start angle in degrees */
343
                    case 5:double_data[5] = get_real(infile,0);break; /* end angle in degrees */
344
                    case 6:stroke_color = get_color(infile,1);/* name or hex color */
345
                    /* in Shape library:
346
                        x[0] = x[1] = xc = double_data[0]
347
                        y[0] = y[1] = yc = double_data[1]
348
                        w[0] = width = double_data[2]
349
                        w[1] = height = double_data[3]
350
                        h[0] = start_angle = double_data[4]
351
                        h[1] = end_angle = double_data[5]
352
                    */
353
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 354
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 355
                        reset();
356
                    break;
357
                }
14208 schaersvoo 358
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
359
                /* click_cnt++;*/
360
 
11806 schaersvoo 361
            }
7614 schaersvoo 362
            break;
11806 schaersvoo 363
        case ARROW:
7614 schaersvoo 364
        /*
11806 schaersvoo 365
        @ arrow x1,y1,x2,y2,h,color
14071 bpr 366
        @ alternative: <code>vector</code>
11806 schaersvoo 367
        @ draw a single headed arrow / vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color 'color'
14077 bpr 368
        @ use command <code>linewidth int</code> to adjust thickness of the arrow
9406 schaersvoo 369
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
13957 schaersvoo 370
        @%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
371
        @%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 372
        */
11806 schaersvoo 373
            for(i=0;i<6;i++){
7614 schaersvoo 374
                switch(i){
375
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
376
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
11806 schaersvoo 377
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
378
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
379
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
380
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
7614 schaersvoo 381
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 382
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
383
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 384
                        /* click_cnt++;*/
385
                        reset();
386
                        break;
387
                }
388
            }
389
            break;
8386 schaersvoo 390
 
11806 schaersvoo 391
        case ARROWS:
7614 schaersvoo 392
        /*
11806 schaersvoo 393
        @ arrows color,head (px),x1,y1,x2,y2...x_n,y_n
14071 bpr 394
        @ alternative: <code>vectors</code>
11806 schaersvoo 395
        @ draw single headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color 'color'
14071 bpr 396
        @ use command <code>linewidth int</code> to adjust thickness of the arrow
11806 schaersvoo 397
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
13957 schaersvoo 398
        @%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%
399
        @%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%
14208 schaersvoo 400
        @%arrows_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click arrow(s) to activate %slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%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 401
        */
402
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
403
            fill_color = stroke_color;
11806 schaersvoo 404
            arrow_head = (int) get_real(infile,0);/* h */
7614 schaersvoo 405
            i=0;
406
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 407
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 408
                if(i%2 == 0 ){
409
                    double_data[i] = get_real(infile,0); /* x */
410
                }
411
                else
412
                {
413
                    double_data[i] = get_real(infile,1); /* y */
414
                }
415
                i++;
416
            }
417
            decimals = find_number_of_digits(precision);
11806 schaersvoo 418
            for(c = 0 ; c < i-1 ; c = c+4){
14208 schaersvoo 419
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
420
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 421
                /* click_cnt++; */
7614 schaersvoo 422
            }
423
            reset();
424
            break;
8386 schaersvoo 425
 
11806 schaersvoo 426
        case ARROW2:
7614 schaersvoo 427
        /*
11806 schaersvoo 428
        @ arrow2 x1,y1,x2,y2,h,color
14071 bpr 429
        @ draw a double headed arrow/vector from (x1:y1) to (x2:y2)<br />with arrowhead size h in px and in color ''color``
430
        @ use command <code>arrowhead int</code> to adjust the arrow head size
431
        @ use command <code>linewidth int</code> to adjust thickness of the arrow
9406 schaersvoo 432
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 433
        @%arrow2%size 400,400%xrange -10,10%yrange -10,10%drag xy%arrow2 0,0,4,3,8,blue%
7614 schaersvoo 434
        */
11806 schaersvoo 435
            for(i=0;i<6;i++){
7614 schaersvoo 436
                switch(i){
437
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
438
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
11806 schaersvoo 439
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
440
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
441
                    case 4: arrow_head = (int) get_real(infile,0);break;/* h */
442
                    case 5: stroke_color = get_color(infile,1);/* name or hex color */
443
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 444
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
445
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 446
                        /* click_cnt++;*/
447
                        reset();
448
                        break;
449
                }
450
            }
451
            break;
8386 schaersvoo 452
 
11806 schaersvoo 453
        case ARROWS2:
7614 schaersvoo 454
        /*
11806 schaersvoo 455
        @ arrows2 color,head (px),x1,y1,x2,y2...x_n,y_n
14071 bpr 456
        @ draw double headed arrows / vectors from (x1:y1) to (x2:y2) ... (x3:y3) to (x4:y4) etc ... in color ''color``
457
        @ use command <code>linewidth int</code> to adjust thickness of the arrows
11806 schaersvoo 458
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
12107 schaersvoo 459
        @%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 460
        */
461
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
462
            fill_color = stroke_color;
11806 schaersvoo 463
            arrow_head = (int) get_real(infile,0);/* h */
7614 schaersvoo 464
            i=0;
465
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 466
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 467
                if(i%2 == 0 ){
468
                    double_data[i] = get_real(infile,0); /* x */
469
                }
470
                else
471
                {
472
                    double_data[i] = get_real(infile,1); /* y */
473
                }
474
                i++;
475
            }
8224 bpr 476
            decimals = find_number_of_digits(precision);
11806 schaersvoo 477
            for(c = 0 ; c < i-1 ; c = c+4){
14208 schaersvoo 478
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
479
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 480
                /* click_cnt++; */
11806 schaersvoo 481
 
7614 schaersvoo 482
            }
483
            reset();
484
            break;
11806 schaersvoo 485
        case ARROWHEAD:
9427 schaersvoo 486
        /*
11806 schaersvoo 487
        @ arrowhead int
488
        @ default 8 (pixels)
9427 schaersvoo 489
        */
11806 schaersvoo 490
            arrow_head = (int) (get_real(infile,1));
491
            break;
492
 
493
        case AUDIO:
494
        /*
495
        @ audio x,y,w,h,loop,visible,audiofile location
14066 bpr 496
        @ x,y: left top corner of audio element (in xrange / yrange)
497
        @ w,y: width and height in pixels
498
        @ loop: 0 or 1 ( 1 = loop audio fragment)
499
        @ visible: 0 or 1 (1 = show controls)
11806 schaersvoo 500
        @ audio format may be in *.mp3 or *.ogg
14066 bpr 501
        @ If you are using *.mp3: be aware that FireFox will not (never) play this ! (Pattented format)
502
        @ if you are using *.ogg: be aware that Microsoft based systems not support it natively
11806 schaersvoo 503
        @ To avoid problems supply both types (mp3 and ogg) of audiofiles.<br />the program will use both as source tag
504
        */
505
            if( js_function[DRAW_AUDIO] != 1 ){ js_function[DRAW_AUDIO] = 1;}
506
            for(i=0;i<7;i++){
507
                switch(i){
508
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
509
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system  -> pixel */
510
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
511
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
512
                    case 4: int_data[4] = (int) (get_real(infile,0)); if(int_data[4] != TRUE){int_data[4] = FALSE;} break; /* loop boolean */
513
                    case 5: int_data[5] = (int) (get_real(infile,0)); if(int_data[5] != TRUE){int_data[5] = FALSE;} break; /* visible boolean */
514
                    case 6:
515
                    temp = get_string(infile,1);
516
                    if( strstr(temp,".mp3") != 0 ){ temp = str_replace(temp,".mp3","");}
517
                    if( strstr(temp,".ogg") != 0 ){ temp = str_replace(temp,".ogg","");}
14208 schaersvoo 518
                    string_length = 1 + 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);
519
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 520
                    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);
521
                    add_to_buffer(tmp_buffer);
522
                    break;
523
                    default:break;
9427 schaersvoo 524
                }
11806 schaersvoo 525
            }
526
            reset();
527
            break;
528
 
529
 
530
        case AXIS_NUMBERING:
531
        /*
532
            @ axisnumbering
533
            @ keyword (no arguments required)
14246 bpr 534
            @ 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>
11806 schaersvoo 535
            @ to be used before command grid (see <a href="#grid">command grid</a>)
536
        */
11891 schaersvoo 537
            use_axis_numbering++;
11806 schaersvoo 538
            break;
539
        case AXIS:
540
        /*
541
            @ axis
542
            @ keyword (no arguments required)
543
            @ to be used before command grid (see <a href="#grid">command grid</a>)
544
 
545
        */
546
            use_axis = TRUE;
547
            break;
548
 
549
        case BARCHART:
550
        /*
551
        @ barchart x_1:y_1:color_1:x_2:y_2:color_2:...x_n:y_n:color_n
14066 bpr 552
        @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
553
        @ 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>
554
        @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
11806 schaersvoo 555
        @ multiple barchart command may be used in a single script
14066 bpr 556
        @ also see command <a href='#piechart'>piechart</a>
557
        @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
12107 schaersvoo 558
        @%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 559
        */
560
            temp = get_string(infile,1);
561
            if( strstr( temp,":" ) != 0 ){ temp = str_replace(temp,":","\",\""); }
562
            fprintf(js_include_file,"var barchart_%d = [\"%s\"];",barchart_cnt,temp);
563
            barchart_cnt++;
564
            reset();
565
            break;
566
 
567
        case BEZIER:
568
        /*
569
        @ bezier color,x_start,y_start,x_first,y_first,x_second,y_second,x_end,y_end
570
        @ draw a bezier curve between points, starting from (x_start:y_start)
571
        @ can <b>not</b> be dragged or set onclick
572
        */
573
            if( js_function[DRAW_BEZIER] != 1 ){ js_function[DRAW_BEZIER] = 1;}
574
            decimals = find_number_of_digits(precision);
575
            for(i = 0 ; i < 9; i++){
576
                switch(i){
577
                    case 0: stroke_color = get_color(infile,0);break;
578
                    case 1: double_data[0] = get_real(infile,0);break;/* start x */
579
                    case 2: double_data[1] = get_real(infile,0);break;/* start y */
580
                    case 3: double_data[2] = get_real(infile,0);break;/*The x-coordinate of the first Bézier control point */
581
                    case 4: double_data[3] = get_real(infile,0);break;/*The y-coordinate of the first Bézier control point */
582
                    case 5: double_data[4] = get_real(infile,0);break;/*The x-coordinate of the second Bézier control point */
583
                    case 6: double_data[5] = get_real(infile,0);break;/*The y-coordinate of the second Bézier control point */
584
                    case 7: double_data[6] = get_real(infile,0);break;/*The x-coordinate of the Bézier end point */
585
                    case 8: double_data[7] = get_real(infile,1);/*The y-coordinate of the Bézier end point */
14208 schaersvoo 586
                        string_length = 1 + 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);
587
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 588
                        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);
589
                        add_to_buffer(tmp_buffer);
590
                        break;
591
                    default: break;
9427 schaersvoo 592
                }
593
            }
594
            reset();
595
            break;
11806 schaersvoo 596
 
597
 
598
        case BGCOLOR:
9427 schaersvoo 599
        /*
11806 schaersvoo 600
         @ bgcolor colorname or #hex
601
         @ use this color as background of the "div" containing the canvas(es)
12110 schaersvoo 602
         @%bgcolor%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue
9427 schaersvoo 603
        */
11806 schaersvoo 604
        /* [255,255,255]*/
605
            bgcolor = get_string(infile,1);
606
            if(strstr(bgcolor,"#") == NULL){ /* convert colorname -> #ff00ff */
607
                int found = 0;
608
                for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
609
                    if( strcmp( colors[i].name , bgcolor ) == 0 ){
610
                        bgcolor = colors[i].hex;
611
                        found = 1;
612
                        break;
613
                    }
9427 schaersvoo 614
                }
14066 bpr 615
                if(found == 0){canvas_error("your bgcolor is not in my rgb.txt data list: use hexcolor...something like #a0ffc4");}
11806 schaersvoo 616
            }
13970 obado 617
            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 618
            break;
619
 
620
        case BGIMAGE:
621
        /*
622
         @ bgimage image_location
14071 bpr 623
         @ use an image as background; technical: we use the background of ''canvas_div``
11806 schaersvoo 624
         @ the background image will be resized to match "width = xsize" and "height = ysize"
12110 schaersvoo 625
         @%bgimage%size 400,400%xrange -10,10%yrange -10,10%bgimage https://wims.unice.fr/wims/gifs/en.gif
11806 schaersvoo 626
        */
627
        URL = get_string(infile,1);
13970 obado 628
        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 629
            break;
630
 
631
        case BLINK:
632
        /*
633
         @ blink time(seconds)
634
         @ NOT IMPLEMETED -YET
635
        */
636
            break;
637
 
638
        case BOXPLOT:
639
        /*
640
        @ boxplot x_or_y,box-height_or_box-width,position,min,Q1,median,Q3,max
14066 bpr 641
        @ example:<br /><code>xrange 0,300<br />yrange 0,10<br />boxplot x,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in x-direction, with height 4 (in yrange) and centered around line y=8
642
        @ example:<br /><code>xrange 0,10<br />yrange 0,300<br />boxplot y,4,8,120,160,170,220,245</code><br />meaning: create a boxplot in y-direction, with width 4 (in xrange) and centered around line x=8
643
        @ 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
644
        @ use command <a href='#fillpattern'>fillpattern some_pattern</a> to use a (diamond for Q1, hatch for Q3) pattern.
645
        @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of stroke and fill colours
14071 bpr 646
        @ use command <a href='#legend'>legend</a> to automatically create a legend <br />unicode allowed in legend<br />use command <code>fontfamily</code> to set the font of the legend.
11806 schaersvoo 647
        @ there is no limit to the number of boxplots used.
14078 bpr 648
        @ can <b>not</b> be set draggable and <a href='#onclick'>onclick</a> is not ready yet
14066 bpr 649
        @ 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)
650
        @ use keyword <a href="#userboxplotdata">userboxplotdata</a> before command boxplot, if a pupil must generate the data by some means.
651
        @ use command <a href="#boxplotdata">boxplotdata</a> when the boxplot should be drawn from wims-generated raw statistical date
12110 schaersvoo 652
        @%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
653
        @%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 654
        @%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 655
        */
656
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
657
            for(i=0;i<8;i++){
658
                switch(i){
659
                    case 0: temp = get_string_argument(infile,0);
660
                            if( strstr(temp,"x") != 0){int_data[0] = 1;}else{int_data[0] = 0;} break; /* x or y */
661
                    case 1: double_data[0] = get_real(infile,0);break;/* height | width  */
662
                    case 2:
663
                    if( js_function[DRAW_JSBOXPLOT] == 0 ){
664
                     double_data[1] = get_real(infile,0);
665
                     fprintf(js_include_file,"var boxplot_source = 0;\n");/* we use given min,Q1,median,Q3,max */
666
                    }
667
                    else
668
                    {
669
                     double_data[1] = get_real(infile,1);
670
                     double_data[2] = 1;
671
                     double_data[3] = 1;
672
                     double_data[4] = 1;
673
                     double_data[5] = 1;
674
                     double_data[6] = 1;
675
                     double_data[7] = 1;
676
                     i=8;
677
                    }
678
                    break;/* center value x or y */
679
                    case 3: double_data[2] = get_real(infile,0); break;/* min */
680
                    case 4: double_data[3] = get_real(infile,0); break;/* Q1 */
681
                    case 5: double_data[4] = get_real(infile,0); break;/* median */
682
                    case 6: double_data[5] = get_real(infile,0); break;/* Q3 */
683
                    case 7: double_data[6] = get_real(infile,1); break;/* max */
684
                    default:break;
9427 schaersvoo 685
                }
686
            }
687
            decimals = find_number_of_digits(precision);
11806 schaersvoo 688
            /*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)*/
14208 schaersvoo 689
            string_length = 1 + 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]);
11806 schaersvoo 690
            check_string_length(string_length);
14208 schaersvoo 691
            tmp_buffer = my_newmem(string_length);
11806 schaersvoo 692
            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]);
693
            add_to_buffer(tmp_buffer);
694
            boxplot_cnt++;
695
            reset();
696
        break;
697
        case BOXPLOTDATA:
698
        /*
699
        @ boxplotdata some_data
700
        @ 'some_data' are a list of numbers separated by a comma "," (items)
14071 bpr 701
        @ only be used before command <code>boxplot</code>: the command <a href="#boxplot">boxplot</a> will provide the boxplot drawing of the data.
11806 schaersvoo 702
        @ 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
703
        @ note: wims will not check your data input | format. use js-error console to debug any problems.
14071 bpr 704
        @ a javascript function <code>statistics()</code> will parse the data and calculate the values [min,Q1,median,Q3,max] and hand them to the boxplot draw function.
705
        @ only a single call to <code>boxplotdata</code> can be made. If multiple boxplots should be present in a single canvas, then use multiple calls to command <a href='#boxplot'>boxplot</a>
13959 bpr 706
        @%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 707
        */
708
            if( js_function[DRAW_JSBOXPLOT] != 1 ){ js_function[DRAW_JSBOXPLOT] = 1;}
709
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
710
            fprintf(js_include_file,"var boxplot_source = 1;var jsboxplot_data = [%s];\n",get_string(infile,1));
711
 
712
        break;
713
 
714
        case CANVASTYPE:
715
         canvas_type = (int) (get_real(infile,1));
716
        /*
717
        @ canvastype TYPE
14246 bpr 718
        @ 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 719
        @ default value of TYPE is DRAG_CANVAS e.g. 5 (all clickable / draggable object are in this canvas)
720
        @ use another TYPE, if you know what you are doing...
14246 bpr 721
        @ 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>
11806 schaersvoo 722
        */
723
        break;
724
 
725
        case CENTERSTRING:
726
        /*
727
         @ centerstring color,y-value,the text string
728
         @ title color,y-value,the text string
729
         @ draw a string centered on the canvas at y = y-value
14071 bpr 730
         @ can not be set ''onclick`` or ''drag xy`` (...)
14162 bpr 731
         @ unicode supported: <code>centerstring red,5,\\u2232</code>
14071 bpr 732
         @ use a command like <code>fontfamily italic 24pt Ariel</code> to set fonts on browser that support font change
12110 schaersvoo 733
         @%centerstring%size 400,400%xrange -10,10%yrange -10,10%bgcolor lightblue%fontfamily italic 22pt Courier%centerstring blue,7,the center
11806 schaersvoo 734
        */
735
            if( js_function[DRAW_CENTERSTRING] != 1 ){ js_function[DRAW_CENTERSTRING] = 1;}
736
            for(i=0;i<3;i++){
737
                switch(i){
738
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
739
                    case 1: double_data[0] = get_real(infile,0);break; /* y in xrange*/
740
                    case 2: temp = get_string_argument(infile,1);
741
                            /* draw_text = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text) */
742
                            decimals = find_number_of_digits(precision);
14208 schaersvoo 743
                            string_length = 1 + snprintf(NULL,0,
11806 schaersvoo 744
                            "draw_centerstring(%d,%.*f,\"%s\",\"%s\",%.2f,\"%s\");\n",canvas_root_id,decimals,double_data[0],font_family,stroke_color,stroke_opacity,temp);
14208 schaersvoo 745
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 746
                            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);
747
                            add_to_buffer(tmp_buffer);
748
                            break;
749
                    default:break;
750
                }
9427 schaersvoo 751
            }
752
            break;
8386 schaersvoo 753
 
11806 schaersvoo 754
 
8386 schaersvoo 755
        case CIRCLE:
8299 schaersvoo 756
        /*
8386 schaersvoo 757
        @ circle xc,yc,width (2*r in pixels),color
14071 bpr 758
        @ use command <code>fcircle xc,yc,d,color</code>
9383 schaersvoo 759
        @ alternative: disk for a filled circle
14071 bpr 760
        @ use command <code>fillcolor color</code> to set the fillcolor
761
        @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a>
8386 schaersvoo 762
        @ will shrink / expand on zoom out / zoom in
12110 schaersvoo 763
        @%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 764
        */
8386 schaersvoo 765
            for(i=0;i<4;i++){
766
                switch(i){
767
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
768
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
14066 bpr 769
                    case 2: double_data[2] = px2x((get_real(infile,0))/2) - px2x(0);break; /* for zoom in/out: radius in 'dx' xrange*/
8386 schaersvoo 770
                    case 3: stroke_color = get_color(infile,1);/* name or hex color */
771
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 772
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
773
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8386 schaersvoo 774
                        /* click_cnt++;*/
775
                        reset();
776
                        break;
777
                    default : break;
778
                }
779
            }
780
            break;
781
 
782
        case CIRCLES:
783
        /*
784
        @ circles color,xc1,yc1,r1,xc2,yc2,r2...xc_n,yc_n,r_n
9383 schaersvoo 785
        @ <b>attention</b> r = radius in x-range (!)
14071 bpr 786
        @ use keyword <code>filled</code> or command <code>fcircles</code> to produce solid circles
14066 bpr 787
        @ alternative: disks for filled circles
14071 bpr 788
        @ use command <code>fillcolor color</code> to set the fillcolor
789
        @ may be set <a href='#drag'>draggable</a> / <a href='#onclick'>onclick</a> (individually)
8386 schaersvoo 790
        @ will shrink / expand on zoom out / zoom in
14208 schaersvoo 791
        @%circles_drag%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
792
        @%circles_onclick%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%onclick%circles blue,0,0,2,2,2,3,-3,-3,3,3,3,4,3,-4,2%zoom red
793
        @%circles_drag_slider%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag xy%# Click circles(s) to activate%opacity 200,50%fillcolor orange%rotationcenter 2,3%slider 0,2*pi,300,30,angle degrees,Rotate%slider -5,5*pi,300,30,x display,move in x-direction%slider -10,10*pi,300,30,y display,move in y-direction%fcircles blue,0,0,0.5,2,2,1,-3,-3,1.5,3,3,0.5,3,-4,0.5
8386 schaersvoo 794
        */
8299 schaersvoo 795
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
796
            fill_color = stroke_color;
8386 schaersvoo 797
            i=1;
8299 schaersvoo 798
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 799
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8386 schaersvoo 800
                switch (i%3){
801
                 case 1:double_data[i-1] = get_real(infile,0);break; /* x */
802
                 case 2:double_data[i-1] = get_real(infile,0);break; /* y */
803
                 case 0:double_data[i-1] = get_real(infile,1);break; /* r */
8299 schaersvoo 804
                }
805
                i++;
806
            }
807
            decimals = find_number_of_digits(precision);
8386 schaersvoo 808
            for(c = 0 ; c < i-1 ; c = c+3){
14208 schaersvoo 809
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
810
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8386 schaersvoo 811
                /* click_cnt++; */
8299 schaersvoo 812
            }
813
            reset();
814
            break;
11806 schaersvoo 815
        case CLEARBUTTON:
816
        /*
817
         @ clearbutton value
14071 bpr 818
         @ alternative: <code>delete</code>
819
         @ alternative: <code>erase</code>
14078 bpr 820
         @ adds a button to clear the <a href="#userdraw">userdraw</a> canvas with text ''value``
14246 bpr 821
         @ <b>attention</b> command <code>clearbutton</code> is incompatible with <a href="#multidraw">multidraw</a> based drawings<br/>(in <code>multidraw</code> there is always a remove_object_button for every draw primitive)
11806 schaersvoo 822
         @ 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
14071 bpr 823
         @ uses the tooltip placeholder div element: may not be used with command <code>intooltip</code>
14066 bpr 824
         @ use command <a href="#inputstyle">inputstyle</a> to style the button...
14071 bpr 825
         @ 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 /><code>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;</code> or <code>document.getElementById("clearbutton"+canvas_scripts[p]).setAttribute("style","some_style"); &minus;&minus;&gt;<br />&nbsp;&nbsp;p++;<br />&nbsp;};<br />};</code>
13935 bpr 826
         @%clearbutton%size 400,400%xrange -10,10%yrange -10,10%filled%fillcolor lightblue%opacity 255,50%userdraw circles,red%clearbutton Remove All
11806 schaersvoo 827
        */
828
        if(reply_format == 29){/* eg multidraw is selected */
14054 schaersvoo 829
        // canvas_error("command clearbutton incompatible with multidraw...only suitable for userdraw");
11806 schaersvoo 830
        }
831
            add_clear_button(js_include_file,canvas_root_id,input_style,get_string(infile,1));
832
        break;
8386 schaersvoo 833
 
11806 schaersvoo 834
        case CLOCK:
7614 schaersvoo 835
        /*
11806 schaersvoo 836
        @ clock x,y,r(px),H,M,S,type hourglass,interactive [ ,H_color,M_color,S_color,background_color,foreground_color ]
14071 bpr 837
        @ use command <code>opacity stroke-opacity,fill-opacity</code> to adjust foreground (stroke) and background (fill) transparency
14066 bpr 838
        @ type hourglass:<br />type = 0: only segments<br />type = 1: only numbers<br />type = 2: numbers and segments
11806 schaersvoo 839
        @ 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
840
        @ if you don't want a seconds hand (or minutes...), just make it invisible by using the background color of the hourglass...
14162 bpr 841
        @ 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>
11806 schaersvoo 842
        @ canvasdraw will not check validity of colornames...the javascript console is your best friend
843
        @ no combinations with other reply_types allowed, for now
14077 bpr 844
        @ 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
845
        @ 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
14066 bpr 846
        @ note: clocks will not zoom or pan, when using command <a href='#zoom'>zoom</a>
12110 schaersvoo 847
        @%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
848
        @%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
849
        @%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
850
        @%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
851
        @%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
852
        @%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
853
        @%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 854
        */
11806 schaersvoo 855
            if( js_function[DRAW_CLOCK] != 1 ){ js_function[DRAW_CLOCK] = 1;}
856
 
857
        /*    var clock = function(xc,yc,radius,H,M,S,h_color,m_color,s_color,bg_color,fg_color) */
858
            for(i=0;i<9;i++){
859
             switch(i){
860
              case 0: int_data[0] = x2px(get_real(infile,0)); break; /* xc */
861
              case 1: int_data[1] = y2px(get_real(infile,0)); break; /* yc */
862
              case 2: int_data[2] = get_real(infile,0);break;/* radius in px */
863
              case 3: int_data[3] = get_real(infile,0);break;/* hours */
864
              case 4: int_data[4] = get_real(infile,0);break;/* minutes */
865
              case 5: int_data[5] = get_real(infile,0);break;/* seconds */
866
              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 */
867
              case 7: int_data[7] = (int)(get_real(infile,1));/* interactive 0,1,2*/
868
                switch(int_data[7]){
869
                    case 0:break;
870
                    case 1:if(clock_cnt == 0){
871
                           if( reply_format == 0 ){
872
                            reply_format = 18; /* user sets clock */
14208 schaersvoo 873
                            /* string_length = 1 + 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");
874
                               check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 875
                               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");
876
                               add_to_buffer(tmp_buffer);
877
                           */
878
                            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");
879
                           }
880
                           else
881
                           {
882
                            canvas_error("interactive clock may not be used together with other reply_types...");
883
                           }
884
                          }
885
                          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);
886
                    break;
887
                    case 3:if(clock_cnt == 0){
888
                            if( reply_format == 0 ){
889
                             reply_format = 18; /* user sets clock */
890
                             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");
891
                            }
892
                            else
893
                            {
894
                             canvas_error("interactive clock may not be used together with other reply_types...");
895
                            }
896
                           }
897
                            /*
898
                            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);
899
                           */
900
                    break;
901
                    case 2:if( reply_format == 0 ){
902
                                reply_format = 19; /* "onclick */
13970 obado 903
                                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 904
                            }
905
                            else
906
                            {
907
                                if( reply_format != 19){
908
                                   canvas_error("clickable clock(s) may not be used together with other reply_types...");
909
                                 }
910
                            }
911
                     break;
912
                     default: canvas_error("interactive must be set 0,1 or 2");break;
913
                }
914
                break;
915
                case 8:
14078 bpr 916
                        if(clock_cnt == 0 ){ /* set opacity's just once .... it should be a argument to clock(), for now it's OK */
11806 schaersvoo 917
                            fprintf(js_include_file,"var clock_bg_opacity = %.2f;var clock_fg_opacity = %.2f;",fill_opacity,stroke_opacity);
918
                        }
919
                        temp = get_string(infile,3);/* optional colors, like: ,,red,,blue*/
920
                        if( strstr( temp,",") != 0 ){ temp = str_replace(temp,",","\",\""); }
921
                        else{
922
                        /* h_color,m_color,s_color,bg_color,fg_color */
11991 schaersvoo 923
                        temp = ",black\",\"black\",\"black\",\"white\",\"black";}
14208 schaersvoo 924
                        string_length = 1 + 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);
925
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 926
                        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);
927
                        add_to_buffer(tmp_buffer);
928
                        fprintf(js_include_file,"var clocks%d;",clock_cnt);
929
                        clock_cnt++;
930
                        break;
931
                default:break;
932
             }
933
            }
934
            break;
935
 
936
 
937
        case COLORPALETTE:
938
        /*
939
         @ colorpalette color_name_1,color_name_2,...,color_name_8
940
         @ opacity will be the same for all colors and is set by command <a href="#opacity">opacity [0-255],[0-255]</a>
14066 bpr 941
         @ 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
14077 bpr 942
         @ make sure to include the ''remove button`` by using command <a href='#clearbutton'>clearbutton some_text</a>
11806 schaersvoo 943
        */
944
            if( use_tooltip == 1 ){canvas_error("command 'colorpalette' is incompatible with command 'intooltip tip_text'");}
945
            fprintf(js_include_file,"var multifillcolors = [];var palettecolors = [");
946
            while( ! done ){
947
                temp = get_color(infile,1);
948
                fprintf(js_include_file,"\"%s\",",temp);
949
            }
950
            fprintf(js_include_file,"];");/* add black to avoid trouble with dangling comma... */
951
            add_color_palette(js_include_file,canvas_root_id,input_style);
952
            break;
13829 bpr 953
 
11806 schaersvoo 954
        case COPY:
955
        /*
956
        @ copy x,y,x1,y1,x2,y2,[filename URL]
957
        @ The image may be "bitmap" or "SVG"
958
        @ Insert the region from (x1,y1) to (x2,y2) (in pixels) of [filename] to (x,y) in x/y-range
959
        @ If x1=y1=x2=y2=-1, the whole [filename URL] is copied.
960
        @ [filename] is the URL of the image
14077 bpr 961
        @ URL is normal URL of network reachable image file location<br />(eg special url for ''classexo`` not -yet- implemented)
962
        @ 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 <code>snaptopoints x1,y1,x2,y2...</code>.
963
        @ 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
964
        @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc)
11806 schaersvoo 965
        @ you may draw / userdraw / drag other stuff on top of an "imported" image
14077 bpr 966
        @ 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``<br />note: when dragging the image anchor is the center of the picture, this can not be changed (it's a feature and not a flaw!)
967
        @ use keyword <a href='#centered'>centered</a> before command ''copy`` to place image center at given coordinates.
13967 schaersvoo 968
        @%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
14066 bpr 969
        @%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
970
        @%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 971
        */
972
            for(i = 0 ; i<7;i++){
7614 schaersvoo 973
                switch(i){
11806 schaersvoo 974
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x left top corner in x/y range  */
975
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y left top corner in x/y range */
976
                    case 2: int_data[2]=(int)(get_real(infile,0));break;/* x1 in px of external image */
977
                    case 3: int_data[3]=(int)(get_real(infile,0));break;/* y1 in px of external image */
978
                    case 4: int_data[4]=(int)(get_real(infile,0));break;/* x2 --> width  */
979
                    case 5: int_data[5]=(int)(get_real(infile,0)) ;break;/* y2 --> height */
980
                    case 6: URL = get_string(infile,1);
981
                            int_data[6] = int_data[4] - int_data[2];/* swidth & width (if not scaling )*/
982
                            int_data[7] = int_data[5] - int_data[3];/* sheight & height (if not scaling )*/
983
                            if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
984
                            int_data[9] = click_cnt;
985
                            if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
14038 schaersvoo 986
                                 //if( reply_format == 0 ){ reply_format = 20; }
11806 schaersvoo 987
                                 int_data[8] = 2;/* drag & drop */
14044 schaersvoo 988
                                 if(use_offset == 0 ){use_offset = 4;} /* mouse is attached to the center of the image !! */
11806 schaersvoo 989
                            }
990
                            else
991
                            {
992
                                if( onclick == 1  ){
14038 schaersvoo 993
                                //    reply_format = 20;
11806 schaersvoo 994
                                    int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
995
                                    click_cnt++; /* will also be used in dragstuff ! */
996
                                }
997
                                else
998
                                {
999
                                    int_data[8] = 0; /* just static image */
1000
                                }
1001
                            }
14038 schaersvoo 1002
                            if( include_special_OEF_reply == FALSE){
1003
                             if( int_data[8] == 1 || int_data[8] == 2 ){
1004
                              include_special_OEF_reply = TRUE;
1005
                              fprintf(js_include_file,"\
1006
                              \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
1007
                              read_canvas_images = function(){\
1008
                               var prec = %d;\
1009
                               var len  = ext_drag_images.length;\
1010
                               var reply = new Array(len);\
1011
                               for(var p = 0 ; p < len ; p++){\
1012
                                var img = ext_drag_images[p];\
1013
                                reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
1014
                               };\
1015
                               return reply;\
1016
                              };\n\
14062 schaersvoo 1017
                              /* end function 34 read_canvas_images() */",reply_precision);
14038 schaersvoo 1018
                             }
1019
                            }
11806 schaersvoo 1020
/*
14062 schaersvoo 1021
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
11806 schaersvoo 1022
*/
14208 schaersvoo 1023
                            string_length = 1 + 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);
1024
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
14044 schaersvoo 1025
                            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 1026
                            add_to_buffer(tmp_buffer);
11806 schaersvoo 1027
                            drag_type = -1; /* reset the drag_type indicator */
1028
                            ext_img_cnt++;
1029
                            onclick=0;
14038 schaersvoo 1030
                            use_offset=0;
1031
                            reset();
11806 schaersvoo 1032
                            break;
7614 schaersvoo 1033
                    default: break;
1034
                }
1035
            }
1036
            break;
11806 schaersvoo 1037
/*
1038
HTML5 specs:
1039
context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
1040
img     Specifies the image, canvas, or video element to use
14066 bpr 1041
sx      The x coordinate where to start clipping: x1 = int_data[0]
1042
sy      The y coordinate where to start clipping: x2 = int_data[1]
1043
swidth  The width of the clipped image: int_data[2] - int_data[0]
1044
sheight The height of the clipped image: int_data[3] - int_data[1]
1045
x       The x coordinate where to place the image on the canvas: dx1 = int_data[4]
1046
y       The y coordinate where to place the image on the canvas: dy1 = int_data[5]
1047
width   The width of the image to use (stretch or reduce the image): dx2 - dx1 = int_data[6]
1048
height  The height of the image to use (stretch or reduce the image): dy2 - dy1 = int_data[7]
11806 schaersvoo 1049
*/
1050
        case COPYRESIZED:
1051
        /*
1052
        @ copyresized x1,y2,x2,y2,dx1,dy1,dx2,dy2,image_file_url
1053
        @ The image may be any "bitmap" or "SVG"
1054
        @ 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
14066 bpr 1055
        @ (dx1:dy1) must be left top corner; (dx2:dy2) must be right bottom corner of inserted image
11806 schaersvoo 1056
        @ If x1=y1=x2=y2=-1, the whole [filename / URL ] is copied and resized.
1057
        @ 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 !!)
14077 bpr 1058
        @ 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 <code>snaptopoints x1,y1,x2,y2...</code>
1059
        @ 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
1060
        @ ''onclick`` for external images may be mixed with canvas generated stuff (like lines,curves etc)
11806 schaersvoo 1061
        @ you may draw / userdraw / drag stuff on top of an "imported" image
14077 bpr 1062
        @ 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``
14038 schaersvoo 1063
        @ use keyword <a href='#centered'>centered</a> before command 'copyresized' to place image center at given coordinates.
11806 schaersvoo 1064
        */
1065
            for(i = 0 ; i<9;i++){
1066
                switch(i){
1067
                    case 0: int_data[0] = (int)(get_real(infile,0));break; /* x1 */
1068
                    case 1: int_data[1] = (int)(get_real(infile,0));break; /* y1 */
1069
                    case 2: int_data[2] = (int)(get_real(infile,0));break;/* x2 */
1070
                    case 3: int_data[3] = (int)(get_real(infile,0));break;/* y2 */
1071
                    case 4: int_data[4] = x2px(get_real(infile,0));break;/* dx1 */
1072
                    case 5: int_data[5] = y2px(get_real(infile,0));break;/* dy1 */
1073
                    case 6: int_data[6] = x2px(get_real(infile,0));break;/* dx2 */
1074
                    case 7: int_data[7] = y2px(get_real(infile,0));break;/* dy2 */
1075
                    case 8: URL = get_string(infile,1);
1076
                            /* flag error when wrong diagonal:  copyresized -1,-1,-1,-1,0,0,7,7,testfig.gif */
1077
                            if( int_data[7] < int_data[5] || int_data[6] < int_data[4]){
1078
                                canvas_error("in copyresized , use:<br />left top corner (dx1:dy1) and right bottom corner (dx2:dy2) ! ");
1079
                            }
1080
                            int_data[2] = abs(int_data[2] - int_data[0]);/* swidth */
1081
                            int_data[3] = abs(int_data[3] - int_data[1]);/* sheight */
1082
                            int_data[6] = abs(int_data[6] - int_data[4]);/* width */
1083
                            int_data[7] = abs(int_data[7] - int_data[5]);/* height */
1084
                            if( js_function[DRAW_EXTERNAL_IMAGE] != 1 ){ js_function[DRAW_EXTERNAL_IMAGE] = 1;}
1085
                            int_data[9] = click_cnt;
1086
                            if( drag_type > -1 ){/* e.g. we are dragging images x/y/xy */
14038 schaersvoo 1087
                                // if( reply_format == 0 ){ reply_format = 20; }
11806 schaersvoo 1088
                                 int_data[8] = 2;/* drag & drop */
1089
                            }
1090
                            else
1091
                            {
1092
                                if( onclick == 1  ){
14038 schaersvoo 1093
                                //    reply_format = 20;
11806 schaersvoo 1094
                                    int_data[8] = 1; /* onclick will be reset using 'void reset()'*/
1095
                                    click_cnt++; /* will also be used in dragstuff ! */
1096
                                }
1097
                                else
1098
                                {
1099
                                    int_data[8] = 0; /* just static image */
1100
                                }
1101
                            }
14038 schaersvoo 1102
                            if( include_special_OEF_reply == FALSE){
1103
                             if( int_data[8] == 1 || int_data[8] == 2 ){
1104
                              include_special_OEF_reply = TRUE;
1105
                              fprintf(js_include_file,"\
1106
                              \n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
1107
                              read_canvas_images = function(){\
1108
                               var prec = %d;\
1109
                               var len  = ext_drag_images.length;\
1110
                               var reply = new Array(len);\
1111
                               for(var p = 0 ; p < len ; p++){\
1112
                                var img = ext_drag_images[p];\
1113
                                reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
1114
                               };\
1115
                               return reply;\
1116
                              };\n\
14062 schaersvoo 1117
                              /* end function 34 read_canvas_images() */",reply_precision);
14038 schaersvoo 1118
                             }
1119
                            }
1120
 
11806 schaersvoo 1121
/*
1122
(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt)
1123
URL,[2],[3],[6],    [7], [4],[5],[6],[7],ext_img_cnt,1,    [8],      [9]
1124
*/
14208 schaersvoo 1125
                            string_length = 1 + 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);
1126
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
14044 schaersvoo 1127
                            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 1128
                            add_to_buffer(tmp_buffer);
11806 schaersvoo 1129
                            drag_type = -1; /* reset the drag_type indicator */
1130
                            ext_img_cnt++;
1131
                            onclick=0;
14038 schaersvoo 1132
                            use_offset=0;
1133
                            reset();
11806 schaersvoo 1134
                            break;
1135
                    default: break;
1136
                }
1137
            }
14038 schaersvoo 1138
            reset();
11806 schaersvoo 1139
            break;
8386 schaersvoo 1140
 
11806 schaersvoo 1141
        case CROSSHAIR:
8386 schaersvoo 1142
        /*
11806 schaersvoo 1143
        @ crosshair x,y,color
1144
        @ draw a single crosshair point at (x;y) in color 'color'
14246 bpr 1145
        @ use command 'crosshairsize int' and / or 'linewidth int' to adjust
11806 schaersvoo 1146
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 1147
        @%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 1148
        */
1149
            for(i=0;i<3;i++){
1150
                switch(i){
1151
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
1152
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
1153
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
1154
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 1155
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1156
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 1157
                        /* click_cnt++ */
1158
                        reset();
1159
                        break;
1160
                    default:break;
1161
                }
1162
            }
1163
            break;
1164
 
1165
        case CROSSHAIRS:
1166
        /*
1167
        @ crosshairs color,x1,y1,x2,y2,...,x_n,y_n
14077 bpr 1168
        @ draw multiple crosshair points at given coordinates in color ''color``
14246 bpr 1169
        @ use command <code>crosshairsize int</code> and / or <code>linewidth int</code> to adjust
9406 schaersvoo 1170
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12107 schaersvoo 1171
        @%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
1172
        @%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
1173
*/
8386 schaersvoo 1174
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1175
            fill_color = stroke_color;
1176
            i=0;
1177
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 1178
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8386 schaersvoo 1179
                if(i%2 == 0 ){
1180
                    double_data[i] = get_real(infile,0); /* x */
1181
                }
1182
                else
1183
                {
1184
                    double_data[i] = get_real(infile,1); /* y */
1185
                }
1186
                i++;
1187
            }
1188
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1189
            for(c=0 ; c < i-1 ; c = c+2){
14208 schaersvoo 1190
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1191
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 1192
                /* click_cnt++; */
8386 schaersvoo 1193
            }
1194
            reset();
1195
            break;
1196
 
11806 schaersvoo 1197
        case CROSSHAIRSIZE:
7614 schaersvoo 1198
        /*
11806 schaersvoo 1199
        @ crosshairsize int
1200
        @ default 8 (px)
7614 schaersvoo 1201
        */
11806 schaersvoo 1202
            crosshair_size = (int) (get_real(infile,1));
1203
            break;
1204
 
1205
        case CURSOR:
1206
        /*
14086 bpr 1207
        @ cursor some CSS cursor_style
14071 bpr 1208
        @ alternative: <code>pointer</code>
13956 schaersvoo 1209
        @ style can be any valid CSS property value
1210
        @ 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
1211
        @ note: wims will not check the validity of your cursor declaration
1212
        @%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 1213
        */
1214
            fprintf(js_include_file,"canvas_div%d.style.cursor = \"%s\";",canvas_root_id,get_string(infile,1));
1215
            break;
1216
 
1217
        case CURVE:
1218
        /*
1219
         @ curve color,formula(x)
14066 bpr 1220
         @ alernative: plot color,formula(x)
14071 bpr 1221
         @ use command <a href="#trange">trange</a> in parametric functions before command curve / plot <code>trange -pi,pi<br />curve color,formula1(t),formula2(t)</code>
14086 bpr 1222
         @ use command <a href="#precision">precision</a> to increase the number of digits of the plotted points
14066 bpr 1223
         @ use command <a href="#plotsteps">plotsteps</a> to increase / decrease the amount of plotted points (default 150)
11806 schaersvoo 1224
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
14071 bpr 1225
         @ 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 1226
         @%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 1227
        */
1228
            if( use_parametric == TRUE ){ /* parametric color,fun1(t),fun2(t)*/
1229
                use_parametric = FALSE;
1230
                stroke_color = get_color(infile,0);
1231
                char *fun1 = get_string_argument(infile,0);
1232
                char *fun2 = get_string_argument(infile,1);
1233
                if( strlen(fun1) == 0 || strlen(fun2) == 0 ){canvas_error("parametric functions are NOT OK !");}
14208 schaersvoo 1234
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 1235
            }
1236
            else
1237
            {
1238
                stroke_color = get_color(infile,0);
1239
                char *fun1 = get_string_argument(infile,1);
1240
                if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
14208 schaersvoo 1241
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 1242
            }
14208 schaersvoo 1243
            if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 1244
            /* click_cnt++; */
1245
            reset();
1246
            break;
14038 schaersvoo 1247
    case CURVEDARROW:
1248
    /*
1249
    @ curvedarrow x1,y1,xc,yc,x2,y2,color
14248 bpr 1250
    @ draw a single headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2)<br /> note: the curve will <b>not go through</b> point (xc:yc)
14038 schaersvoo 1251
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
14077 bpr 1252
    @ use command <code>linewidth int</code> to adjust thickness of the arrow
14038 schaersvoo 1253
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1254
    @%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
1255
    @%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 1256
 
14029 schaersvoo 1257
h[0] = arrowhead
14066 bpr 1258
h[1] = type: 1 = single 2=double arrow
14208 schaersvoo 1259
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,current_sliders,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1260
    */
1261
            for(i=0;i<7;i++){
1262
            switch(i){
1263
                case 0: double_data[0] = get_real(infile,0);break; /* x1 */
1264
                case 1: double_data[1] = get_real(infile,0);break; /* y1 */
1265
                case 2: double_data[2] = get_real(infile,0);break; /* xc */
1266
                case 3: double_data[3] = get_real(infile,0);break; /* yc */
1267
                case 4: double_data[4] = get_real(infile,0);break; /* y3 */
1268
                case 5: double_data[5] = get_real(infile,0);break; /* y3 */
1269
                case 6: stroke_color = get_color(infile,1);/* name or hex color */
1270
                decimals = find_number_of_digits(precision);
14208 schaersvoo 1271
            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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1272
            if(onclick > 0 || slider_cnt > 0){click_cnt++;}
14038 schaersvoo 1273
            /* click_cnt++;*/
1274
            reset();
1275
            break;
1276
            }
1277
            }
1278
            break;
14029 schaersvoo 1279
 
14038 schaersvoo 1280
    case CURVEDARROW2:
1281
    /*
1282
    @ curvedarrow2 x1,y1,xc,yc,x2,y2,color
14248 bpr 1283
    @ draw a double headed curved arrow from (x1:y1) in direction of (xc:yc) to point (x2:y2)<br /> note: the curve will <b>not go through</b> point (xc:yc)
14038 schaersvoo 1284
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
14077 bpr 1285
    @ use command <code>linewidth int</code> to adjust thickness of the arrow
14038 schaersvoo 1286
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1287
    @%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
1288
    @%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 1289
 
1290
h[0] = arrowhead
14066 bpr 1291
h[1] = type: 1 = single 2=double arrow
14208 schaersvoo 1292
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,current_sliders,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1293
    */
1294
            for(i=0;i<7;i++){
1295
            switch(i){
1296
                case 0: double_data[0] = get_real(infile,0);break; /* x1 */
1297
                case 1: double_data[1] = get_real(infile,0);break; /* y1 */
1298
                case 2: double_data[2] = get_real(infile,0);break; /* xc */
1299
                case 3: double_data[3] = get_real(infile,0);break; /* yc */
1300
                case 4: double_data[4] = get_real(infile,0);break; /* y3 */
1301
                case 5: double_data[5] = get_real(infile,0);break; /* y3 */
1302
                case 6: stroke_color = get_color(infile,1);/* name or hex color */
1303
                decimals = find_number_of_digits(precision);
14208 schaersvoo 1304
            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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1305
            if(onclick > 0 || slider_cnt > 0){click_cnt++;}
14038 schaersvoo 1306
            /* click_cnt++;*/
1307
            reset();
1308
            break;
1309
            }
1310
            }
1311
            break;
1312
    case CURVEDARROWS:
1313
    /*
14248 bpr 1314
    @ curvedarrows color,x1,y1,xc,yc,x2,y2,...,x_(n-1),y_(n-1),xc,yc,x_n,y_n
1315
    @ draw curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc<br /> note: the curve will <b>not go through</b> point (xc:yc)
14038 schaersvoo 1316
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
14077 bpr 1317
    @ use command <code>linewidth int</code> to adjust thickness of the arrow
14038 schaersvoo 1318
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1319
    @%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
1320
    @%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 1321
 
14030 schaersvoo 1322
h[0] = arrowhead
14066 bpr 1323
h[1] = type: 1 = single 2=double arrow
14208 schaersvoo 1324
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,current_sliders,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1325
    */
1326
        stroke_color = get_color(infile,0);/* name or hex color */
1327
        i = 0;
1328
        decimals = find_number_of_digits(precision);
1329
        while( ! done ){
1330
        if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
1331
        double_data[0] = get_real(infile,0); /* x1 */
1332
        double_data[1] = get_real(infile,0); /* y1 */
1333
        double_data[2] = get_real(infile,0); /* xc */
1334
        double_data[3] = get_real(infile,0); /* yc */
1335
        double_data[4] = get_real(infile,0); /* x3 */
1336
        double_data[5] = get_real(infile,1); /* y3 */
14208 schaersvoo 1337
        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1338
        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
14038 schaersvoo 1339
        i = i + 6;
1340
            }
1341
            reset();
1342
            break;
14030 schaersvoo 1343
 
14038 schaersvoo 1344
    case CURVEDARROWS2:
1345
    /*
1346
    @ curvedarrows2 color,x1,y1,xc,yc,x2,y2,...x_(n-1),y_(n-1),xc,yc,x_n,y_n
14248 bpr 1347
    @ draw double headed curved arrows from (x1:y1) in direction of (xc:yc) to point (x2:y2), etc. <br /> note: the curve will <b>not go through</b> point (xc:yc)
14038 schaersvoo 1348
    @ use command <a href='#arrowhead'>arrowhead</a> to set the size of the arrow head.
14077 bpr 1349
    @ use command <code>linewidth int</code> to adjust thickness of the arrow
14038 schaersvoo 1350
    @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1351
    @%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
1352
    @%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 1353
 
1354
h[0] = arrowhead
14066 bpr 1355
h[1] = type: 1 = single 2=double arrow
14208 schaersvoo 1356
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,current_sliders,rotation_center,use_offset,use_pattern)
14038 schaersvoo 1357
    */
1358
        stroke_color = get_color(infile,0);/* name or hex color */
1359
        i = 0;
1360
        decimals = find_number_of_digits(precision);
1361
        while( ! done ){
1362
        if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
1363
        double_data[0] = get_real(infile,0); /* x1 */
1364
        double_data[1] = get_real(infile,0); /* y1 */
1365
        double_data[2] = get_real(infile,0); /* xc */
1366
        double_data[3] = get_real(infile,0); /* yc */
1367
        double_data[4] = get_real(infile,0); /* x3 */
1368
        double_data[5] = get_real(infile,1); /* y3 */
14208 schaersvoo 1369
        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1370
        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
14038 schaersvoo 1371
        i = i + 6;
1372
            }
1373
            reset();
1374
            break;
11806 schaersvoo 1375
        case DASHED:
1376
        /*
1377
        @ dashed
1378
        @ keyword (no arguments required)
1379
        @ next object will be drawn with a dashed line
1380
        @ change dashing scheme by using command <a href="#dashtype">dashtype</a>
12107 schaersvoo 1381
        @%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 1382
        */
1383
            use_dashed = TRUE;
1384
            break;
1385
 
1386
        case DASHTYPE:
1387
        /*
1388
        @ dashtype line_width_px,space_width_px
1389
        @ every indiviual object may have its own dashtype, if needed...
1390
        @ When keyword <a href='#dashed'>dashed</a> is set, the objects will be drawn with this dashtype
14086 bpr 1391
        @ default value <code>dashtype 2,2</code> e.g. 2px line and 2px space
13957 schaersvoo 1392
        @ HTML5 canvas specification supports more arguments (dashing schemes) ... but not all modern browsers are yet capable
13949 schaersvoo 1393
        @%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 1394
        */
1395
            for(i=0;i<2;i++){
1396
                switch(i){
1397
                    case 0 : dashtype[0] = (int) line_width*( get_real(infile,0)) ; break;
1398
                    case 1 : dashtype[1] = (int) line_width*( get_real(infile,1)) ; break;
1399
                }
1400
            }
1401
        break;
1402
 
1403
        case DIAMONDFILL:
1404
        /*
1405
        @ diamondfill x0,y0,dx,dy,color
1406
        @ x0,y0 in xrange / yrange
1407
        @ distances dx,dy in pixels
13936 bpr 1408
        @ there is also a command <a href="#userdraw">userdraw diamondfill,color</a>
12110 schaersvoo 1409
        @%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 1410
        */
1411
            if( js_function[DRAW_DIAMONDFILL] != 1 ){ js_function[DRAW_DIAMONDFILL] = 1;}
11820 schaersvoo 1412
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1413
             js_function[DRAW_FILLTOBORDER] = 1;
1414
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1415
            }
1416
            decimals = find_number_of_digits(precision);
7614 schaersvoo 1417
            for(i=0;i<5;i++){
1418
                switch(i){
11820 schaersvoo 1419
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
14032 schaersvoo 1420
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
11820 schaersvoo 1421
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1422
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1423
                    case 4: stroke_color = get_color(infile,1);
1424
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
14208 schaersvoo 1425
                    string_length = 1 + 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);
1426
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11820 schaersvoo 1427
                    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 1428
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1429
                    fill_cnt++;
11806 schaersvoo 1430
                    break;
1431
                    default:break;
1432
                }
1433
            }
1434
            reset();
1435
        break;
8224 bpr 1436
 
11806 schaersvoo 1437
        case DOTFILL:
1438
        /*
1439
        @ dotfill x0,y0,dx,dy,color
1440
        @ x0,y0 in xrange / yrange
1441
        @ distances dx,dy in pixels
1442
        @ radius of dots is linewidth
13936 bpr 1443
        @ there is also a command <a href="#userdraw">userdraw dotfill,color</a>
12110 schaersvoo 1444
        @%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 1445
        */
1446
            if( js_function[DRAW_DOTFILL] != 1 ){ js_function[DRAW_DOTFILL] = 1;}
11817 schaersvoo 1447
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1448
             js_function[DRAW_FILLTOBORDER] = 1;
1449
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1450
            }
1451
            decimals = find_number_of_digits(precision);
11806 schaersvoo 1452
            for(i=0;i<5;i++){
1453
                switch(i){
11817 schaersvoo 1454
                    case 0: double_data[0] = get_real(infile,0); break; /* x in px */
1455
                    case 1: double_data[1] = get_real(infile,0); break; /* y in py */
1456
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1457
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1458
                    case 4: stroke_color = get_color(infile,1);
1459
                    /* draw_dotfill(ctx,x0,y0,dx,dy,radius,color,opacity,xsize,ysize) */
14208 schaersvoo 1460
                    string_length = 1 + 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);
1461
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11817 schaersvoo 1462
                    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 1463
                    add_to_buffer(tmp_buffer);
11817 schaersvoo 1464
                    fill_cnt++;
7614 schaersvoo 1465
                    break;
11806 schaersvoo 1466
                    default:break;
7614 schaersvoo 1467
                }
1468
            }
11806 schaersvoo 1469
            reset();
1470
        break;
1471
 
1472
        case DRAG:
1473
        /*
1474
         @ drag [x][y][xy]
1475
         @ the next object will be draggable in x / y / xy direction
14077 bpr 1476
         @ the displacement can be read by <code>javascript:read_dragdrop();</code>
14066 bpr 1477
         @ 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' !
14078 bpr 1478
         @ <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 )
14077 bpr 1479
         @ ''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)
14177 bpr 1480
         @ <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 /><code>linewidth 4<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />the red point will not be recognised as draggable !<br /><code>linewidth 4<br />drag xy<br />point 0,0,red<br />drag xy<br />point 0,0,blue</code><br />both points will be recognised
14066 bpr 1481
         @ 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)
14078 bpr 1482
         @ 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 1483
         @ 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.
14177 bpr 1484
         @ note: in case an object is dragged, zooming or panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost (array with ''drag data`` is erased). This is a design flaw and not a feature !!
13829 bpr 1485
         @%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
1486
         @%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
1487
         @%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 1488
        */
1489
            temp = get_string(infile,1);
1490
            if(strstr(temp,"xy") != NULL ){
1491
                drag_type = 0;
1492
            }
1493
            else
1494
            {
1495
                if(strstr(temp,"x") != NULL ){
1496
                    drag_type = 1;
1497
                }
1498
                else
1499
                {
1500
                    drag_type = 2;
1501
                }
1502
            }
1503
            /* assuming all drag&drop coordinates the same precision: so set only once */
1504
            if( print_drag_params_only_once == FALSE ){
1505
             fprintf(js_include_file,"dragdrop_precision = %d;use_dragdrop_reply = true;\n",precision);
1506
             print_drag_params_only_once = TRUE;
1507
            }
1508
            onclick = 2;
1509
            /* if(use_userdraw == TRUE ){canvas_error("\"drag & drop\" may not be combined with \"userdraw\" or \"pan and zoom\" \n");} */
7614 schaersvoo 1510
            break;
8386 schaersvoo 1511
 
11806 schaersvoo 1512
        case ELLIPSE:
8351 schaersvoo 1513
        /*
11806 schaersvoo 1514
        @ ellipse xc,yc,radius_x,radius_y,color
1515
        @ a ellipse with center xc/yc in x/y-range
1516
        @ radius_x and radius_y are in pixels
9406 schaersvoo 1517
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
11806 schaersvoo 1518
        @ will shrink / expand on zoom out / zoom in
13949 schaersvoo 1519
        @%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 1520
        */
11806 schaersvoo 1521
            for(i=0;i<5;i++){
1522
                switch(i){
1523
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
1524
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
14066 bpr 1525
                    case 2:double_data[2] = get_real(infile,0);break; /* rx -> px */
1526
                    case 3:double_data[3] = get_real(infile,0);break; /* ry -> px */
11806 schaersvoo 1527
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
1528
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 1529
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1530
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 1531
                        /* click_cnt++; */
1532
                        reset();
1533
                    break;
1534
                }
1535
            }
1536
            break;
13829 bpr 1537
 
12110 schaersvoo 1538
        case ELLIPSES:
1539
        /*
1540
        @ ellipses color,xc1,yc1,radius_x1,radius_y1,xc2,yc2,radius_x2,radius_y2,xc3,yc3,radius_x3,radius_y3,...
1541
        @ a ellipses with center xc/yc in x/y-range
1542
        @ radius_x and radius_y are in pixels
1543
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
1544
        @ will shrink / expand on zoom out / zoom in
13949 schaersvoo 1545
        @%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 1546
        */
13829 bpr 1547
 
12110 schaersvoo 1548
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
1549
            fill_color = stroke_color;
1550
            i=1;
1551
            while( ! done ){     /* get next item until EOL*/
1552
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
1553
                switch (i%4){
1554
                 case 1:double_data[i-1] = get_real(infile,0);break; /* x */
1555
                 case 2:double_data[i-1] = get_real(infile,0);break; /* y */
1556
                 case 3:double_data[i-1] = get_real(infile,0);break; /* rx */
1557
                 case 0:double_data[i-1] = get_real(infile,1);break; /* ry */
1558
                 default: break;
1559
                }
1560
                i++;
1561
            }
1562
            decimals = find_number_of_digits(precision);
1563
            for(c = 0 ; c < i-1 ; c = c+4){
14208 schaersvoo 1564
             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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1565
             if(onclick > 0 || slider_cnt > 0){click_cnt++;} /* click_cnt++; */
12110 schaersvoo 1566
            }
1567
            reset();
1568
            break;
1569
 
11806 schaersvoo 1570
        case FILLALL:
1571
        /*
1572
        @ fillall color,x1,y1,x2,y2...x_n,y_n
1573
        @ fill all region containing points (x1:y1),(x2:y2)...(x_n:y_n) with color 'color'
1574
        @ any other colors (objects) in the <a href="#canvastype>canvastype</a> will act as border to the bucket fill
14246 bpr 1575
        @ use this command after all boundary objects are declared.
11806 schaersvoo 1576
        @ Use command 'userdraw clickfill,color' for user click driven flood fill.
1577
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
14071 bpr 1578
        @ note: the fill-family of commands are very (client) cpu intensive operations!<br />filling is done pixel by pixel 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 1579
        @%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 1580
        */
1581
            decimals = find_number_of_digits(precision);
1582
            fill_color=get_color(infile,0); /* how nice: now the color comes first...*/
8351 schaersvoo 1583
            i=0;
11806 schaersvoo 1584
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1585
             js_function[DRAW_FILLTOBORDER] = 1;
1586
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1587
            }
8351 schaersvoo 1588
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 1589
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8351 schaersvoo 1590
                if(i%2 == 0 ){
1591
                    double_data[i] = get_real(infile,0); /* x */
1592
                }
1593
                else
1594
                {
1595
                    double_data[i] = get_real(infile,1); /* y */
14208 schaersvoo 1596
                    string_length = 1 + 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);
1597
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11818 schaersvoo 1598
                    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 1599
                    add_to_buffer(tmp_buffer);
1600
                    fill_cnt++;
8351 schaersvoo 1601
                }
1602
                i++;
1603
            }
11806 schaersvoo 1604
        break;
1605
 
1606
        case FILLED:
1607
        /*
1608
        @ filled
1609
        @ keyword (no arguments required)
14077 bpr 1610
        @ the next ''fillable`` object (only the next !) will be filled
14066 bpr 1611
        @ use command <a href="#fillcolor">fillcolor color</a> to set fillcolor
11839 schaersvoo 1612
        @ use <a href="#fillpattern">fillpattern</a> for non-solid color filling.
14086 bpr 1613
        @ use command <code>opacity 0-255,0-255</code> to set stroke and fill-opacity
14066 bpr 1614
        @ 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 1615
        */
11839 schaersvoo 1616
            use_filled = 1;
11859 schaersvoo 1617
            use_pattern = 0;
11806 schaersvoo 1618
            break;
1619
 
1620
        case FILLCOLOR:
1621
        /*
1622
        @ fillcolor colorname or #hex
14066 bpr 1623
        @ set the color: mainly used for command 'userdraw obj,stroke_color'
11806 schaersvoo 1624
        @ all fillable massive objects will have a fillcolor == strokecolor (just to be compatible with flydraw...)
11839 schaersvoo 1625
        @ see <a href="#fillpattern">fillpattern</a> for non-solid color filling.
11806 schaersvoo 1626
        */
1627
            fill_color = get_color(infile,1);
11874 schaersvoo 1628
            use_pattern = 0;
11806 schaersvoo 1629
            break;
1630
 
11837 schaersvoo 1631
        case FILLPATTERN:
1632
        /*
11854 schaersvoo 1633
        @ fillpattern grid | hatch | diamond | dot | image-url
11837 schaersvoo 1634
        @ use a pattern as fillstyle
14066 bpr 1635
        @ suitable for all fillable object including the <a href="#userdraw">userdraw objects' family</a>
14077 bpr 1636
        @ not -yet- implemented in the <a href="#multidraw">multidraw objects family</a>...(will probably be too complex)
14066 bpr 1637
        @ the fillcolor is set by the object command, for example:<br /><code>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</code>
14078 bpr 1638
        @ the pattern dimensions are hardcoded (linewidth, radius,dx,dy are fixed)
11837 schaersvoo 1639
        @ the pattern color is set by command <a href='#fillcolor'>fillcolor</a> and <a href='#opacity'>opacity</a>
11839 schaersvoo 1640
        @ see <a href="#fillcolor">fillcolor</a> for solid color filling.
14086 bpr 1641
        @ 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`` 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 /><code>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</code>
1642
        @ 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 1643
        @%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
1644
        @%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 1645
        */
1646
            temp = get_string(infile,1);
11875 schaersvoo 1647
            if( strstr(temp,"grid") != 0 ){ use_pattern = 2;use_filled = 2;} /* use_pattern is used in dragstuff library */
11837 schaersvoo 1648
            else
11875 schaersvoo 1649
            if( strstr(temp,"hatch") != 0 ){ use_pattern = 3;use_filled = 3;}
11837 schaersvoo 1650
            else
11875 schaersvoo 1651
            if( strstr(temp,"diamond") != 0 ){ use_pattern = 4;use_filled = 4;}
11837 schaersvoo 1652
            else
11875 schaersvoo 1653
            if( strstr(temp,"dot") != 0 ){ use_pattern = 5;use_filled = 5;}
11837 schaersvoo 1654
            else
11875 schaersvoo 1655
            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 1656
            else
13829 bpr 1657
            canvas_error("fillpattern unknown or typo...choose grid,hatch,diamond of dot...");
11837 schaersvoo 1658
            break;
11806 schaersvoo 1659
        case FILLTOBORDER:
1660
        /*
1661
        @ filltoborder x,y,bordercolor,color
14246 bpr 1662
        @ fill the region of point (x:y) with color 'color'
11806 schaersvoo 1663
        @ any other color will not act as border to the bucket fill
14246 bpr 1664
        @ use this command after all boundary objects are declared.
11806 schaersvoo 1665
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
14071 bpr 1666
        @ note: filltoborder is a very (client) cpu intensive operation!<br />filling is done pixel by pixel 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..
11806 schaersvoo 1667
        @ maybe used together with command <a href="#userdraw">userdraw clickfill,color</a>
12110 schaersvoo 1668
        @%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 1669
        */
1670
            for(i=0 ;i < 4 ; i++){
1671
                switch(i){
1672
                    case 0:double_data[0] = get_real(infile,0);break;
1673
                    case 1:double_data[1] = get_real(infile,0);break;
1674
                    case 2:bgcolor = get_color(infile,0);break;
1675
                    case 3:fill_color = get_color(infile,1);
1676
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1677
                                js_function[DRAW_FILLTOBORDER] = 1;
1678
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1679
                           }
1680
                           decimals = find_number_of_digits(precision);
1681
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
14208 schaersvoo 1682
                           string_length = 1 + 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);
1683
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11818 schaersvoo 1684
                           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 1685
                           add_to_buffer(tmp_buffer);
1686
                           fill_cnt++;
1687
                           break;
1688
                    default:break;
8351 schaersvoo 1689
                }
11806 schaersvoo 1690
            }
1691
            reset();
1692
        break;
1693
        case FLOODFILL:
1694
        /*
1695
        @ floodfill x,y,color
14071 bpr 1696
        @ alternative: <code>fill x,y,color</code>
11806 schaersvoo 1697
        @ fill the region of point (x:y) with color 'color'
1698
        @ any other color or size of picture (borders of picture) will act as border to the bucket fill
14246 bpr 1699
        @ use this command after all boundary objects are declared.
14077 bpr 1700
        @ Use command <code>userdraw clickfill,color</code> for user click driven flood fill.
11806 schaersvoo 1701
        @ use command <a href="#canvastype">canvastype </a> to fill another canvas (default should be fine: DRAG_CANVAS = 5)
14071 bpr 1702
        @ note: floodfill is a very (client) cpu intensive operation!<br />filling is done pixel by pixel 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 1703
        @%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 1704
        */
1705
            for(i=0 ;i < 4 ; i++){
1706
                switch(i){
1707
                    case 0:double_data[0] = get_real(infile,0);break;
1708
                    case 1:double_data[1] = get_real(infile,0);break;
1709
                    case 2:fill_color = get_color(infile,1);
1710
                           if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1711
                                js_function[DRAW_FILLTOBORDER] = 1;
1712
                                add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1713
                           }
1714
                           decimals = find_number_of_digits(precision);
1715
                           /* we need to set a timeout: the canvas is not yet draw in memory? when floodfill is called directly... */
14208 schaersvoo 1716
                           string_length = 1 + 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);
1717
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11818 schaersvoo 1718
                           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 1719
                           add_to_buffer(tmp_buffer);
1720
                           fill_cnt++;
1721
                           break;
1722
                    default:break;
1723
                }
1724
            }
1725
            reset();
1726
        break;
1727
 
1728
        case FONTCOLOR:
1729
        /*
1730
         @ fontcolor color
1731
         @ color: hexcolor or colorname
1732
         @ default: black
13956 schaersvoo 1733
         @ use command <a href="#fontfamily'>fontfamily</a> to deviate from default font type
1734
         @%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 1735
        */
1736
            font_color = get_color(infile,1);
1737
            break;
1738
 
1739
        case FONTFAMILY:
1740
        /*
1741
         @ fontfamily font_description
1742
         @ set the font family; for browsers that support it
14078 bpr 1743
         @ font_description: Ariel, Courier, Helvetica etc
14246 bpr 1744
         @ in case commands <code>string color,x,y,the string</code>, <code>stringup color,x,y,rotation,the string</code>, ''fontfamily`` can be something like:<code>fontfamily italic 34pt Ariel</code>. Use correct syntax: ''font style``, ''font size pt``, ''fontfamily``
13959 bpr 1745
         @%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
1746
 
11806 schaersvoo 1747
        */
1748
            font_family = get_string(infile,1);
1749
            break;
1750
 
1751
        case FONTSIZE:
1752
        /*
1753
         @ fontsize font_size
1754
         @ default value 12
14247 bpr 1755
         @ note: for some macros (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
11806 schaersvoo 1756
        */
1757
            font_size = (int) (get_real(infile,1));
1758
            break;
1759
 
1760
        case FUNCTION_LABEL:
1761
        /*
14071 bpr 1762
         @ functionlabel some string
14086 bpr 1763
         @ default value ''f(x)=``
11806 schaersvoo 1764
         @ no mathml allowed (just ascii string)
13956 schaersvoo 1765
         @ use command <a href='#fontsize'>fontsize int</a> to adjust the size
1766
         @ use command <a href='#strokecolor'>strokecolor colorname</a> to adjust the labels (individually, if needed)
14066 bpr 1767
         @ if needed, use before every command <a href='#userinput'>userinput function | inputfield | textarea</a>
13956 schaersvoo 1768
         @ no limit in amount of inputfields for userbased function plotting
11806 schaersvoo 1769
        */
1770
            function_label = get_string_argument(infile,1);
1771
            break;
1772
 
14078 bpr 1773
        case GRID:/* xmajor,ymajor,gridcolor [,xminor,yminor,tick length (px), axis/tickscolor]*/
11806 schaersvoo 1774
        /*
1775
         @ grid step_x,step_y,gridcolor
14177 bpr 1776
         @ if keywords <a href="#axis">axis</a> or <a href="#axisnumbering">axisnumbering</a> are set, use: <code>grid step_x,step_y,major_color,minor_x,minor_y,tics height in px,axis_color</code> minor x step = step_x / minor_x
1777
         @ 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; defaults: black,12,Ariel
14071 bpr 1778
         @ if xmin > 0 and/or ymin > 0 and zooming / panning is not active: be aware that the x/y-axis numbering and x/y major/minor tic marks will not be visual as they are placed under the x-axis and left to the y-axis (in Quadrant II and IV)
14066 bpr 1779
         @ can <b>not</b> be set <a href="#onclick">onclick</a> or <a href="#drag">drag xy</a>
14177 bpr 1780
         @ use commands <a href="#xlabel">xlabel some_string</a> and/or <a href="#ylabel">ylabel some_string</a> to label axis; use command ''fontsize`` to adjust size: the font family is non-configurable 'italic your_fontsize px Ariel' !
14066 bpr 1781
         @ 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')
14177 bpr 1782
         @ see command <a href="#legend">legend</a> to set a legend for the graph; use command <a href="#fontsize">fontsize</a> to adjust size (the font family is non-configurable 'bold your_fontsize px Ariel')
12110 schaersvoo 1783
         @%grid%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%zoom red
1784
         @%grid_axis%size 400,400%xrange -10,10%yrange -10,10%axis%grid 1,1,grey,2,2,6,black%zoom red
1785
         @%grid_axisnumbering%size 400,400%xrange -10,10%yrange -10,10%axisnumbering%precision 0%grid 1,1,grey,2,2,6,black%zoom red
1786
         @%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 1787
        */
1788
            if( js_function[DRAW_YLOGSCALE] == 1 ){canvas_error("only one grid type is allowed...");}
1789
            if( js_function[DRAW_GRID] != 1 ){ js_function[DRAW_GRID] = 1;}
1790
            for(i=0;i<4;i++){
1791
                switch(i){
1792
                    case 0:double_data[0] = get_real(infile,0);break;/* xmajor */
1793
                    case 1:double_data[1] = get_real(infile,0);break;/* ymajor */
1794
                    case 2:
1795
                    if( use_axis == TRUE ){
1796
                        stroke_color = get_color(infile,0);
1797
                        done = FALSE;
1798
                        int_data[0] = (int) (get_real(infile,0));/* xminor */
1799
                        int_data[1] = (int) (get_real(infile,0));/* yminor */
1800
                        int_data[2] = (int) (get_real(infile,0));/* tic_length */
1801
                        fill_color = get_color(infile,1); /* used as axis_color*/
8351 schaersvoo 1802
                    }
1803
                    else
1804
                    {
11806 schaersvoo 1805
                        int_data[0] = 1;
1806
                        int_data[1] = 1;
1807
                        stroke_color = get_color(infile,1);
1808
                        fill_color = stroke_color;
8351 schaersvoo 1809
                    }
11806 schaersvoo 1810
                    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 !");}
1811
                    /* set snap_x snap_y values in pixels */
1812
                    fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[0] / int_data[0],double_data[1] / int_data[1]);
14208 schaersvoo 1813
                    string_length = 1 + 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);
1814
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 1815
                    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);
1816
                    add_to_buffer(tmp_buffer);
1817
                    break;
8351 schaersvoo 1818
                }
1819
            }
1820
            reset();
1821
            break;
11806 schaersvoo 1822
        case GRIDFILL:
1823
        /*
1824
        @ gridfill x0,y0,dx,dy,color
1825
        @ x0,y0 in xrange / yrange
1826
        @ distances dx,dy in pixels
13936 bpr 1827
        @ there is also a command <a href="#userdraw">userdraw gridfill,color</a>
12110 schaersvoo 1828
        @%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
1829
 
11806 schaersvoo 1830
        */
1831
            if( js_function[DRAW_GRIDFILL] != 1 ){ js_function[DRAW_GRIDFILL] = 1;}
11820 schaersvoo 1832
            decimals = find_number_of_digits(precision);
1833
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1834
             js_function[DRAW_FILLTOBORDER] = 1;
1835
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1836
            }
11806 schaersvoo 1837
            for(i=0;i<5;i++){
1838
                switch(i){
11820 schaersvoo 1839
                    case 0: double_data[0] = get_real(infile,0); break; /* x  */
1840
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
1841
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
1842
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 1843
                    case 4: stroke_color = get_color(infile,1);
14208 schaersvoo 1844
                    string_length = 1 + 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);
1845
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11820 schaersvoo 1846
                    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 1847
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 1848
                    fill_cnt++;
11806 schaersvoo 1849
                    break;
1850
                    default:break;
1851
                }
1852
            }
1853
            reset();
1854
        break;
8386 schaersvoo 1855
 
8244 schaersvoo 1856
        case HALFLINE:
1857
        /*
1858
        @ demiline x1,y1,x2,y2,color
14071 bpr 1859
        @ alternative: <code>halfline</code>
8244 schaersvoo 1860
        @ draws a halfline starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex)
9406 schaersvoo 1861
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12110 schaersvoo 1862
        @%halfline%size 400,400%xrange -10,10%yrange -10,10%halfline -5,5,0,0,red%halfline -5,-5,0,0,blue
8244 schaersvoo 1863
        */
1864
            for(i=0;i<5;i++){
1865
                switch(i){
1866
                    case 0: double_data[0]= get_real(infile,0);break; /* x-values */
1867
                    case 1: double_data[1]= get_real(infile,0);break; /* y-values */
1868
                    case 2: double_data[10]= get_real(infile,0);break; /* x-values */
1869
                    case 3: double_data[11]= get_real(infile,0);break; /* y-values */
1870
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
1871
                    if(double_data[0] == double_data[10]){ /* vertical halfline */
1872
                        if(double_data[1] < double_data[11]){
1873
                         double_data[3] = ymax + 1000;
1874
                        }
1875
                        else
1876
                        {
1877
                         double_data[3] = ymin - 1000;
1878
                        }
10953 bpr 1879
                        double_data[2] = double_data[0];
8244 schaersvoo 1880
                    }
1881
                    else
1882
                    { /* horizontal halfline*/
1883
                     if( double_data[1] == double_data[11] ){
1884
                      if( double_data[0] < double_data[10] ){
1885
                        double_data[2] = xmax + 1000; /* halfline to the right */
1886
                      }
1887
                      else
1888
                      {
1889
                        double_data[2] = xmin - 1000; /* halfline to the left */
1890
                      }
1891
                      double_data[3] = double_data[1];
1892
                     }
1893
                     else
1894
                     {
1895
                      /* any other halfline */
1896
                      /* slope */
1897
                      double_data[12] = (double_data[11] - double_data[1])/(double_data[10] - double_data[0]);
1898
                      /* const */
1899
                      double_data[13] = double_data[1] - double_data[12]*double_data[0];
1900
                      if( double_data[0] < double_data[10] ){
1901
                       double_data[2] = double_data[2] + 1000;
1902
                      }
1903
                      else
1904
                      {
1905
                       double_data[2] = double_data[2] - 1000;
1906
                      }
1907
                      double_data[3] = double_data[12]*double_data[2] + double_data[13];
1908
                     }
10953 bpr 1909
                    }
14208 schaersvoo 1910
                    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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1911
                    if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 1912
                    /* click_cnt++; */
1913
                    reset();
8244 schaersvoo 1914
                    break;
1915
                }
1916
            }
1917
            break;
8386 schaersvoo 1918
 
8365 schaersvoo 1919
        case HALFLINES:
1920
        /*
1921
        @ demilines color,x1,y1,x2,y2,....
14071 bpr 1922
        @ alternative: <code>halflines</code>
14246 bpr 1923
        @ draws halflines starting in (x1:y1) and through (x2:y2) in color 'color' (colorname or hex) etc
9406 schaersvoo 1924
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> indiviually
12110 schaersvoo 1925
        @%halflines%size 400,400%xrange -10,10%yrange -10,10%halflines red,-5,5,0,0,-5,-5,0,0
8365 schaersvoo 1926
        */
1927
            stroke_color=get_color(infile,0);
1928
            fill_color = stroke_color;
1929
            i=0;
1930
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 1931
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8365 schaersvoo 1932
                if(i%2 == 0 ){
1933
                    double_data[i] = get_real(infile,0); /* x */
1934
                }
1935
                else
1936
                {
1937
                    double_data[i] = get_real(infile,1); /* y */
1938
                }
1939
                i++;
1940
            }
1941
            decimals = find_number_of_digits(precision);
1942
            for(c = 0 ; c < i-1 ; c = c+4){
1943
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
1944
                    if(double_data[c+1] < double_data[c+3]){ /* upright halfline */
1945
                        double_data[c+3] = ymax + 1000;
1946
                    }
1947
                    else
1948
                    {
1949
                     double_data[c+3] = ymin - 1000;/* descending halfline */
1950
                    }
1951
                }
1952
                else
1953
                {
1954
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
1955
                        if(double_data[c] < double_data[c+2] ){ /* halfline to the right */
1956
                            double_data[c+2] = xmax+100;
1957
                        }
1958
                        else
1959
                        {
1960
                            double_data[c+2] = xmin-1000; /* halfline to the right */
1961
                        }
1962
                    }
1963
                    else
1964
                    {
1965
                        /* m */
1966
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
1967
                        /* q */
1968
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
1969
                        if(double_data[c] < double_data[c+2]){ /* to the right */
14071 bpr 1970
                            double_data[c+2] = xmax+1000; /* 1000 is needed for dragging...otherwise it is just segment */
8365 schaersvoo 1971
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1972
                        }
1973
                        else
1974
                        { /* to the left */
1975
                            double_data[c+2] = xmin - 1000;
1976
                            double_data[c+3] = (m)*(double_data[c+2])+(q);
1977
                        }
1978
                    }
1979
                }
14208 schaersvoo 1980
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
1981
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 1982
                /* click_cnt++; */
8365 schaersvoo 1983
            }
1984
            reset();
1985
            break;
11806 schaersvoo 1986
        case HATCHFILL:
1987
        /*
1988
        @ hatchfill x0,y0,dx,dy,color
1989
        @ x0,y0 in xrange / yrange
1990
        @ distances dx,dy in pixels
13936 bpr 1991
        @ there is also a command <a href="#userdraw">userdraw hatchfill,color</a>
12110 schaersvoo 1992
        @%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 1993
        */
1994
            if( js_function[DRAW_HATCHFILL] != 1 ){ js_function[DRAW_HATCHFILL] = 1;}
11820 schaersvoo 1995
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
1996
             js_function[DRAW_FILLTOBORDER] = 1;
1997
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
1998
            }
1999
            decimals = find_number_of_digits(precision);
11806 schaersvoo 2000
            for(i=0;i<5;i++){
2001
                switch(i){
11820 schaersvoo 2002
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
2003
                    case 1: double_data[1] = get_real(infile,0); break; /* y  */
2004
                    case 2: int_data[0] = (int) (get_real(infile,0)); break; /* dx pixel */
2005
                    case 3: int_data[1] = (int) (get_real(infile,0)); break; /* dy pixel*/
11806 schaersvoo 2006
                    case 4: stroke_color = get_color(infile,1);
2007
                    /* draw_hatchfill(ctx,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize) */
14208 schaersvoo 2008
                    string_length = 1 + 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);
2009
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11820 schaersvoo 2010
                    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 2011
                    add_to_buffer(tmp_buffer);
11820 schaersvoo 2012
                    fill_cnt++;
11806 schaersvoo 2013
                    break;
2014
                    default:break;
2015
                }
2016
            }
2017
            reset();
2018
        break;
8386 schaersvoo 2019
 
8224 bpr 2020
        case HLINE:
7614 schaersvoo 2021
        /*
2022
        @ hline x,y,color
14071 bpr 2023
        @ alternative: <code>horizontalline</code>
7614 schaersvoo 2024
        @ draw a horizontal line through point (x:y) in color 'color'
14066 bpr 2025
        @ 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 2026
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12110 schaersvoo 2027
        @%hline%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hline 0,0,red%dhline 0,5,blue
7614 schaersvoo 2028
        */
2029
            for(i=0;i<3;i++) {
2030
                switch(i){
2031
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
2032
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
2033
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
2034
                    double_data[3] = double_data[1];
2035
                    decimals = find_number_of_digits(precision);
14208 schaersvoo 2036
                    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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
2037
                    if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 2038
                    /* click_cnt++; */
2039
                    reset();
7614 schaersvoo 2040
                    break;
2041
                }
2042
            }
2043
            break;
8366 schaersvoo 2044
 
2045
        case HLINES:
2046
        /*
2047
        @ hlines color,x1,y1,x2,y2,...
14071 bpr 2048
        @ alternative: <code>horizontallines</code>
8366 schaersvoo 2049
        @ draw horizontal lines through points (x1:y1)...(xn:yn) in color 'color'
9406 schaersvoo 2050
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
12110 schaersvoo 2051
        @%hlines%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%hlines red,0,0,0,5,0,-5
8366 schaersvoo 2052
        */
2053
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2054
            fill_color = stroke_color;
2055
            i=0;
2056
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 2057
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8366 schaersvoo 2058
                if(i%2 == 0 ){
2059
                    double_data[i] = get_real(infile,0); /* x */
2060
                }
2061
                else
2062
                {
2063
                    double_data[i] = get_real(infile,1); /* y */
2064
                }
2065
                i++;
2066
            }
2067
            decimals = find_number_of_digits(precision);
2068
            for(c = 0 ; c < i-1 ; c = c+2){
14208 schaersvoo 2069
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
2070
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 2071
                /* click_cnt++; */
8366 schaersvoo 2072
            }
2073
            reset();
2074
            break;
11806 schaersvoo 2075
        case HTTP:
7614 schaersvoo 2076
        /*
11806 schaersvoo 2077
         @ http x1,y1,x2,y2,http://some_adress.com
14078 bpr 2078
         @ an active html-page will be displayed in an "iframe" rectangle left top (x1:y1), right bottom (x2:y2)
11806 schaersvoo 2079
         @ do not use interactivity (or mouse) if the mouse needs to be active in the iframe
14071 bpr 2080
         @ can <b>not</b> be ''set onclick`` or ''drag xy``
12110 schaersvoo 2081
         @%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 2082
        */
11806 schaersvoo 2083
            if( js_function[DRAW_HTTP] != 1 ){ js_function[DRAW_HTTP] = 1;}
2084
            for(i=0;i<5;i++){
7614 schaersvoo 2085
                switch(i){
11806 schaersvoo 2086
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
14032 schaersvoo 2087
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
11806 schaersvoo 2088
                    case 2: int_data[2]=x2px(get_real(infile,0)) - int_data[0];break; /* width in x/y-range coord system -> pixel width */
2089
                    case 3: int_data[3]=y2px(get_real(infile,0)) - int_data[1];break; /* height in x/y-range coord system  -> pixel height */
2090
                    case 4: decimals = find_number_of_digits(precision);
2091
                            temp = get_string(infile,1);
2092
                            if(strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'");}
14208 schaersvoo 2093
                            string_length = 1 + 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);
11806 schaersvoo 2094
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length+2);
2095
                            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);
2096
                            add_to_buffer(tmp_buffer);
7614 schaersvoo 2097
                    break;
2098
                }
2099
            }
11806 schaersvoo 2100
            reset();
7614 schaersvoo 2101
            break;
11806 schaersvoo 2102
        case HTML:
8366 schaersvoo 2103
        /*
11806 schaersvoo 2104
         @ html x1,y1,x2,y2,html_string
14071 bpr 2105
         @ all tags are allowed, html code using inputfields could be read using your own javascript code. Do not use ids like 'canvas_input0' etc.
2106
         @ can be set onclick (however dragging not supported)
14038 schaersvoo 2107
         @ use keyword <a href='#centered'>centered</a> to center the html object on (x1:y1)
12110 schaersvoo 2108
         @%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 2109
        */
11806 schaersvoo 2110
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
2111
            for(i=0;i<5;i++){
2112
                switch(i){
2113
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
14032 schaersvoo 2114
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
14066 bpr 2115
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow  */
2116
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */
11806 schaersvoo 2117
                    case 4: decimals = find_number_of_digits(precision);
2118
                            temp = get_string(infile,1);
2119
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
14208 schaersvoo 2120
                            string_length = 1 + 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);
2121
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
14044 schaersvoo 2122
                            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 2123
                            add_to_buffer(tmp_buffer);
2124
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
14038 schaersvoo 2125
                            use_offset = 0;
11806 schaersvoo 2126
                            break;
2127
                    default:break;
8366 schaersvoo 2128
                }
2129
            }
2130
            break;
8386 schaersvoo 2131
 
11806 schaersvoo 2132
        case IMAGEFILL:
7614 schaersvoo 2133
        /*
11996 schaersvoo 2134
        @ imagefill x,y,scaling to xsize &times; ysize?,image_url
11874 schaersvoo 2135
        @ The next suitable <b>filled object</b> will be filled with "image_url" tiled
2136
        @ scaling to xsize &times; ysize ? ... 1 = yes 0 = no
14078 bpr 2137
        @ After pattern filling, the fill-color should be reset !
14066 bpr 2138
        @ wims getins / image from class directory: imagefill 80,80,my_image.gif
2139
        @ normal url: imagefill 80,80,0,$module_dir/gifs/my_image.gif
2140
        @ normal url: imagefill 80,80,1,http://adres/a/b/c/my_image.jpg
11874 schaersvoo 2141
        @ if dx,dy is larger than the image, the whole image will be background to the next object.
13967 schaersvoo 2142
        @%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
2143
        @%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 2144
        */
11806 schaersvoo 2145
            if( js_function[DRAW_IMAGEFILL] != 1 ){ js_function[DRAW_IMAGEFILL] = 1;}
11854 schaersvoo 2146
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
2147
             js_function[DRAW_FILLTOBORDER] = 1;
2148
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
2149
            }
11874 schaersvoo 2150
            for(i=0 ;i < 4 ; i++){
7614 schaersvoo 2151
                switch(i){
11806 schaersvoo 2152
                    case 0:int_data[0] = (int) (get_real(infile,0));break;
2153
                    case 1:int_data[1] = (int) (get_real(infile,0));break;
11874 schaersvoo 2154
                    case 2:int_data[2] = (int) (get_real(infile,0));break; /* 0 | 1 */
2155
                    case 3: URL = get_string_argument(infile,1);
14208 schaersvoo 2156
                            string_length = 1 + 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]);
2157
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11874 schaersvoo 2158
                            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 2159
                            add_to_buffer(tmp_buffer);
11874 schaersvoo 2160
                            fill_cnt++;
11806 schaersvoo 2161
                    break;
7614 schaersvoo 2162
                }
2163
            }
11806 schaersvoo 2164
            reset();
2165
        break;
14066 bpr 2166
 
14038 schaersvoo 2167
        case IMAGEPALETTE:
2168
        /*
2169
         @ imagepalette image1,image2,image3,...
14071 bpr 2170
         @ if used before & together with command <a href='#multidraw'>multidraw images,..,...,etc</a> the imag as will be presented in a small table in the 'control panel'
14246 bpr 2171
         @%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
14038 schaersvoo 2172
         */
2173
           temp = get_string(infile,1);
2174
           temp = str_replace(temp,",","\",\"");
2175
            if( use_tooltip == 1 ){canvas_error("command 'imagepalette' is incompatible with command 'intooltip tip_text',as they use the same div-element ");}
2176
            fprintf(js_include_file,"\nvar current_id;var imagepalette = [\" %s \"];\n",temp);
2177
        break;
14066 bpr 2178
 
11806 schaersvoo 2179
        case INPUTSTYLE:
2180
        /*
2181
        @ inputstyle style_description
14071 bpr 2182
        @ may be used before any ''style-able`` html object (like inputfields or buttons) or any html objects that are generated by some canvasdraw commands
12107 schaersvoo 2183
        @%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 2184
        */
2185
            input_style = get_string(infile,1);
7614 schaersvoo 2186
            break;
11806 schaersvoo 2187
        case INPUT:
2188
        /*
2189
         @ input x,y,size,editable,value
2190
         @ to set inputfield "readonly", use editable = 0
2191
         @ only active inputfields (editable = 1) will be read with read_canvas();
14246 bpr 2192
         @ 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>
14066 bpr 2193
         @ may be further controlled by <a href="#inputstyle">inputstyle</a> (inputcss is not yet implemented...)
11806 schaersvoo 2194
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (javascript:read_canvas();)
2195
         @ 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 2196
         @ 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>
2197
         @%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 2198
        */
2199
        if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
2200
            for(i = 0 ; i<5;i++){
2201
                switch(i){
2202
                    case 0: int_data[0]=x2px(get_real(infile,0));break;/* x in px */
2203
                    case 1: int_data[1]=y2px(get_real(infile,0));break;/* y in px */
2204
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break; /* size */
2205
                    case 3: if( get_real(infile,1) >0){int_data[3] = 1;}else{int_data[3] = 0;};break; /* readonly */
2206
                    case 4:
2207
                            temp = get_string_argument(infile,1);
14208 schaersvoo 2208
                            string_length = 1 + 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);
2209
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 2210
                            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);
2211
                            add_to_buffer(tmp_buffer);
2212
                            input_cnt++;break;
2213
                    default: break;
2214
                }
2215
            }
2216
            if(reply_format == 0 ){reply_format = 15;}
2217
            reset();
2218
            break;
8386 schaersvoo 2219
 
11806 schaersvoo 2220
        case INTOOLTIP:
2221
            /*
2222
            @ intooltip link_text
2223
            @ link_text is a single line (span-element)
14071 bpr 2224
            @ link_text may also be an image URL ''http://some_server/images/my_image.png`` or ''$module_dir/gifs/my_image.jpg``
11806 schaersvoo 2225
            @ link_text may contain HTML markup
14071 bpr 2226
            @ the canvas will be displayed in a tooltip on ''link_text``
2227
            @ the canvas is default transparent: use command <a href="#bgcolor">bgcolor color</a> to adjust background-color, the link text will also be shown with this 'bgcolor'.
2228
            @ many ''userinput stuff`` will use the tooltip_placeholder_div element...only one is defined in the wims-page<br />and are therefore these commands are mutually exclusive.<br />keep this in mind...
14246 bpr 2229
            @%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 2230
            */
2231
            if(use_input_xy != FALSE ){canvas_error("intooltip can not be combined with userinput_xy or other commands using the tooltip-div...see documentation");}
2232
            if( use_tooltip == 1 ){ canvas_error("command 'intooltip' cannot be combined with command 'popup'...");}
2233
            tooltip_text = get_string(infile,1);
2234
            if(strstr(tooltip_text,"\"") != 0 ){ tooltip_text = str_replace(tooltip_text,"\"","'"); }
2235
            use_tooltip = 1;
2236
            break;
2237
 
2238
        case JSCURVE:
7614 schaersvoo 2239
        /*
11893 schaersvoo 2240
         @ jscurve color,formula1(x),formula2(x),formula3(x),...
14071 bpr 2241
         @ alternative: <code>jsplot color,formula(x)</code>
11893 schaersvoo 2242
         @ your function will be plotted by the javascript engine of the client browser
2243
         @ 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
14071 bpr 2244
         @ use only basic math in your curve: <code>sqrt,^,asin,acos,atan,log,pi,abs,sin,cos,tan,e</code>
2245
         @ use parenthesis and rawmath: use 2*x instead of 2x ; use 2^(sin(x))...etc etc (use error console to debug any errors...)
2246
         @ <b>attention</b>: last ''precision`` command in the canvasdraw script determines the calculation precision of the javascript curve plot !
11806 schaersvoo 2247
         @ no validity check is done by wims.
14071 bpr 2248
         @ 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
11806 schaersvoo 2249
         @ 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 2250
         @ use keyword <a href='animate'>animate</a> for animating a point on the curve
14071 bpr 2251
         @ use command ''trace_jscurve formula(x)`` for tracing
14246 bpr 2252
         @ use command ''jsmath formula(x)`` for calculating and displaying indiviual points on the curve
11806 schaersvoo 2253
         @ can <b>not</b> be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> (yet)
14071 bpr 2254
         @ commands plotjump / plotstep are not active for ''jscurve``
11806 schaersvoo 2255
         @ every command jscurve will produce a new canvas (canvastype 111,112,113...) for this one curve.
14071 bpr 2256
         @ plotting multiple js-curves on the same canvas (for example if you want to use 'userdraw clickfill,color' on <a href="#canvastype">canvastype</a> number 111, use:<br/> <code>jscurve red,fun1(x),fun2(x)...fun_n(x)</code>, you must specify individual multistrokecolors &amp; multistrokeopacity &amp; multilinewidth for these multiple js-curves to use different colors. Otherwise all curves will be the same color... Use commands like: <a href="#multistrokecolors">multistrokecolors</a>, <a href="#multilinewidth">multilinewidth</a>, <a href="#multidash">multidash</a>, <a href="#multistrokeopacity">multistroke</a>, <b>color</b> given for the command <code>jscurve color,formulas(x)</code> will not be used in that case... but the color argument must still be given in any case (otherwise syntax error...)
12107 schaersvoo 2257
         @%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 2258
        */
2259
            stroke_color = get_color(infile,0);
2260
            if( use_js_math == FALSE){/* add this stuff only once...*/
2261
                add_to_js_math(js_include_file);
2262
                use_js_math = TRUE;
2263
            }
2264
            if( use_js_plot == FALSE){
2265
                use_js_plot = TRUE;
2266
                add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
2267
            }
11893 schaersvoo 2268
            int use_paramteric = 0;
2269
            if( tmin != 0 && tmax !=0){use_parametric = 1;}
11806 schaersvoo 2270
            temp = get_string(infile,1);
2271
            temp = str_replace(temp,",","\",\"");
14208 schaersvoo 2272
            string_length = 1 + 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);
2273
            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11893 schaersvoo 2274
            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 2275
            add_to_buffer(tmp_buffer);
2276
            jsplot_cnt++;
2277
             /* we need to create multiple canvasses, so we may zoom and pan ?? */
2278
        break;
2279
 
2280
        case JSMATH:
2281
        /*
2282
            @ jsmath some_math_function
2283
            @ will calculate an y-value from a userinput x-value and draws a crosshair on these coordinates.
14246 bpr 2284
            @ default labels ''x`` and ''y``; the commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` will set the label for the input fields
14077 bpr 2285
            @ use command 'inputstyle some_css' for styling the display fields. Use command 'fontsize int' to size the labels ''x`` and ''y``
14066 bpr 2286
            @ 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...
11806 schaersvoo 2287
            @ be aware that the formula's of the plotted function(s) can be found in the page javascript source
12111 schaersvoo 2288
            @%jsmath%size 400,400%xrange -10,10%yrange -10,10%jsplot blue,sin(x^2)%jsmath sin(x^2)
11806 schaersvoo 2289
        */
2290
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
2291
            if( use_js_math == FALSE){
2292
                add_to_js_math(js_include_file);
2293
                use_js_math = TRUE;
2294
            }
2295
            add_calc_y(js_include_file,canvas_root_id,get_string(infile,1),font_size,input_style);
2296
            break;
2297
        case KILLAFFINE:
2298
        /*
2299
        @ killaffine
14066 bpr 2300
        @ keyword: resets the transformation matrix to 1,0,0,1,0,0
11806 schaersvoo 2301
        */
2302
            use_affine = FALSE;
2303
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
2304
            break;
2305
 
2306
        case KILLROTATE:
2307
        /*
14071 bpr 2308
         @ killrotate
2309
         @ will reset the command <a href="#rotationcenter">rotationcenter xc,yc</a>
11806 schaersvoo 2310
         @ a following rotate command will have the first object point as rotation center
2311
         @ if not set, the rotation center will remain unchanged
2312
        */
2313
            rotation_center= my_newmem(6);
2314
            snprintf(rotation_center,5,"null");
2315
         break;
2316
 
2317
        case KILLSLIDER:
2318
        /*
2319
         @ killslider
2320
         @ keyword (no arguments required)
2321
         @ ends grouping of object under a previously defined slider
2322
        */
14208 schaersvoo 2323
            slider_type = "0";
2324
            current_sliders = "[-1]";
14234 schaersvoo 2325
            for(i=0;i<slider_cnt;i++){active_sliders[i]=-1;}
11806 schaersvoo 2326
            break;
2327
 
2328
        case KILLTRANSLATION:
2329
        /*
2330
         @ killtranslation
14071 bpr 2331
         @ alternative: <code>killtranslate</code>
11806 schaersvoo 2332
         @ resets the translation matrix to 1,0,0,1,0,0
2333
        */
2334
            use_affine = FALSE;
2335
            snprintf(affine_matrix,14,"[1,0,0,1,0,0]");
2336
            break;
14225 schaersvoo 2337
        case LATEX:
2338
        /*
2339
         @ latex x,y,latex string
14230 schaersvoo 2340
         @ 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
2341
         @ can be set draggable<br /> the favascript:read_dragdrop() will return all coordinates <br />in same order as the canvas script: unmoved object will have their original coordinates...
2342
         @ 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
2343
         @ 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
2344
         @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
14246 bpr 2345
         @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
14230 schaersvoo 2346
         @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
2347
         @ 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();"
2348
         @ 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....
14225 schaersvoo 2349
         @ use keyword <a href='#centered'>centered</a> to center the katex div object on (x1:y1)
14230 schaersvoo 2350
         @%latex_drag%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%snaptogrid%strokecolor red%drag xy%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%drag xy%snaptogrid%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%drag xy%snaptogrid%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%drag xy%snaptogrid%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6}
2351
         @%latex_onclick%size 400,400%xrange -10,10%yrange -10,10%grid 2,2,grey%strokecolor red%onclick%latex -6,5,\\frac{1}{2}+ \\frac{\\pi}{2}%strokecolor blue%onclick%latex -3,5,\\frac{1}{3}+ \\frac{\\pi}{3}%strokecolor green%onclick%latex 0,5,\\frac{1}{4}+ \\frac{\\pi}{4}%strokecolor orange%onclick%latex 3,5,\\frac{1}{5}+ \\frac{\\pi}{6}
14225 schaersvoo 2352
        */
2353
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
14227 schaersvoo 2354
            drag_type=-1; /* hmmm */
14225 schaersvoo 2355
            for(i=0;i<4;i++){
2356
                switch(i){
2357
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
2358
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
2359
                    case 2: decimals = find_number_of_digits(precision);
14233 schaersvoo 2360
                            temp = get_string(infile,1);
14232 schaersvoo 2361
/*          !!!! UNTIL MATHJAX IS REPLACED BY KATEX !!!!       */
2362
                            browser_type = 1;
14230 schaersvoo 2363
                            if(browser_type == 1 ){ /* GECKO needs  TEX --> MML  */
2364
                             temp = getMML(temp);
2365
                             if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
2366
                             string_length = 1 + 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);
2367
                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
2368
                             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);
2369
                            }
2370
                            else
2371
                            {
2372
                             if( strstr(temp,"\\") != 0 ){ temp = str_replace(temp,"\\","\\\\"); }
2373
                             string_length = 1 + snprintf(NULL,0,"draw_xml(%d,%d,%d,\"<div name='zoom_0' class='wims_katex' id='katex%d'>%s</div>\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],click_cnt,temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
2374
                             check_string_length(string_length);tmp_buffer = my_newmem(string_length);
2375
                             snprintf(tmp_buffer,string_length,  "draw_xml(%d,%d,%d,\"<div name='zoom_0' class='wims_katex' id='katex%d'>%s</div>\",%d,%d,%d,\"%s\",%.2f,\"%s\",%.2f,%d,%d);\n",canvas_root_id,int_data[0],int_data[1],click_cnt,temp,drag_type,onclick,click_cnt,stroke_color,stroke_opacity,fill_color,fill_opacity,use_offset,use_snap);
2376
                            }
14225 schaersvoo 2377
                            add_to_buffer(tmp_buffer);
2378
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
2379
                            use_offset = 0;
2380
                            break;
2381
                    default:break;
2382
                }
2383
            }
2384
            break;
14230 schaersvoo 2385
        case LATTICE:
2386
        /*
2387
         @ lattice x0,y0,xv1,yv1,xv2,yv2,n1,n2,color
2388
         @ can <b>not</b> be set ''onclick`` or ''drag xy``
2389
         @%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
2390
        */
2391
            if( js_function[DRAW_LATTICE] != 1 ){ js_function[DRAW_LATTICE] = 1;}
2392
            for( i = 0; i<9; i++){
2393
                switch(i){
2394
                    case 0: int_data[0] = x2px(get_real(infile,0));break; /* x0-values  -> x-pixels*/
2395
                    case 1: int_data[1] = y2px(get_real(infile,0));break; /* y0-values  -> y-pixels*/
2396
                    case 2: int_data[2] = (int) (get_real(infile,0));break; /* x1-values  -> x-pixels*/
2397
                    case 3: int_data[3] = (int) -1*(get_real(infile,0));break; /* y1-values  -> y-pixels*/
2398
                    case 4: int_data[4] = (int) (get_real(infile,0));break; /* x2-values  -> x-pixels*/
2399
                    case 5: int_data[5] = (int) -1*(get_real(infile,0));break; /* y2-values  -> y-pixels*/
2400
                    case 6: int_data[6] = (int) (get_real(infile,0));break; /* n1-values */
2401
                    case 7: int_data[7] = (int) (get_real(infile,0));break; /* n2-values */
2402
                    case 8: stroke_color=get_color(infile,1);
2403
                        decimals = find_number_of_digits(precision);
2404
                        string_length = 1 + 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);
2405
                        check_string_length(string_length);tmp_buffer = my_newmem(string_length);
2406
                        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);
2407
                        add_to_buffer(tmp_buffer);break;
2408
                    default:break;
2409
                }
2410
            }
2411
            reset();
2412
            break;
2413
 
11806 schaersvoo 2414
        case LINE:
2415
        /*
2416
        @ line x1,y1,x2,y2,color
2417
        @ draw a line through points (x1:y1)--(x2:y2) in color 'color'
14071 bpr 2418
        @ or use command ''curve color,formula`` to draw the line <br />(uses more points to draw the line; is however better draggable)
9406 schaersvoo 2419
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 2420
        @%line%size 400,400%xrange -10,10%yrange -10,10%line 0,1,2,-1,green
7614 schaersvoo 2421
        */
8386 schaersvoo 2422
            for(i=0;i<5;i++){
7614 schaersvoo 2423
                switch(i){
11806 schaersvoo 2424
                    case 0: double_data[10]= get_real(infile,0);break; /* x-values */
2425
                    case 1: double_data[11]= get_real(infile,0);break; /* y-values */
2426
                    case 2: double_data[12]= get_real(infile,0);break; /* x-values */
2427
                    case 3: double_data[13]= get_real(infile,0);break; /* y-values */
2428
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
2429
                    if( double_data[10] == double_data[12] ){ /* vertical line*/
2430
                        double_data[1] = xmin;
2431
                        double_data[3] = ymax;
2432
                        double_data[0] = double_data[10];
2433
                        double_data[2] = double_data[10];
2434
                    }
2435
                    else
2436
                    {
2437
                        if( double_data[11] == double_data[13] ){ /* horizontal line */
2438
                            double_data[1] = double_data[11];
2439
                            double_data[3] = double_data[11];
2440
                            double_data[0] = ymin;
2441
                            double_data[2] = xmax;
2442
                        }
2443
                        else
2444
                        {
2445
                        /* m */
2446
                        double_data[5] = (double_data[13] - double_data[11]) /(double_data[12] - double_data[10]);
2447
                        /* q */
2448
                        double_data[6] = double_data[11] - ((double_data[13] - double_data[11]) /(double_data[12] - double_data[10]))*double_data[10];
2449
 
2450
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
2451
 
2452
                            double_data[1] = (double_data[5])*(xmin)+(double_data[6]);
2453
                            double_data[3] = (double_data[5])*(xmax)+(double_data[6]);
2454
                            double_data[0] = xmin;
2455
                            double_data[2] = xmax;
2456
                        }
2457
                    }
2458
                    decimals = find_number_of_digits(precision);
14208 schaersvoo 2459
                    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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
2460
                    if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 2461
                    /* click_cnt++;*/
2462
                    reset();
2463
                    break;
7614 schaersvoo 2464
                }
2465
            }
2466
            break;
8386 schaersvoo 2467
 
11806 schaersvoo 2468
        case LINES:
8370 schaersvoo 2469
        /*
11806 schaersvoo 2470
        @ lines color,x1,y1,x2,y2...x_n-1,y_n-1,x_n,y_n
2471
        @ draw multiple lines through points (x1:y1)--(x2:y2) ...(x_n-1:y_n-1)--(x_n:y_n) in color 'color'
14071 bpr 2472
        @ 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)
11806 schaersvoo 2473
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
14071 bpr 2474
        @ <b>attention</b>: the flydraw command ''lines`` is equivalent to canvasdraw command <a href="#polyline">polyline</a>
12107 schaersvoo 2475
        @%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 2476
        */
2477
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
2478
            fill_color = stroke_color;
2479
            i=0;
2480
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 2481
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8370 schaersvoo 2482
                if(i%2 == 0 ){
2483
                    double_data[i] = get_real(infile,0); /* x */
2484
                }
2485
                else
2486
                {
2487
                    double_data[i] = get_real(infile,1); /* y */
2488
                }
2489
                i++;
2490
            }
2491
            decimals = find_number_of_digits(precision);
2492
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 2493
                if( double_data[c] == double_data[c+2] ){ /* vertical line*/
2494
                    double_data[c+1] = xmin;
2495
                    double_data[c+3] = ymax;
2496
                    double_data[c+2] = double_data[c];
2497
                }
2498
                else
2499
                {
2500
                    if( double_data[c+1] == double_data[c+3] ){ /* horizontal line */
2501
                        double_data[c+3] = double_data[c+1];
2502
                        double_data[c] = ymin;
2503
                        double_data[c+2] = xmax;
2504
                    }
2505
                    else
2506
                    {
2507
                        /* m */
2508
                        double m = (double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]);
2509
                        /* q */
2510
                        double q = double_data[c+1] - ((double_data[c+3] - double_data[c+1]) /(double_data[c+2] - double_data[c]))*double_data[c];
2511
                        /*xmin,m*xmin+q,xmax,m*xmax+q*/
2512
                        double_data[c+1] = (m)*(xmin)+(q);
2513
                        double_data[c+3] = (m)*(xmax)+(q);
2514
                        double_data[c] = xmin;
2515
                        double_data[c+2] = xmax;
2516
                    }
2517
                }
14208 schaersvoo 2518
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
2519
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 2520
                /* click_cnt++; */
8370 schaersvoo 2521
            }
2522
            reset();
2523
            break;
8386 schaersvoo 2524
 
11806 schaersvoo 2525
 
2526
        case LINEWIDTH:
7614 schaersvoo 2527
        /*
11806 schaersvoo 2528
        @ linewidth int
2529
        @ default 1
12107 schaersvoo 2530
        @%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 2531
        */
11806 schaersvoo 2532
            line_width = (int) (get_real(infile,1));
2533
            break;
2534
 
2535
        case LEVELCURVE:
8363 schaersvoo 2536
        /*
11806 schaersvoo 2537
        @ levelcurve color,expression in x/y,l1,l2,...
2538
        @ draws very primitive level curves for expression, with levels l1,l2,l3,...,l_n
2539
        @ the quality is <b>not to be compared</b> with the Flydraw levelcurve. <br />(choose flydraw if you want quality...)
2540
        @ 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
14066 bpr 2541
        @ note: the arrays for holding the javascript data are limited in size
2542
        @ 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 2543
        @%levelcurve%size 400,400%xrange -10,10%yrange -10,10%levelcurve red,x*y,1,2,3,4
8363 schaersvoo 2544
        */
11806 schaersvoo 2545
            fill_color = get_color(infile,0);
2546
            char *fun1 = get_string_argument(infile,0);
2547
            if( strlen(fun1) == 0 ){canvas_error("function is NOT OK !");}
2548
            i = 0;
2549
            done = FALSE;
2550
            while( !done ){
2551
             double_data[i] = get_real(infile,1);
2552
             i++;
2553
            }
2554
            for(c = 0 ; c < i; c++){
14208 schaersvoo 2555
             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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
2556
             if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 2557
             /* click_cnt++; */
2558
            }
2559
            reset();
2560
            break;
8386 schaersvoo 2561
 
11806 schaersvoo 2562
        case LEGEND:
2563
        /*
2564
        @ legend string1:string2:string3....string_n
2565
        @ will be used to create a legend for a graph
14066 bpr 2566
        @ also see command <a href='#piechart'>piechart</a>
14071 bpr 2567
        @ will use the same colors per default as used in the graphs; use command <a href='#legendcolors'>legendcolors</a> to override the default
14086 bpr 2568
        @ use command <a href="#fontsize">fontsize</a> to adjust. (command ''fontfamily`` is not active for command ''legend``)
14066 bpr 2569
        @%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 2570
        */
2571
            temp = get_string(infile,1);
2572
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
14066 bpr 2573
            legend_cnt++; /* attention: starts with -1: it will be used in piechart etc */
11806 schaersvoo 2574
            fprintf(js_include_file,"var legend%d = [\"%s\"];",legend_cnt,temp);
2575
            break;
2576
 
2577
        case LEGENDCOLORS:
2578
        /*
2579
        @ legendcolors color1:color2:color3:...:color_n
2580
        @ 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
2581
        @ make sure the number of colours match the number of legend items
2582
        @ command 'legend' in case of 'piechart' and 'barchart' will use these colours per default (no need to specify 'legendcolors'
13960 bpr 2583
        @%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 2584
        */
2585
            if(legend_cnt == -1){canvas_error("use command \"legend\" before command \"legendcolors\" ! ");}
2586
            temp = get_string(infile,1);
2587
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2588
            fprintf(js_include_file,"var legendcolors%d = [\"%s\"];",legend_cnt,temp);
2589
            break;
2590
 
14078 bpr 2591
        case LINEGRAPH: /* scheme: var linegraph_0 = [ 'stroke_color','line_width','use_dashed', 'dashtype0','dashtype1','x1','y1',...,'x_n','y_n'];*/
11806 schaersvoo 2592
        /*
2593
        @ linegraph x1:y1:x2:y2...x_n:y_n
2594
        @ will plot your data in a graph
14066 bpr 2595
        @ may <b>only</b> to be used together with command <a href='#grid'>grid</a>
2596
        @ 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>
2597
        @ use command <a href='#legend'>legend</a> to provide an optional legend in right-top-corner
2598
        @ also see command <a href='#piechart'>piechart</a>
11806 schaersvoo 2599
        @ multiple linegraphs may be used in a single plot
14066 bpr 2600
        @ note: your arguments are not checked by canvasdraw: use your javascript console in case of trouble...
14247 bpr 2601
        @ <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 2602
        @%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 2603
        */
2604
            temp = get_string(infile,1);
2605
            if( strstr( temp,":") != 0 ){ temp = str_replace(temp,":","\",\""); }
2606
            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);
2607
            linegraph_cnt++;
2608
            reset();
2609
            break;
2610
 
2611
        case MATHML:
2612
        /*
2613
        @ mathml x1,y1,x2,y2,mathml_string
14230 schaersvoo 2614
        @ this command is special for GECKO browsers, and it makes use of Native Mathml
14247 bpr 2615
        @ For use with all browsers use command, <a href='#latex'>latex</a>
14038 schaersvoo 2616
        @ the mathml object is centered at (x1:y1)
14247 bpr 2617
        @ the ``mathml_string'' can be produced using WIMS commands like ``texmath'' followed by ``mathmlmath''... or write correct TeX and use only ``mathmlmath''
13829 bpr 2618
        @ 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.
14246 bpr 2619
        @ in case of drag(xy|x|y) | onclick the div rectangle left to corner will be the drag-anchor of the mathml object
14247 bpr 2620
        @ can be set onclick <code>javascript:read_dragdrop();</code> will return click numbers of mathml-objects; if 4 clickable object are drawn, the reply could be 1,0,1,0 ... meaning clicked on the first and third object
2621
        @ can be set draggable<br /> <code>javascript:read_dragdrop()</code> will return all coordinates in same order as the canvas script: unmoved objects will have their original coordinates...
2622
        @ snaptogrid is supported...snaptopoints will work, but use with care... due to the primitive dragging. Technically: the dragstuff library is not used... the mathml is embedded in a new div element and not in the html5-canvas.
2623
        @ 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 2624
        @ userdraw may be combined with 'mathml' ; the read_canvas() will contain the drawing.
14246 bpr 2625
        @ draggable or onclick 'external images' from command <a href='#copyresized'>copy or copyresized</a> can be combined with drag and/or onclick mathml
14078 bpr 2626
        @ other drag objects (circles/rects etc) are supported, but read_dragdrop() will probably be difficult to interpret...
14066 bpr 2627
        @ 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();"
11806 schaersvoo 2628
        @ 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 2629
        @ use keyword <a href='#centered'>centered</a> to center the mathml/xml object on (x1:y1)
14246 bpr 2630
        @%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>
2631
        @%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 2632
        */
14227 schaersvoo 2633
            if( browser_type == 0 ){ break;} /* should use command latex */
14062 schaersvoo 2634
            if(use_offset == 0){use_offset = 4;} /* always centered if not otherwise stated ! */
11806 schaersvoo 2635
            if( js_function[DRAW_XML] != 1 ){ js_function[DRAW_XML] = 1;}
2636
            for(i=0;i<5;i++){
2637
                switch(i){
2638
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in x/y-range coord system -> pixel width */
14032 schaersvoo 2639
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in x/y-range coord system  -> pixel height */
14066 bpr 2640
                    case 2: int_data[2]=x2px(get_real(infile,0));break;/* no more width needed: overflow  */
2641
                    case 3: int_data[3]=y2px(get_real(infile,0));break;/* no more height needed: overflow */
11806 schaersvoo 2642
                    case 4: decimals = find_number_of_digits(precision);
2643
                            temp = get_string(infile,1);
2644
                            if( strstr(temp,"\"") != 0 ){ temp = str_replace(temp,"\"","'"); }
14208 schaersvoo 2645
                            string_length = 1 + 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);
2646
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
14044 schaersvoo 2647
                            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 2648
                            add_to_buffer(tmp_buffer);
2649
                            if(onclick == 1 || onclick == 2 ){click_cnt++;}
14038 schaersvoo 2650
                            use_offset=0;
11806 schaersvoo 2651
                            /*
14078 bpr 2652
                             in case inputs are present, trigger adding the read_mathml()
11806 schaersvoo 2653
                             if no other reply_format is defined
2654
                             note: all other reply types will include a reading of elements with id='mathml'+p)
2655
                             */
2656
                            if(strstr(temp,"mathml0") != NULL){
2657
                             if(reply_format == 0 ){reply_format = 16;} /* no other reply type is defined */
2658
                            }
2659
                            break;
2660
                    default:break;
2661
                }
2662
            }
2663
            break;
2664
 
2665
        case MOUSE:
2666
        /*
2667
         @ mouse color,fontsize
14246 bpr 2668
         @ will display the cursor (x:y) coordinates in 'color' and 'font size'<br /> using default fontfamily Ariel
11806 schaersvoo 2669
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
12107 schaersvoo 2670
         @%mouse%size 400,400%xrange -10,10%yrange -10,10%mouse red,22
11806 schaersvoo 2671
        */
2672
            stroke_color = get_color(infile,0);
2673
            font_size = (int) (get_real(infile,1));
2674
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2675
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2676
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,2);
2677
            break;
2678
 
2679
 
2680
        case MOUSE_DEGREE:
2681
        /*
2682
         @ mouse_degree color,fontsize
2683
         @ 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
2684
         @ The angle is positive in QI and QIII and the angle value is negative in QII and QIV
2685
         @ note: use command 'mouse' at the end of your script code (the same is true for command 'zoom')
12107 schaersvoo 2686
         @%mouse_degree%size 400,400%xrange -10,10%yrange -10,10%userdraw arc,blue%precision 100000%mouse_degree red,22
11806 schaersvoo 2687
        */
2688
            stroke_color = get_color(infile,0);
2689
            font_size = (int) (get_real(infile,1));
2690
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2691
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2692
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,3);
2693
            js_function[JS_FIND_ANGLE] = 1;
2694
            break;
2695
        case MOUSE_DISPLAY:
2696
        /*
2697
         @ display TYPE,color,fontsize
2698
         @ TYPE may be x | y | xy | degree | radian | radius
14247 bpr 2699
         @ will display the mouse cursor coordinates as x-only,y-only,(x:y), the radius of a circle (this only in case 'userdraw circle(s),color') or the angle in degrees or radians for commands <code>userdraw arc,color</code> or protractor, ruler (if set dynamic).
2700
         @ use commands ``xunit'' and / or ``yunit'' to add the units to the mouse values. The ``degree | radian'' will always have the appropriate symbol).
14077 bpr 2701
         @ just like commands ''mouse``, ''mousex``, ''mousey``, ''mouse_degree``... only other name
12111 schaersvoo 2702
         @%display_x%size 400,400%xrange -10,10%yrange -10,10%xunit \\u212B%display x,red,22
12107 schaersvoo 2703
         @%display_y%size 400,400%xrange -10,10%yrange -10,10%yunit seconds%display y,red,22
13936 bpr 2704
         @%display_xy%size 400,400%xrange -10,10%yrange -10,10%xunit centimetre%yunit seconds%display xy,red,22%userdraw segments,blue
12107 schaersvoo 2705
         @%display_deg%size 400,400%xrange -10,10%yrange -10,10%display degree,red,22%fillcolor orange%opacity 200,50%userdraw arc,blue
2706
         @%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 2707
         @%display_radius%size 400,400%xrange -10,10%yrange -10,10%xunit cm%xunit \\u212b%display radius,red,22%userdraw circle,blue
11806 schaersvoo 2708
        */
2709
        temp = get_string_argument(infile,0);
2710
        if( strstr(temp,"xy") != NULL ){
2711
            int_data[0] = 2;
2712
        }else{
2713
            if( strstr(temp,"y") != NULL ){
2714
                int_data[0] = 1;
2715
            }else{
2716
                if( strstr(temp,"x") != NULL ){
2717
                    int_data[0] = 0;
2718
                }else{
2719
                    if(strstr(temp,"degree") != NULL){
2720
                        int_data[0] = 3;
2721
                        js_function[JS_FIND_ANGLE] = 1;
2722
                    }else{
2723
                        if(strstr(temp,"radian") != NULL){
2724
                            int_data[0] = 4;
2725
                            js_function[JS_FIND_ANGLE] = 1;
2726
                        }else{
2727
                            if(strstr(temp,"radius") != NULL){
2728
                                int_data[0] = 5;
2729
                            }else{
2730
                                int_data[0] = 2;
2731
                            }
2732
                        }
2733
                    }
2734
                }
2735
            }
2736
        }
2737
        stroke_color = get_color(infile,0);
2738
        font_size = (int) (get_real(infile,1));
2739
        tmp_buffer = my_newmem(26);
13371 schaersvoo 2740
        snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2741
        add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,int_data[0]);
2742
        break;
2743
 
2744
        case MOUSE_PRECISION:
2745
        /*
2746
            @ precision int
2747
            @ 1 = no decimals ; 10 = 1 decimal ; 100 = 2 decimals etc
2748
            @ may be used / changed before every object
14247 bpr 2749
            @ 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 2750
            @%precision%size 400,400%xrange -10,10%yrange -10,10%precision 1%userdraw segment,red
11806 schaersvoo 2751
        */
2752
            precision = (int) (get_real(infile,1));
2753
            if(precision < 1 ){precision = 1;};
2754
            break;
2755
 
2756
        case MOUSEX:
2757
        /*
2758
         @ mousex color,fontsize
14247 bpr 2759
         @ will display the cursor x-coordinate in ''color`` and ''font size`` using the fontfamily Ariel.
2760
         @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
11806 schaersvoo 2761
 
2762
        */
2763
            stroke_color = get_color(infile,0);
2764
            font_size = (int) (get_real(infile,1));
2765
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2766
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2767
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,0);
2768
            break;
2769
        case MOUSEY:
2770
        /*
2771
         @ mousey color,fontsize
14247 bpr 2772
         @ will display the cursor y-coordinate in ''color`` and ''font size`` using default fontfamily Ariel.
2773
         @ note: use command ''mouse`` at the end of your script code (the same is true for command ''zoom``).
11806 schaersvoo 2774
 
2775
        */
2776
            stroke_color = get_color(infile,0);
2777
            font_size = (int) (get_real(infile,1));
2778
            tmp_buffer = my_newmem(26);
13371 schaersvoo 2779
            snprintf(tmp_buffer,26,"use_mouse_coordinates();\n");add_to_buffer(tmp_buffer);
11806 schaersvoo 2780
            add_js_mouse(js_include_file,MOUSE_CANVAS,canvas_root_id,precision,stroke_color,font_size,stroke_opacity,1);
2781
            break;
2782
 
2783
        case MULTIDASH:
2784
        /*
2785
         @ multidash 0,1,1
14071 bpr 2786
         @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, are dashed
14066 bpr 2787
         @ use before command <a href='#multidraw'>multidraw</a>
14247 bpr 2788
         @ if not set all objects will be set ''not dashed``... unless a generic keyword ''dashed`` was given before command ''multidraw``
14071 bpr 2789
         @ the dash-type is not -yet- adjustable <br />(e.g. command <code>dashtype line_px,space_px</code> will give no control over multidraw objects)
11806 schaersvoo 2790
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
14077 bpr 2791
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2792
        */
2793
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2794
            temp = get_string(infile,1);
2795
            temp = str_replace(temp,",","\",\"");
2796
            fprintf(js_include_file,"var multidash = [\"%s\"];",temp);
2797
            reset();/* if command 'dashed' was given...reset to not-dashed */
2798
            break;
2799
 
2800
        case MULTIDRAW:
2801
        /*
2802
         @ multidraw obj_type_1,obj_type_2...obj_type_11
14066 bpr 2803
         @ for simple single object user drawings you could also use command <a href="#userdraw">userdraw</a>
14177 bpr 2804
         @ 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><curvedarrow | curvedarrows</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 polygon 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>
14077 bpr 2805
         @ 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
14086 bpr 2806
         @ 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 2807
         @ 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)
14078 bpr 2808
         @ buttons for changing the obj_type (and in case 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'
2809
         @ 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 /><code>multilabel cirkel,lijnstuk,punten,STOP<br />multidraw circle,segment,points</code><br />(see command <a href='#multilabel'>multilabel</a> for more details)
14063 schaersvoo 2810
         @ a right mouse button click will remove the last drawn object of the selected drawing type. All other type of objects are not removed
14071 bpr 2811
         @ multidraw is incompatible with command ''tooltip`` (the reserved div_area is used for the multidraw control buttons)
2812
         @ all ''multidraw`` drawings will scale on zooming.<br />this in contrast to the command <a href="#userdraw">userdraw</a>.
11806 schaersvoo 2813
         @ wims will <b>not</b> check the amount or validity of your command arguments ! <br />( use javascript console to debug any typo's )
14248 bpr 2814
         @ 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_id<br />line 13 = curvedarrows_x +";"+ curvedarrows_y +"\\n"<br />line 14 = curvedarrows2_x +";"+ curvedarrows2_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>
14246 bpr 2815
         @ 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 />
14092 bpr 2816
         @ <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.
14071 bpr 2817
         @ 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.
14247 bpr 2818
         @ 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 <code>multiuserinput 1</code> for ''images``) 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 /><code>&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;</code><br />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
14246 bpr 2819
         @ 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 (making typos 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 /><code>&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; </code><br/> If using multiple canvas scripts in a single page, loop through the canvas_scripts[n] <br />note: if using NOCONTROLS and just a single draw primitive (for example, just: 'multidraw circles'), the object may be drawn directly. (analogue to 'userdraw circles,color')<br />And since a right mouse button click will always remove the last drawn object of the current object type, there is no need for a special "remove button"
12107 schaersvoo 2820
         @%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
14246 bpr 2821
         @%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 2822
         @%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
14063 schaersvoo 2823
         @%multidraw_NOCONTROLS%size 400,400%%xrange -10,10%yrange -10,10%grid 2,2,grey%linewidth 3%strokecolor green%fillcolor blue%filled%opacity 255,60%multilabel NOCONTROLS%multidraw circles%# RIGHT MOUSE CLICK REMOVES LAST OBJECT
11806 schaersvoo 2824
        */
14038 schaersvoo 2825
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
11806 schaersvoo 2826
            if( use_userdraw == TRUE ){canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");}
2827
            use_userdraw = TRUE;
2828
            /* LET OP max 6 DRAW PRIMITIVES + TEXT */
2829
            temp = get_string(infile,1);
2830
            temp = str_replace(temp,",","\",\"");
14044 schaersvoo 2831
            /* if these are not set, set the default values for the 18 (more than enough !)  draw_primitives + draw_text */
14066 bpr 2832
                /* int use_snap = 0;  0 = none 1=grid: 2=x-grid: 3=y-grid: 4=snap to points */
14044 schaersvoo 2833
 
11806 schaersvoo 2834
            fprintf(js_include_file,"\
14044 schaersvoo 2835
            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 2836
            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'];};\
2837
            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'];};\
2838
            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'];};\
2839
            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'];};\
2840
            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'];};\
2841
            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'];};\
2842
            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 2843
            if( typeof(multilabel) === 'undefined' && multilabel == null ){ var multilabel = [\"%s\",\"stop drawing\"];};\
14044 schaersvoo 2844
            if( typeof(multiuserinput) === 'undefined' && multiuserinput == null ){ var multiuserinput = ['0','0','0','0','0','0','0','0'];};\
11806 schaersvoo 2845
            var arrow_head = %d;var multifont_color = '%s';var multifont_family = '%s';",
14044 schaersvoo 2846
            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 2847
            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,
2848
            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,
2849
            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,
2850
            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,
2851
            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,
2852
            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,
2853
            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 2854
            temp,arrow_head,font_color,font_family);
2855
 
2856
            if(strstr(temp,"text") != NULL){
2857
             if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
2858
            }
2859
 
2860
            /* the canvasses range from 1000 ... 1008 */
14038 schaersvoo 2861
            add_js_multidraw(js_include_file,canvas_root_id,temp,input_style,use_offset);
11806 schaersvoo 2862
            reply_precision = precision;
2863
            if( reply_format == 0){reply_format = 29;}
2864
            reset();/* if command 'filled' / 'dashed' was given...reset all */
2865
            break;
2866
        case MULTILABEL:
2867
        /*
2868
         @ multilabel button_label_1,button_label_2,...,button_label_8,'stop drawing text'
14066 bpr 2869
         @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 2870
         @ 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'...)
2871
         @ the ''stop drawing`` button text <b>must</b> be the last item on the ''multilabel`` -list <br />for example:<br /><code>multilabel punten,lijnen,Stop met Tekenen<br />multidraw points,lines</code>
2872
         @ all buttons can be ''styled`` by using command <code>inputstyle</code><br /><b>note:</b>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``
11806 schaersvoo 2873
         @ wims will not check the amount or validity of your input
14071 bpr 2874
         @ always use the same sequence as is used for ''multidraw``
2875
         @ if you don't want the controls, and want to write your own interface, set <code>multilabel NOCONTROLS</code>
11806 schaersvoo 2876
        */
2877
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2878
            temp = get_string(infile,1);
2879
            temp = str_replace(temp,",","\",\"");
2880
            fprintf(js_include_file,"var multilabel = [\"%s\"];",temp);
2881
            break;
2882
        case MULTILINEWIDTH:
2883
        /*
2884
         @ multilinewidth linewidth_1,linewidth_2,...,linewidth_8
14066 bpr 2885
         @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 2886
         @ if not set all line widths will be set by a previous command ''linewidth int``
2887
         @ use these up to 7 different line widths for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code>
11806 schaersvoo 2888
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
14071 bpr 2889
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2890
        */
2891
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2892
            temp = get_string(infile,1);
2893
            temp = str_replace(temp,",","\",\"");
2894
            fprintf(js_include_file,"var multilinewidth = [\"%s\"];",temp);
2895
            break;
2896
        case MULTIFILL:
2897
        /*
2898
         @ multifill 0,0,1,0,1,0,0
14071 bpr 2899
         @ meaning draw objects no. 3 and 5, in the list of command ''multifill``, are filled (if the object is fillable...and not a line,segment,arrow or point...)
14066 bpr 2900
         @ use before command <a href='#multidraw'>multidraw</a>
14246 bpr 2901
         @ if not set all objects -except point|points- will be set ''not filled``... unless a command <code>filled</code> was given before command <code>multifill</code>
14078 bpr 2902
         @ only suitable for draw_primitives like ''circle | circles``, ''triangle | triangles`` and ''polygon``
11806 schaersvoo 2903
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
14071 bpr 2904
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2905
        */
2906
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2907
            temp = get_string(infile,1);
2908
            temp = str_replace(temp,",","\",\"");
2909
            fprintf(js_include_file,"var multifill = [\"%s\"];",temp);
2910
            break;
2911
 
2912
        case MULTIFILLCOLORS:
2913
        /*
2914
         @ multifillcolors color_name_1,color_name_2,...,color_name_8
14066 bpr 2915
         @ use before command <a href='#multidraw'>multidraw</a>
14078 bpr 2916
         @ if not set all fillcolors (for circle | triangle | poly[3-9] | closedpoly ) will be ''stroke_color``, ''fill_opacity``
14071 bpr 2917
         @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_n</code>
11806 schaersvoo 2918
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
14071 bpr 2919
         @ always use the same sequence as is used for ''multidraw'
14078 bpr 2920
         @ 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>
11806 schaersvoo 2921
        */
2922
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2923
            fprintf(js_include_file,"var multifillcolors = [");
2924
            while( ! done ){
2925
                temp = get_color(infile,1);
2926
                fprintf(js_include_file,"\"%s\",",temp);
2927
            }
2928
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2929
            break;
2930
 
2931
        case MULTIFILLOPACITY:
2932
        /*
2933
         @ multifillopacity fill_opacity_1,fill_opacity_2,...,fill_opacity_8
2934
         @ float values 0 - 1 or integer values 0 - 255
14066 bpr 2935
         @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 2936
         @ if not set all fill opacity_ will be set by previous command <code>opacity int,int</code> and keyword ''filled``
2937
         @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_y</code>
11806 schaersvoo 2938
         @ wims will not check the amount or validity of your input
14071 bpr 2939
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2940
        */
2941
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2942
            temp = get_string(infile,1);
2943
            temp = str_replace(temp,",","\",\"");
2944
            fprintf(js_include_file,"var multifillopacity = [\"%s\"];",temp);
2945
            break;
2946
        case MULTISNAPTOGRID:
2947
        /*
2948
         @ multisnaptogrid 0,1,1
14071 bpr 2949
         @ alternative: <code>multisnap</code>
2950
         @ meaning draw objects no. 2 (circle) and 3 (segments), in the list of command like <code>multifill points,circle,segments</code>, will snap to the xy-grid (default 1 in x/y-coordinate system: see command <a href='#snaptogrid'>snaptogrid</a>)
2951
         @ freehand drawing...specify precision for reply: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
14246 bpr 2952
         @ only the xy-values snap_to_grid: all objects snap to grid <code>multisnaptogrid 1,1,1,...</code>
14071 bpr 2953
         @ only the x-values snap_to_grid: all objects snap to x-grid <code>multisnaptogrid 2,2,2,...</code>
2954
         @ only the y-values snap_to_grid: all objects snap to y-grid <code>multisnaptogrid 3,3,3,...</code>
2955
         @ if <a href='#snaptopoints'>snaptopoints</a> is defined: all objects snap to points <code>multisnaptogrid 4,4,4,...</code> <br /><b>make sure to define the points to snap on...</b> use command <a href='#snaptopoints'>snaptopoints</a>
2956
         @ <code>multisnaptogrid 0,1,2,3,4<br />multidraw text,arrow,line,circle,image</code><br />''text`` is free hand, ''arrow`` is snap to grid, ''line`` is snap to x-grid, ''circle`` is snap to y-grid, ''image`` is snap to points defined by command <a href='#snaptopoints'>snaptopoints</a>
14066 bpr 2957
         @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 2958
         @ attention: if not set all objects will be set ''no snap``... unless a generic command ''snaptogrid`` was given before command ''multidraw``
2959
         @ 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 command <a href='#userdraw'>userdraw</a>
2960
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2961
         @ wims will <b>not</b> check if the number of 0 or 1's matches the amount of draw primitives...
2962
        */
2963
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2964
            temp = get_string(infile,1);
14038 schaersvoo 2965
            fprintf(js_include_file,"var multisnaptogrid = [%s];",temp);
11806 schaersvoo 2966
            reset();/* if command 'dashed' was given...reset to not-dashed */
2967
            break;
2968
        case MULTISTROKECOLORS:
2969
        /*
2970
         @ multistrokecolors color_name_1,color_name_2,...,color_name_8
14066 bpr 2971
         @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 2972
         @ if not set all colors will be ''stroke_color``, ''stroke_opacity``
2973
         @ use these up to 6 colors for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code>
11806 schaersvoo 2974
         @ wims will <b>not</b> check if the number of colours matches the amount of draw primitives...
14071 bpr 2975
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2976
        */
2977
            if( use_tooltip == 1 ){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2978
            fprintf(js_include_file,"var multistrokecolors = [");
2979
            while( ! done ){
2980
                temp = get_color(infile,1);
2981
                fprintf(js_include_file,"\"%s\",",temp);
2982
            }
2983
            fprintf(js_include_file,"\"0,0,0\"];");/* add black to avoid trouble with dangling comma... */
2984
            break;
2985
        case MULTISTROKEOPACITY:
2986
        /*
2987
         @ multistrokeopacity stroke_opacity_1,stroke_opacity_2,...,stroke_opacity_7
2988
         @ float values 0 - 1 or integer values 0 - 255
14066 bpr 2989
         @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 2990
         @ if not set all stroke opacity_ will be set by previous command <code>opacity int,int</code>
2991
         @ use these up to 7 different stroke opacities for the draw primitives used by command <code>multidraw obj_type_1,obj_type_2...obj_type_7</code>
11806 schaersvoo 2992
         @ wims will not check the amount or validity of your input
14071 bpr 2993
         @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 2994
        */
2995
            if( use_tooltip == 1){canvas_error("command 'multidraw' is incompatible with command 'intooltip tip_text'");}
2996
            temp = get_string(infile,1);
2997
            temp = str_replace(temp,",","\",\"");
2998
            fprintf(js_include_file,"var multistrokeopacity = [\"%s\"];",temp);
2999
            break;
3000
 
3001
        case MULTIUSERINPUT:
3002
        /*
3003
        @ multiuserinput 0,1,1,0
14071 bpr 3004
        @ alternative: <code>multiinput</code>
3005
        @ meaning, when the command ''multidraw`` is used <code>multidraw circles,points,lines,triangles</code><br />objects ''points`` and ''lines`` may additionally be ''drawn`` by direct input (inputfields)<br/>all other objects must be drawn with a mouse
3006
        @ in case of circle | circles a third inputfield for Radius (R) is added. 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
14086 bpr 3007
        @ 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...
11806 schaersvoo 3008
        @ in case of a triangle | poly3, three inputfields are provided.
14086 bpr 3009
        @ in case of ''text`` and ``multiuserinput=1, 3'' inputfields will be shown: ''x,y,text``
3010
        @ in case of ''text`` and ``multiuserinput=0, 1'' inputfield will be shown: text ... a mouse click will place the text on the canvas.
14066 bpr 3011
        @ may be styled using command <a href="#inputstyle">inputstyle</a>
14071 bpr 3012
        @ an additional button ''stop drawing`` may be used to combine userbased drawings with ''drag&amp;drop`` or ''onclick`` elements
3013
        @ when exercise if finished (status=done) the buttons will not be shown.<br />To override this default behaviour use command / keyword ''status``
14066 bpr 3014
        @ use before command <a href='#multidraw'>multidraw</a>
14071 bpr 3015
        @ always use the same sequence as is used for ''multidraw``
11806 schaersvoo 3016
        */
3017
            /* simple rawmath and input check */
3018
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
3019
            temp = get_string(infile,1);
3020
            temp = str_replace(temp,",","\",\"");
3021
            fprintf(js_include_file,"var multiuserinput = [\"%s\"];",temp);
3022
            break;
3023
 
3024
        case NOXAXIS:
3025
        /*
13829 bpr 3026
        @ noaxis
11806 schaersvoo 3027
        @ keyword
3028
        @ if set, the automatic x-axis numbering will be ignored
13936 bpr 3029
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>
11806 schaersvoo 3030
        @ to be used before command grid (see <a href="#grid">command grid</a>)
3031
        */
11891 schaersvoo 3032
            fprintf(js_include_file,"x_strings = {};x_strings_up = [];\n");
3033
            use_axis_numbering = -1;
11806 schaersvoo 3034
            break;
3035
        case NOYAXIS:
3036
        /*
13829 bpr 3037
        @ noayis
11806 schaersvoo 3038
        @ keyword
3039
        @ if set, the automatic y-axis numbering will be ignored
13936 bpr 3040
        @ use command <a href="#axis">axis</a> to have a visual x/y-axis lines (see command <a href="#grid">grid</a>
11806 schaersvoo 3041
        @ to be used before command grid (see <a href="#grid">command grid</a>)
3042
        */
11891 schaersvoo 3043
            fprintf(js_include_file,"y_strings = {};\n");
11806 schaersvoo 3044
            break;
11890 schaersvoo 3045
        case NUMBERLINE:
3046
        /*
3047
        @ numberline x0,x1,xmajor,xminor,y0,y1
3048
        @ numberline is using xrange/yrange system for all dimensions
11996 schaersvoo 3049
        @ 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 3050
        @ x0 is start x-value in xrange
3051
        @ x1 is end x-value in xrange
3052
        @ xmajor is step for major division
14071 bpr 3053
        @ xminor is divisor of xmajor; using small (30% of major tick) tick marks: this behaviour is ''hardcoded``
3054
        @ is xminor is an even divisor, an extra tickmark (60% of major tick) is added to the numberline: this behaviour is ''hardcoded``
11890 schaersvoo 3055
        @ y0 is bottom of numberline; y1 endpoint of major tics
13829 bpr 3056
        @ use command <a href="#linewidth">linewidth</a> to control appearance
11890 schaersvoo 3057
        @ use <a href="#strokecolor">strokecolor</a> and <a href="#opacity">opacity</a> to controle measure line
3058
        @ for all ticks linewidth and color / opacity are identical.
3059
        @ 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 3060
        @ use <a href="#fontfamily">fontfamily</a> and <a href="#fontcolor">fontcolor</a> to control fonts settings
14078 bpr 3061
        @ 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
11890 schaersvoo 3062
        @ <a href="#snaptogrid">snaptogrid, snaptopoints etc</a> and <a href="#zoom">zooming and panning</a> is supported
3063
        @ onclick and dragging of the numberline are not -yet- supported
14071 bpr 3064
        @ note: in case of multiple numberlines, make sure the numberline without special x-axis numbering (e.g. ranging from xmin to xmax) comes first !
13829 bpr 3065
        @%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 3066
        */
3067
            if( js_function[DRAW_NUMBERLINE] != 1 ){ js_function[DRAW_NUMBERLINE] = 1;}
3068
            for(i=0;i<6;i++){
3069
                switch(i){
3070
                    case 0: double_data[0] = get_real(infile,0);break;/* xmin */
3071
                    case 1: double_data[1] = get_real(infile,0);break;/* xmax */
3072
                    case 2: double_data[2] = get_real(infile,0);break;/* xmajor */
3073
                    case 3: double_data[3] = get_real(infile,0);break;/* xminor */
3074
                    case 4: double_data[4] = get_real(infile,0);break;/* ymin */
3075
                    case 5: double_data[5] = get_real(infile,1);/* ymax */
3076
                            /*
3077
                            var draw_numberline%d = function(canvas_type,xmin,xmax,xmajor,xminor,ymin,ymax,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor);
3078
                            */
3079
                            fprintf(js_include_file,"snap_x = %f;snap_y = %f;",double_data[2] / double_data[3],double_data[5] - double_data[4] );
14208 schaersvoo 3080
                            string_length = 1 + 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);
3081
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11996 schaersvoo 3082
                            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 3083
                            add_to_buffer(tmp_buffer);
3084
                            numberline_cnt++;
3085
                            break;
3086
                    default:break;
3087
                }
3088
            }
3089
            reset();
3090
            break;
3091
 
3092
            break;
11806 schaersvoo 3093
        case OPACITY:
3094
        /*
13951 schaersvoo 3095
        @ opacity [0-255],[0-255]
3096
        @ opacity [0.0 - 1.0],[0.0 - 1.0]
14071 bpr 3097
        @ alternative: <code>transparent</code>
11806 schaersvoo 3098
        @ first item is stroke opacity, second is fill opacity
13951 schaersvoo 3099
        @%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 3100
        */
3101
            for(i = 0 ; i<2;i++){
3102
                switch(i){
3103
                    case 0: double_data[0]= get_real(infile,0);break;
3104
                    case 1: double_data[1]= get_real(infile,1);break;
3105
                    default: break;
3106
                }
3107
            }
13951 schaersvoo 3108
            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 3109
            if( double_data[0] > 1 ){ stroke_opacity = (double) (0.0039215*double_data[0]); }else{ stroke_opacity = 0.0;} /* 0.0 - 1.0 */
3110
            if( double_data[1] > 1 ){ fill_opacity = (double) (0.0039215*double_data[1]); }else{ fill_opacity = 0.0;} /* 0.0 - 1.0 */
11806 schaersvoo 3111
            break;
3112
 
3113
        case ONCLICK:
3114
        /*
3115
         @ onclick
3116
         @ keyword (no arguments required)
14086 bpr 3117
         @ if the next object is clicked, its ''object onclick_or_drag sequence number`` in fly script is returned by <code>javascript:read_canvas();</code>
3118
         @ onclick seqeuence numbering starts at ''0``, e.g. if there are 6 objects set onclick, the first onclick object will have id-number ''0``, the last id-number ''5``
14071 bpr 3119
         @ line based objects will show an increase in line width<br />font based objects will show the text in ''bold`` when clicked.
11806 schaersvoo 3120
         @ the click zone (accuracy) is determined by 2&times; the line width of the object
14071 bpr 3121
         @ onclick and <a href="#drag">drag x|y|xy</a> may be combined in a single flyscript (although a single object can <b>not</b> be onclick and draggable at the same time...)
11806 schaersvoo 3122
         @ note: not all objects may be set onclick
12107 schaersvoo 3123
         @%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 3124
        */
3125
            fprintf(js_include_file,"use_dragdrop_reply = true;");
3126
            onclick = 1;
3127
 
3128
            break;
3129
 
3130
        case PARALLEL:
3131
        /*
3132
         @ parallel x1,y1,x2,y2,dx,dy,n,[colorname or #hexcolor]
14086 bpr 3133
         @ can <b>not</b> be set ''onclick`` or ''drag xy``
12107 schaersvoo 3134
         @%parallel%size 400,400%xrange -10,10%yrange -10,10%parallel -5,5,-4,-5,0.25,0,40,red
11806 schaersvoo 3135
        */
3136
            for( i = 0;i < 8; i++ ){
3137
                switch(i){
14032 schaersvoo 3138
                    case 0: double_data[0] = get_real(infile,0);break; /* x1-values  -> x-pixels*/
3139
                    case 1: double_data[1] = get_real(infile,0);break; /* y1-values  -> y-pixels*/
3140
                    case 2: double_data[2] = get_real(infile,0);break; /* x2-values  -> x-pixels*/
3141
                    case 3: double_data[3] = get_real(infile,0);break; /* y2-values  -> y-pixels*/
11806 schaersvoo 3142
                    case 4: double_data[4] = xmin + get_real(infile,0);break; /* xv -> x-pixels */
3143
                    case 5: double_data[5] = ymax + get_real(infile,0);break; /* yv -> y-pixels */
14032 schaersvoo 3144
                    case 6: int_data[0] = (int) (get_real(infile,0));break; /* n  */
11806 schaersvoo 3145
                    case 7: stroke_color=get_color(infile,1);/* name or hex color */
3146
                    decimals = find_number_of_digits(precision);
14208 schaersvoo 3147
                    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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3148
                    if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 3149
                    /* click_cnt++*/;
3150
                    reset();
3151
                    break;
3152
                    default: break;
3153
                }
3154
            }
3155
            break;
3156
 
3157
 
3158
        case PLOTSTEPS:
3159
            /*
3160
             @ plotsteps a_number
3161
             @ default 150
14066 bpr 3162
             @ only used for commands <a href="#curve">curve / plot</a> and <a href="#levelcurve">levelcurve</a>
11806 schaersvoo 3163
             @ use with care !
3164
            */
3165
            plot_steps = (int) (get_real(infile,1));
3166
            break;
13829 bpr 3167
 
11806 schaersvoo 3168
        case POINT:
3169
        /*
3170
        @ point x,y,color
3171
        @ draw a single point at (x;y) in color 'color'
14246 bpr 3172
        @ use command <code>linewidth int</code> to adjust size
11806 schaersvoo 3173
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
14071 bpr 3174
        @ will not resize on zooming (command <code>circle x,y,r,color</code> will resize on zooming)
14066 bpr 3175
        @ attention: in case of command <a href="#rotate">rotate angle</a> a point has rotation center (0:0) in x/y-range
12107 schaersvoo 3176
        @%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 3177
        */
3178
            for(i=0;i<3;i++){
3179
                switch(i){
3180
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
3181
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
3182
                    case 2: stroke_color = get_color(infile,1);/* name or hex color */
3183
                    decimals = find_number_of_digits(precision);
14208 schaersvoo 3184
                    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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 3185
                    /* click_cnt++; */
14208 schaersvoo 3186
                    if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 3187
                    break;
3188
                    default: break;
3189
                }
3190
            }
3191
            reset();
3192
            break;
3193
 
3194
        case POINTS:
3195
        /*
3196
        @ points color,x1,y1,x2,y2,...,x_n,y_n
3197
        @ draw multiple points at given coordinates in color 'color'
14246 bpr 3198
        @ use command <code>linewidth int</code> to adjust size
11806 schaersvoo 3199
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
14066 bpr 3200
        @ attention: in case of command <a href="#rotate">rotate angle</a> the points have rotation center (0:0) in x/y-range
12107 schaersvoo 3201
        @%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
3202
        @%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 3203
        */
8363 schaersvoo 3204
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3205
            fill_color = stroke_color;
3206
            i=0;
3207
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3208
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8363 schaersvoo 3209
                if(i%2 == 0 ){
3210
                    double_data[i] = get_real(infile,0); /* x */
3211
                }
3212
                else
3213
                {
3214
                    double_data[i] = get_real(infile,1); /* y */
3215
                }
3216
                i++;
3217
            }
3218
            decimals = find_number_of_digits(precision);
11806 schaersvoo 3219
            for(c = 0 ; c < i-1 ; c = c+2){
14208 schaersvoo 3220
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
8379 schaersvoo 3221
                /* click_cnt++; */
14208 schaersvoo 3222
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8363 schaersvoo 3223
            }
3224
            reset();
3225
            break;
11806 schaersvoo 3226
 
3227
        case POLY:
3228
        /*
3229
        @ poly color,x1,y1,x2,y2...x_n,y_n
3230
        @ polygon color,x1,y1,x2,y2...x_n,y_n
3231
        @ draw closed polygon
14071 bpr 3232
        @ use command ''fpoly`` to fill it or use keyword <a href='#filled'>filled</a>
11806 schaersvoo 3233
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 3234
        @%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
3235
        @%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 3236
        */
3237
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3238
            i=0;
3239
            c=0;
3240
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3241
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 3242
                for( c = 0 ; c < 2; c++){
3243
                    if(c == 0 ){
3244
                        double_data[i] = get_real(infile,0);
3245
                        i++;
3246
                    }
3247
                    else
3248
                    {
3249
                        double_data[i] = get_real(infile,1);
3250
                        i++;
3251
                    }
3252
                }
3253
            }
14066 bpr 3254
            /* draw path:  closed & optional filled */
11806 schaersvoo 3255
                decimals = find_number_of_digits(precision);
14208 schaersvoo 3256
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3257
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 3258
                /* click_cnt++; */
3259
                reset();
3260
            break;
3261
 
7614 schaersvoo 3262
        case POLYLINE:
3263
        /*
3264
        @ polyline color,x1,y1,x2,y2...x_n,y_n
10975 schaersvoo 3265
        @ brokenline color,x1,y1,x2,y2...x_n,y_n
3266
        @ path color,x1,y1,x2,y2...x_n,y_n
14086 bpr 3267
        @ remark: there is <b>no</b> command polylines | brokenlines | paths ... just use multiple commands <code>polyline, x1,y1,x2,y2...x_n,y_n</code>
3268
        @ remark: there are commands <code>userdraw path(s),color</code> and <code>userdraw polyline,color</code>... these are two entirely different things ! the path(s) userdraw commands may be used for freehand drawing(s)<br />the polyline userdraw command is analogue to this polyline|brokenline command
10975 schaersvoo 3269
        @ 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)
14071 bpr 3270
        @ use command <a href='#segments'>segments</a> for a series of segments. These may be clicked/dragged individually
9406 schaersvoo 3271
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 3272
        @%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
3273
        @%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 3274
        */
13829 bpr 3275
 
7614 schaersvoo 3276
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3277
            i=0;
3278
            c=0;
3279
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3280
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 3281
                for( c = 0 ; c < 2; c++){
3282
                    if(c == 0 ){
3283
                        double_data[i] = get_real(infile,0);
3284
                        i++;
3285
                    }
3286
                    else
3287
                    {
3288
                        double_data[i] = get_real(infile,1);
3289
                        i++;
3290
                    }
3291
                }
3292
            }
14066 bpr 3293
            /* draw path: not closed & not filled */
7614 schaersvoo 3294
            decimals = find_number_of_digits(precision);
14208 schaersvoo 3295
            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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3296
            if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 3297
            /* click_cnt++;*/
3298
            reset();
7614 schaersvoo 3299
            break;
11806 schaersvoo 3300
 
3301
        case POPUP:
3302
            /*
3303
            @ popup
3304
            @ keyword (no arguments)
14086 bpr 3305
            @ if fly-script starts with keyword ''popup``, the canvas image will be exclusively in a popup window (xsize px &times; ysize px)
14071 bpr 3306
            @ if keyword ''popup`` is used after command <code>size xsize,ysize</code> the canvas will also be displayed in a popup window with size ''xsize &times; ysize``
14086 bpr 3307
            @ the popup window will be embedded into the page as a ''normal`` image, when ''status=done``; override with keyword <a href="#status">nostatus</a>
14246 bpr 3308
            @ to access the read_canvas and read_dragdrop functions in a popup window, use: <code> 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 /> };</code>
14071 bpr 3309
            @ to set a canvasdraw produced <a href="#clock">clock</a> or multiple clocks...use something like: <code>popup.set_clock(clock_id,type,diff);</code> as js-function for a button (or something else) in your document page.<br />where in <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 3310
            @%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 3311
            */
3312
            use_tooltip = 2;
3313
            break;
3314
 
3315
        case PROTRACTOR:
7614 schaersvoo 3316
        /*
11806 schaersvoo 3317
         @ protractor x,y,x_width,type,mode,use_a_scale
3318
         @ x,y are the initial location
14066 bpr 3319
         @ x_width: give the width in x-coordinate system (e.g. not in pixels !)
14246 bpr 3320
         @ type = 1: a triangle range 0 - 180<br />type = 2: a circle shape 0 - 360
14066 bpr 3321
         @ 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
11806 schaersvoo 3322
         @ 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>
14066 bpr 3323
         @ use_scale = 1: the protractor will have some scale values printed; use_scale=0 to disable
11806 schaersvoo 3324
         @ the rotating direction of the mouse around the protractor determines the clockwise/ counter clockwise rotation of the protractor...
14071 bpr 3325
         @ commands ''stroke_color | fill_color | linewidth | opacity | font_family`` will determine the looks of the protractor.
3326
         @ default replyformat: reply[0] = x;reply[1] = y;reply[2] = angle_in_radians<br />use command ''precision`` to set the reply precision.
11806 schaersvoo 3327
         @ if combined with a ruler, use replyformat = 32
14071 bpr 3328
         @ command <code>snap_to_grid</code> may be used to assist the pupil at placing the protractor
3329
         @ 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 />technical: 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...
11806 schaersvoo 3330
         @ only one protractor allowed (for the time being)
3331
         @ 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 3332
         @%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 3333
        */
11806 schaersvoo 3334
            for( i = 0;i < 6; i++ ){
3335
                switch(i){
3336
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
3337
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
3338
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
3339
                    case 3: int_data[0] = (int)(get_real(infile,0));break; /* type: 1==triangle 2 == circle */
3340
                    case 4: int_data[1] = (int)(get_real(infile,0));break; /* passive mode == 0; active mode == -1 */
3341
                    case 5: int_data[2] = (int)(get_real(infile,1)); /* use scale */
3342
                    decimals = find_number_of_digits(precision);
11821 schaersvoo 3343
                    if( int_data[1] < 0 ){ js_function[JS_FIND_ANGLE] = 1;}
14057 schaersvoo 3344
                    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 3345
 
14208 schaersvoo 3346
                    string_length = 1 + snprintf(NULL,0,";protractor%d(); ",canvas_root_id);
3347
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 3348
                    snprintf(tmp_buffer,string_length,";protractor%d(); ",canvas_root_id);
3349
                    add_to_buffer(tmp_buffer);
3350
                    reply_precision = precision;
3351
                    /* no reply from protractor if non-interactive */
3352
                    if( reply_format == 0 && int_data[1] == -1 ){reply_format = 30;}
3353
                    break;
3354
                    default: break;
3355
                }
3356
            }
3357
            break;
3358
 
3359
        case PIXELS:
3360
        /*
3361
        @ pixels color,x1,y1,x2,y2,x3,y3...
3362
        @ draw rectangular "points" with diameter 1 pixel
3363
        @ pixels can <b>not</b> be dragged or clicked
14086 bpr 3364
        @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
12111 schaersvoo 3365
        @%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 3366
        */
3367
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
3368
            stroke_color=get_color(infile,0);
7614 schaersvoo 3369
            i=0;
3370
            c=0;
3371
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3372
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
7614 schaersvoo 3373
                for( c = 0 ; c < 2; c++){
3374
                    if(c == 0 ){
3375
                        double_data[i] = get_real(infile,0);
3376
                        i++;
3377
                    }
3378
                    else
3379
                    {
3380
                        double_data[i] = get_real(infile,1);
3381
                        i++;
3382
                    }
3383
                }
3384
            }
11806 schaersvoo 3385
            decimals = find_number_of_digits(precision);
3386
            /*  *double_xy2js_array(double xy[],int len,int decimals) */
14208 schaersvoo 3387
            string_length = 1 + snprintf(NULL,0,  "draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
3388
            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 3389
            snprintf(tmp_buffer,string_length,"draw_setpixel(%s,\"%s\",%.2f,%d);\n",double_xy2js_array(double_data,i,decimals),stroke_color,stroke_opacity,pixelsize);
3390
            add_to_buffer(tmp_buffer);
3391
            reset();
7614 schaersvoo 3392
            break;
11806 schaersvoo 3393
 
3394
        case PIXELSIZE:
7614 schaersvoo 3395
        /*
11806 schaersvoo 3396
        @ pixelsize int
3397
        @ in case you want to deviate from default pixelsize = 1(...)
12111 schaersvoo 3398
        @ pixelsize 100 is of course a filled rectangle 100px &times; 100px
7614 schaersvoo 3399
        */
11806 schaersvoo 3400
            pixelsize = (int) get_real(infile,1);
3401
        break;
8105 schaersvoo 3402
 
11806 schaersvoo 3403
        case PIECHART:
7614 schaersvoo 3404
        /*
11806 schaersvoo 3405
        @ piechart xc,yc,radius,'data+colorlist'
14066 bpr 3406
        @ (xc: yc) center of circle diagram in xrange/yrange
11806 schaersvoo 3407
        @ radius in pixels
3408
        @ 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
14066 bpr 3409
        @ example data+colorlist: 32:red:65:green:23:black:43:orange:43:yellow:14:white
11806 schaersvoo 3410
        @ the number of colors must match the number of data.
14066 bpr 3411
        @ 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,...
14086 bpr 3412
        @ use command <a href='#opacity'>opacity</a> to adjust fill_opacity of colours
3413
        @ use command <a href='#legend'>legend</a> to automatically create a legend using the same colours as pie segments; unicode allowed in legend; expect javascript trouble if the amount of ''pie-slices``, ''pie-colors``, ''pie-legend-titles`` do not match, a javascript console is your best friend...<br />use command ''fontfamily`` to set the font of the legend.
14066 bpr 3414
        @ 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 3415
        @%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%
3416
        @%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 3417
        */
11806 schaersvoo 3418
            if( js_function[DRAW_PIECHART] != 1 ){ js_function[DRAW_PIECHART] = 1;}
7614 schaersvoo 3419
            for(i=0;i<5;i++){
3420
                switch(i){
11806 schaersvoo 3421
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x */
14032 schaersvoo 3422
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y  */
11806 schaersvoo 3423
                    case 2: int_data[2] = (int)(get_real(infile,1));break;/* radius*/
3424
                    case 3: temp = get_string(infile,1);
3425
                            if( strstr( temp, ":" ) != 0 ){ temp = str_replace(temp,":","\",\"");}
14208 schaersvoo 3426
                            string_length = 1 + 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);
3427
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
12538 schaersvoo 3428
                            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 3429
                            add_to_buffer(tmp_buffer);
3430
                           break;
3431
                    default:break;
7614 schaersvoo 3432
                }
3433
            }
11806 schaersvoo 3434
            reset();
7614 schaersvoo 3435
        break;
8304 schaersvoo 3436
 
7614 schaersvoo 3437
        case RAYS:
3438
        /*
3439
         @ rays color,xc,yc,x1,y1,x2,y2,x3,y3...x_n,y_n
3440
         @ draw rays in color 'color' and center (xc:yc)
7786 schaersvoo 3441
         @ may be set draggable or onclick (every individual ray)
12111 schaersvoo 3442
         @%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
3443
         @%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 3444
        */
3445
            stroke_color=get_color(infile,0);
7786 schaersvoo 3446
            fill_color = stroke_color;
3447
            double_data[0] = get_real(infile,0);/* xc */
3448
            double_data[1] = get_real(infile,0);/* yc */
3449
            i=2;
3450
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3451
                if(i > MAX_INT - 1){canvas_error("in command rays too many points / rays in argument: repeat command multiple times to fit");}
7786 schaersvoo 3452
                if(i%2 == 0 ){
3453
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 3454
                }
7786 schaersvoo 3455
                else
3456
                {
3457
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 3458
                }
7786 schaersvoo 3459
            fprintf(js_include_file,"/* double_data[%d] = %f */\n",i,double_data[i]);
3460
                i++;
7614 schaersvoo 3461
            }
8224 bpr 3462
 
3463
            if( i%2 != 0 ){canvas_error("in command rays: unpaired x or y value");}
3464
            decimals = find_number_of_digits(precision);
7786 schaersvoo 3465
            for(c=2; c<i;c = c+2){
14208 schaersvoo 3466
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
8379 schaersvoo 3467
                /* click_cnt++; */
14208 schaersvoo 3468
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
7614 schaersvoo 3469
            }
3470
            reset();
3471
            break;
8304 schaersvoo 3472
 
11806 schaersvoo 3473
        case RECT:
8386 schaersvoo 3474
        /*
11806 schaersvoo 3475
        @ rect x1,y1,x2,y2,color
14071 bpr 3476
        @ use command <code>frect x1,y1,x2,y2,color</code> for a filled rectangle
14246 bpr 3477
        @ use command/keyword <a href='#filled'>filled</a> before command <code>rect x1,y1,x2,y2,color</code>
9406 schaersvoo 3478
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12111 schaersvoo 3479
        @%rect%size 400,400%xrange -10,10%yrange -10,10%rect 0,0,4,-4,green%rect 0,5,4,1,red
8386 schaersvoo 3480
        */
11806 schaersvoo 3481
            for(i=0;i<5;i++){
3482
                switch(i){
3483
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
3484
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
3485
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
3486
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
3487
                    case 4:stroke_color = get_color(infile,1);/* name or hex color */
8386 schaersvoo 3488
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 3489
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3490
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 3491
                        /* click_cnt++; */
8386 schaersvoo 3492
                        reset();
3493
                        break;
11806 schaersvoo 3494
                }
3495
            }
3496
            break;
8386 schaersvoo 3497
 
11806 schaersvoo 3498
        case RECTS:
8304 schaersvoo 3499
        /*
11806 schaersvoo 3500
        @ rects color,x1,y1,x2,y2,.....
14071 bpr 3501
        @ use command <code>frect color,x1,y1,x2,y2,.....</code> for a filled rectangle
14246 bpr 3502
        @ use command/keyword <a href='#filled'>filled</a> before command <code>rects color,x1,y1,x2,y2,....</code>
14071 bpr 3503
        @ use command <code>fillcolor color</code> before ''frects`` to set the fill colour.
9406 schaersvoo 3504
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
12111 schaersvoo 3505
        @%rects%size 400,400%xrange -10,10%yrange -10,10%rects red,0,0,4,-4,0,5,4,1
8304 schaersvoo 3506
        */
3507
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3508
            fill_color = stroke_color;
3509
            i=0;
3510
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3511
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8304 schaersvoo 3512
                if(i%2 == 0 ){
3513
                    double_data[i] = get_real(infile,0); /* x */
3514
                }
3515
                else
3516
                {
3517
                    double_data[i] = get_real(infile,1); /* y */
3518
                }
3519
                i++;
3520
            }
3521
            decimals = find_number_of_digits(precision);
3522
            for(c = 0 ; c < i-1 ; c = c+4){
14208 schaersvoo 3523
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3524
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 3525
                /* click_cnt++; */
8304 schaersvoo 3526
            }
3527
            reset();
3528
            break;
8386 schaersvoo 3529
 
11806 schaersvoo 3530
        case REPLYFORMAT:
7614 schaersvoo 3531
        /*
11806 schaersvoo 3532
        @ replyformat number
3533
        @ use number=-1 to deactivate the js-functions read_canvas() and read_dragdrop()
3534
        @ default values should be fine !
14071 bpr 3535
        @ use command <code>precision [0,1,10,100,1000,10000...]</code> before command ''replyformat`` to set the desired number of decimals in the student reply / drawing
14246 bpr 3536
        @ the last value for ''precision int`` will be used to calculate the reply coordinates, if needed (read_canvas();)
14248 bpr 3537
        @ choose<ul><li>replyformat 1: <code>x1,x2,x3,x4....x_n<br />y1,y2,y3,y4....y_n</code> x/y in pixels</li><li>replyformat 2: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 3: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in pixels, r in pixels</li><li>replyformat 4: <code> x1,x2,x3,x4....x_n<br /> y1,y2,y3,y4....y_n<br /> r1,r2,r3,r4....r_n</code> x/y in xrange / yrange coordinate system, r in pixels</li><li>replyformat 5: <code> 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</code> x/y in pixels</li><li>replyformat 6: <code> 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</code> x/y in xrange / yrange coordinate system</li><li>replyformat 7: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in pixels</li><li>replyformat 8: <code> x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 9: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in pixels</li><li>replyformat 10: <code> x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 11: <code> 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</code> x/y in xrange / yrange coordinate system</li><li>replyformat 12: <code> 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</code> x/y in pixels</li><li>replyformat 13: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ... ,Zx1:Zy1:Zx2:Zy2</code> x/y in xrange / yrange coordinate system</li><li>replyformat 14: <code> Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2</code> x/y in pixels</li><li>replyformat 15: reply from inputfields,textareas <code>reply1,reply2,reply3,...,reply_n</code></li><li>replyformat 16: mathml input fields</li><li>replyformat 17: read ''userdraw text,color`` only <code>x1,y1,text1 \\n x2,y2,text2...\\n...x_n,y_n,text_n </code> x/y-values are in xrange/yrange</li><li>replyformat 18: read_canvas() will read all interactive clocks in <codeWH1:M1:S1,H2:M2:S2...Hn:Mn:Sn</code></li><li>replyformat 19: read_canvas() will return the object number of marked / clicked object (clock), analogue to (shape library) onclick command</li><li>replyformat 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, e.g. expect something like 0:-5:4,1:6:2,2:-2:-5, the first image position is (-5:4), the second image position is (6:2) and the third image position is (-2:-5)         <li>replyformat 21: <code> (x1:y1) (x2:y2) ... (x_n:y_n)</code> verbatim coordinate return</li><li>replyformat 22: returns an array .... <code>reply[0]=x1 reply[1]=y1 reply[2]=x2 reply[3]=y2 ... reply[n-1]=x_n reply[n]=y_n</code> x/y in xrange / yrange coordinate system</li><li>replyformat 23: can only be used for drawtype ''polyline``. 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 gives <code>x1,y1,x2,y2,x3,y3,.....x(n-1),y(n-1),xn,yn</code>; multiple occurences will be filtered out. The reply will be in x-y-range (xreply \\n yreply)</li><li>replyformat 24: read all inputfield values: even those set ''readonly``</li><li>replyformat 25: <code> angle1,angle2;...;angle_n</code> will return the radius (one or many) of the user drawn circle segment in degrees</li><li>replyformat 26: <code> rad1,rad2,...rad_n</code> will return the radius (one or many) of the user drawn circle segment in radians</li><li>replyformat 27: return (only) userdraw inputfields <code>x1,y1,text1<br /> x2,y2,text2...<br />...x_n,y_n,textn</code></li><li>replyformat 28: <code> x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> x / y / r in xrange / yrange coordinate system: may be used to reinput into command <code>circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n</code> will not return anything else (e.g. no inputfields, text etc)</li><li>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 <code>read_canvas_images()</code> 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)</li></ul>
11806 schaersvoo 3538
        */
3539
         reply_format = (int) get_real(infile,1);
3540
         reply_precision = precision;
3541
        break;
3542
 
3543
        case ROUNDRECT:
3544
        /*
3545
        @ roundrect x1,y1,x2,y2,radius in px,color
14071 bpr 3546
        @ use command <code>froundrect x1,y1,x2,y2,radius,color</code> for a filled rectangle
3547
        @ use command/keyword <a href='#filled'>filled</a> before command <code>roundrect x1,y1,x2,y2,radius,color</code>
3548
        @ fillcolor will be identical to ''color``
9406 schaersvoo 3549
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12111 schaersvoo 3550
        @%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 3551
        */
11806 schaersvoo 3552
            for(i=0;i<6;i++){
3553
                switch(i){
3554
                    case 0:double_data[0] = get_real(infile,0);break; /* x-values */
3555
                    case 1:double_data[1] = get_real(infile,0);break; /* y-values */
3556
                    case 2:double_data[2] = get_real(infile,0);break; /* x-values */
3557
                    case 3:double_data[3] = get_real(infile,0);break; /* y-values */
3558
                    case 4:int_data[0] = (int) (get_real(infile,0));break; /* radius value in pixels */
3559
                    case 5:stroke_color = get_color(infile,1);/* name or hex color */
3560
                        /* ensure no inverted roundrect is produced... */
3561
                        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];}
3562
                        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 3563
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 3564
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3565
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 3566
                        /* click_cnt++;*/
3567
                        reset();
11806 schaersvoo 3568
                    break;
3569
                }
3570
            }
3571
            break;
8386 schaersvoo 3572
 
11806 schaersvoo 3573
        case ROUNDRECTS:
8347 schaersvoo 3574
        /*
11806 schaersvoo 3575
        @ roundrects color,radius in px,x1,y1,x2,y2,x3,y3,x4,y4,....
14066 bpr 3576
        @ for filled roundrects use command/keyword <a href='#filled'>filled</a> before command
9406 schaersvoo 3577
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
13935 bpr 3578
        @%roundrects%size 400,400%xrange -10,10%yrange -10,10%roundrects blue,5,0,0,4,-4,5,4,1,2
8347 schaersvoo 3579
        */
11806 schaersvoo 3580
 
8347 schaersvoo 3581
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
11806 schaersvoo 3582
            int_data[0] = (int) (get_real(infile,0)); /* radius value in pixels */
8347 schaersvoo 3583
            fill_color = stroke_color;
3584
            i=0;
3585
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3586
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
8347 schaersvoo 3587
                if(i%2 == 0 ){
3588
                    double_data[i] = get_real(infile,0); /* x */
3589
                }
3590
                else
3591
                {
3592
                    double_data[i] = get_real(infile,1); /* y */
3593
                }
3594
                i++;
3595
            }
3596
            decimals = find_number_of_digits(precision);
3597
            for(c = 0 ; c < i-1 ; c = c+4){
11806 schaersvoo 3598
                /* ensure no inverted roundrect is produced... */
3599
                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];}
3600
                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];}
14208 schaersvoo 3601
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3602
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8379 schaersvoo 3603
                /* click_cnt++; */
8347 schaersvoo 3604
            }
3605
            reset();
3606
            break;
8386 schaersvoo 3607
 
11806 schaersvoo 3608
        case RULER:
7614 schaersvoo 3609
        /*
14078 bpr 3610
        @ ruler x,y,x-width,y-height,mode
11806 schaersvoo 3611
        @ x,y are the initial location
14078 bpr 3612
        @ x-width, y-height are the ruler dimensions width &amp; height in xy-coordinate system
14071 bpr 3613
        @ the ruler scale is by definition the x-scale, set by command ''xrange``. For example: a ruler x-width of 6 will have a scale ranging from 0 to 6
14066 bpr 3614
        @ 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
11806 schaersvoo 3615
        @ if combined with a protractor, use replyformat = 32
3616
        @ only one ruler allowed (for the time being)
14247 bpr 3617
        @ when using command ''zoom``, pay <b>attention</b> to the size and symmetry of your canvas to avoid a partial image, locate the start position near the center of the visual canvas; technical: the actual ''ruler`` is just a static generated image in a new canvas-memory. This image is only generated once, and a copy of its bitmap is translated & rotated onto the visible canvas. That is the reason for the ``high-speed dragging and rotating''. I have limited its size to xsize &times; ysize e.g. the same size as the visual canvas...
3618
        @ usage: first left click on the ruler will activate dragging; a second left click will activate rotating (just move mouse around), a third click will freeze this position and the x/y-coordinate and angle in radians will be stored in reply(3), a next click will restart this sequence...
12111 schaersvoo 3619
        @%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
3620
        @%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
3621
        @%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 3622
        */
11806 schaersvoo 3623
            for( i = 0;i < 5; i++ ){
7614 schaersvoo 3624
                switch(i){
11806 schaersvoo 3625
                    case 0: double_data[0] = get_real(infile,0);break; /* x-center */
3626
                    case 1: double_data[1] = get_real(infile,0);break; /* y-center */
3627
                    case 2: double_data[2] = get_real(infile,0);break; /* x-width */
3628
                    case 3: double_data[3] = get_real(infile,0);break; /* y-width */
3629
                    case 4: int_data[0] = (int)(get_real(infile,1)); /* passive mode */
3630
                    decimals = find_number_of_digits(precision);
3631
                    if( int_data[0] < 0 ){
14032 schaersvoo 3632
                      if( js_function[JS_FIND_ANGLE] != 1 ){  js_function[JS_FIND_ANGLE] = 1; }
11806 schaersvoo 3633
                    }
14057 schaersvoo 3634
                    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);
14208 schaersvoo 3635
                    string_length = 1 + snprintf(NULL,0,";ruler%d(); ",canvas_root_id);
3636
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 3637
                    snprintf(tmp_buffer,string_length,";ruler%d(); ",canvas_root_id);
3638
                    add_to_buffer(tmp_buffer);
3639
                    reply_precision = precision;
3640
                    /* no reply from ruler if non-interactive */
3641
                    if( reply_format == 0 && int_data[0] == -1 ){reply_format = 31;}
7614 schaersvoo 3642
                    break;
3643
                    default: break;
3644
                }
3645
            }
3646
            break;
8386 schaersvoo 3647
 
11806 schaersvoo 3648
        case RESETOFFSET:
7614 schaersvoo 3649
        /*
11806 schaersvoo 3650
         @ resetoffset
3651
         @ keyword ; use to restore text placement on the canvas to the real (x;y) coordinates of the left bottom corner of the text
3652
         @ 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 3653
        */
11806 schaersvoo 3654
         use_offset = 0;
3655
         break;
3656
 
3657
        case ROTATE:
3658
        /*
3659
         @ rotate rotation_angle
3660
         @ angle in degrees
3661
         @ (only) the next object will be rotated is given angle
3662
         @ positive values rotate counter clockwise
14066 bpr 3663
         @ attention: all objects will be rotated around their first point...<br /><code>rotate 45<br />triangle 1,1,5,1,3,4,red</code><br />will rotate 45 degrees around point (1:1)
3664
         @ 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>
3665
         @ 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 3666
         @%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 3667
        */
3668
            use_rotate = TRUE;
14066 bpr 3669
            angle = -1*(get_real(infile,1));/* -1: to be compatible with Flydraw... */
7614 schaersvoo 3670
            break;
11806 schaersvoo 3671
        case ROTATION_CENTER:
9306 schaersvoo 3672
        /*
11806 schaersvoo 3673
        @ rotationcenter x_center,y_center
3674
        @ define an rotation center in your x/y-coordinate system
3675
        @ wims will not check the validity of your input; use javascript console to debug any erors
3676
        @ if not defined a rotation will be around the first point of an object
3677
        @ to be used before command <a href="#rotate">rotate</a>
3678
        @ all other commands will use this rotation center, unless a <a href="#killrotation">killrotation</a> is given
13956 schaersvoo 3679
        @%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 3680
        @%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 3681
        */
11806 schaersvoo 3682
            temp = get_string(infile,1);
14208 schaersvoo 3683
            string_length = 1 + snprintf(NULL,0,"[ %s ]",temp);
11806 schaersvoo 3684
            check_string_length(string_length);
14208 schaersvoo 3685
            rotation_center = my_newmem(string_length);
11806 schaersvoo 3686
            snprintf(rotation_center,string_length,"[%s]",temp);
9306 schaersvoo 3687
            break;
11806 schaersvoo 3688
 
3689
        case SIZE:
3690
            /*
3691
            @ size width,height
3692
            @ set canvas size in pixels
14066 bpr 3693
            @ mandatory first command (can only be preceded by keyword <a href="#popup">popup</a>)
14162 bpr 3694
            @ 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
11806 schaersvoo 3695
            */
3696
            found_size_command = 1;
14066 bpr 3697
            /* using fabs: however "xsize == int": so "xsize = abs( (int) get_real(infile,0))" would be the idea... */
11806 schaersvoo 3698
            xsize = (int)(fabs(round(get_real(infile,0)))); /* just to be sure that sizes > 0 */
3699
            ysize = (int)(fabs(round(get_real(infile,1))));
3700
            /* sometimes we want xrange / yrange to be in pixels...without telling x/y-range */
3701
            xmin = 0;xmax = xsize;
3702
            ymin = 0;ymax = ysize;
3703
 
3704
/*
3705
 The sequence in which stuff is finally printed is important !!
3706
*/
3707
fprintf(stdout,"\n\
13970 obado 3708
<script>\n\
11806 schaersvoo 3709
/*<![CDATA[*/\n\
3710
if( typeof(wims_status) === 'undefined' ){ var wims_status = \"$status\";};\
3711
if( typeof(use_dragdrop_reply) === 'undefined' ){ var use_dragdrop_reply = false;};\
3712
if( typeof(canvas_scripts) === 'undefined' ){ var canvas_scripts = new Array();};\
3713
canvas_scripts.push(\"%d\");\n/*]]>*/\n</script>\n\
3714
",canvas_root_id);
3715
 
3716
/* style=\"display:block;position:relative;margin-left:auto;margin-right:auto;margin-bottom:4px;\" */
3717
if( use_tooltip != 2){
3718
 fprintf(stdout,"<!-- canvasdraw div  -->\n\
3719
<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\
3720
<!-- tooltip and input placeholder  -->\n\
3721
<div id=\"tooltip_placeholder_div%d\" style=\"text-align:center\"><span id=\"tooltip_placeholder%d\" style=\"display:none;\"></span></div>\
3722
<!-- include actual object code via include file -->\n\
13970 obado 3723
<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 3724
}
3725
else
3726
{
3727
/*
14066 bpr 3728
set canvas_div invisible and do not include placeholder in main html page:
11806 schaersvoo 3729
the js-include will also be in a popup window...to be shown when wims $status = done
3730
*/
3731
 fprintf(stdout,"<!-- canvasdraw div invisible  -->\n\
3732
<div tabindex=\"0\" id=\"canvas_div%d\" style=\"display:none;position:relative;width:%dpx;height:%dpx;margin-left:auto;margin-right:auto;\" ></div>\n\
3733
<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>\
3734
<!-- include actual object code via include file -->\n\
13970 obado 3735
<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 3736
}
3737
 
14071 bpr 3738
/* these must be global...it is all really very poor javascript:( */
13970 obado 3739
fprintf(js_include_file,"\n/* begin generated javascript include for canvasdraw */\n\
11806 schaersvoo 3740
\"use strict\";\n\
13970 obado 3741
/* these variables and functions must be global */\n\
11806 schaersvoo 3742
var read_dragdrop%d;\
14038 schaersvoo 3743
var read_canvas_images;\
11806 schaersvoo 3744
var read_canvas%d;\
3745
var set_clock;\
3746
var clear_draw_area%d;\
3747
var update_draw_area%d;\
14038 schaersvoo 3748
var place_image_on_canvas;\
11806 schaersvoo 3749
var draw_boxplot;\
3750
var redraw_all%d;\
3751
var userdraw_primitive;\n\
13970 obado 3752
var wims_canvas_function%d = function(){\n/* common used stuff */\n\
11806 schaersvoo 3753
var userdraw_x = [];var userdraw_y = [];var userdraw_radius = [];\n\
3754
var xsize = %d;\
3755
var ysize = %d;\
3756
var precision = 100;\
3757
var canvas_div = document.getElementById(\"canvas_div%d\");\
3758
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;};\
3759
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;};\
3760
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);};};\
3761
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);};};\
3762
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);};};\
3763
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);};};\
3764
function scale_x_radius(rx){return rx*xsize/(xmax - xmin);};\
3765
function scale_y_radius(ry){return ry*ysize/(ymax - ymin);};\
3766
function distance(x1,y1,x2,y2){return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );};\
3767
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) ));};\
3768
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;};\
14208 schaersvoo 3769
function slide(obj,dx,dy){for(var p = 0 ; p < obj.x.length; p++){obj.x[p] = parseInt(obj.x[p] + dx);obj.y[p] = parseInt(obj.y[p] + dy);};return obj;};\
14044 schaersvoo 3770
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));var snap_x = 1;var snap_y = 1;\
11806 schaersvoo 3771
function snap_to_x(x){return x2px(snap_x*(Math.round((px2x(x))/snap_x)));};\
11890 schaersvoo 3772
function snap_to_y(y){return y2px(snap_y*(Math.round((px2y(y))/snap_y)));};\
14044 schaersvoo 3773
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 3774
var xlogbase = 10;\
3775
var ylogbase = 10;\
3776
var use_xlogscale = 0;\
3777
var use_ylogscale = 0;\
11891 schaersvoo 3778
var x_strings = {};var x_strings_up = [];\
11806 schaersvoo 3779
var y_strings = null;\
3780
var use_pan_and_zoom = 0;\
3781
var use_jsmath = 0;\
3782
var xstart = 0;\
3783
var ystart = 0;\
3784
var unit_x=\" \";\
3785
var unit_y=\" \";\
14038 schaersvoo 3786
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);
14066 bpr 3787
/* default add the drag code: nearly always used ...*/
11806 schaersvoo 3788
  add_drag_code(js_include_file,DRAG_CANVAS,canvas_root_id);
3789
 
3790
            break;
3791
 
3792
 
3793
        case SEGMENT:
7614 schaersvoo 3794
        /*
11806 schaersvoo 3795
        @ segment x1,y1,x2,y2,color
14071 bpr 3796
        @ alternative: <code>seg</code>
3797
        @ draw a line segment between points (x1:y1)--(x2:y2) in color ''color``
11806 schaersvoo 3798
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
14061 schaersvoo 3799
        @%segment_onclick%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%onclick%segment 1,1,-9,3,green
3800
        @%segment_drag_y%size 400,400%xrange -10,10%yrange -10,10%linewidth 2%drag y%segment 1,1,-9,3,green
7614 schaersvoo 3801
        */
11806 schaersvoo 3802
            for(i=0;i<5;i++) {
7614 schaersvoo 3803
                switch(i){
11806 schaersvoo 3804
                    case 0: double_data[0]= get_real(infile,0);break; /* x1-values */
3805
                    case 1: double_data[1]= get_real(infile,0);break; /* y1-values */
3806
                    case 2: double_data[2]= get_real(infile,0);break; /* x2-values */
3807
                    case 3: double_data[3]= get_real(infile,0);break; /* y2-values */
3808
                    case 4: stroke_color=get_color(infile,1);/* name or hex color */
3809
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 3810
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3811
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 3812
                        /* click_cnt++; */
3813
                        reset();
3814
                        break;
3815
                    default: break;
7614 schaersvoo 3816
                }
3817
            }
3818
            break;
10953 bpr 3819
 
11806 schaersvoo 3820
        case SEGMENTS:
9213 schaersvoo 3821
        /*
11806 schaersvoo 3822
        @ segments color,x1,y1,x2,y2,...,x_n,y_n
14071 bpr 3823
        @ alternative: <code>segs</code>
3824
        @ draw multiple segments between points (x1:y1)--(x2:y2).....and... (x_n-1:y_n-1)--(x_n:y_n) in color ''color``
14162 bpr 3825
        @ use command ''linewidth int'' to adust size
11806 schaersvoo 3826
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12111 schaersvoo 3827
        @%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
3828
        @%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 3829
        */
11806 schaersvoo 3830
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
3831
            fill_color = stroke_color;
3832
            i=0;
3833
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 3834
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 3835
                if(i%2 == 0 ){
3836
                    double_data[i] = get_real(infile,0); /* x */
3837
                }
3838
                else
3839
                {
3840
                    double_data[i] = get_real(infile,1); /* y */
3841
                }
3842
                i++;
3843
            }
3844
            decimals = find_number_of_digits(precision);
3845
            for(c = 0 ; c < i-1 ; c = c+4){
14208 schaersvoo 3846
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
3847
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 3848
                /* click_cnt++;*/
3849
            }
3850
            reset();
9213 schaersvoo 3851
            break;
11806 schaersvoo 3852
 
3853
        case SETLIMITS:
9213 schaersvoo 3854
        /*
11806 schaersvoo 3855
            @ setlimits
14071 bpr 3856
            @ keyword: if set, it will produce 4 inputfields for ''xmin,xmax,ymin,ymax`` and an ''ok`` button
11806 schaersvoo 3857
            @ may be used for inputfield based zooming / panning
3858
            @ may be styled using command <a href="#inputstyle">inputstyle</a>
14071 bpr 3859
            @ use commands <a href="#xlabel">xlabel / ylabel</a> to change text from xmin to ''xlabel`` etc
14247 bpr 3860
            @ note: the input value will not be checked on validity
12107 schaersvoo 3861
            @%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 3862
        */
11806 schaersvoo 3863
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
3864
            add_setlimits(js_include_file,canvas_root_id,font_size,input_style);
3865
            /* add_setlimits provides 'fprintf(js_include_file,"use_pan_and_zoom = 1;");' */
3866
            use_pan_and_zoom = TRUE;
3867
            done = TRUE;
9213 schaersvoo 3868
            break;
11806 schaersvoo 3869
 
3870
        case SETPIXEL:
9213 schaersvoo 3871
        /*
11806 schaersvoo 3872
        @ setpixel x,y,color
3873
        @ A rectangular "point" with diameter 1 pixel centered at (x:y) in xrange / yrange
3874
        @ pixels can <b>not</b> be dragged or clicked
14086 bpr 3875
        @ "pixelsize = 1" may be changed by command <code>pixelsize int</code>
12107 schaersvoo 3876
        @%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 3877
        */
11806 schaersvoo 3878
            if( js_function[DRAW_PIXELS] != 1 ){ js_function[DRAW_PIXELS] = 1;}
3879
            for(i=0;i<3;i++){
3880
                switch(i){
3881
                    case 0: double_data[0] = get_real(infile,0); break; /* x */
14162 bpr 3882
                    case 1: double_data[1] = get_real(infile,0); break; /* y */
11806 schaersvoo 3883
                    case 2: stroke_color = get_color(infile,1);
14208 schaersvoo 3884
                           string_length = 1 + snprintf(NULL,0,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3885
                           check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 3886
                           snprintf(tmp_buffer,string_length,"draw_setpixel([%f],[%f],\"%s\",%.2f,%d);\n",double_data[0],double_data[1],stroke_color,stroke_opacity,pixelsize);
3887
                           add_to_buffer(tmp_buffer);
3888
                           break;
3889
                    default:break;
3890
                }
3891
            }
3892
            reset();
3893
        break;
3894
        case SLIDER:
9213 schaersvoo 3895
        /*
14071 bpr 3896
        @ slider start_value,end_value,width px,height px,type,label
14247 bpr 3897
        @ type may be: ``xy,x,y,angle''
11806 schaersvoo 3898
        @ 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
14071 bpr 3899
        @ if a unit (or something like that...) for x/y-value display is needed, use commands ''xunit`` and / or ''yunit``
14066 bpr 3900
        @ 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 /><code>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... etc</code>
14071 bpr 3901
        @ use command ''slider`` before draggable/clickable objects.
14066 bpr 3902
        @ drag and drop may be combined with rotation slider<br />for example an arrow rotated by a slider may be placed anywhere (drag&drop)<br /><code>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</code>
14071 bpr 3903
        @ no slider for a math function, these can be traced using command ''trace_jscurve some_function_in_x``
3904
        @ 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``
11806 schaersvoo 3905
        @ amount of sliders is not limited.
14208 schaersvoo 3906
        @ a slider can not be set ''snaptogrid`` or other ''snapto*`` : you may always use 'drag xy' in combination with the slider objects
14071 bpr 3907
        @ <code>javascript:read_dragdrop();</code> will return an array with ''object_number:slider_value``
3908
        @ type=xy: will produce a 2D ''slider`` [rectangle width x heigh px] in your web page
11806 schaersvoo 3909
        @ every draggable object may have its own slider (no limit in amount of sliders)
3910
        @ label: some slider text
3911
        @ use fillcolor for slider ball
3912
        @ use strokecolor for slider bar
3913
        @ use fontfamily / fontcolor to set used fonts
3914
        @ use opacity (only fill opacity will be used) to set transparency
14071 bpr 3915
        @ the slider canvas will be added to the ''tooltip div``: so incompatible with command tooltip ; setlimits etc
13950 schaersvoo 3916
        @%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
3917
        @%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 3918
        @%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 3919
        */
14208 schaersvoo 3920
            int_data[2] = 0; /* --> show_display = 0; */
11806 schaersvoo 3921
            for(i=0; i<6 ; i++){
3922
                switch(i){
3923
                    case 0: double_data[0] = get_real(infile,0);break; /* start value */
3924
                    case 1: double_data[1] = get_real(infile,0);break; /* end value */
3925
                    case 2: int_data[0] = (int)(get_real(infile,0));break; /* width */
3926
                    case 3: int_data[1] = (int)(get_real(infile,0));break; /* height */
14066 bpr 3927
                    case 4: temp = get_string_argument(infile,0); /* type: xy,x,y,angle */
14208 schaersvoo 3928
                            if( ( strstr(temp,"displ")!=0 ||  strstr(temp,"deg")!=0 ||  strstr(temp,"rad")!=0 ) && int_data[2] == 0 ){
11806 schaersvoo 3929
                                add_slider_display(js_include_file,canvas_root_id,precision,font_size,font_color,stroke_opacity);
3930
                            }
14208 schaersvoo 3931
                            if(strstr(temp,"angle")!= 0){slider_type="R";if( strstr(temp,"rad")!= 0){int_data[2] = 3;}if( strstr(temp,"deg")!= 0){int_data[2] = 4;}}
11806 schaersvoo 3932
                            else
14208 schaersvoo 3933
                            if(strstr(temp,"xy") != 0){slider_type = "XY";if( strstr(temp,"disp")!= 0){int_data[2] = 5;}}
11806 schaersvoo 3934
                            else
14208 schaersvoo 3935
                            if(strstr(temp,"x") != 0){slider_type = "X";if( strstr(temp,"disp")!= 0){int_data[2] = 1;}}
3936
                            else
3937
                            if(strstr(temp,"y") != 0){slider_type = "Y";if( strstr(temp,"disp")!= 0){int_data[2] = 2;}}
3938
                            else
3939
                            canvas_error("slider can be of type: xy,x,y,angle,fun_x:fun_y");
3940
                            break;
3941
                    case 5: temp = get_string_argument(infile,1); /* slider label */ break;
11806 schaersvoo 3942
                }
3943
             }
14208 schaersvoo 3944
/*
3945
function add_slider(type,titletext,id,width,height,linewidth,fillcolor,strokecolor,opacity,min,max,fun,fontfamily)
3946
*/
3947
            if(slider_cnt == 0){
3948
             add_slider(js_include_file,canvas_root_id);
3949
             active_sliders[0] = 0;
3950
            }
3951
            string_length = 1 + snprintf(NULL,0,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,null,'%s',%d);\n",slider_cnt,slider_type,temp,slider_cnt,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]);
3952
            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
3953
            snprintf(tmp_buffer,string_length  ,"slider%d = new slider(\"%s\",\"%s\",%d,%d,%d,%d,\"%s\",\"%s\",[%f,%f],%f,%f,null,'%s',%d);\n",slider_cnt,slider_type,temp,slider_cnt,int_data[0],int_data[1],line_width,fill_color,stroke_color,fill_opacity,stroke_opacity,double_data[0],double_data[1],font_family,int_data[2]);
3954
            add_to_buffer(tmp_buffer);
3955
            fprintf(js_include_file,"var slider%d;",slider_cnt);
3956
            /* increment here */
3957
            slider_cnt++;
3958
            active_sliders[slider_cnt] = slider_cnt;
3959
            current_sliders = data2js_array(active_sliders,slider_cnt);
3960
        break;
3961
 
14246 bpr 3962
        case SLIDER_X:
9213 schaersvoo 3963
        /*
11806 schaersvoo 3964
         @ sliderfunction_x some_function_in_x
3965
         @ default value "x"
14208 schaersvoo 3966
         @ the x-value of the slider object will be calculated with this function.
11806 schaersvoo 3967
         @ default is the x-slider value itself
14071 bpr 3968
         @ only used by command ''slider``
11806 schaersvoo 3969
         @ define before a slider command !
9213 schaersvoo 3970
        */
11806 schaersvoo 3971
         slider_function_x = get_string(infile,1);
3972
        break;
3973
        case SLIDER_Y:
3974
         slider_function_y = get_string(infile,1);
3975
         /*
3976
         @ sliderfunction_y some_function_in_y
3977
         @ default value "y"
3978
         @ the y-value of the slider object(s) will be calculated with this function.
14071 bpr 3979
         @ only used by command ''slider``
11806 schaersvoo 3980
         @ define before a slider command !
3981
         */
3982
        break;
3983
        case SGRAPH:
3984
        /*
3985
         @ sgraph xstart,ystart,xmajor,ymajor,xminor,yminor,majorgrid_color,minorgrid_color
14071 bpr 3986
         @ primitive implementation of a ''broken scale`` graph...
3987
         @ 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 3988
         @%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 3989
        */
3990
            if( js_function[DRAW_SGRAPH] != 1 ){ js_function[DRAW_SGRAPH] = 1;}
3991
            for(i = 0 ; i < 8 ;i++){
3992
                switch(i){
3993
                    case 0:double_data[0] = get_real(infile,0);break;
3994
                    case 1:double_data[1] = get_real(infile,0);break;
3995
                    case 2:double_data[2] = get_real(infile,0);break;
3996
                    case 3:double_data[3] = get_real(infile,0);break;
3997
                    case 4:int_data[0] = (int)(get_real(infile,0));break;
3998
                    case 5:int_data[1] = (int)(get_real(infile,0));break;
3999
                    case 6:stroke_color = get_color(infile,0);break;
4000
                    case 7:font_color = get_color(infile,1);
14208 schaersvoo 4001
                    string_length = 1 + 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);
4002
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 4003
                    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);
4004
                    add_to_buffer(tmp_buffer);
4005
                    break;
4006
                    default:break;
4007
                }
4008
            }
4009
            /* sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity)*/
9213 schaersvoo 4010
            break;
11806 schaersvoo 4011
 
4012
        case SNAPTOFUNCTION:
9213 schaersvoo 4013
        /*
11806 schaersvoo 4014
        @ snaptofunction some_function_in_x,some_funtion_in_y
14066 bpr 4015
        @ alternative: <code>snaptofun some_function_in_x,some_funtion_in_y</code>
11806 schaersvoo 4016
        @ the next object will snap to the calculated values
14071 bpr 4017
        @ note: snaptofun is probably not really useful feature...
14066 bpr 4018
        @ if you want only modification of y-values,just use: <code>snaptofunction x,5*sin(1/y)</code>
4019
        @ if you want only modification of x-values,just use: <code>snaptofunction 5*sin(1/x),y</code>
14071 bpr 4020
        @ for now only one instance of ''snaptofunction`` is allowed
11806 schaersvoo 4021
        @ use rawmath on your functions: no validity checking is done by wims !
14071 bpr 4022
        @ note: switching x and y coordinates? <code>snaptofunction y,x</code>
13960 bpr 4023
        @%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
4024
        @%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 4025
        */
11806 schaersvoo 4026
        temp = get_string_argument(infile,0);
14038 schaersvoo 4027
        use_snap = 2;
11806 schaersvoo 4028
        if( use_js_math == FALSE){/* add this stuff only once...*/
4029
            add_to_js_math(js_include_file); use_js_math = TRUE;
4030
        }
4031
        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));
4032
        break;
4033
        case SNAPTOPOINTS:
4034
        /*
4035
        @ snaptopoints x1,y1,x2,y2,x3,y3....
4036
        @ a userdraw object will snap to these points.
14071 bpr 4037
        @ the array size (e.g. the number of points) of command ''snaptopoints`` is limited by constant MAX_INT (canvasdraw.h)
14162 bpr 4038
        @ a draggable object (use command ''drag x|y|xy``) will snap to the closed of these points when dragged (mouseup)
14078 bpr 4039
        @ other options: use keyword ''snaptogrid``, ''xsnaptogrid`` or ''ysnaptogrid``
13950 schaersvoo 4040
        @%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 4041
        */
4042
            i = 0;
14038 schaersvoo 4043
            use_snap = 4;
11806 schaersvoo 4044
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 4045
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 4046
                if(i%2 == 0 ){
4047
                    double_data[i] = get_real(infile,0); /* x */
4048
                }
4049
                else
4050
                {
4051
                    double_data[i] = get_real(infile,1); /* y */
4052
                }
4053
                i++;
4054
            }
4055
            decimals = find_number_of_digits(precision);
14044 schaersvoo 4056
            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 4057
        break;
4058
 
4059
        case SNAPTOGRID:
4060
        /*
4061
         @ snaptogrid
4062
         @ keyword (no arguments required)
14162 bpr 4063
         @ a draggable object (use command ''drag x|y|xy``) will snap to the given grid when dragged (mouseup)
11806 schaersvoo 4064
         @ in case of userdraw the drawn points will snap to xmajor / ymajor grid
14078 bpr 4065
         @ if no grid is defined, points will snap to every integer xrange/yrange value. (eg snap_x=1,snap_y=1)
14071 bpr 4066
         @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
14162 bpr 4067
         @ 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 <code>snaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code> will snap on x=0, x=0.5, x=1, x=1.5 .... will snap on y=0, y=0.25 y=0.5 y=0.75 ...
12311 schaersvoo 4068
         @%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
4069
         @%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 4070
        */
14038 schaersvoo 4071
        use_snap = 1;
11806 schaersvoo 4072
        break;
4073
 
4074
        case SQUARE:
4075
        /*
14078 bpr 4076
        @ square x,y,side (px),color
14071 bpr 4077
        @ draw a square with left top corner (x:y) with side ''side`` in color 'color'
4078
        @ use command <code>fsquare x,y,side,color</code> for a filled square
14162 bpr 4079
        @ use command/keyword <a href='#filled'>filled</a> before command <code>square x,y,side,color</code>
11806 schaersvoo 4080
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 4081
        @%square%size 400,400%xrange -10,10%yrange -10,10%linewidth 3%filled%fillcolor blue%square 0,0,120,green
11806 schaersvoo 4082
        */
11991 schaersvoo 4083
            for(i=0;i<4;i++){
11806 schaersvoo 4084
                switch(i){
4085
                    case 0:double_data[0] = get_real(infile,0);break; /* x1-values */
4086
                    case 1:double_data[1] = get_real(infile,0);break; /* y1-values */
11991 schaersvoo 4087
                    case 2:double_data[2] = get_real(infile,0);break; /* width in px */
4088
                    case 3:stroke_color = get_color(infile,1);/* name or hex color */
4089
                           decimals = find_number_of_digits(precision);
4090
                           double_data[3] = double_data[0] + (xmax - xmin)*double_data[2]/xsize;
4091
                           double_data[4] = double_data[1] + -1*(ymax - ymin)*double_data[2]/ysize;
14208 schaersvoo 4092
                           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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
4093
                           if(onclick > 0 || slider_cnt > 0){click_cnt++;}/* click_cnt++; */
11991 schaersvoo 4094
                           reset();break;
4095
                    default: break;
11806 schaersvoo 4096
                }
4097
            }
9213 schaersvoo 4098
            break;
13829 bpr 4099
 
11806 schaersvoo 4100
        case STATUS:
9213 schaersvoo 4101
        /*
11806 schaersvoo 4102
        @ status
4103
        @ keyword
14066 bpr 4104
        @ alernative: nostatus
14078 bpr 4105
        @ used to override the effects of ''status=done`` in wims (answer.phtml)
14071 bpr 4106
        @ affects ''readonly`` in inputfields / textareas in canvasimage and all userdraw based commands
4107
        @ 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 4108
        */
11806 schaersvoo 4109
 
4110
            fprintf(js_include_file,"\nwims_status=\"waiting\";\n");
9213 schaersvoo 4111
            break;
11806 schaersvoo 4112
 
4113
        case STRING:
9213 schaersvoo 4114
        /*
11806 schaersvoo 4115
         @ string color,x,y,the text string
14078 bpr 4116
         @ may be set ''onclick`` or ''drag xy``
14071 bpr 4117
         @ unicode supported: <code>string red,0,0,\\u2232</code>
4118
         @ use a command like <code>fontfamily italic 24px Ariel</code> to set fonts on browser that support font change
12311 schaersvoo 4119
         @%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 4120
        */
11806 schaersvoo 4121
            for(i=0;i<5;i++){
4122
                switch(i){
4123
                    case 0: stroke_color = get_color(infile,0);break;/* name or hex color */
4124
                    case 1: double_data[0] = get_real(infile,0);break; /* x in xrange*/
4125
                    case 2: double_data[1] = get_real(infile,0);break; /* y in yrange*/
4126
                    case 3: decimals = find_number_of_digits(precision);
4127
                        temp = get_string_argument(infile,1);
4128
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 4129
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
4130
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
14038 schaersvoo 4131
                        onclick = 0;
4132
                        use_offset = 0;
4133
                        reset();;
11806 schaersvoo 4134
                        break;
4135
                    default:break;
4136
                }
9213 schaersvoo 4137
            }
4138
            break;
11806 schaersvoo 4139
 
4140
        case STRINGUP:
9213 schaersvoo 4141
        /*
11806 schaersvoo 4142
         @ stringup color,x,y,rotation_degrees,the text string
14078 bpr 4143
         @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translation matrix...mouse incompatible)
14071 bpr 4144
         @ unicode supported: <code>stringup red,0,0,45,\\u2232</code>
4145
         @ use a command like <code>fontfamily bold 34px Courier</code> to set fonts on browser that support font change
4146
         @ you could use keyword <a href='#yoffset'>yoffset</a> to -sometimes- do a small correction of text placement under/above a point (e.g. text &amp; point have thesame coordinates)
12311 schaersvoo 4147
         @%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 4148
 
9213 schaersvoo 4149
        */
14066 bpr 4150
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}   /* can not be added to shape library: rotate / mouse issues */
11806 schaersvoo 4151
            for(i=0;i<6;i++){
4152
                switch(i){
4153
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
4154
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
4155
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
4156
                    case 3: double_data[0] = get_real(infile,0);break;/* rotation */
4157
                    case 4: decimals = find_number_of_digits(precision);
4158
                            temp = get_string_argument(infile,1);
14208 schaersvoo 4159
                            string_length = 1 + 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);
4160
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11811 schaersvoo 4161
                            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 4162
                            add_to_buffer(tmp_buffer);
14038 schaersvoo 4163
                            use_offset=0;
4164
                            reset();
11806 schaersvoo 4165
                            break;
4166
                    default:break;
4167
                }
9213 schaersvoo 4168
            }
4169
            break;
11767 schaersvoo 4170
 
11806 schaersvoo 4171
        case STYLE:
11767 schaersvoo 4172
        /*
11806 schaersvoo 4173
         @ highlight color,opacity,linewidth
4174
         @ NOT IMPLEMENTED
14071 bpr 4175
         @ use command ''onclick``: when the object receives a userclick it will increase its linewidth
11767 schaersvoo 4176
        */
4177
            break;
11806 schaersvoo 4178
 
4179
 
4180
        case STROKECOLOR:
9213 schaersvoo 4181
        /*
11806 schaersvoo 4182
        @ strokecolor colorname or #hex
14071 bpr 4183
        @ to be used for commands that do not supply a color argument (like command ''linegraph``)
9213 schaersvoo 4184
        */
11806 schaersvoo 4185
            stroke_color = get_color(infile,1);
9213 schaersvoo 4186
            break;
11806 schaersvoo 4187
 
4188
        case FLY_TEXT:
9213 schaersvoo 4189
        /*
11806 schaersvoo 4190
        @ text fontcolor,x,y,font,text_string
14066 bpr 4191
        @ font may be described by keywords: giant,huge,normal,small,tiny
14071 bpr 4192
        @ use command ''fontsize`` to increase base fontsize for these keywords
14086 bpr 4193
        @ may be set ''onclick`` or ''drag xy``
11806 schaersvoo 4194
        @ backwards compatible with flydraw
4195
        @ unicode supported: text red,0,0,huge,\\u2232
14071 bpr 4196
        @ use command ''string`` combined with ''fontfamily`` for a more fine grained control over html5 canvas text element
14246 bpr 4197
        @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``, ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something lke ''fontfamily Ariel`` before the old flydraw commands.
12311 schaersvoo 4198
        @%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 4199
        */
11806 schaersvoo 4200
            for(i = 0; i < 5 ;i++){
4201
                switch(i){
4202
                    case 0: stroke_color = get_color(infile,0);break;/* font_color == stroke_color name or hex color */
4203
                    case 1: double_data[0] = get_real(infile,0);break; /* x */
4204
                    case 2: double_data[1] = get_real(infile,0);break; /* y */
4205
                    case 3: fly_font = get_string_argument(infile,0);
4206
                            if(strcmp(fly_font,"giant") == 0){
4207
                                fly_font_size = (int)(font_size + 24);
4208
                            }
4209
                            else
4210
                            {
4211
                                if(strcmp(fly_font,"huge") == 0){
4212
                                    fly_font_size = (int)(font_size + 14);
4213
                                }
4214
                                else
4215
                                {
4216
                                    if(strcmp(fly_font,"large") == 0){
4217
                                        fly_font_size = (int)(font_size + 6);
4218
                                        }
4219
                                        else
4220
                                        {
4221
                                            if(strcmp(fly_font,"small") == 0){
4222
                                                fly_font_size = (int)(font_size - 4);
4223
                                                if(fly_font_size<0){fly_font_size = 8;}
4224
                                        }
4225
                                    }
4226
                                }
4227
                            }
4228
                            break;
4229
                    case 4:
4230
                        temp = get_string_argument(infile,1);
4231
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 4232
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
4233
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
14038 schaersvoo 4234
                        onclick=0;
4235
                        use_offset = 0;
11806 schaersvoo 4236
                        reset();
4237
                        break;
4238
                    default:break;
4239
                }
10953 bpr 4240
            }
9213 schaersvoo 4241
            break;
11806 schaersvoo 4242
        case TEXTAREA:
9289 schaersvoo 4243
        /*
11806 schaersvoo 4244
         @ textarea x,y,cols,rows,readonly,value
14066 bpr 4245
         @ may be further controlled by <a href="#inputstyle">inputstyle</a>
14162 bpr 4246
         @ if ''&#36;status=done`` (e.g. in answer.phtml) the inputfield will be cleared and set readonly. Override this by keyword <a href="#status">status</a>.
14066 bpr 4247
         @ if mathml inputfields are present and / or some userdraw is performed, these data will <b>not</b> be send as well (<code>javascript:read_canvas();</code>)
14071 bpr 4248
         @ keyword ''xoffset | centered`` is not active for command ''textarea``
12107 schaersvoo 4249
         @%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 4250
        */
11806 schaersvoo 4251
            if( js_function[DRAW_TEXTAREAS] != 1 ){ js_function[DRAW_TEXTAREAS] = 1;}
4252
            for(i = 0 ; i<6;i++){
9289 schaersvoo 4253
                switch(i){
11806 schaersvoo 4254
                    case 0: int_data[0]=x2px(get_real(infile,0));break; /* x in px */
4255
                    case 1: int_data[1]=y2px(get_real(infile,0));break; /* y in px */
4256
                    case 2: int_data[2]=abs( (int)(get_real(infile,0)));break;/* cols */
4257
                    case 3: int_data[3]=abs( (int)(get_real(infile,0)));break;/* rows */
4258
                    case 4: if( get_real(infile,1) >0){int_data[4] = 1;}else{int_data[3] = 0;};break; /* readonly */
4259
                    case 5: temp = get_string_argument(infile,1);
14208 schaersvoo 4260
                            string_length = 1 + 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);
4261
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 4262
                            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);
4263
                            add_to_buffer(tmp_buffer);
4264
                            input_cnt++;break;
9289 schaersvoo 4265
                    default: break;
4266
                }
4267
            }
11806 schaersvoo 4268
            if(reply_format == 0 ){reply_format = 15;}
4269
            reset();
9289 schaersvoo 4270
            break;
11806 schaersvoo 4271
 
11830 schaersvoo 4272
        case TEXTFILL:
4273
        /*
4274
        @ textfill x0,y0,color,some_text
4275
        @ x0,y0 in xrange / yrange
4276
        @ color will be used for the font color
4277
        @ use command <a href="#fontfamily">fontfamily</a> to set font type and size
13829 bpr 4278
        @ there is also a command <a href="#userdraw">userdraw textfill,color,some_text</a>
13951 schaersvoo 4279
        @%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 4280
        */
4281
 
4282
            js_function[DRAW_TEXTFILL] = 1;
4283
            if(js_function[DRAW_FILLTOBORDER] != 1 ){/* use only once */
4284
             js_function[DRAW_FILLTOBORDER] = 1;
4285
             add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);
4286
            }
4287
            decimals = find_number_of_digits(precision);
4288
            for(i=0;i<4;i++){
4289
                switch(i){
4290
                    case 0: double_data[0] = get_real(infile,0); break; /* x in px */
4291
                    case 1: double_data[1] = get_real(infile,0); break; /* y in py */
13829 bpr 4292
                    case 2: font_color = get_color(infile,0); break;
11830 schaersvoo 4293
                    case 3: temp = get_string(infile,1);
14208 schaersvoo 4294
                    string_length = 1 + 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);
4295
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11830 schaersvoo 4296
                    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);
4297
                    add_to_buffer(tmp_buffer);
4298
                    fill_cnt++;
4299
                    break;
4300
                    default:break;
4301
                }
4302
            }
4303
            reset();
4304
        break;
4305
 
4306
 
11806 schaersvoo 4307
        case FLY_TEXTUP:
9289 schaersvoo 4308
        /*
11806 schaersvoo 4309
         @ textup fontcolor,x,y,font,text_string
14078 bpr 4310
         @ can <b>not</b> be set ''onclick`` or ''drag xy`` (because of translaton matrix...mouse incompatible)
14066 bpr 4311
         @ font may be described by keywords: giant,huge,normal,small,tiny
14071 bpr 4312
         @ use command ''fontsize`` to increase base fontsize for the keywords
11806 schaersvoo 4313
         @ backwards compatible with flydraw
4314
         @ unicode supported: textup red,0,0,huge,\\u2232
14071 bpr 4315
         @ use command ''stringup`` and ''fontfamily`` for a more fine grained control over html5 canvas text element
14162 bpr 4316
         @ Avoid mixing old flydraw commands ''text``, ''textup`` with new canvasdraw commands ''string``; ''stringup``. If the fontfamily was set completely like <code>fontfamily italic 24px Ariel</code>. In that case reset ''fontfamily`` to something like ''fontfamily Ariel`` before the old flydraw commands.
9289 schaersvoo 4317
        */
11806 schaersvoo 4318
            if( js_function[DRAW_TEXTS] != 1 ){ js_function[DRAW_TEXTS] = 1;}
4319
            for(i = 0; i<5 ;i++){
9289 schaersvoo 4320
                switch(i){
11806 schaersvoo 4321
                    case 0: font_color = get_color(infile,0);break;/* name or hex color */
4322
                    case 1: int_data[0] = x2px(get_real(infile,0));break; /* x */
4323
                    case 2: int_data[1] = y2px(get_real(infile,0));break; /* y */
4324
                    case 3: fly_font = get_string_argument(infile,0);
4325
                            if(strcmp(fly_font,"giant") == 0){
4326
                                fly_font_size = (int)(font_size + 24);
4327
                            }
4328
                            else
4329
                            {
4330
                                if(strcmp(fly_font,"huge") == 0){
4331
                                    fly_font_size = (int)(font_size + 14);
4332
                                }
4333
                                else
4334
                                {
4335
                                    if(strcmp(fly_font,"large") == 0){
4336
                                        fly_font_size = (int)(font_size + 6);
4337
                                        }
4338
                                        else
4339
                                        {
4340
                                            if(strcmp(fly_font,"small") == 0){
4341
                                                fly_font_size = (int)(font_size - 4);
4342
                                                if(fly_font_size<0){fly_font_size = 8;}
4343
                                        }
4344
                                    }
4345
                                }
4346
                            }
4347
                            break;
4348
                    case 4:
9289 schaersvoo 4349
                    decimals = find_number_of_digits(precision);
11806 schaersvoo 4350
                    temp = get_string_argument(infile,1);
14208 schaersvoo 4351
                    string_length = 1 + 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);
4352
                    check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11811 schaersvoo 4353
                    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 4354
                    add_to_buffer(tmp_buffer);
14038 schaersvoo 4355
                    reset();use_offset = 0;
9289 schaersvoo 4356
                    break;
11806 schaersvoo 4357
                    default:break;
4358
                }
4359
            }
4360
            break;
4361
 
4362
 
4363
        case TRACE_JSCURVE:
4364
        /*
4365
         @ trace_jscurve some_math_function
4366
         @ will use a crosshair to trace the jsmath curve
4367
         @ two inputfields will display the current x/y-values (numerical evaluation by javascript)
14071 bpr 4368
         @ default labels ''x`` and ''y``; use commands ''xlabel some_x_axis_name`` and ''ylabel some_y_axis_name`` to customize the labels for the input fields
11806 schaersvoo 4369
         @ use commands fontsize and inputstyle to format the fonts for labels and inputfields.
14071 bpr 4370
         @ use commands ''linewidth, strokecolor, crosshairsize`` to adjust the corsshair.
4371
         @ the client browser will convert your math function to javascript math.<br />use parenthesis and rawmath: use 2*x instead of 2x etc etc no check is done on the validity of your function and/or syntax (use error console to debug any errors...)
4372
         @ be aware that the formulas of the plotted function(s) can be found in the page javascript source
13959 bpr 4373
         @%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 4374
        */
4375
            if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
4376
            if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4377
            if( use_js_math == FALSE){
4378
                add_to_js_math(js_include_file);
4379
                use_js_math = TRUE;
4380
            }
4381
            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);
4382
            break;
4383
 
4384
 
4385
        case TRANGE:
4386
        /*
4387
        @ trange tmin,tmax
14071 bpr 4388
        @ alternative: <code>ranget</code>
11806 schaersvoo 4389
        @ default -2,2
4390
        */
4391
            use_parametric = TRUE;
4392
            for(i = 0 ; i<2; i++){
4393
                switch(i){
4394
                    case 0: tmin = get_real(infile,0);break;
4395
                    case 1: tmax = get_real(infile,1);break;
9289 schaersvoo 4396
                    default: break;
4397
                }
4398
            }
14066 bpr 4399
            if(tmin >= tmax ){canvas_error(" trange is not OK: tmin &lt; tmax!\n");}
9289 schaersvoo 4400
            break;
11806 schaersvoo 4401
        case TRANSLATION:
4402
        /*
4403
         @ translation tx,ty
14071 bpr 4404
         @ alternative: <code>translate</code>
11806 schaersvoo 4405
         @ will translate the next objects tx in xrange and ty in yrange
14071 bpr 4406
         @ use command ''killtranstation`` to end the command
13958 schaersvoo 4407
         @%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 4408
        */
4409
            for(i = 0 ; i<2;i++){
4410
                switch(i){
4411
                    case 0: double_data[0] = get_real(infile,0);break;
4412
                    case 1: double_data[1] = get_real(infile,1);
4413
                        use_affine = TRUE;
4414
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 4415
                        string_length = 1 + snprintf(NULL,0, "[1,0,0,1,%.*f,%.*f] ",decimals,double_data[0]*xsize/(xmax - xmin),decimals,-1*double_data[1]*ysize/(ymax - ymin));
4416
                        check_string_length(string_length);affine_matrix = my_newmem(string_length);
11806 schaersvoo 4417
                        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));
4418
                        break;
4419
                    default: break;
4420
                }
4421
            }
4422
        break;
4423
 
4424
        case TRIANGLE:
4425
        /*
4426
         @ triangle x1,y1,x2,y2,x3,y3,color
14066 bpr 4427
         @ use ftriangle or keyword <a href='#filled'>filled</a> for a solid triangle
11806 schaersvoo 4428
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
13948 schaersvoo 4429
         @%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 4430
        */
4431
            for(i=0;i<7;i++){
4432
                switch(i){
4433
                    case 0: double_data[0] = get_real(infile,0);break; /* x */
4434
                    case 1: double_data[1] = get_real(infile,0);break; /* y */
4435
                    case 2: double_data[2] = get_real(infile,0);break; /* x */
4436
                    case 3: double_data[3] = get_real(infile,0);break; /* y */
4437
                    case 4: double_data[4] = get_real(infile,0);break; /* x */
4438
                    case 5: double_data[5] = get_real(infile,0);break; /* y */
4439
                    case 6: stroke_color = get_color(infile,1);/* name or hex color */
4440
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 4441
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
4442
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 4443
                        /* click_cnt++;*/
4444
                        reset();
4445
                        break;
4446
                    default: break;
4447
                }
4448
            }
4449
            break;
4450
        case TRIANGLES:
4451
        /*
4452
         @ triangles color,x1,y1,x2,y2,x3,y3,...
14066 bpr 4453
         @ use ftriangles or keyword <a href='#filled'>filled</a> for solid triangles
11806 schaersvoo 4454
         @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
13948 schaersvoo 4455
         @%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 4456
        */
4457
            stroke_color = get_color(infile,0);/* name or hex color */
4458
            i = 0;
4459
            decimals = find_number_of_digits(precision);
4460
            while( ! done ){
11997 schaersvoo 4461
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 4462
                double_data[0] = get_real(infile,0); /* x1 */
4463
                double_data[1] = get_real(infile,0); /* y1 */
4464
                double_data[2] = get_real(infile,0); /* x2 */
4465
                double_data[3] = get_real(infile,0); /* y2 */
4466
                double_data[4] = get_real(infile,0); /* x3 */
4467
                double_data[5] = get_real(infile,1); /* y3 */
14208 schaersvoo 4468
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
4469
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 4470
                i = i + 6;
4471
            }
4472
            reset();
4473
            break;
4474
        case USERBOXPLOT:
4475
        /*
4476
         @ userboxplot
4477
         @ keyword, no arguments
14066 bpr 4478
         @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
14071 bpr 4479
         @ if set, the student will have to calculate "min,Q1,median,Q3,max" and feed these data into the ''draw_boxplot`` function
4480
         @ for example: 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 /><code>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 />};</code><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)
11806 schaersvoo 4481
        */
4482
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
4483
            fprintf(js_include_file,"var boxplot_source = 3;\n");
4484
            js_function[DRAW_JSBOXPLOT] = 2;
4485
        break;
4486
 
4487
        case USERBOXPLOTDATA:
4488
        /*
4489
         @ userboxplotdata
4490
         @ keyword, no arguments
14066 bpr 4491
         @ use before command <a href="#boxplot">boxplot x_or_y,box-height_or_box-width,x_or_y-position</a>
14071 bpr 4492
         @ if set, the student will have to generate some statistical data. These data should be put in a named array ''student_boxplot_data``
14078 bpr 4493
         @ ''min,Q1,median,Q3,max`` are calculated by a js-function and the 'draw_boxplot' function will draw a boxplot.
14066 bpr 4494
         @ see command <a href="#userboxplot">userboxplot</a> for calling 'draw_boxplot()'
11806 schaersvoo 4495
        */
4496
            if( js_function[DRAW_BOXPLOT] != 1 ){ js_function[DRAW_BOXPLOT] = 1;}
4497
            fprintf(js_include_file,"var boxplot_source = 2;\n");
4498
            js_function[DRAW_JSBOXPLOT] = 1;
4499
 
4500
        break;
4501
 
7614 schaersvoo 4502
        case USERDRAW:
4503
        /*
4504
        @ userdraw object_type,color
9213 schaersvoo 4505
        @ only a single object_type is allowed.
14066 bpr 4506
        @ for multiple different 'userdraw' objects in an exercise, use command <a href="#multidraw">multidraw</a>
14162 bpr 4507
        @ 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>
14078 bpr 4508
        @ 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)
4509
        @ 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 4510
        @ note: object_type polygone: Will be finished (the object is closed) when clicked on the first point of the polygone again.
14066 bpr 4511
        @ 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)
14071 bpr 4512
        @ use a prefix <a href='#filled'>filled</a> or ''f`` to set fillable objects filled. (fcircles,filledcircles etc)
11839 schaersvoo 4513
        @ for non solid filling, use command <a href="#fillpattern">fillpattern grid,hatch,diamond,dot</a>
14071 bpr 4514
        @ use <a href='#opacity'>opacity int,int</a> and <a href='#fillcolor'>fillcolor color</a> to trigger coloured filling of fillable objects
14078 bpr 4515
        @ use command ''dashed`` and/or ''dashtype int,int`` to trigger dashing
4516
        @ use command ''replyformat int`` to control / adjust output formatting of javascript function read_canvas(); (the defaults should be fine...)
14071 bpr 4517
        @ may be combined with onclick or drag xy of other components of flyscript objects (although not very useful...)
14066 bpr 4518
        @ may be combined with keyword <a href='#userinput_xy'>userinput_xy</a>
4519
        @ may be combined width the <a href='#snaptogrid'>snaptogrid snaptopoints </a> etc, to simplify the checking of the student reply
13956 schaersvoo 4520
        @ the cursor may be appropriately styled using command <a href='cursor'>cursor</a>
11088 schaersvoo 4521
        @ 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...
14247 bpr 4522
        @ 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)
14162 bpr 4523
        @ note: a special case is ''userdraw images,boguscolor``. Images (bitmap or svg) present in the exercise page and the img-tag with an unique 'id' and <code>onclick='javascript:place_image_on_canvas(this.id)'</code> 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 /><code>&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;</code><br />To resize and used the svg element, a small piece of javascript is needed...<br /><code>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_ids ];<br />resize_svg_mathml(mythings);</code>
12107 schaersvoo 4524
        @%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
4525
        @%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
4526
        @%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
4527
        @%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
4528
        @%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
4529
        @%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
4530
        @%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
4531
        @%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
4532
        @%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
4533
        @%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
4534
        @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
4535
        @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
4536
        @%userdraw_vline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vline,green
4537
        @%userdraw_vlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw vlines,green
4538
        @%userdraw_hline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hline,green
4539
        @%userdraw_hlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw hlines,green
4540
        @%userdraw_demiline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demiline,green
4541
        @%userdraw_demilines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw demilines,green
4542
        @%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
4543
        @%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
4544
        @%userdraw_point%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw point,green
4545
        @%userdraw_points%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw points,green
4546
        @%userdraw_arrow%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow,green
4547
        @%userdraw_arrows%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrows,green
4548
        @%userdraw_arrow2%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw arrow2,green
4549
        @%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 4550
        @%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
4551
        @%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
14071 bpr 4552
  @%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
4553
  @%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 4554
        @%userdraw_crosshair%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshair,green
4555
        @%userdraw_crosshairs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw crosshairs,green
4556
        @%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
4557
        @%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
4558
        @%userdraw_segment%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segment,green
4559
        @%userdraw_segments%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw segments,green
4560
        @%userdraw_line%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw line,green
4561
        @%userdraw_lines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw lines,green
4562
        @%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
4563
        @%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
4564
        @%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
4565
        @%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
4566
        @%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
4567
        @%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
4568
        @%userdraw_freehandline%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandline,green
4569
        @%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
4570
        @%userdraw_freehandlines%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%linewidth 2%opacity 200,50%userdraw freehandlines,green
4571
        @%userdraw_input%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw input,green
4572
        @%userdraw_inputs%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%userdraw inputs,green
4573
        @%userdraw_text%size 400,400%xrange -10,10%yrange -10,10%grid 1,1,grey%fontfamily 42px Courier%userdraw text,green
14044 schaersvoo 4574
        @%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 4575
        @%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
4576
        @%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
14071 bpr 4577
        @%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 4578
        */
4579
            if( use_userdraw == TRUE ){ /* only one object type may be drawn*/
14038 schaersvoo 4580
                canvas_error("Only one userdraw primitive may be used in command 'userdraw' use command 'multidraw' for this...");
7614 schaersvoo 4581
            }
8074 schaersvoo 4582
            reply_precision = precision;
7614 schaersvoo 4583
            use_userdraw = TRUE;
13970 obado 4584
            fprintf(js_include_file,"\n/* begin userdraw mouse events */\n\
11839 schaersvoo 4585
            userdraw_x = new Array();userdraw_y = new Array();\
11041 schaersvoo 4586
            userdraw_radius = new Array();var xy_cnt=0;var canvas_userdraw = create_canvas%d(%d,xsize,ysize);\
11001 schaersvoo 4587
            var context_userdraw = canvas_userdraw.getContext(\"2d\");var use_dashed = %d;\
4588
            if(use_dashed == 1){if( context_userdraw.setLineDash ){context_userdraw.setLineDash([%d,%d]);}else{if(context_userdraw.mozDash){context_userdraw.mozDash = [%d,%d];};};};\
4589
            if(wims_status != \"done\"){\
14038 schaersvoo 4590
             canvas_div.addEventListener(\"mousedown\" ,user_draw,false);\
4591
             canvas_div.addEventListener(\"mousemove\" ,user_drag,false);\
4592
             canvas_div.addEventListener(\"touchstart\",function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);\
4593
             canvas_div.addEventListener(\"touchmove\" ,function(e){ e.preventDefault();user_drag(e.changedTouches[0]);},false);\
14044 schaersvoo 4594
            }\n/* end userdraw mouse & touch events */",canvas_root_id,DRAW_CANVAS,use_dashed,dashtype[0],dashtype[1],dashtype[0],dashtype[1]);
14123 schaersvoo 4595
 
4596
//           canvas_div.addEventListener(\"touchend\"  ,function(e){ e.preventDefault();user_draw(e.changedTouches[0]);},false);
7614 schaersvoo 4597
            draw_type = get_string_argument(infile,0);
4598
            stroke_color = get_color(infile,1);
4599
            if( strcmp(draw_type,"point") == 0 ){
4600
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4601
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 4602
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
12006 schaersvoo 4603
/*
14066 bpr 4604
type = 0: a point ...radius is fixed
4605
type = 1: a circle ... read inputfield userinput_r
4606
num = 1: a single point / circle
4607
num = 2: multiple points / circles
12006 schaersvoo 4608
*/
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){
12006 schaersvoo 4611
                    add_input_circle(js_include_file,0,1);
8815 schaersvoo 4612
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4613
                }
14044 schaersvoo 4614
                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 4615
            }
4616
            else
4617
            if( strcmp(draw_type,"points") == 0 ){
4618
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4619
                if(reply_format == 0 ){reply_format = 8;}
7614 schaersvoo 4620
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
8071 schaersvoo 4621
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4622
                if(use_input_xy == 1){
12006 schaersvoo 4623
                    add_input_circle(js_include_file,0,2);
8815 schaersvoo 4624
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4625
                }
14044 schaersvoo 4626
                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 4627
            }
4628
            else
4629
            if( strcmp(draw_type,"segment") == 0 ){
4630
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4631
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 4632
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 4633
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4634
                if(use_input_xy == 1){
7652 schaersvoo 4635
                    add_input_segment(js_include_file,1);
8815 schaersvoo 4636
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4637
                }
14044 schaersvoo 4638
                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 4639
            }
4640
            else
10975 schaersvoo 4641
            if( strcmp(draw_type,"polyline") == 0 ||  strcmp(draw_type,"brokenline") == 0 ){
7663 schaersvoo 4642
                if( js_function[DRAW_POLYLINE] != 1 ){ js_function[DRAW_POLYLINE] = 1;}
7876 schaersvoo 4643
                if(reply_format == 0){reply_format = 23;}
8071 schaersvoo 4644
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7780 schaersvoo 4645
                if( use_input_xy == 1 ){
4646
                    add_input_polyline(js_include_file);
8815 schaersvoo 4647
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7663 schaersvoo 4648
                }
14044 schaersvoo 4649
                add_js_polyline(js_include_file,draw_type,line_width,stroke_color,stroke_opacity,use_dashed,dashtype[0],dashtype[1],use_snap);
7663 schaersvoo 4650
            }
4651
            else
7614 schaersvoo 4652
            if( strcmp(draw_type,"segments") == 0 ){
4653
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4654
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
7876 schaersvoo 4655
                if(reply_format == 0){reply_format = 11;}
8071 schaersvoo 4656
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4657
                if(use_input_xy == 1){
7652 schaersvoo 4658
                    add_input_segment(js_include_file,2);
8815 schaersvoo 4659
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4660
                }
14044 schaersvoo 4661
                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 4662
            }
4663
            else
11839 schaersvoo 4664
            if( strcmp(draw_type,"circle") == 0 || strcmp(draw_type,"fcircle") == 0  || strcmp(draw_type,"filledcircle") == 0 ){
7614 schaersvoo 4665
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4666
                if(reply_format == 0){reply_format = 10;}
11875 schaersvoo 4667
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
7614 schaersvoo 4668
                /* 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 4669
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4670
                if(use_input_xy == 1){
12006 schaersvoo 4671
/*
14066 bpr 4672
type = 0: a point ...radius is fixed
4673
type = 1: a circle ... read inputfield userinput_r
4674
num = 1: a single point / circle
4675
num = 2: multiple points / circles
12006 schaersvoo 4676
*/
4677
                    add_input_circle(js_include_file,1,1);
8815 schaersvoo 4678
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4679
                }
14044 schaersvoo 4680
                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 4681
            }
4682
            else
11839 schaersvoo 4683
            if( strcmp(draw_type,"circles") == 0 || strcmp(draw_type,"fcircles") == 0 || strcmp(draw_type,"filledcircles") == 0 ){
7614 schaersvoo 4684
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
7876 schaersvoo 4685
                if(reply_format == 0){reply_format = 10;}
11839 schaersvoo 4686
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7614 schaersvoo 4687
                /* 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 4688
                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 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){
12006 schaersvoo 4691
                    add_input_circle(js_include_file,1,2);
8815 schaersvoo 4692
                    add_input_xyr(js_include_file,canvas_root_id,font_size,input_style);
7652 schaersvoo 4693
                }
7614 schaersvoo 4694
            }
4695
            else
4696
            if(strcmp(draw_type,"crosshair") == 0 ){
4697
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4698
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4699
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
14044 schaersvoo 4700
                add_js_crosshairs(js_include_file,1,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
8071 schaersvoo 4701
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4702
                if(use_input_xy == 1){
7654 schaersvoo 4703
                    add_input_crosshair(js_include_file,1);
8815 schaersvoo 4704
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4705
                }
7614 schaersvoo 4706
            }
4707
            else
4708
            if(strcmp(draw_type,"crosshairs") == 0 ){
4709
                if( js_function[DRAW_CROSSHAIRS] != 1 ){ js_function[DRAW_CROSSHAIRS] = 1;}
7876 schaersvoo 4710
                if(reply_format == 0){reply_format = 8;}
7614 schaersvoo 4711
                /* 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n in x/y-range */
14044 schaersvoo 4712
                add_js_crosshairs(js_include_file,2,draw_type,line_width,crosshair_size ,stroke_color,stroke_opacity,use_snap);
8071 schaersvoo 4713
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
8224 bpr 4714
                if(use_input_xy == 1){
7654 schaersvoo 4715
                    add_input_crosshair(js_include_file,2);
8815 schaersvoo 4716
                    add_input_xy(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4717
                }
7614 schaersvoo 4718
            }
4719
            else
4720
            if(strcmp(draw_type,"freehandline") == 0 ){
4721
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4722
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4723
                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 4724
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4725
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4726
            }
4727
            else
4728
            if(strcmp(draw_type,"freehandlines") == 0 ){
4729
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4730
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4731
                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 4732
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4733
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4734
            }
4735
            else
11839 schaersvoo 4736
            if(strcmp(draw_type,"path") == 0 || strcmp(draw_type,"fpath") == 0 || strcmp(draw_type,"filledpath") == 0 ){
7614 schaersvoo 4737
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
13829 bpr 4738
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4739
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4740
                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 4741
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4742
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4743
            }
4744
            else
11839 schaersvoo 4745
            if(strcmp(draw_type,"paths") == 0 || strcmp(draw_type,"fpaths") == 0  || strcmp(draw_type,"filledpaths") == 0 ){
7614 schaersvoo 4746
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
13829 bpr 4747
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4748
                if(reply_format == 0){reply_format = 6;}
14044 schaersvoo 4749
                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 4750
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4751
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4752
            }
4753
            else
4754
            if(strcmp(draw_type,"arrows") == 0 ){
4755
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4756
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4757
                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 4758
                if(use_input_xy == 1){
7654 schaersvoo 4759
                    add_input_arrow(js_include_file,2);
8815 schaersvoo 4760
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4761
                }
8071 schaersvoo 4762
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4763
            }
4764
            else
7874 schaersvoo 4765
            if(strcmp(draw_type,"arrows2") == 0 ){
4766
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4767
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4768
                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 4769
                if(use_input_xy == 1){
7874 schaersvoo 4770
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4771
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4772
                }
8071 schaersvoo 4773
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4774
            }
4775
            else
4776
            if(strcmp(draw_type,"arrow2") == 0 ){
4777
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4778
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4779
                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 4780
                if(use_input_xy == 1){
7874 schaersvoo 4781
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4782
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7874 schaersvoo 4783
                }
8071 schaersvoo 4784
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7874 schaersvoo 4785
            }
4786
            else
7614 schaersvoo 4787
            if(strcmp(draw_type,"arrow") == 0 ){
4788
                if( js_function[DRAW_ARROWS] != 1 ){ js_function[DRAW_ARROWS] = 1;}
7876 schaersvoo 4789
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4790
                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 4791
                if(use_input_xy == 1){
7654 schaersvoo 4792
                    add_input_arrow(js_include_file,1);
8815 schaersvoo 4793
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7654 schaersvoo 4794
                }
8071 schaersvoo 4795
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4796
            }
4797
            else
14027 schaersvoo 4798
            if( strcmp(draw_type,"curvedarrow2") == 0 ){
14035 schaersvoo 4799
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4800
                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 4801
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4802
            }
4803
            else
4804
            if( strcmp(draw_type,"curvedarrows2") == 0 ){
14035 schaersvoo 4805
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4806
                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 4807
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4808
            }
4809
            else
4810
            if( strcmp(draw_type,"curvedarrows") == 0 ){
14035 schaersvoo 4811
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4812
                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 4813
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4814
            }
4815
            else
4816
            if( strcmp(draw_type,"curvedarrow") == 0 ){
14035 schaersvoo 4817
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4818
                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 4819
                if(use_input_xy > 0){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
14038 schaersvoo 4820
            }
14025 schaersvoo 4821
            else
11839 schaersvoo 4822
            if(strcmp(draw_type,"polygon") == 0 || strcmp(draw_type,"fpolygon") == 0 || strcmp(draw_type,"filledpolygon") == 0){
7614 schaersvoo 4823
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
11839 schaersvoo 4824
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4825
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4826
                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 4827
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4828
                if(use_input_xy == 2){
7780 schaersvoo 4829
                  add_textarea_polygon(js_include_file);
8815 schaersvoo 4830
                  add_textarea_xy(js_include_file,canvas_root_id,input_style);
7746 schaersvoo 4831
                }
7614 schaersvoo 4832
            }
8224 bpr 4833
            else
7614 schaersvoo 4834
            if(strncmp(draw_type,"poly",4) == 0){
4835
                if(strlen(draw_type) < 5){canvas_error("use command \"userdraw poly[3-9],color\" eg userdraw poly6,blue");}
4836
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
7876 schaersvoo 4837
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4838
                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 4839
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4840
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4841
            }
8224 bpr 4842
            else
11839 schaersvoo 4843
            if(strcmp(draw_type,"triangle") == 0 || strcmp(draw_type,"ftriangle") == 0 || strcmp(draw_type,"filledtriangle") == 0){
7614 schaersvoo 4844
                if( js_function[DRAW_PATHS] != 1 ){ js_function[DRAW_PATHS] = 1;}
11839 schaersvoo 4845
                if(strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4846
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4847
                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 4848
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4849
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4850
            }
8224 bpr 4851
            else
7989 schaersvoo 4852
            if( strcmp(draw_type,"hline") == 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,1,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
4860
            if( strcmp(draw_type,"hlines") == 0 ){
4861
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4862
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4863
                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 4864
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4865
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4866
            }
4867
            else
4868
            if( strcmp(draw_type,"vline") == 0 ){
4869
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4870
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4871
                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 4872
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4873
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4874
            }
4875
            else
4876
            if( strcmp(draw_type,"vlines") == 0 ){
4877
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
4878
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4879
                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 4880
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4881
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7989 schaersvoo 4882
            }
4883
            else
7614 schaersvoo 4884
            if( strcmp(draw_type,"line") == 0 ){
4885
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4886
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4887
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4888
                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 4889
                if( use_input_xy == 1 ){
7780 schaersvoo 4890
                    add_input_line(js_include_file,1);
8815 schaersvoo 4891
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7747 schaersvoo 4892
                }
8071 schaersvoo 4893
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4894
            }
4895
            else
4896
            if( strcmp(draw_type,"lines") == 0 ){
4897
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4898
                if( js_function[DRAW_LINES] != 1 ){ js_function[DRAW_LINES] = 1;}
7876 schaersvoo 4899
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4900
                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 4901
                if( use_input_xy == 1 ){
7780 schaersvoo 4902
                    add_input_line(js_include_file,2);
8815 schaersvoo 4903
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
7746 schaersvoo 4904
                }
8071 schaersvoo 4905
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4906
            }
4907
            else
8362 schaersvoo 4908
            if( strcmp(draw_type,"demilines") == 0 || strcmp(draw_type,"halflines") == 0 ){
8244 schaersvoo 4909
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4910
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4911
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4912
                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 4913
                if( use_input_xy == 1 ){
4914
                    add_input_demiline(js_include_file,2);
8815 schaersvoo 4915
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4916
                }
4917
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4918
            }
4919
            else
8362 schaersvoo 4920
            if( strcmp(draw_type,"demiline") == 0 || strcmp(draw_type,"halfline") == 0 ){
8244 schaersvoo 4921
                if( js_function[DRAW_CIRCLES] != 1 ){ js_function[DRAW_CIRCLES] = 1;}
4922
                if( js_function[DRAW_DEMILINES] != 1 ){ js_function[DRAW_DEMILINES] = 1;}
4923
                if(reply_format == 0){reply_format = 11;}
14044 schaersvoo 4924
                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 4925
                if( use_input_xy == 1 ){
4926
                    add_input_demiline(js_include_file,1);
8815 schaersvoo 4927
                    add_input_x1y1x2y2(js_include_file,canvas_root_id,font_size,input_style);
8244 schaersvoo 4928
                }
4929
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4930
            }
4931
            else
11839 schaersvoo 4932
            if( strcmp(draw_type,"rects") == 0 || strcmp(draw_type,"frects") == 0  || strcmp(draw_type,"filledrects") == 0 ){
7614 schaersvoo 4933
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
12008 schaersvoo 4934
                if(strstr(draw_type,"f") != NULL){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4935
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4936
                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 4937
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4938
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4939
            }
8224 bpr 4940
            else
11839 schaersvoo 4941
            if( strcmp(draw_type,"roundrects") == 0 ||  strcmp(draw_type,"froundrects") == 0  ||  strcmp(draw_type,"filledroundrects") == 0){
7614 schaersvoo 4942
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
11839 schaersvoo 4943
                if( strstr(draw_type,"f") != NULL ){ if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4944
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4945
                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 4946
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4947
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4948
            }
8224 bpr 4949
            else
11839 schaersvoo 4950
            if( strcmp(draw_type,"rect") == 0 || strcmp(draw_type,"frect") == 0 || strcmp(draw_type,"filledrect") == 0 ){
7614 schaersvoo 4951
                if( js_function[DRAW_RECTS] != 1 ){ js_function[DRAW_RECTS] = 1;}
13829 bpr 4952
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled =1;}}
7876 schaersvoo 4953
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4954
                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 4955
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4956
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4957
            }
8224 bpr 4958
            else
11839 schaersvoo 4959
            if( strcmp(draw_type,"roundrect") == 0 || strcmp(draw_type,"froundrect") == 0  || strcmp(draw_type,"filledroundrect") == 0){
7614 schaersvoo 4960
                if( js_function[DRAW_ROUNDRECTS] != 1 ){ js_function[DRAW_ROUNDRECTS] = 1;}
11839 schaersvoo 4961
                if( strstr(draw_type,"f") != NULL ){if( use_pattern != 0 ){ use_filled = use_pattern;}else{use_filled = 1;}}
7876 schaersvoo 4962
                if(reply_format == 0){reply_format = 2;}
14044 schaersvoo 4963
                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 4964
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4965
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4966
            }
4967
            else
11839 schaersvoo 4968
            if( strcmp(draw_type,"arcs") == 0 || strcmp(draw_type,"farcs") == 0  || strcmp(draw_type,"filledarcs") == 0 ){
8083 schaersvoo 4969
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
11839 schaersvoo 4970
                if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
4971
                if( strstr(draw_type,"f") != NULL ){use_filled =1;}
8083 schaersvoo 4972
                if(reply_format == 0){reply_format = 25;}
14044 schaersvoo 4973
                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 4974
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4975
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4976
            }
4977
            else
11839 schaersvoo 4978
            if( strcmp(draw_type,"arc") == 0 || strcmp(draw_type,"farc") == 0 || strcmp(draw_type,"filledarc") == 0){
8071 schaersvoo 4979
                if( js_function[DRAW_SEGMENTS] != 1 ){ js_function[DRAW_SEGMENTS] = 1;}
11017 schaersvoo 4980
                if( js_function[JS_FIND_ANGLE] != 1 ){ js_function[JS_FIND_ANGLE] = 1;}
11839 schaersvoo 4981
                if( strstr(draw_type,"f") != NULL ){use_filled =1;}
8083 schaersvoo 4982
                if(reply_format == 0){reply_format = 25;}
14044 schaersvoo 4983
                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 4984
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
4985
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
4986
            }
4987
            else
7614 schaersvoo 4988
            if( strcmp(draw_type,"text") == 0){
7876 schaersvoo 4989
                if(reply_format == 0){reply_format = 17;}
14044 schaersvoo 4990
                add_js_text(js_include_file,canvas_root_id,font_size,font_family,stroke_color,stroke_opacity,use_snap);
7652 schaersvoo 4991
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
8071 schaersvoo 4992
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
7614 schaersvoo 4993
            }
8116 schaersvoo 4994
            else
14038 schaersvoo 4995
            if( strcmp(draw_type,"images") == 0){
4996
                if(reply_format == 0){reply_format = 29;}
4997
                add_js_images(js_include_file,canvas_root_id,use_offset,use_snap);
4998
            }
4999
            else
8116 schaersvoo 5000
            if( strcmp(draw_type,"inputs") == 0){
8224 bpr 5001
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 5002
                if(reply_format == 0){reply_format = 27;}
14044 schaersvoo 5003
                add_js_inputs(js_include_file,canvas_root_id,2,input_cnt,input_style,line_width,use_offset,use_snap);
8116 schaersvoo 5004
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
5005
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
5006
            }
5007
            else
5008
            if( strcmp(draw_type,"input") == 0){
8224 bpr 5009
                if( js_function[DRAW_INPUTS] != 1 ){ js_function[DRAW_INPUTS] = 1;}
8127 schaersvoo 5010
                if(reply_format == 0){reply_format = 27;}
14044 schaersvoo 5011
                add_js_inputs(js_include_file,canvas_root_id,1,input_cnt,input_style,line_width,use_offset,use_snap);
8116 schaersvoo 5012
                if(use_input_xy == 1){ canvas_error("userinput_xy not yet implemented for this userdraw type !");}
5013
                if(use_input_xy == 2){ canvas_error("usertextarea_xy not yet implemented for this userdraw type !");}
5014
            }
11839 schaersvoo 5015
            else /* attention: THIS NEEDS TO BE LAST ! */
11825 schaersvoo 5016
            if( strstr(draw_type,"fill") != NULL ){
11005 schaersvoo 5017
                decimals = find_number_of_digits(precision);
14044 schaersvoo 5018
                add_js_clickfill(js_include_file,canvas_root_id,stroke_color,(int) (fill_opacity/0.0039215),use_snap);
5019
                if( reply_format == 0){reply_format = 10;}
11825 schaersvoo 5020
                if( js_function[DRAW_FILLTOBORDER] != 1 ){js_function[DRAW_FILLTOBORDER] = 1;add_js_filltoborder(js_include_file,canvas_root_id,canvas_type);}
14208 schaersvoo 5021
                if( strcmp(draw_type,"gridfill") == 0){js_function[DRAW_GRIDFILL] = 1;string_length = 1 + 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);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++;}
5022
                if( strcmp(draw_type,"diamondfill") == 0){js_function[DRAW_DIAMONDFILL] = 1;string_length = 1 + 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);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++;}
5023
                if( strcmp(draw_type,"dotfill") == 0){js_function[DRAW_DOTFILL] = 1;string_length = 1 + 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);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++;}
5024
                if( strcmp(draw_type,"hatchfill") == 0){js_function[DRAW_HATCHFILL] = 1;string_length = 1 + 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);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++;}
5025
                if( strcmp(draw_type,"textfill") == 0){js_function[DRAW_TEXTFILL] = 1;temp = get_string(infile,1);string_length = 1 + 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);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 5026
            }
5027
            else
7614 schaersvoo 5028
            {
5029
                canvas_error("unknown drawtype or typo? ");
5030
            }
5031
            reset();
5032
        break;
8386 schaersvoo 5033
 
5034
        case USERINPUT:
5035
        /*
13955 schaersvoo 5036
         @ userinput function inputfield
14071 bpr 5037
         @ alternative: <code>userinput_function</code>
5038
         @ alternative: <code>userinput_xy</code>
14086 bpr 5039
         @ textarea and inputfield are only usable in combination with some ''userdraw draw_ type``
8386 schaersvoo 5040
         @ function may be used any time (e.g. without userdraw)
14071 bpr 5041
         @ multiple ''userinput function`` commands may be used.
5042
         @ use command <code>functionlabel some_string</code> to define the inputfield text: default value "f(x)="
5043
         @ use command <code>strokecolor some_color</code> to adjust the plot / functionlabel color
5044
         @ use command <code>inputstyle some_css</code> to adjust the inputfields
5045
         @ use command <code>fontsize int</code> to adjust the label fonts. (default 12px)
5046
         @ 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 5047
         @%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 5048
         @%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
5049
         @%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
5050
         @%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 5051
        */
5052
            temp = get_string_argument(infile,1);
5053
            if(strstr(temp,"function") != 0  || strstr(temp,"curve") != 0  || strstr(temp,"plot") != 0 ){
5054
             if( js_function[DRAW_JSFUNCTION] != 1 ){
5055
              add_rawmath(js_include_file);/* add simple rawmath routine to correct user input of function */
5056
              js_function[DRAW_JSFUNCTION] = 1;
5057
              if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 5058
              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 5059
              input_cnt++;
5060
             }
10953 bpr 5061
             else
8386 schaersvoo 5062
             {
14078 bpr 5063
              /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
8815 schaersvoo 5064
              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 5065
              input_cnt++;
5066
             }
5067
             if( use_js_math == FALSE){/* add this stuff only once...*/
5068
              add_to_js_math(js_include_file);
5069
              use_js_math = TRUE;
5070
             }
5071
             if( use_js_plot == FALSE){
5072
              use_js_plot = TRUE;
5073
              add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
5074
             }
5075
            }
5076
            else
5077
            {
5078
             if(strstr(temp,"inputfield") != 0 ){
5079
              if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
5080
              if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5081
              use_input_xy = 1;
5082
             }
5083
             else
5084
             {
5085
              if(strstr(temp,"textarea") != 0 ){
5086
               if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
5087
               if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5088
               use_input_xy = 2;
5089
              }
5090
              else
5091
              {
5092
                canvas_error("userinput argument may be \"function,inputfield,textarea\"");
5093
              }
5094
             }
5095
            }
5096
            break;
5097
        case USERINPUT_XY:
5098
        /*
5099
        @ userinput_xy
9372 schaersvoo 5100
        @ keyword (no arguments required)
8386 schaersvoo 5101
        @ to be used in combination with command "userdraw object_type,color"
14078 bpr 5102
        @ 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)
8386 schaersvoo 5103
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
14071 bpr 5104
        @ 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.
14086 bpr 5105
        @ can <b>not</b> be combined with command ''intooltip tiptext`` <br />note: the ''tooltip div element`` is used for placing inputfields
8386 schaersvoo 5106
        @ user drawings will not zoom on zooming (or pan on panning)
14071 bpr 5107
        @ use command inputstyle some_css`` to adjust the inputarea.
5108
        @ use command ''fontsize int`` to adjust the text labels (if needed)
13950 schaersvoo 5109
        @%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 5110
        */
5111
            /* add simple eval check to avoid code injection with unprotected eval(string) */
5112
            if( use_input_xy != 0 ){canvas_error("userinput_xy can not be combined with usertextarea_xy command");}
5113
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5114
            use_input_xy = 1;
5115
            break;
5116
 
5117
        case USERINPUT_FUNCTION:
5118
        /*
5119
        @ userinput_function
9372 schaersvoo 5120
        @ keyword (no arguments required)
14078 bpr 5121
        @ if set, a inputfield will be added to the page
8386 schaersvoo 5122
        @ repeat keyword for more function input fields
5123
        @ the userinput value will be plotted in the canvas
14071 bpr 5124
        @ this value may be read with <code>read_canvas()</code>. <br />for do it yourself js-scripters: If this is the first inputfield in the script, its id is canvas_input0
14078 bpr 5125
        @ 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
14071 bpr 5126
        @ fontsize can be set using command ''fontsize int``
5127
        @ incompatible with command ''intooltip link_text_or_image``: it uses the tooltip div for adding the inputfield
13950 schaersvoo 5128
        @%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 5129
        */
5130
            if( js_function[DRAW_JSFUNCTION] != 1 ){
5131
             js_function[DRAW_JSFUNCTION] = 1;
5132
             add_rawmath(js_include_file);
5133
             if(reply_format == 0){reply_format = 24;}/* read canvas_input values */
8815 schaersvoo 5134
             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 5135
             input_cnt++;
5136
            }
10953 bpr 5137
            else
8386 schaersvoo 5138
            {
14078 bpr 5139
              /* no need to add DRAW_JSFUNCTION, just call it with the parameters */
8815 schaersvoo 5140
             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 5141
             input_cnt++;
5142
            }
5143
            if( use_js_math == FALSE){/* add this stuff only once...*/
5144
             add_to_js_math(js_include_file);
5145
             use_js_math = TRUE;
5146
            }
5147
            if( use_js_plot == FALSE){
5148
             use_js_plot = TRUE;
5149
             add_jsplot(js_include_file,canvas_root_id); /* this plots the function on JSPLOT_CANVAS */
5150
            }
5151
            break;
5152
 
5153
 
5154
 
11806 schaersvoo 5155
        case USERTEXTAREA_XY:
7788 schaersvoo 5156
        /*
11806 schaersvoo 5157
        @ usertextarea_xy
13955 schaersvoo 5158
        @ NOT IMPLEMENTED !!
11806 schaersvoo 5159
        @ keyword (no arguments required)
14086 bpr 5160
        @ to be used in combination with command <code>userdraw object_type,color</code> wherein object_type is only segment / polyline for the time being...
5161
        @ if set two textareas are added to the document (one for x-values, one for y-values)
11806 schaersvoo 5162
        @ the student may use this as correction for (x:y) on a drawing (or to draw without mouse, using just the coordinates)
5163
        @ user drawings will not zoom on zooming (or pan on panning)
14071 bpr 5164
        @ use command ''inputstyle some_css`` to adjust the inputarea.
5165
        @ use command ''fontsize int`` to adjust the text labels (if needed)
7788 schaersvoo 5166
        */
11806 schaersvoo 5167
            if( use_input_xy != 0 ){canvas_error("usertextarea_xy can not be combined with userinput_xy command");}
5168
            if( use_safe_eval == FALSE){use_safe_eval = TRUE;add_safe_eval(js_include_file);} /* just once */
5169
            use_input_xy = 2;
7788 schaersvoo 5170
            break;
8386 schaersvoo 5171
 
11806 schaersvoo 5172
        case VLINE:
8386 schaersvoo 5173
        /*
11806 schaersvoo 5174
        @ vline x,y,color
14071 bpr 5175
        @ alternative: <code>verticalline</code>
11806 schaersvoo 5176
        @ draw a vertical line through point (x:y) in color 'color'
5177
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a>
12107 schaersvoo 5178
        @%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 5179
        */
11806 schaersvoo 5180
            for(i=0;i<3;i++) {
7614 schaersvoo 5181
                switch(i){
11806 schaersvoo 5182
                    case 0: double_data[0] = get_real(infile,0);break; /* x-values */
5183
                    case 1: double_data[1] = get_real(infile,0);break; /* y-values */
5184
                    case 2: stroke_color=get_color(infile,1);/* name or hex color */
5185
                        double_data[2] = double_data[0];
7614 schaersvoo 5186
                        decimals = find_number_of_digits(precision);
14208 schaersvoo 5187
                        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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
5188
                        if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 5189
                        /* click_cnt++; */
8379 schaersvoo 5190
                        reset();
7614 schaersvoo 5191
                    break;
5192
                }
5193
            }
5194
            break;
5195
 
11806 schaersvoo 5196
        case VLINES:
11802 schaersvoo 5197
        /*
11806 schaersvoo 5198
        @ vlines color,x1,y1,x2,y2....
14071 bpr 5199
        @ alternative: <code>verticallines</code>
11806 schaersvoo 5200
        @ draw vertical lines through points (x1:y1),(x2:y2)... in color 'color'
5201
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually
13939 bpr 5202
        @%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 5203
        */
11806 schaersvoo 5204
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5205
            fill_color = stroke_color;
5206
            i=0;
5207
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 5208
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 5209
                if(i%2 == 0 ){
5210
                    double_data[i] = get_real(infile,0); /* x */
7614 schaersvoo 5211
                }
11806 schaersvoo 5212
                else
5213
                {
5214
                    double_data[i] = get_real(infile,1); /* y */
7983 schaersvoo 5215
                }
11806 schaersvoo 5216
                i++;
7983 schaersvoo 5217
            }
11806 schaersvoo 5218
            decimals = find_number_of_digits(precision);
5219
            for(c = 0 ; c < i-1 ; c = c+2){
14208 schaersvoo 5220
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
5221
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 5222
                /* click_cnt++; */
5223
            }
5224
            reset();
7983 schaersvoo 5225
            break;
11806 schaersvoo 5226
 
5227
        case VIDEO:
7614 schaersvoo 5228
        /*
11806 schaersvoo 5229
        @ video x,y,w,h,videofile location
14066 bpr 5230
        @ x,y: left top corner of audio element (in xrange / yrange)
5231
        @ w,y: width and height in pixels
5232
        @ video format may be in *.mp4 (todo: other formats)
13950 schaersvoo 5233
        @%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 5234
        */
11806 schaersvoo 5235
            if( js_function[DRAW_VIDEO] != 1 ){ js_function[DRAW_VIDEO] = 1;}
7614 schaersvoo 5236
            for(i=0;i<5;i++){
5237
                switch(i){
11806 schaersvoo 5238
                    case 0: int_data[0] = x2px(get_real(infile,0)); break; /* x in x/y-range coord system -> pixel */
14162 bpr 5239
                    case 1: int_data[1] = y2px(get_real(infile,0)); break; /* y in x/y-range coord system -> pixel */
11806 schaersvoo 5240
                    case 2: int_data[2] = (int) (get_real(infile,0)); break; /* pixel width */
5241
                    case 3: int_data[3] = (int) (get_real(infile,0)); break; /* height pixel height */
5242
                    case 4: temp = get_string(infile,1);
14208 schaersvoo 5243
                            string_length = 1 + 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);
5244
                            check_string_length(string_length);tmp_buffer = my_newmem(string_length);
11806 schaersvoo 5245
                            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 5246
                            add_to_buffer(tmp_buffer);
5247
                            break;
5248
                    default:break;
5249
                }
5250
            }
5251
            reset();
5252
            break;
11806 schaersvoo 5253
 
7614 schaersvoo 5254
        case X_AXIS_STRINGS:
5255
        /*
5256
         @ xaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
14071 bpr 5257
         @ alternative: <code>xaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
13936 bpr 5258
         @ usable for commands <a href="#numberline">numberline</a> and <a href="#grid">grid</a> or combinations thereof
9346 schaersvoo 5259
         @ use these x-axis num1...num_n values instead of default xmin...xmax
14071 bpr 5260
         @ in case of command ''grid``. there is no need to use keyword <a href="#axisnumbering">axisnumbering</a>
13936 bpr 5261
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
14086 bpr 5262
         @ 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 5263
         @ a javascript error message will flag non-matching value:name pairs
14071 bpr 5264
         @ if the ''x-axis words`` are too big and will overlap, a simple alternating offset will be applied
11044 schaersvoo 5265
         @ to be used before command grid (see <a href="#grid">command grid</a>)
14078 bpr 5266
         @ ''xmajor`` steps should be synchronised with numbers eg. ''1`` in the next example <code>grid 1,100,grey,1,4,6,grey</code>
13937 schaersvoo 5267
         @%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 5268
        */
11891 schaersvoo 5269
            use_axis_numbering++;
7614 schaersvoo 5270
            temp = get_string(infile,1);
5271
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
5272
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
11891 schaersvoo 5273
            fprintf(js_include_file,"x_strings[%d] = [\"%s\"];x_strings_up[%d] = null;",use_axis_numbering,temp,use_axis_numbering);
7614 schaersvoo 5274
            break;
9341 schaersvoo 5275
        case X_AXIS_STRINGS_UP:
5276
        /*
5277
         @ xaxisup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
14071 bpr 5278
         @ alternative: <code>xaxistextup num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
9341 schaersvoo 5279
         @ the text will be rotated 90&deg; up
11044 schaersvoo 5280
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
13936 bpr 5281
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
9346 schaersvoo 5282
         @ use these x-axis num1...num_n values instead of default xmin...xmax
14086 bpr 5283
         @ 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 5284
         @ a javascript error message will flag non-matching value:name pairs
14071 bpr 5285
         @ 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 5286
         @ to be used before command grid (see <a href="#grid">command grid</a>)
14086 bpr 5287
         @''xmajor`` steps should be synchronised with numbers eg. "1" in the next example <code>grid 1,100,grey,1,4,6,grey</code>
13937 schaersvoo 5288
         @%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 5289
        */
11891 schaersvoo 5290
            use_axis_numbering++;
9341 schaersvoo 5291
            temp = get_string(infile,1);
5292
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
5293
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
11891 schaersvoo 5294
            fprintf(js_include_file,"x_strings_up[%d] = 1;x_strings[%d] = [\"%s\"];",use_axis_numbering,use_axis_numbering,temp);
9341 schaersvoo 5295
            break;
8224 bpr 5296
 
11806 schaersvoo 5297
        case XERRORBARS:
7614 schaersvoo 5298
        /*
11806 schaersvoo 5299
        @ xerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
5300
        @ 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'
5301
        @ the errors E1 and E2 values are in xrange.
14071 bpr 5302
        @ use command ''linewidth int`` to adust size
11806 schaersvoo 5303
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12107 schaersvoo 5304
        @%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 5305
 
7614 schaersvoo 5306
        */
11806 schaersvoo 5307
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5308
            fill_color = stroke_color;
5309
            i=0;
5310
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 5311
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11806 schaersvoo 5312
                if(i%2 == 0 ){
5313
                    double_data[i] = get_real(infile,0); /* x */
8071 schaersvoo 5314
                }
11806 schaersvoo 5315
                else
5316
                {
5317
                    double_data[i] = get_real(infile,1); /* y */
7614 schaersvoo 5318
                }
11806 schaersvoo 5319
                i++;
7614 schaersvoo 5320
            }
11806 schaersvoo 5321
            decimals = find_number_of_digits(precision);
5322
            for(c = 2 ; c < i-1 ; c = c+2){
14208 schaersvoo 5323
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 5324
                /* click_cnt++; */
14208 schaersvoo 5325
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
11806 schaersvoo 5326
            }
7614 schaersvoo 5327
            reset();
5328
            break;
11806 schaersvoo 5329
 
5330
        case XRANGE:
7614 schaersvoo 5331
        /*
11806 schaersvoo 5332
        @ xrange xmin,xmax
14071 bpr 5333
        @ alternative: <code>rangex</code>
11806 schaersvoo 5334
        @ if not given: 0,xsize (eg in pixels)
7614 schaersvoo 5335
        */
11806 schaersvoo 5336
            for(i = 0 ; i<2; i++){
7614 schaersvoo 5337
                switch(i){
11806 schaersvoo 5338
                    case 0: xmin = get_real(infile,0);break;
5339
                    case 1: xmax = get_real(infile,1);break;
7614 schaersvoo 5340
                    default: break;
5341
                }
5342
            }
14066 bpr 5343
            if(xmin >= xmax){canvas_error(" xrange is not OK: xmin &lt; xmax !\n");}
11806 schaersvoo 5344
            fprintf(js_include_file,"var xmin = %f;var xmax = %f;\n",xmin,xmax);
5345
            found_size_command++;
7614 schaersvoo 5346
            break;
8386 schaersvoo 5347
 
5348
 
5349
 
11806 schaersvoo 5350
        case XSNAPTOGRID:
7614 schaersvoo 5351
        /*
11806 schaersvoo 5352
         @ xsnaptogrid
5353
         @ keyword (no arguments required)
14086 bpr 5354
         @ a draggable object (use command ''drag x|y|xy``) will snap to the given x-grid values when dragged (mouseup)
11806 schaersvoo 5355
         @ in case of userdraw the drawn points will snap to xmajor grid
14078 bpr 5356
         @ if no grid is defined, points will snap to every integer xrange value. (eg snap_x=1)
14071 bpr 5357
         @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
5358
         @ 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 /><code>xsnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><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 5359
         @%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
5360
         @%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 5361
 
7614 schaersvoo 5362
        */
14038 schaersvoo 5363
        use_snap = 2;
11806 schaersvoo 5364
        break;
8386 schaersvoo 5365
 
11806 schaersvoo 5366
        case XOFFSET:
7614 schaersvoo 5367
        /*
12063 schaersvoo 5368
         @ xoffset
13829 bpr 5369
         @ keyword ; to place the text centered above the text coordinates(x:y) ...
5370
         @ may be used for points or other things requiring centered labels
12063 schaersvoo 5371
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
11811 schaersvoo 5372
         @ 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 5373
        @%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 5374
        */
12063 schaersvoo 5375
         use_offset = 2;
11806 schaersvoo 5376
         break;
8386 schaersvoo 5377
 
11806 schaersvoo 5378
        case XYOFFSET:
7614 schaersvoo 5379
        /*
11806 schaersvoo 5380
         @ xyoffset
5381
         @ keyword ; to place the text (x:y) to (x+dx:y+dy)... dx/dy are dependent on fontsize/fontfamily
13829 bpr 5382
         @ may be used for points or other things requiring labels
12063 schaersvoo 5383
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
11806 schaersvoo 5384
         @ only active for commands <a href="#text">text</a> and <a href="#string">string</a> (e.g. objects in the drag/drop/onclick-librariy
14071 bpr 5385
         @ in case of inputfields the inputfield will be centered x and y on its 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 5386
         @%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 5387
        */
12063 schaersvoo 5388
         use_offset = 3;
11806 schaersvoo 5389
         break;
8386 schaersvoo 5390
 
7996 schaersvoo 5391
        case XUNIT:
5392
        /*
5393
         @ xunit some_unit_for_x-values
5394
         @ unicode allowed (no html code)
12007 schaersvoo 5395
         @ use together with command <a href='#display'>display or mouse</a>
14071 bpr 5396
         @ will display the cursor x-coordinate in ''unit``
12107 schaersvoo 5397
         @%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 5398
        */
5399
            fprintf(js_include_file,"unit_x = \"%s\";",get_string(infile,1));
5400
            break;
11806 schaersvoo 5401
 
5402
        case XLABEL:
7996 schaersvoo 5403
        /*
11806 schaersvoo 5404
        @ xlabel some_string
5405
        @ will be used to create a label for the x-axis (label is in quadrant I)
14071 bpr 5406
        @ can only be used together with command ''grid``<br />not depending on keywords ''axis`` and ''axisnumbering``
14086 bpr 5407
        @ 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)
14071 bpr 5408
        @ see <a href=''z#ylabel'>ylabel</a>
12107 schaersvoo 5409
        @%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 5410
        */
11806 schaersvoo 5411
            temp = get_string(infile,1);
5412
            fprintf(js_include_file,"var xaxislabel = \"%s\";",temp);
7996 schaersvoo 5413
            break;
8071 schaersvoo 5414
 
11806 schaersvoo 5415
        case XLOGBASE:
7991 schaersvoo 5416
        /*
11806 schaersvoo 5417
        @ xlogbase number
5418
        @ sets the logbase number for the x-axis
5419
        @ default value 10
5420
        @ use together with commands xlogscale / xylogscale
7991 schaersvoo 5421
        */
11806 schaersvoo 5422
            fprintf(js_include_file,"xlogbase=%d;",(int)(get_real(infile,1)));
7991 schaersvoo 5423
            break;
5424
 
11806 schaersvoo 5425
        case XLOGSCALE:
7614 schaersvoo 5426
        /*
11806 schaersvoo 5427
         @ xlogscale ymajor,yminor,majorcolor,minorcolor
14071 bpr 5428
         @ the x/y-range are set using commands <code>xrange xmin,xmax</code> and <code>yrange ymin,ymax</code>
11806 schaersvoo 5429
         @ ymajor is the major step on the y-axis; yminor is the divisor for the y-step
14071 bpr 5430
         @ the linewidth is set using command ''linewidth int``
14066 bpr 5431
         @ the opacity of major / minor grid lines is set by command <a href='#opacity'>opacity</a>
14078 bpr 5432
         @ default logbase number = 10 ... when needed, set the logbase number with command ``xlogbase number``
14071 bpr 5433
         @ 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>
5434
         @ note: the complete canvas will be used for the ''log paper``
11806 schaersvoo 5435
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
14071 bpr 5436
         @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
5437
         @ 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
14078 bpr 5438
         @ note: in case of userdraw, the use of keyword <a href='#userinput_xy'>userinput_xy</a> may be handy !
14071 bpr 5439
         @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
12107 schaersvoo 5440
         @%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 5441
        */
11972 schaersvoo 5442
            use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
11806 schaersvoo 5443
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
5444
            if( js_function[DRAW_XLOGSCALE] != 1 ){ js_function[DRAW_XLOGSCALE] = 1;}
5445
            for(i=0;i<4;i++){
7614 schaersvoo 5446
                switch(i){
11806 schaersvoo 5447
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
5448
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
5449
                    case 2: stroke_color = get_color(infile,0); break;
5450
                    case 3: fill_color = get_color(infile,1);
14208 schaersvoo 5451
                        string_length = 1 + 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);
5452
                        tmp_buffer = my_newmem(string_length);
11806 schaersvoo 5453
                        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);
5454
                        fprintf(js_include_file,"use_xlogscale=1;snap_y = %f;snap_x = xlogbase;",double_data[0]/int_data[0]);
5455
                        add_to_buffer(tmp_buffer);
5456
                        break;
7614 schaersvoo 5457
                    default:break;
5458
                }
5459
            }
5460
            break;
11806 schaersvoo 5461
 
5462
        case XYLOGSCALE:
7614 schaersvoo 5463
        /*
11806 schaersvoo 5464
         @ xylogscale majorcolor,minorcolor
14071 bpr 5465
         @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
5466
         @ the linewidth is set using command ''linewidth int``
5467
         @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
14078 bpr 5468
         @ default logbase number = 10 ... when needed, set the logbase number with command ''xlogbase number`` and/or ''ylogbase number``
14071 bpr 5469
         @ 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>
5470
         @ note: the complete canvas will be used for the ''log paper``
11806 schaersvoo 5471
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
14071 bpr 5472
         @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
5473
         @ 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``)
14078 bpr 5474
         @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
14071 bpr 5475
         @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
13829 bpr 5476
         @%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 5477
        */
11972 schaersvoo 5478
            use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
11806 schaersvoo 5479
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
5480
            if( js_function[DRAW_XYLOGSCALE] != 1 ){ js_function[DRAW_XYLOGSCALE] = 1;}
5481
            for(i=0;i<2;i++){
7614 schaersvoo 5482
                switch(i){
11806 schaersvoo 5483
                    case 0: stroke_color = get_color(infile,0); break;
5484
                    case 1: fill_color = get_color(infile,1);
14208 schaersvoo 5485
                        string_length = 1 + 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);
5486
                        tmp_buffer = my_newmem(string_length);
11806 schaersvoo 5487
                        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);
5488
                        fprintf(js_include_file,"use_xlogscale=1;use_ylogscale=1;snap_x = xlogbase;snap_y = ylogbase;");
5489
                        add_to_buffer(tmp_buffer);
5490
                        break;
7614 schaersvoo 5491
                    default:break;
5492
                }
5493
            }
5494
        break;
11806 schaersvoo 5495
 
5496
 
5497
        case Y_AXIS_STRINGS:
7647 schaersvoo 5498
        /*
11806 schaersvoo 5499
         @ yaxis num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n
14071 bpr 5500
         @ alternative: <code>yaxistext num1:string1:num2:string2:num3:string3:num4:string4:....num_n:string_n</code>
14086 bpr 5501
         @ 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>)
11806 schaersvoo 5502
         @ no need to use keyword <a href="#axisnumbering">axisnumbering</a>
13936 bpr 5503
         @ use command <a href="#axis">axis</a> to have visual x/y-axis lines (see command <a href="#grid">grid</a>
14071 bpr 5504
         @ use these y-axis num1...num_n values instead of default ymin...ymax
11806 schaersvoo 5505
         @ a javascript error message will flag non-matching value:name pairs
5506
         @ to be used before command grid (see <a href="#grid">command grid</a>)
12107 schaersvoo 5507
         @%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 5508
        */
11806 schaersvoo 5509
            temp = get_string(infile,1);
5510
            if( strstr(temp,":") != 0 ){ temp = str_replace(temp,":","\",\"");}
5511
            if( strstr(temp,"pi") != 0 ){ temp = str_replace(temp,"pi","(3.1415927)");}/* we need to replace pi for javascript y-value*/
5512
            fprintf(js_include_file,"y_strings = [\"%s\"];\n ",temp);
11891 schaersvoo 5513
            use_axis_numbering++;
11806 schaersvoo 5514
            break;
5515
 
5516
 
5517
        case YERRORBARS:
7614 schaersvoo 5518
        /*
11806 schaersvoo 5519
        @ yerrorbars color,E1,E2,x1,y1,x2,y2,...,x_n,y_n
5520
        @ draw multiple points with y-errorbars E1 (error value under point) and E2 (error value above point) at given coordinates in color 'color'
5521
        @ the errors E1 and E2 values are in yrange.
14071 bpr 5522
        @ use command ''linewidth int`` to adust size
11806 schaersvoo 5523
        @ may be set <a href="#drag">draggable</a> / <a href="#onclick">onclick</a> individually (!)
12107 schaersvoo 5524
        @%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 5525
        */
11806 schaersvoo 5526
            stroke_color=get_color(infile,0); /* how nice: now the color comes first...*/
5527
            fill_color = stroke_color;
11772 schaersvoo 5528
            i=0;
5529
            while( ! done ){     /* get next item until EOL*/
11997 schaersvoo 5530
                if(i > MAX_INT - 1){canvas_error("too many points in argument: repeat command multiple times to fit");}
11772 schaersvoo 5531
                if(i%2 == 0 ){
5532
                    double_data[i] = get_real(infile,0); /* x */
5533
                }
5534
                else
5535
                {
5536
                    double_data[i] = get_real(infile,1); /* y */
5537
                }
5538
                i++;
5539
            }
11806 schaersvoo 5540
            for(c = 2 ; c < i-1 ; c = c+2){
14208 schaersvoo 5541
                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,%s,%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,current_sliders,rotation_center,use_offset,use_pattern);
11806 schaersvoo 5542
                /* click_cnt++; */
14208 schaersvoo 5543
                if(onclick > 0 || slider_cnt > 0){click_cnt++;}
8083 schaersvoo 5544
            }
11806 schaersvoo 5545
            decimals = find_number_of_digits(precision);
8083 schaersvoo 5546
            reset();
11806 schaersvoo 5547
            break;
11811 schaersvoo 5548
        case YOFFSET:
5549
        /*
5550
         @ yoffset
14162 bpr 5551
         @ keyword; to place the text centered above the text coordinates(x:y) ...
13829 bpr 5552
         @ may be used for points or other things requiring centered labels
12063 schaersvoo 5553
         @ use <a href="#fontfamily">fontfamily</a> for setting the font
5554
         @ 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 5555
         @%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 5556
        */
12063 schaersvoo 5557
         use_offset = 1;
11811 schaersvoo 5558
         break;
5559
 
11806 schaersvoo 5560
        case YRANGE:
7614 schaersvoo 5561
        /*
11806 schaersvoo 5562
        @ yrange ymin,ymax
14071 bpr 5563
        @ alternative: <code>rangey</code>
11806 schaersvoo 5564
        @ if not given 0,ysize (eg in pixels)
7614 schaersvoo 5565
        */
11806 schaersvoo 5566
            for(i = 0 ; i<2; i++){
7614 schaersvoo 5567
                switch(i){
11806 schaersvoo 5568
                    case 0: ymin = get_real(infile,0);break;
5569
                    case 1: ymax = get_real(infile,1);break;
5570
                    default: break;
7614 schaersvoo 5571
                }
5572
            }
14066 bpr 5573
            if(ymin >= ymax){canvas_error(" yrange is not OK: ymin &lt; ymax !\n");}
11806 schaersvoo 5574
            fprintf(js_include_file,"var ymin = %f;var ymax = %f;\n",ymin,ymax);
5575
            found_size_command++;
5576
            break;
5577
 
5578
        case YSNAPTOGRID:
7614 schaersvoo 5579
        /*
11806 schaersvoo 5580
         @ ysnaptogrid
5581
         @ keyword (no arguments required)
14162 bpr 5582
         @ a draggable object (use command ''drag x|y|xy``) will snap to the given y-grid values when dragged (mouseup)
11806 schaersvoo 5583
         @ in case of userdraw the drawn points will snap to ymajor grid
14078 bpr 5584
         @ if no grid is defined, points will snap to every integer yrange value. (eg snap_y=1)
14071 bpr 5585
         @ if you do not want a visible grid, but you only want a ''snaptogrid`` with some value...define this grid with opacity 0.
5586
         @ 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 /><code>ysnaptogrid<br />axis<br />grid 2,1,grey,4,4,7,red</code><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 5587
         @%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
5588
         @%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 5589
        */
14038 schaersvoo 5590
        use_snap = 3;
7614 schaersvoo 5591
        break;
11080 schaersvoo 5592
 
7614 schaersvoo 5593
        case YLABEL:
5594
        /*
5595
        @ ylabel some_string
8224 bpr 5596
        @ will be used to create a (vertical) label for the y-axis (label is in quadrant I)
14071 bpr 5597
        @ can only be used together with command <a href="#grid">grid</a><br />not depending on keywords ''axis`` and ''axisnumbering``
14086 bpr 5598
        @ font setting: italic Courier, fontsize will be slightly larger (fontsize + 4)<br />use command ''fontsize`` to adjust (command ''fontsize`` is not active for this command)
12107 schaersvoo 5599
        @%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 5600
        */
5601
            temp = get_string(infile,1);
7653 schaersvoo 5602
            fprintf(js_include_file,"var yaxislabel = \"%s\";",temp);
7614 schaersvoo 5603
            break;
7735 schaersvoo 5604
        case YLOGBASE:
5605
        /*
5606
        @ ylogbase number
5607
        @ sets the logbase number for the y-axis
5608
        @ default value 10
5609
        @ use together with commands ylogscale / xylogscale
5610
        */
5611
            fprintf(js_include_file,"ylogbase=%d;",(int)(get_real(infile,1)));
5612
            break;
7614 schaersvoo 5613
        case YLOGSCALE:
7729 schaersvoo 5614
        /*
5615
         @ ylogscale xmajor,xminor,majorcolor,minorcolor
14071 bpr 5616
         @ the x/y-range are set using commands ''xrange xmin,xmax`` and ''yrange ymin,ymax``
7729 schaersvoo 5617
         @ xmajor is the major step on the x-axis; xminor is the divisor for the x-step
14071 bpr 5618
         @ the linewidth is set using command ''linewidth int``
5619
         @ the opacity of major / minor grid lines is set by command ''opacity [0-255],[0-255]``
14078 bpr 5620
         @ default logbase number = 10 ... when needed, set the logbase number with command ''ylogbase number``
14071 bpr 5621
         @ 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 color</li></ul>
5622
         @ note: the complete canvas will be used for the ''log paper``
11088 schaersvoo 5623
         @ note: userdrawings are done in the log paper, e.g. javascript:read_canvas() will return the real values
14071 bpr 5624
         @ note: command ''mouse color,fontsize`` will show the real values in the logpaper.<br />\
5625
         @ 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``)
14078 bpr 5626
         @ note: in case of userdraw, the use of keyword ''userinput_xy`` may be handy !
14071 bpr 5627
         @ <b>attention</b>: keyword ''snaptogrid`` may not lead to the desired result...
7729 schaersvoo 5628
        */
11972 schaersvoo 5629
            use_axis_numbering++;if(use_axis_numbering > 1){use_axis_numbering = 1;}
7729 schaersvoo 5630
            if( js_function[DRAW_GRID] == 1 ){canvas_error("only one type of grid is allowed...");}
5631
            if( js_function[DRAW_YLOGSCALE] != 1 ){ js_function[DRAW_YLOGSCALE] = 1;}
5632
            for(i=0;i<4;i++){
5633
                switch(i){
5634
                    case 0: double_data[0] = get_real(infile,0);break; /* xmajor */
5635
                    case 1: int_data[0] = (int) (get_real(infile,0));break; /* xminor */
5636
                    case 2: stroke_color = get_color(infile,0); break;
8224 bpr 5637
                    case 3: fill_color = get_color(infile,1);
14208 schaersvoo 5638
                        string_length = 1 + 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);
5639
                        tmp_buffer = my_newmem(string_length);
7779 schaersvoo 5640
                        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 5641
                        fprintf(js_include_file,"use_ylogscale=1;snap_x = %f;snap_y = ylogbase;",double_data[0]/int_data[0]);
7729 schaersvoo 5642
                        add_to_buffer(tmp_buffer);
5643
                        break;
5644
                    default:break;
5645
                }
5646
            }
7614 schaersvoo 5647
            break;
11806 schaersvoo 5648
 
5649
        case YUNIT:
7735 schaersvoo 5650
        /*
11806 schaersvoo 5651
         @ yunit some_unit_for_y-values
5652
         @ unicode allowed (no html code)
5653
         @ use together with command mousey
14071 bpr 5654
         @ will display the cursor y-coordinate in ''unit``
7735 schaersvoo 5655
        */
11806 schaersvoo 5656
            fprintf(js_include_file,"unit_y = \"%s\";",get_string(infile,1));
5657
            break;
5658
 
5659
        case ZOOM:
5660
        /*
5661
         @ zoom button_color
14071 bpr 5662
         @ introduce a very small ''controlpanel`` at the lower right corner
5663
         @ 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
5664
         @ the ''x`` symbol will do a <code>location.reload</code> of the page, and thus reset all canvas drawings.
14247 bpr 5665
         @ choose an appropriate color, so the small ''x,arrows,-,+`` are clearly visible
14071 bpr 5666
         @ command ''opacity`` may be used to set stroke_opacity of buttons
5667
         @ note: use command ''zoom`` at the end of your script code (the same is true for command ''mouse``)
11806 schaersvoo 5668
         @ note: only objects that may be set draggable / clickable will be zoomed / panned
14071 bpr 5669
         @ note: when an object is dragged, zooming / panning will cause the coordinates to be reset to the original position: e.g. dragging / panning will get lost. (array with ''drag data`` is erased). This is a design flaw and not a feature !!
11806 schaersvoo 5670
        */
5671
            fprintf(js_include_file,"use_pan_and_zoom = 1;");
5672
            use_pan_and_zoom = TRUE;
5673
            stroke_color = get_color(infile,1);
5674
            /* we use BG_CANVAS (0) */
5675
            add_zoom_buttons(js_include_file,canvas_root_id,stroke_color,stroke_opacity);
5676
            done = TRUE;
5677
            break;
5678
 
5679
/* ready */
7614 schaersvoo 5680
        default:sync_input(infile);
5681
        break;
5682
    }
8224 bpr 5683
  }
7614 schaersvoo 5684
  /* we are done parsing script file */
14066 bpr 5685
  /* check if xrange / yrange was set explicit ... or use xmin=0 xmax=xsize ymin=0 ymax=ysize: Quadrant I */
7983 schaersvoo 5686
  if( found_size_command == 1 ){
5687
    fprintf(js_include_file,"var xmin = 0;var xmax = %d;var ymin = 0;var ymax = %d",xsize,ysize);
5688
  }
5689
  else
5690
  {
5691
    if( found_size_command != 3 ){
8222 schaersvoo 5692
     canvas_error("Please specify both xrange and yrange ...");
7983 schaersvoo 5693
    }
5694
  }
8257 schaersvoo 5695
 
14066 bpr 5696
  /* if needed, add generic draw functions (grid / xml etc) to buffer: these are no draggable/clickable shapes / objects  ! */
11021 schaersvoo 5697
  add_javascript_function(js_function,canvas_root_id);
7614 schaersvoo 5698
   /* add read_canvas() etc functions if needed */
8257 schaersvoo 5699
  if( reply_format > 0 ){ add_read_canvas(canvas_root_id,reply_format,reply_precision);}
7797 schaersvoo 5700
  if( use_pan_and_zoom == TRUE ){
5701
  /* in case of zooming ... */
13970 obado 5702
  fprintf(js_include_file,"\n/* some extra global stuff : need to rethink panning and zooming !!! */\n\
7797 schaersvoo 5703
  precision = %d;var xmin_start=xmin;var xmax_start=xmax;\
7729 schaersvoo 5704
  var ymin_start=ymin;var ymax_start=xmax;\
5705
  var zoom_x_increment=0;var zoom_y_increment=0;\
5706
  var pan_x_increment=0;var pan_y_increment=0;\
5707
  if(use_ylogscale == 0 ){\
7956 schaersvoo 5708
   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 5709
  }else{\
5710
   zoom_x_increment = (xmax - xmin)/20;\
5711
   pan_x_increment = (xmax - xmin)/20;\
5712
  };\
9406 schaersvoo 5713
  var zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 5714
  function start_canvas%d(type){\
9406 schaersvoo 5715
   zoom_xy=[xmin,xmax,ymin,ymax];\
7653 schaersvoo 5716
   switch(type){\
7729 schaersvoo 5717
    case 0:xmin = xmin + zoom_x_increment;ymin = ymin + zoom_y_increment;xmax = xmax - zoom_x_increment;ymax = ymax - zoom_y_increment;break;\
5718
    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 5719
    case 2:xmin = xmin - pan_x_increment;ymin = ymin ;xmax = xmax - pan_x_increment;ymax = ymax;break;\
5720
    case 3:xmin = xmin + pan_x_increment;ymin = ymin ;xmax = xmax + pan_x_increment;ymax = ymax;break;\
5721
    case 4:xmin = xmin;ymin = ymin - pan_y_increment ;xmax = xmax;ymax = ymax - pan_y_increment;break;\
5722
    case 5:xmin = xmin;ymin = ymin + pan_y_increment ;xmax = xmax;ymax = ymax + pan_y_increment;break;\
11004 schaersvoo 5723
    case 6:xmin = xmin_start; xmax = xmax_start;ymin = ymin_start;ymax = ymax_start;break;\
7653 schaersvoo 5724
    default:break;\
5725
   };\
5726
   if(xmax<=xmin){xmin=xmin_start;xmax=xmax_start;};\
5727
   if(ymax<=ymin){ymin=ymin_start;ymax=ymax_start;};\
9406 schaersvoo 5728
   try{dragstuff.Zoom(xmin,xmax,ymin,ymax);}catch(e){};\
11088 schaersvoo 5729
   if(typeof(redraw_all%d) === 'function' ){redraw_all%d(zoom_xy);}\
9406 schaersvoo 5730
   %s ;\
7653 schaersvoo 5731
  };\
7797 schaersvoo 5732
  start_canvas%d(333);\
9438 schaersvoo 5733
 };\
13970 obado 5734
\n/* end wims_canvas_function */\n\
9406 schaersvoo 5735
wims_canvas_function%d();\n",precision,canvas_root_id,canvas_root_id,canvas_root_id,buffer,canvas_root_id,canvas_root_id);
7797 schaersvoo 5736
  }
5737
  else
5738
  {
5739
  /* no zoom, just add buffer */
13970 obado 5740
  fprintf(js_include_file,"\n/* add buffer */\n\
7797 schaersvoo 5741
  %s\
5742
 };\n\
13970 obado 5743
/* end wims_canvas_function */\n\
7797 schaersvoo 5744
wims_canvas_function%d();\n",buffer,canvas_root_id);
5745
  }
7614 schaersvoo 5746
/* done writing the javascript include file */
5747
fclose(js_include_file);
5748
 
5749
}
5750
 
5751
/* if using a tooltip, this should always be printed to the *.phtml file, so stdout */
9329 schaersvoo 5752
 if( use_tooltip > 0 ){
5753
  if( use_tooltip == 1 ){
5754
   add_js_tooltip(canvas_root_id,tooltip_text,bgcolor,xsize,ysize);
5755
  }
5756
  else
5757
  {
5758
   if( use_tooltip == 2 ){
5759
    add_js_popup(canvas_root_id,xsize,ysize,getfile_cmd);
5760
   }
5761
  }
5762
 }
7614 schaersvoo 5763
exit(EXIT_SUCCESS);
5764
}
5765
/* end main() */
5766
 
5767
/******************************************************************************
5768
**
5769
**  sync_input
5770
**
5771
**  synchronises input line - reads to end of line, leaving file pointer
5772
**  at first character of next line.
5773
**
5774
**  Used by:
5775
**  main program - error handling.
5776
**
5777
******************************************************************************/
5778
void sync_input(FILE *infile)
5779
{
5780
        int c = 0;
5781
 
7658 schaersvoo 5782
        if( c == '\n' || c == ';' ) return;
5783
        while( ( (c=getc(infile)) != EOF ) && (c != '\n') && (c != '\r') && (c != ';')) ;
7614 schaersvoo 5784
        if( c == EOF ) finished = 1;
7658 schaersvoo 5785
        if( c == '\n' || c == '\r' || c == ';') line_number++;
7614 schaersvoo 5786
        return;
5787
}
5788
 
5789
/******************************************************************************/
5790
 
5791
char *str_replace(const char *str, const char *old, const char *new){
5792
/* http://creativeandcritical.net/str-replace-c/ */
5793
    if(strlen(str) > MAX_BUFFER){canvas_error("string argument too big");}
5794
    char *ret, *r;
5795
    const char *p, *q;
5796
    size_t oldlen = strlen(old);
5797
    size_t count = 0;
5798
    size_t retlen = 0;
5799
    size_t newlen = strlen(new);
5800
    if (oldlen != newlen){
5801
        for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen){
5802
            count++;
5803
            retlen = p - str + strlen(p) + count * (newlen - oldlen);
5804
        }
8224 bpr 5805
    }
7614 schaersvoo 5806
    else
5807
    {
5808
        retlen = strlen(str);
5809
    }
8224 bpr 5810
 
7614 schaersvoo 5811
    if ((ret = malloc(retlen + 1)) == NULL){
5812
        ret = NULL;
5813
        canvas_error("string argument is NULL");
5814
    }
5815
    else
5816
    {
5817
        for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
5818
            size_t l = q - p;
5819
            memcpy(r, p, l);
5820
            r += l;
5821
            memcpy(r, new, newlen);
5822
            r += newlen;
5823
        }
5824
        strcpy(r, p);
5825
    }
5826
    return ret;
5827
}
5828
 
5829
/******************************************************************************/
7848 bpr 5830
 
7614 schaersvoo 5831
char *get_color(FILE *infile , int last){
5832
    int c,i = 0,is_hex = 0;
5833
    char temp[MAX_COLOR_STRING], *string;
8305 schaersvoo 5834
    const char *not_allowed = "0123456789";
10891 schaersvoo 5835
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != ',' ) && ( c != ';' )  && ( c != '\t' ) ){
7614 schaersvoo 5836
        if( i > MAX_COLOR_STRING ){ canvas_error("colour string is too big ... ? ");}
5837
        if( c == '#' ){
5838
            is_hex = 1;
5839
        }
5840
        if( c != ' '){
8304 schaersvoo 5841
            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 5842
            temp[i]=tolower(c);
5843
            i++;
5844
        }
5845
    }
10891 schaersvoo 5846
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5847
    if( c == '\n' || c == ';'  || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5848
    if( c == EOF ){finished = 1;}
5849
    if( finished == 1 && last != 1 ){ canvas_error("expected more arguments");}
5850
    temp[i]='\0';
5851
    if( strlen(temp) == 0 ){ canvas_error("expected a colorname or hexnumber, but found nothing !!");}
5852
    if( is_hex == 1 ){
5853
        char red[3], green[3], blue[3];
5854
        red[0]   = toupper(temp[1]); red[1]   = toupper(temp[2]); red[2]   = '\0';
5855
        green[0] = toupper(temp[3]); green[1] = toupper(temp[4]); green[2] = '\0';
5856
        blue[0]  = toupper(temp[5]); blue[1]  = toupper(temp[6]); blue[2]  = '\0';
5857
        int r = (int) strtol(red,   NULL, 16);
5858
        int g = (int) strtol(green, NULL, 16);
5859
        int b = (int) strtol(blue,  NULL, 16);
5860
        string = (char *)my_newmem(12);
5861
        snprintf(string,11,"%d,%d,%d",r,g,b);
5862
        return string;
5863
    }
5864
    else
5865
    {
5866
        string = (char *)my_newmem(sizeof(temp));
5867
        snprintf(string,sizeof(temp),"%s",temp);
8304 schaersvoo 5868
        for( i = 0; i < NUMBER_OF_COLORNAMES ; i++ ){
7614 schaersvoo 5869
            if( strcmp( colors[i].name , string ) == 0 ){
5870
                return colors[i].rgb;
5871
            }
5872
        }
8304 schaersvoo 5873
        canvas_error("I was expecting a color name or hexnumber...but found nothing.");
7614 schaersvoo 5874
    }
8304 schaersvoo 5875
    return "0,0,255";
7614 schaersvoo 5876
}
5877
 
14066 bpr 5878
char *get_string(FILE *infile,int last){ /* last = 0: more arguments ; last=1 final argument */
7614 schaersvoo 5879
    int c,i=0;
5880
    char  temp[MAX_BUFFER], *string;
10891 schaersvoo 5881
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') ){
7614 schaersvoo 5882
        temp[i]=c;
5883
        i++;
5884
        if(i > MAX_BUFFER){ canvas_error("string size too big...repeat command to fit string");break;}
5885
    }
10891 schaersvoo 5886
    if( ( c == '\n' ||  c == '\t'  || c == EOF ) && last == 0){canvas_error("expecting more arguments in command");}
5887
    if( c == '\n' ||  c == '\t') { done = TRUE; line_number++; }
11022 schaersvoo 5888
    if( c == EOF ) {finished = 1;}
7614 schaersvoo 5889
    temp[i]='\0';
11022 schaersvoo 5890
    if( strlen(temp) == 0 && last != 3 ){ canvas_error("expected a word or string, but found nothing !!");}
7614 schaersvoo 5891
    string=(char *)my_newmem(strlen(temp));
5892
    snprintf(string,sizeof(temp),"%s",temp);
5893
    return string;
5894
}
5895
 
14066 bpr 5896
char *get_string_argument(FILE *infile,int last){  /* last = 0: more arguments ; last=1 final argument */
7614 schaersvoo 5897
    int c,i=0;
5898
    char temp[MAX_BUFFER], *string;
10891 schaersvoo 5899
    while(( (c=getc(infile)) != EOF ) && ( c != '\n') && ( c != '\t') && ( c != ',')){
7614 schaersvoo 5900
        temp[i]=c;
5901
        i++;
5902
        if(i > MAX_BUFFER){ canvas_error("string size too big...will cut it off");break;}
5903
    }
8224 bpr 5904
    if( ( c == '\n' || c == EOF) && last == 0){canvas_error("expecting more arguments in command");}
10891 schaersvoo 5905
    if( c == '\n' || c == '\t' ) { line_number++; }
7614 schaersvoo 5906
    if( c == EOF ) {finished = 1;}
9478 schaersvoo 5907
    if( finished == 1 && last == 0 ){ canvas_error("expected more arguments");}
7614 schaersvoo 5908
    temp[i]='\0';
10953 bpr 5909
/*
8322 schaersvoo 5910
    17.10.2014 removed (question Perrin)
5911
    may cause some unwanted effects...
14078 bpr 5912
    if( strlen(temp) == 0 ){ canvas_error("expected a word or string (without comma), but found nothing !!");}
8322 schaersvoo 5913
*/
7614 schaersvoo 5914
    string=(char *)my_newmem(sizeof(temp));
5915
    snprintf(string,sizeof(temp),"%s",temp);
5916
    done = TRUE;
5917
    return string;
5918
}
5919
 
14066 bpr 5920
double get_real(FILE *infile, int last){ /* accept anything that looks like an number ?  last = 0: more arguments ; last=1 final argument */
7614 schaersvoo 5921
    int c,i=0,found_calc = 0;
5922
    double y;
5923
    char tmp[MAX_INT];
10953 bpr 5924
    /*
14066 bpr 5925
     these things are 'allowed functions': *,^,+,-,/,(,),e,arc,cos,tan,pi,log,ln,sqrt,abs
8383 schaersvoo 5926
     but there should be a better way to avoid segfaults !
8348 schaersvoo 5927
    */
5928
    const char *allowed = "earcostanpilogqb*+-/^()";/* assuming these are allowed stuff in a 'number'*/
5929
    const char *not_allowed = "#dfhjkmuvwxyz{}[]%&~!$";/* avoid segmentation faults in a "atof()" and "wims eval" */
10891 schaersvoo 5930
    while(( (c=getc(infile)) != EOF ) && ( c != ',') && (c != '\n') && (c != '\t') && ( c != ';')){
7614 schaersvoo 5931
     if( c != ' ' ){
8224 bpr 5932
      if( i == 0 &&  c == '+' ){
7614 schaersvoo 5933
       continue;
8224 bpr 5934
      }
7614 schaersvoo 5935
      else
5936
      {
8304 schaersvoo 5937
       c = tolower(c);
5938
       if( strchr(not_allowed,c) != 0 ){canvas_error("found a character not associated with a number...");}
5939
       if( strchr(allowed,c) != 0 ){found_calc = 1;}/* hand the string over to wims eval() */
7614 schaersvoo 5940
       tmp[i] = c;
5941
       i++;
5942
      }
5943
     }
5944
     if( i > MAX_INT - 1){canvas_error("number too large");}
5945
    }
10891 schaersvoo 5946
    if( ( c == '\n' || c == EOF || c == ';' || c == '\t' ) && last == 0){canvas_error("expecting more arguments in command");}
5947
    if( c == '\n' || c == ';' || c == '\t' ){ done = TRUE; line_number++; }
7614 schaersvoo 5948
    if( c == EOF ){done = TRUE ; finished = 1;}
5949
    tmp[i]='\0';
5950
    if( strlen(tmp) == 0 ){canvas_error("expected a number , but found nothing !!");}
8304 schaersvoo 5951
    if( found_calc == 1 ){ /* use wims eval to calculate 2*pi/3 */
7848 bpr 5952
     void *f = eval_create(tmp);
7614 schaersvoo 5953
     assert(f);if( f == NULL ){canvas_error("I'm having trouble parsing your \"expression\" ") ;}
7848 bpr 5954
     y = eval_x(f, 1);
14066 bpr 5955
     /* if function is bogus; y = 1: so no core dumps */
7848 bpr 5956
     eval_destroy(f);
7614 schaersvoo 5957
    }
5958
    else
5959
    {
5960
     y = atof(tmp);
5961
    }
5962
    return y;
5963
}
8304 schaersvoo 5964
 
13829 bpr 5965
 
7614 schaersvoo 5966
void canvas_error(char *msg){
14066 bpr 5967
    fprintf(stdout,"\n</script><hr /><span style=\"color:red\">FATAL syntax error:line %d: %s</span><hr />",line_number,msg);
7614 schaersvoo 5968
    finished = 1;
5969
    exit(EXIT_SUCCESS);
5970
}
5971
 
5972
 
5973
/* convert x/y coordinates to pixel */
5974
int x2px(double x){
5975
 return x*xsize/(xmax - xmin) -  xsize*xmin/(xmax - xmin);
5976
}
5977
 
5978
int y2px(double y){
5979
 return -1*y*ysize/(ymax - ymin) + ymax*ysize/(ymax - ymin);
5980
}
5981
 
5982
double px2x(int x){
5983
 return (x*(xmax - xmin)/xsize + xmin);
5984
}
5985
double px2y(int y){
5986
 return (y*(ymax - ymin)/ysize + ymin);
5987
}
5988
 
5989
void add_to_buffer(char *tmp){
5990
 if( tmp == NULL || tmp == 0 ){ canvas_error("nothing to add_to_buffer()...");}
5991
 /*  do we have enough space left in buffer[MAX_BUFFER] ? */
5992
 int space_left = (int) (sizeof(buffer) - strlen(buffer));
5993
 if( space_left > strlen(tmp)){
5994
  strncat(buffer,tmp,space_left - 1);/* add safely "tmp" to the string buffer */
5995
 }
5996
 else
5997
 {
5998
  canvas_error("buffer is too big\n");
5999
 }
6000
 tmp = NULL;free(tmp);
6001
 return;
6002
}
6003
 
6004
void reset(){
14038 schaersvoo 6005
 use_filled = FALSE;
6006
 use_dashed = FALSE;
6007
 use_rotate = FALSE;
8379 schaersvoo 6008
 onclick = 0;
7614 schaersvoo 6009
}
6010
 
6011
 
6012
 
6013
/* What reply format in read_canvas();
6014
 
14247 bpr 6015
note: if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
7614 schaersvoo 6016
1 = x1,x2,x3,x4....x_n
6017
    y1,y2,y3,y4....y_n
6018
 
6019
    x/y in pixels
6020
 
6021
2 = x1,x2,x3,x4....x_n
6022
    y1,y2,y3,y4....y_n
14162 bpr 6023
    x/y in xrange / yrange coordinate system
7614 schaersvoo 6024
 
6025
3 = x1,x2,x3,x4....x_n
6026
    y1,y2,y3,y4....y_n
6027
    r1,r2,r3,r4....r_n
6028
 
8224 bpr 6029
    x/y in pixels
7614 schaersvoo 6030
    r in pixels
6031
 
6032
4 = x1,x2,x3,x4....x_n
6033
    y1,y2,y3,y4....y_n
6034
    r1,r2,r3,r4....r_n
6035
 
14162 bpr 6036
    x/y in xrange / yrange coordinate system
7614 schaersvoo 6037
    r in pixels
6038
 
6039
5 = Ax1,Ax2,Ax3,Ax4....Ax_n
6040
    Ay1,Ay2,Ay3,Ay4....Ay_n
6041
    Bx1,Bx2,Bx3,Bx4....Bx_n
6042
    By1,By2,By3,By4....By_n
6043
    Cx1,Cx2,Cx3,Cx4....Cx_n
6044
    Cy1,Cy2,Cy3,Cy4....Cy_n
6045
    ....
6046
    Zx1,Zx2,Zx3,Zx4....Zx_n
6047
    Zy1,Zy2,Zy3,Zy4....Zy_n
8224 bpr 6048
 
7614 schaersvoo 6049
    x/y in pixels
6050
 
6051
6 = Ax1,Ax2,Ax3,Ax4....Ax_n
6052
    Ay1,Ay2,Ay3,Ay4....Ay_n
6053
    Bx1,Bx2,Bx3,Bx4....Bx_n
6054
    By1,By2,By3,By4....By_n
6055
    Cx1,Cx2,Cx3,Cx4....Cx_n
6056
    Cy1,Cy2,Cy3,Cy4....Cy_n
6057
    ....
6058
    Zx1,Zx2,Zx3,Zx4....Zx_n
6059
    Zy1,Zy2,Zy3,Zy4....Zy_n
6060
 
14162 bpr 6061
    x/y in xrange / yrange coordinate system
8224 bpr 6062
 
7614 schaersvoo 6063
7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 6064
 
7614 schaersvoo 6065
    x/y in pixels
6066
 
6067
8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
8224 bpr 6068
 
14162 bpr 6069
    x/y in xrange / yrange coordinate system
7614 schaersvoo 6070
 
8224 bpr 6071
9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
7614 schaersvoo 6072
 
6073
    x/y in pixels
6074
 
14044 schaersvoo 6075
10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n
7614 schaersvoo 6076
 
14162 bpr 6077
    x/y in xrange / yrange coordinate system
14044 schaersvoo 6078
    r is userdraw_radius
7614 schaersvoo 6079
 
6080
11 = Ax1,Ay1,Ax2,Ay2
6081
     Bx1,By1,Bx2,By2
6082
     Cx1,Cy1,Cx2,Cy2
6083
     Dx1,Dy1,Dx2,Dy2
6084
     ......
6085
     Zx1,Zy1,Zx2,Zy2
8224 bpr 6086
 
7614 schaersvoo 6087
    x/y in  xrange / yrange coordinate system
6088
 
6089
12 = Ax1,Ay1,Ax2,Ay2
6090
     Bx1,By1,Bx2,By2
6091
     Cx1,Cy1,Cx2,Cy2
6092
     Dx1,Dy1,Dx2,Dy2
6093
     ......
6094
     Zx1,Zy1,Zx2,Zy2
8224 bpr 6095
 
7614 schaersvoo 6096
    x/y in pixels
6097
 
14078 bpr 6098
13 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2,Cx1:Cy1:Cx2:Cy2,Dx1:Dy1:Dx2:Dy2, ..., Zx1:Zy1:Zx2:Zy2
7614 schaersvoo 6099
 
14162 bpr 6100
    x/y in xrange / yrange coordinate system
7614 schaersvoo 6101
14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
6102
    x/y in pixels
6103
15 = reply from inputfields,textareas
6104
    reply1,reply2,reply3,...,reply_n
14071 bpr 6105
    only fields set write (e.g. will not read readonly inputfield values.
7614 schaersvoo 6106
 
6107
16 = read mathml inputfields only
6108
 
11080 schaersvoo 6109
17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
14066 bpr 6110
 when ready: calculate size_t of string via snprintf(NULL,0,"blah blah...");
7614 schaersvoo 6111
 
14066 bpr 6112
18 = read clock(s): H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
7614 schaersvoo 6113
19 = return clicked object number (analogue to shape-library onclick)
14071 bpr 6114
20 = return x/y-data in x-range/y-range of all ''draggable`` images
7614 schaersvoo 6115
21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
14066 bpr 6116
22 = array: x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
14162 bpr 6117
    x/y in xrange / yrange coordinate system
14071 bpr 6118
23 = answertype for a polyline: remove multiple occurences due to reclick on a point to create next polyline segment
6119
24 = read all inputfield values: even those set <code>readonly</code>
8224 bpr 6120
25 = return all userdrawn arcs in degrees:
6121
26 = return all userdrawn arcs in radians:
11080 schaersvoo 6122
27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
8322 schaersvoo 6123
28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
14162 bpr 6124
    x/y/r in xrange / yrange coordinate system: may be used to reinput into command
6125
    circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
14078 bpr 6126
    will not return anything else (e.g. no inputfields, text etc)
14066 bpr 6127
29 = mulidraw read:
10953 bpr 6128
 
7614 schaersvoo 6129
*/
6130
 
14066 bpr 6131
/*
6132
SCHAERSVOORDE: replyformat 2,7,8,21,22,23,24
14044 schaersvoo 6133
USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31
14066 bpr 6134
OEF: 22,23,28
14044 schaersvoo 6135
*/
8257 schaersvoo 6136
void add_read_canvas(int canvas_root_id,int type_reply,int reply_precision){
14038 schaersvoo 6137
/* just 1 reply type allowed...except for format 34 !!!  */
8074 schaersvoo 6138
fprintf(js_include_file,"\
13970 obado 6139
\n/* begin set_reply_precision() */\n\
8074 schaersvoo 6140
function set_reply_precision(){\
6141
 var len = userdraw_x.length;\
6142
 var prec = %d;\
6143
 for(var p = 0 ; p < len ; p++ ){\
6144
  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
6145
  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
6146
 };\
6147
 len = userdraw_radius.length;\
6148
 if( len > 0 ){\
6149
  for(var p = 0 ; p < len ; p++ ){\
6150
   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
6151
  };\
6152
 };\
6153
};",reply_precision);
7963 schaersvoo 6154
 
7614 schaersvoo 6155
switch(type_reply){
8224 bpr 6156
/*
7614 schaersvoo 6157
answers may have:
6158
x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
6159
*/
6160
    case 1: fprintf(js_include_file,"\
13970 obado 6161
\n/* begin function 1 read_canvas%d() */\n\
8257 schaersvoo 6162
read_canvas%d = function(){\
7614 schaersvoo 6163
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 6164
 set_reply_precision();\
7614 schaersvoo 6165
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6166
  var p = 0;var input_reply = new Array();\
6167
  if( document.getElementById(\"canvas_input0\")){\
6168
   var t = 0;\
6169
   while(document.getElementById(\"canvas_input\"+t)){\
6170
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6171
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6172
     p++;\
6173
    };\
6174
    t++;\
6175
   };\
6176
  };\
11088 schaersvoo 6177
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6178
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply + \"\\n\"+userdraw_text;\
6179
  }\
6180
  else\
6181
  {\
6182
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+input_reply;\
6183
  }\
6184
 }\
6185
 else\
6186
 {\
11088 schaersvoo 6187
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6188
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_text;\
6189
  }\
6190
  else\
6191
  {\
6192
   return userdraw_x+\"\\n\"+userdraw_y;\
6193
  }\
6194
 };\
8108 schaersvoo 6195
};\n\
13970 obado 6196
/* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6197
    break;
6198
    case 2: fprintf(js_include_file,"\
13970 obado 6199
\n/* begin function 2 read_canvas%d() */\n\
8257 schaersvoo 6200
read_canvas%d = function(){\
7614 schaersvoo 6201
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 6202
 set_reply_precision();\
7614 schaersvoo 6203
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
8074 schaersvoo 6204
 var prec = %d;\
7614 schaersvoo 6205
 while(userdraw_x[p]){\
8074 schaersvoo 6206
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
6207
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 6208
  p++;\
6209
 };\
11806 schaersvoo 6210
 if(p == 0){return;};\
7614 schaersvoo 6211
 if( document.getElementById(\"canvas_input0\")){\
6212
  var p = 0;var input_reply = new Array();\
6213
  if( document.getElementById(\"canvas_input0\")){\
6214
   var t = 0;\
6215
   while(document.getElementById(\"canvas_input\"+t)){\
6216
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6217
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6218
     p++;\
6219
    };\
6220
    t++;\
6221
   };\
6222
  };\
11088 schaersvoo 6223
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6224
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6225
  }\
6226
  else\
6227
  {\
6228
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
6229
  }\
6230
 }\
6231
 else\
6232
 {\
11088 schaersvoo 6233
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6234
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
6235
  }\
6236
  else\
6237
  {\
6238
   return reply_x+\"\\n\"+reply_y;\
6239
  };\
6240
 };\
8108 schaersvoo 6241
};\n\
13970 obado 6242
/* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6243
    break;
6244
    case 3: fprintf(js_include_file,"\
13970 obado 6245
\n/* begin function 3 read_canvas%d() */\n\
8257 schaersvoo 6246
read_canvas%d = function(){\
7614 schaersvoo 6247
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
8074 schaersvoo 6248
 set_reply_precision();\
7614 schaersvoo 6249
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6250
  var p = 0;var input_reply = new Array();\
6251
  if( document.getElementById(\"canvas_input0\")){\
6252
   var t = 0;\
6253
   while(document.getElementById(\"canvas_input\"+t)){\
6254
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6255
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6256
     p++;\
6257
    };\
6258
    t++;\
6259
   };\
6260
  };\
11088 schaersvoo 6261
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6262
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6263
  }\
6264
  else\
6265
  {\
6266
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
6267
  }\
6268
 }\
6269
 else\
6270
 {\
11088 schaersvoo 6271
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6272
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius+\"\\n\"+userdrawW_text;\
6273
  }\
6274
  else\
6275
  {\
6276
   return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
6277
  }\
6278
 }\
8108 schaersvoo 6279
};\n\
13970 obado 6280
/* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6281
    break;
6282
    case 4: fprintf(js_include_file,"\
13970 obado 6283
\n/* begin function 4 read_canvas%d() */\n\
8257 schaersvoo 6284
read_canvas%d = function(){\
8074 schaersvoo 6285
 var prec = %d;\
7614 schaersvoo 6286
 var reply_x = new Array();var reply_y = new Array();var p = 0;\
6287
 while(userdraw_x[p]){\
8074 schaersvoo 6288
  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
6289
  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;;\
7614 schaersvoo 6290
  p++;\
6291
 };\
11806 schaersvoo 6292
 if(p == 0){return;};\
7614 schaersvoo 6293
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6294
  var p = 0;var input_reply = new Array();\
6295
  if( document.getElementById(\"canvas_input0\")){\
6296
   var t = 0;\
6297
   while(document.getElementById(\"canvas_input\"+t)){\
6298
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6299
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6300
     p++;\
6301
    };\
6302
    t++;\
6303
   };\
6304
  };\
11088 schaersvoo 6305
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6306
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6307
  }\
6308
  else\
6309
  {\
6310
   return reply_x+\"\\n\"+reply_y +\"\\n\"+userdraw_radius+\"\\n\"+input_reply;\
6311
  }\
6312
 }\
6313
 else\
6314
 {\
11088 schaersvoo 6315
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6316
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius+\"\\n\"+userdraw_text;\
6317
  }\
6318
  else\
6319
  {\
6320
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
6321
  }\
6322
 };\
8108 schaersvoo 6323
};\n\
13970 obado 6324
/* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6325
    break;
8224 bpr 6326
    /*
14066 bpr 6327
        attention: we reset userdraw_x / userdraw_y: because  userdraw_x = [][] userdraw_y = [][]
8224 bpr 6328
        used for userdraw multiple paths
7614 schaersvoo 6329
    */
6330
    case 5: fprintf(js_include_file,"\
13970 obado 6331
\n/* begin function 5 read_canvas%d() */\n\
8257 schaersvoo 6332
read_canvas%d = function(){\
8074 schaersvoo 6333
 set_reply_precision();\
7614 schaersvoo 6334
 var p = 0;\
6335
 var reply = \"\";\
6336
 for(p = 0; p < userdraw_x.length;p++){\
6337
  if(userdraw_x[p] != null ){\
6338
   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
6339
  };\
6340
 };\
11806 schaersvoo 6341
 if(p == 0){return;};\
7614 schaersvoo 6342
 userdraw_x = [];userdraw_y = [];\
6343
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6344
  var p = 0;var input_reply = new Array();\
6345
  if( document.getElementById(\"canvas_input0\")){\
6346
   var t = 0;\
6347
   while(document.getElementById(\"canvas_input\"+t)){\
6348
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6349
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6350
     p++;\
6351
    };\
6352
    t++;\
6353
   };\
6354
  };\
11088 schaersvoo 6355
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6356
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6357
  }\
6358
  else\
6359
  {\
6360
   return reply +\"\\n\"+input_reply;\
6361
  }\
6362
 }\
6363
 else\
6364
 {\
11088 schaersvoo 6365
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6366
   return reply+\"\\n\"+userdraw_text;\
6367
  }\
6368
  else\
6369
  {\
6370
   return reply;\
6371
  }\
6372
 };\
8108 schaersvoo 6373
};\n\
13970 obado 6374
/* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6375
    break;
8224 bpr 6376
    /*
14162 bpr 6377
        attention: we reset userdraw_x / userdraw_y: because userdraw_x = [][] userdraw_y = [][]
8224 bpr 6378
        used for userdraw multiple paths
7614 schaersvoo 6379
    */
6380
    case 6: fprintf(js_include_file,"\
13970 obado 6381
\n/* begin function 6 read_canvas%d() */\n\
8257 schaersvoo 6382
read_canvas%d = function(){\
7614 schaersvoo 6383
 var p = 0;\
6384
 var reply = \"\";\
6385
 var tmp_x = new Array();\
6386
 var tmp_y = new Array();\
8074 schaersvoo 6387
 var prec = %d;\
7614 schaersvoo 6388
 for(p = 0 ; p < userdraw_x.length; p++){\
6389
  tmp_x = userdraw_x[p];\
6390
  tmp_y = userdraw_y[p];\
6391
  if(tmp_x != null){\
6392
   for(var i = 0 ; i < tmp_x.length ; i++){\
8074 schaersvoo 6393
    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
6394
    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
7614 schaersvoo 6395
   };\
6396
   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
6397
  };\
6398
 };\
11806 schaersvoo 6399
 if(p == 0){return;};\
7614 schaersvoo 6400
 userdraw_x = [];userdraw_y = [];\
6401
 if( document.getElementById(\"canvas_input0\") ){\
6402
  var p = 0;var input_reply = new Array();\
6403
  if( document.getElementById(\"canvas_input0\")){\
6404
   var t = 0;\
6405
   while(document.getElementById(\"canvas_input\"+t)){\
6406
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6407
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6408
     p++;\
6409
    };\
6410
    t++;\
6411
   };\
6412
  };\
11088 schaersvoo 6413
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6414
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6415
  }\
6416
  else\
6417
  {\
6418
   return reply +\"\\n\"+input_reply;\
6419
  }\
6420
 }\
6421
 else\
6422
 {\
11088 schaersvoo 6423
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6424
   return reply +\"\\n\"+userdraw_text;\
6425
  }\
6426
  else\
6427
  {\
6428
   return reply;\
6429
  }\
6430
 };\
8108 schaersvoo 6431
};\n\
13970 obado 6432
/* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6433
    break;
6434
    case 7: fprintf(js_include_file,"\
13970 obado 6435
\n/* begin function 7 read_canvas%d() */\n\
8257 schaersvoo 6436
read_canvas%d = function(){\
8074 schaersvoo 6437
 set_reply_precision();\
7614 schaersvoo 6438
 var reply = new Array();\
6439
 var p = 0;\
6440
 while(userdraw_x[p]){\
6441
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
6442
  p++;\
6443
 };\
11806 schaersvoo 6444
 if(p == 0){return;};\
7614 schaersvoo 6445
 if( document.getElementById(\"canvas_input0\") ){\
6446
  var p = 0;var input_reply = new Array();\
6447
  if( document.getElementById(\"canvas_input0\")){\
6448
   var t = 0;\
6449
   while(document.getElementById(\"canvas_input\"+t)){\
6450
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6451
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6452
     p++;\
6453
    };\
6454
    t++;\
6455
   };\
6456
  };\
11088 schaersvoo 6457
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6458
   return reply+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6459
  }\
6460
  else\
6461
  {\
6462
   return reply+\"\\n\"+input_reply;\
6463
  }\
7862 schaersvoo 6464
 }\
7614 schaersvoo 6465
 else\
6466
 {\
11088 schaersvoo 6467
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6468
   return reply+\"\\n\"+userdraw_text;\
6469
  }\
6470
  else\
6471
  {\
6472
   return reply;\
6473
  }\
6474
 };\
8108 schaersvoo 6475
};\n\
13970 obado 6476
/* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6477
    break;
6478
    case 8: fprintf(js_include_file,"\
13970 obado 6479
\n/* begin function 8 read_canvas%d() */\n\
8257 schaersvoo 6480
read_canvas%d = function(){\
7614 schaersvoo 6481
 var reply = new Array();\
6482
 var p = 0;\
8074 schaersvoo 6483
 var prec = %d;\
7614 schaersvoo 6484
 while(userdraw_x[p]){\
8074 schaersvoo 6485
  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7614 schaersvoo 6486
  p++;\
6487
 };\
11806 schaersvoo 6488
 if(p == 0){return;};\
7614 schaersvoo 6489
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6490
  var p = 0;var input_reply = new Array();\
6491
  if( document.getElementById(\"canvas_input0\")){\
6492
   var t = 0;\
6493
   while(document.getElementById(\"canvas_input\"+t)){\
6494
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6495
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6496
     p++;\
6497
    };\
6498
    t++;\
6499
   };\
6500
  };\
11088 schaersvoo 6501
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6502
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6503
  }\
6504
  else\
6505
  {\
6506
   return reply +\"\\n\"+input_reply;\
6507
  }\
6508
 }\
6509
 else\
6510
 {\
11088 schaersvoo 6511
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6512
   return reply +\"\\n\"+userdraw_text;\
6513
  }\
6514
  else\
6515
  {\
6516
   return reply;\
6517
  }\
6518
 };\
8108 schaersvoo 6519
};\n\
13970 obado 6520
/* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6521
    break;
6522
    case 9: fprintf(js_include_file,"\
13970 obado 6523
\n/* begin function 9 read_canvas%d() */\n\
8257 schaersvoo 6524
read_canvas%d = function(){\
8074 schaersvoo 6525
 set_reply_precision();\
7614 schaersvoo 6526
 var reply = new Array();\
6527
 var p = 0;\
6528
 while(userdraw_x[p]){\
6529
  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
6530
  p++;\
6531
 };\
11806 schaersvoo 6532
 if(p == 0){return;};\
7614 schaersvoo 6533
 if( document.getElementById(\"canvas_input0\") ){\
6534
  var p = 0;var input_reply = new Array();\
6535
  if( document.getElementById(\"canvas_input0\")){\
6536
   var t = 0;\
6537
   while(document.getElementById(\"canvas_input\"+t)){\
6538
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6539
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6540
     p++;\
6541
    };\
6542
    t++;\
6543
   };\
6544
  };\
11088 schaersvoo 6545
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6546
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6547
  }\
6548
  else\
6549
  {\
6550
   return reply +\"\\n\"+input_reply;\
6551
  }\
6552
 }\
6553
 else\
6554
 {\
11088 schaersvoo 6555
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6556
   return reply +\"\\n\"+userdraw_text;\
6557
  }\
6558
  else\
6559
  {\
6560
   return reply;\
6561
  }\
6562
 };\
8108 schaersvoo 6563
};\n\
13970 obado 6564
/* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6565
    break;
6566
    case 10: fprintf(js_include_file,"\
13970 obado 6567
\n/* begin function 10 read_canvas%d() */\n\
8257 schaersvoo 6568
read_canvas%d = function(){\
7614 schaersvoo 6569
 var reply = new Array();\
6570
 var p = 0;\
8074 schaersvoo 6571
 var prec = %d;\
14044 schaersvoo 6572
 var reply = \"\";\
7614 schaersvoo 6573
 while(userdraw_x[p]){\
14044 schaersvoo 6574
  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 6575
  p++;\
6576
 };\
11806 schaersvoo 6577
 if(p == 0){return;};\
14044 schaersvoo 6578
 return reply;\
8108 schaersvoo 6579
};\n\
13970 obado 6580
/* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6581
    break;
6582
    case 11: fprintf(js_include_file,"\
13970 obado 6583
\n/* begin function 11 read_canvas%d() */\n\
8257 schaersvoo 6584
read_canvas%d = function(){\
7614 schaersvoo 6585
 var reply = \"\";\
6586
 var p = 0;\
8074 schaersvoo 6587
 var prec = %d;\
13521 schaersvoo 6588
 while(userdraw_x[p+1]){\
8074 schaersvoo 6589
  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 6590
  p = p+2;\
6591
 };\
11806 schaersvoo 6592
 if(p == 0){return;};\
7614 schaersvoo 6593
 if( document.getElementById(\"canvas_input0\") || document.getElementById(\"mathml0\") ){\
6594
  var p = 0;var input_reply = new Array();\
6595
  if( document.getElementById(\"canvas_input0\")){\
6596
   var t = 0;\
6597
   while(document.getElementById(\"canvas_input\"+t)){\
6598
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6599
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6600
     p++;\
6601
    };\
6602
    t++;\
6603
   };\
6604
  };\
11088 schaersvoo 6605
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6606
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6607
  }\
6608
  else\
6609
  {\
6610
   return reply +\"\\n\"+input_reply;\
6611
  }\
6612
 }\
6613
 else\
6614
 {\
11088 schaersvoo 6615
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6616
   return reply +\"\\n\"+userdraw_text;\
6617
  }\
6618
  else\
6619
  {\
6620
   return reply;\
6621
  }\
6622
 };\
8108 schaersvoo 6623
};\n\
13970 obado 6624
/* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6625
    break;
6626
    case 12: fprintf(js_include_file,"\
13970 obado 6627
\n/* begin function 12 read_canvas%d() */\n\
8257 schaersvoo 6628
read_canvas%d = function(){\
8074 schaersvoo 6629
 set_reply_precision();\
7614 schaersvoo 6630
 var reply = \"\";\
6631
 var p = 0;\
13522 schaersvoo 6632
 while(userdraw_x[p+1]){\
6633
 reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
6634
 p=p+2;\
7614 schaersvoo 6635
 };\
13522 schaersvoo 6636
 };\
11806 schaersvoo 6637
 if(p == 0){return;};\
7614 schaersvoo 6638
 if( document.getElementById(\"canvas_input0\") ){\
6639
  var p = 0;var input_reply = new Array();\
6640
  if( document.getElementById(\"canvas_input0\")){\
6641
   var t = 0;\
6642
   while(document.getElementById(\"canvas_input\"+t)){\
6643
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6644
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6645
     p++;\
6646
    };\
6647
    t++;\
6648
   };\
6649
  };\
11088 schaersvoo 6650
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6651
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6652
  }\
6653
  else\
6654
  {\
6655
   return reply +\"\\n\"+input_reply;\
6656
  }\
6657
 }\
6658
 else\
6659
 {\
11088 schaersvoo 6660
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6661
   return reply +\"\\n\"+userdraw_text\
6662
  }\
6663
  else\
6664
  {\
6665
   return reply;\
6666
  }\
6667
 };\
8108 schaersvoo 6668
};\n\
13970 obado 6669
/* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6670
    break;
6671
    case 13: fprintf(js_include_file,"\
13970 obado 6672
\n/* begin function 13 read_canvas%d() */\n\
8257 schaersvoo 6673
read_canvas%d = function(){\
7614 schaersvoo 6674
 var reply = new Array();\
6675
 var p = 0;var i = 0;\
8074 schaersvoo 6676
 var prec = %d;\
13521 schaersvoo 6677
 while(userdraw_x[p+1]){\
8074 schaersvoo 6678
  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 6679
  p = p+2;i++;\
6680
 };\
11806 schaersvoo 6681
 if(p == 0){return;};\
7614 schaersvoo 6682
 if( document.getElementById(\"canvas_input0\") ){\
6683
  var p = 0;var input_reply = new Array();\
6684
  if( document.getElementById(\"canvas_input0\")){\
6685
   var t = 0;\
6686
   while(document.getElementById(\"canvas_input\"+t)){\
6687
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6688
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6689
     p++;\
6690
    };\
6691
    t++;\
6692
   };\
6693
  };\
11088 schaersvoo 6694
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6695
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6696
  }\
6697
  else\
6698
  {\
6699
   return reply +\"\\n\"+input_reply;\
6700
  }\
6701
 }\
6702
 else\
6703
 {\
11088 schaersvoo 6704
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6705
   return reply +\"\\n\"+userdraw_text\
6706
  }\
6707
  else\
6708
  {\
6709
   return reply;\
6710
  }\
6711
 };\
8108 schaersvoo 6712
};\n\
13970 obado 6713
/* end function 13 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6714
    break;
6715
    case 14: fprintf(js_include_file,"\
13970 obado 6716
\n/* begin function 14 read_canvas%d() */\n\
8257 schaersvoo 6717
read_canvas%d = function(){\
8074 schaersvoo 6718
 set_reply_precision();\
7614 schaersvoo 6719
 var reply = new Array();\
6720
 var p = 0;var i = 0;\
13521 schaersvoo 6721
 while(userdraw_x[p+1]){\
7614 schaersvoo 6722
  reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
6723
  p = p+2;i++;\
6724
 };\
11806 schaersvoo 6725
 if(p == 0){return;};\
7614 schaersvoo 6726
 if( document.getElementById(\"canvas_input0\") ){\
6727
  var p = 0;var input_reply = new Array();\
6728
  if( document.getElementById(\"canvas_input0\")){\
6729
   var t = 0;\
6730
   while(document.getElementById(\"canvas_input\"+t)){\
6731
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6732
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6733
     p++;\
6734
    };\
6735
    t++;\
6736
   };\
6737
  };\
11088 schaersvoo 6738
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6739
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6740
  }\
6741
  else\
6742
  {\
6743
   return reply +\"\\n\"+input_reply;\
6744
  }\
6745
 }\
6746
 else\
6747
 {\
11088 schaersvoo 6748
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6749
   return reply +\"\\n\"+userdraw_text;\
6750
  }\
6751
  else\
6752
  {\
6753
   return reply;\
6754
  }\
6755
 };\
8108 schaersvoo 6756
};\n\
13970 obado 6757
/* end function 14 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6758
    break;
6759
    case 15: fprintf(js_include_file,"\
13970 obado 6760
\n/* begin function 15  read_canvas%d() */\n\
8257 schaersvoo 6761
read_canvas%d = function(){\
7614 schaersvoo 6762
 var input_reply = new Array();\
6763
 var p = 0;\
6764
 if( document.getElementById(\"canvas_input0\")){\
6765
  var t = 0;\
6766
  while(document.getElementById(\"canvas_input\"+t)){\
6767
   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6768
    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6769
    p++;\
6770
   };\
6771
   t++;\
6772
  };\
6773
 };\
11088 schaersvoo 6774
 if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6775
   return input_reply +\"\\n\"+userdraw_text;\
6776
 }\
6777
 else\
6778
 {\
6779
  return input_reply;\
6780
 };\
8108 schaersvoo 6781
};\n\
13970 obado 6782
/* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6783
    break;
6784
    case 16: fprintf(js_include_file,"\
13970 obado 6785
\n/* begin function 16 read_mathml() */\n\
7614 schaersvoo 6786
function read_mathml(){\
6787
 var reply = new Array();\
6788
 var p = 0;\
6789
 if( document.getElementById(\"mathml0\")){\
6790
  while(document.getElementById(\"mathml\"+p)){\
6791
   reply[p] = document.getElementById(\"mathml\"+p).value;\
6792
   p++;\
6793
  };\
6794
 };\
6795
return reply;\
6796
};\
6797
this.read_mathml = read_mathml;\n\
13970 obado 6798
/* end function 16 read_mathml() */");
7614 schaersvoo 6799
    break;
6800
    case 17:  fprintf(js_include_file,"\
13970 obado 6801
\n/* begin function 17 read_canvas%d() */\n\
8257 schaersvoo 6802
read_canvas%d = function(){\
11080 schaersvoo 6803
 var len = userdraw_x.length;\
6804
 if( len == 0){alert(\"no text typed...\");return;}\
6805
 var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
6806
 for(var p = 1 ; p < len ; p++){\
6807
  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
6808
 };\
6809
 return rep;\
8108 schaersvoo 6810
};\n\
13970 obado 6811
/* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6812
    break;
6813
    case 18: fprintf(js_include_file,"\
13970 obado 6814
\n/* javascript has no real modulo function */\n\
10956 schaersvoo 6815
function mod(n, m){\
6816
 var m = parseInt(((n %% m) + m) %% m);\
6817
 return m;\
6818
};\
13970 obado 6819
\n/* begin function 18 read_canvas%d() */\n\
8257 schaersvoo 6820
read_canvas%d = function(){\
7614 schaersvoo 6821
 var p = 0;\
6822
 var reply = new Array();\
6823
 var name;\
6824
 var t = true;\
8000 schaersvoo 6825
 var h;var m;var s;\
7614 schaersvoo 6826
 while(t){\
8000 schaersvoo 6827
  try{\
6828
   name = eval('clocks'+p);\
6829
   h = name.H;m = name.M;s = name.S;\
10956 schaersvoo 6830
   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
8000 schaersvoo 6831
   reply[p] = h+\":\"+m+\":\"+s;\
6832
   p++;\
6833
  }catch(e){t=false;};\
7614 schaersvoo 6834
 };\
8000 schaersvoo 6835
 if( p == 0 ){alert(\"clock(s) not modified...\");return;}\
7614 schaersvoo 6836
 return reply;\
8108 schaersvoo 6837
};\n\
13970 obado 6838
/* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 6839
    break;
6840
    case 19: fprintf(js_include_file,"\
13970 obado 6841
\n/* begin function 19 read_canvas%d() */\n\
8257 schaersvoo 6842
read_canvas%d = function(){\
7614 schaersvoo 6843
 return reply[0];\
8108 schaersvoo 6844
};\n\
13970 obado 6845
/* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
8130 schaersvoo 6846
    break;
7614 schaersvoo 6847
    case 20: fprintf(js_include_file,"\
13970 obado 6848
\n/* begin function 20 read_canvas%d() */\n\
8257 schaersvoo 6849
read_canvas%d = function(){\
8074 schaersvoo 6850
 var prec = %d;\
7614 schaersvoo 6851
 var len  = ext_drag_images.length;\
6852
 var reply = new Array(len);\
6853
 for(var p = 0 ; p < len ; p++){\
6854
    var img = ext_drag_images[p];\
8556 schaersvoo 6855
    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7614 schaersvoo 6856
 };\
6857
 return reply;\
8108 schaersvoo 6858
};\n\
13970 obado 6859
/* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6860
    break;
6861
    case 21: fprintf(js_include_file,"\
13970 obado 6862
\n/* begin function 21 read_canvas%d() */\n\
8257 schaersvoo 6863
read_canvas%d = function(){\
7614 schaersvoo 6864
 if( userdraw_x.length == 0){alert(\"nothing drawn...\");return;}\
6865
 var reply_coord = new Array();var p = 0;\
8074 schaersvoo 6866
 var prec = %d;\
7614 schaersvoo 6867
 while(userdraw_x[p]){\
8074 schaersvoo 6868
  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
7614 schaersvoo 6869
  p++;\
6870
 };\
11806 schaersvoo 6871
 if(p == 0){return;};\
7614 schaersvoo 6872
 if( document.getElementById(\"canvas_input0\") ){\
6873
  var p = 0;var input_reply = new Array();\
6874
  if( document.getElementById(\"canvas_input0\")){\
6875
   var t = 0;\
6876
   while(document.getElementById(\"canvas_input\"+t)){\
6877
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6878
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6879
     p++;\
6880
    };\
6881
    t++;\
6882
   };\
6883
  };\
11088 schaersvoo 6884
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6885
   return reply_coord+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6886
  }\
6887
  else\
6888
  {\
6889
   return reply_coord+\"\\n\"+input_reply;\
6890
  }\
6891
 }\
6892
 else\
6893
 {\
11088 schaersvoo 6894
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6895
   return reply_coord+\"\\n\"+userdraw_text;\
6896
  }\
6897
  else\
6898
  {\
6899
   return reply_coord;\
6900
  };\
6901
 };\
8108 schaersvoo 6902
};\n\
13970 obado 6903
/* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6904
    break;
6905
    case 22: fprintf(js_include_file,"\
13970 obado 6906
\n/* begin function 22 read_canvas%d() */\n\
8257 schaersvoo 6907
read_canvas%d = function(){\
7614 schaersvoo 6908
 var reply = new Array();\
7963 schaersvoo 6909
 var lu = userdraw_x.length;\
11806 schaersvoo 6910
 if(lu == 0){return;};\
7614 schaersvoo 6911
 var idx = 0;\
8074 schaersvoo 6912
 var prec = %d;\
7963 schaersvoo 6913
 for(var p = 0 ; p < lu ; p++){\
8074 schaersvoo 6914
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
6915
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
7614 schaersvoo 6916
 };\
6917
 if( document.getElementById(\"canvas_input0\") ){\
6918
  var p = 0;var input_reply = new Array();\
6919
  if( document.getElementById(\"canvas_input0\")){\
6920
   var t = 0;\
6921
   while(document.getElementById(\"canvas_input\"+t)){\
6922
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6923
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6924
     p++;\
6925
    };\
6926
    t++;\
6927
   };\
6928
  };\
11088 schaersvoo 6929
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6930
   return reply +\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6931
  }\
6932
  else\
6933
  {\
6934
   return reply +\"\\n\"+input_reply;\
6935
  }\
6936
 }\
6937
 else\
6938
 {\
11088 schaersvoo 6939
  if( typeof(userdraw_text) !== 'undefined' ){\
7614 schaersvoo 6940
   return reply +\"\\n\"+userdraw_text;\
6941
  }\
6942
  else\
6943
  {\
6944
   return reply;\
6945
  }\
6946
 };\
8108 schaersvoo 6947
};\n\
13970 obado 6948
/* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7614 schaersvoo 6949
    break;
7782 schaersvoo 6950
    case 23: fprintf(js_include_file,"\
13970 obado 6951
\n/* begin function 23 read_canvas%d() default 5 px marge */\n\
8257 schaersvoo 6952
read_canvas%d = function(){\
7782 schaersvoo 6953
 if( userdraw_x.length < 2){alert(\"nothing drawn...\");return;}\
6954
 var lu = userdraw_x.length;\
6955
 if( lu != userdraw_y.length ){ alert(\"x / y mismatch !\");return;}\
7962 schaersvoo 6956
 var reply_x = new Array();var reply_y = new Array();\
6957
 var marge = 5;var p = 0;\
8074 schaersvoo 6958
 var prec = %d;\
7782 schaersvoo 6959
 for(var i = 0; i < lu - 1 ; i++ ){\
10987 schaersvoo 6960
  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
8074 schaersvoo 6961
   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
7962 schaersvoo 6962
   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){ alert(\"hmmmm ?\");return; };\
6963
   p++;\
7782 schaersvoo 6964
  };\
8074 schaersvoo 6965
  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 6966
 };\
6967
 if( document.getElementById(\"canvas_input0\")){\
6968
  var p = 0;var input_reply = new Array();\
6969
  if( document.getElementById(\"canvas_input0\")){\
6970
   var t = 0;\
6971
   while(document.getElementById(\"canvas_input\"+t)){\
6972
    if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
6973
     input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
6974
     p++;\
6975
    };\
6976
    t++;\
6977
   };\
6978
  };\
11088 schaersvoo 6979
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6980
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply+\"\\n\"+userdraw_text;\
6981
  }\
6982
  else\
6983
  {\
6984
   return reply_x+\"\\n\"+reply_y+\"\\n\"+input_reply;\
6985
  }\
6986
 }\
6987
 else\
6988
 {\
11088 schaersvoo 6989
  if( typeof(userdraw_text) !== 'undefined' ){\
7782 schaersvoo 6990
   return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_text;\
6991
  }\
6992
  else\
6993
  {\
6994
   return reply_x+\"\\n\"+reply_y;\
6995
  };\
6996
 };\
8108 schaersvoo 6997
};\n\
13970 obado 6998
/* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
7782 schaersvoo 6999
    break;
7984 schaersvoo 7000
    case 24: fprintf(js_include_file,"\n\
13970 obado 7001
/* begin function 24  read_canvas%d() */\n\
8257 schaersvoo 7002
read_canvas%d = function(){\
7984 schaersvoo 7003
 var input_reply = new Array();\
7004
 var p = 0;\
7005
 if( document.getElementById(\"canvas_input0\")){\
7006
  while(document.getElementById(\"canvas_input\"+p)){\
7007
    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
7008
    p++;\
7009
  };\
7010
  return input_reply;\
7011
 };\
8108 schaersvoo 7012
};\n\
13970 obado 7013
/* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7984 schaersvoo 7014
    break;
8083 schaersvoo 7015
    case 25:
14066 bpr 7016
    fprintf(js_include_file,"\n/* begin function 25 read_canvas%d(): angle(s) in degrees */\n\
8257 schaersvoo 7017
read_canvas%d = function(){\
8083 schaersvoo 7018
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
7019
 var lu = userdraw_radius.length;\
7020
 var prec = %d;\
7021
 var angle_reply = new Array(lu);\
7022
 for(var p = 0 ; p < lu ; p++){\
7023
  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
7024
 };\
7025
 return angle_reply;\
8108 schaersvoo 7026
};\n\
13970 obado 7027
/* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 7028
    break;
7029
    case 26:
14066 bpr 7030
    fprintf(js_include_file,"\n/* begin function 26 read_canvas%d(): angle(s) in radians */\n\
8257 schaersvoo 7031
read_canvas%d = function(){\
8083 schaersvoo 7032
 if( userdraw_radius.length < 1){alert(\"nothing drawn...\");return;}\
7033
 var lu = userdraw_radius.length;\
7034
 var prec = %d;\
7035
 var angle_reply = new Array(lu);\
7036
 for(var p = 0 ; p < lu ; p++){\
7037
  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
7038
 };\
7039
 return angle_reply;\
8108 schaersvoo 7040
};\n\
13970 obado 7041
/* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8083 schaersvoo 7042
    break;
8127 schaersvoo 7043
    case 27:
14066 bpr 7044
    fprintf(js_include_file,"\n/* begin function 27 read_canvas%d(): inputfield(s) location and their values: */\n\
8257 schaersvoo 7045
read_canvas%d = function(){\
8127 schaersvoo 7046
 var lu = userdraw_x.length;\
14044 schaersvoo 7047
 if( lu < 1){alert(\"nothing drawn...\");return;};\
8127 schaersvoo 7048
 set_reply_precision();\
14044 schaersvoo 7049
 var prec = %d;var rep = \"\";\
8127 schaersvoo 7050
 for(var p = 0 ; p < lu ; p++){\
14044 schaersvoo 7051
   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 7052
 };\
11080 schaersvoo 7053
 return rep;\
8127 schaersvoo 7054
};\n\
13970 obado 7055
/* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8127 schaersvoo 7056
    break;
8322 schaersvoo 7057
    case 28:
13970 obado 7058
    fprintf(js_include_file,"\n/* begin function 28 read_canvas%d() */\n\
8322 schaersvoo 7059
read_canvas%d = function(){\
7060
 var prec = %d;\
7061
 var reply = new Array();var p = 0;\
7062
 var idx = 0;\
7063
 while(userdraw_x[p]){\
7064
  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
7065
  idx++;\
7066
  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
7067
  idx++;\
7068
  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
7069
  idx++;\
7070
  p++;\
7071
 };\
7072
 if( p == 0){alert(\"nothing drawn...\");return;}\
7073
 return reply;\
7074
};\n\
13970 obado 7075
/* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
8322 schaersvoo 7076
    break;
9213 schaersvoo 7077
    case 29:
13970 obado 7078
    fprintf(js_include_file,"\n/* begin function 29 read_canvas%d() */\n\
14038 schaersvoo 7079
function x_precision(array_x){\
9213 schaersvoo 7080
 var len = array_x.length;\
7081
 var x_array = new Array(len);\
14038 schaersvoo 7082
 var prec = %d;\
7083
 for(var p = 0 ; p < len ; p++ ){\
7084
  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
7085
 };\
7086
 return x_array;\
7087
};\
7088
function y_precision(array_y){\
7089
 var len = array_y.length;\
9213 schaersvoo 7090
 var y_array = new Array(len);\
7091
 var prec = %d;\
7092
 for(var p = 0 ; p < len ; p++ ){\
7093
  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
7094
 };\
14038 schaersvoo 7095
 return y_array;\
7096
};\
9213 schaersvoo 7097
function round_to_pixel(array_r){\
7098
var len = array_r.length;\
7099
 for(var p = 0 ; p < len ; p++ ){\
7100
  array_r[p] = Math.round(array_r[p]);\
7101
 };\
7102
 return array_r;\
7103
};\
7104
read_canvas%d = function(){\
14038 schaersvoo 7105
 function uniq_fast(arr){\
7106
  var seen = {};\
7107
  var out = [];\
7108
  var len = arr.length;\
7109
  var j = 0;\
7110
  for(var i = 0; i < len; i++){\
7111
   var item = arr[i];\
7112
   if(seen[item] !== 1) {\
7113
    seen[item] = 1;out[j++] = item;\
7114
   };\
7115
  };\
7116
  return out;\
7117
 };\
7118
 function list_unique(arr1,arr2,arr3){\
7119
  var len1 = arr1.length;\
7120
  if(len1 != arr2.length){alert('mismatch in number of x and y values...');return;};\
7121
  var sum = [];var R1=[];var R2=[];\
7122
  arr1 = x_precision(arr1);\
7123
  arr2 = y_precision(arr2);\
7124
  if(arr3 == null){\
7125
   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\
7126
   sum = uniq_fast(sum);var len2=sum.length;\
7127
   for(var p=0;p<len2;p++){\
7128
    var tmp = (sum[p]).split('#');\
7129
    R1[p] = tmp[0];\
7130
    R2[p] = tmp[1];\
7131
   };\
7132
   return [R1,R2];\
7133
  }else{\
7134
   var R3 = [];\
7135
   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\
7136
   sum = uniq_fast(sum);var len2=sum.length;\
7137
   for(var p=0;p<len2;p++){\
7138
    var tmp = (sum[p]).split('#');\
7139
    R1[p] = tmp[0];\
7140
    R2[p] = tmp[1];\
7141
    R3[p] = tmp[2];\
7142
   };\
7143
   return [R1,R2,R3];\
7144
  };\
7145
 };\
9300 schaersvoo 7146
 var reply=\" \";\
14038 schaersvoo 7147
 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\"; };\
14161 schaersvoo 7148
 if(  typeof(circles_x) === 'object' && circles_x.length > 0 ){var xyz = list_unique(circles_x,circles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+round_to_pixel(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
14038 schaersvoo 7149
 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\"; };\
7150
 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\"; };\
7151
 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\"; };\
7152
 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\"; };\
7153
 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\"; };\
7154
 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\"; };\
7155
 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\"; };\
7156
 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\"; };\
7157
 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\"; };\
7158
 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\"; };\
7159
 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\";};\
7160
 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\";};\
7161
 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;;};\
7162
 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 7163
 return reply;\
14038 schaersvoo 7164
};\
14044 schaersvoo 7165
/* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,canvas_root_id,canvas_root_id);
9213 schaersvoo 7166
    break;
9289 schaersvoo 7167
    case 30:
13970 obado 7168
    fprintf(js_include_file,"\n/* begin function 30 read_canvas%d() */\n\
9289 schaersvoo 7169
read_canvas%d = function(){\
7170
 var reply = new Array(3);\
7171
 var prec = %d;\
7172
 reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
7173
 reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
7174
 reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
7175
 return reply;\
7176
};\n\
13970 obado 7177
/* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
9289 schaersvoo 7178
    break;
7179
    case 31:
13970 obado 7180
    fprintf(js_include_file,"\n/* begin function 31 read_canvas%d() */\n\
9289 schaersvoo 7181
read_canvas%d = function(){\
7182
 var reply = new Array(3);\
7183
 var prec = %d;\
7184
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
7185
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
7186
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
7187
 return reply;\
7188
};\n\
13970 obado 7189
/* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
9289 schaersvoo 7190
    break;
7191
    case 32:
13970 obado 7192
    fprintf(js_include_file,"\n/* begin function 32 read_canvas%d() */\n\
9289 schaersvoo 7193
read_canvas%d = function(){\
7194
 var reply = new Array(6);\
7195
 var prec = %d;\
7196
 reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
7197
 reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
7198
 reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
7199
 reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
7200
 reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
7201
 reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
7202
 return reply;\
7203
};\n\
13970 obado 7204
/* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
9289 schaersvoo 7205
    break;
14038 schaersvoo 7206
    case 33:
7207
    fprintf(js_include_file,"\n/* begin function 33 read_canvas%d() */\n\
7208
read_canvas%d = function(){\
7209
 var reply = userdraw_x+'\\n'+userdraw_y;\
7210
 return reply;\
7211
};\n\
7212
/* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
7213
    break;
7214
    case 34: fprintf(js_include_file,"\
7215
\n/* begin special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\n\
7216
var read_canvas_images = function(){\
7217
 var prec = %d;\
7218
 var len  = ext_drag_images.length;\
7219
 var reply = new Array(len);\
7220
 for(var p = 0 ; p < len ; p++){\
7221
    var img = ext_drag_images[p];\
7222
    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
7223
 };\
7224
 return reply;\
7225
};\n\
7226
/* end function 20 read_canvas_images() */",reply_precision);
7227
    break;
7228
 
7614 schaersvoo 7229
    default: canvas_error("hmmm unknown replyformat...");break;
7230
}
7231
 return;
7232
}
7233
 
7234
 
8224 bpr 7235
/*
14066 bpr 7236
 add drawfunction:
7614 schaersvoo 7237
 - functions used by userdraw_primitives (circle,rect,path,triangle...)
14078 bpr 7238
 - things not covered by the drag&drop library (static objects like parallel, lattice, gridfill, imagefill)
7614 schaersvoo 7239
 - grid / mathml
7240
 - will not scale or zoom in
7241
 - will not be filled via pixel operations like fill / floodfill / filltoborder / clickfill
8224 bpr 7242
 - is printed directly into 'js_include_file'
7614 schaersvoo 7243
*/
7244
 
11021 schaersvoo 7245
void add_javascript_function(int js_function[],int canvas_root_id){
7614 schaersvoo 7246
int i;
7247
for(i = 0 ; i < MAX_JS_FUNCTIONS; i++){
11017 schaersvoo 7248
 if( js_function[i] == 1){
7614 schaersvoo 7249
    switch(i){
11026 bpr 7250
    case JS_FIND_ANGLE:
11025 schaersvoo 7251
    fprintf(js_include_file,"\n\
13970 obado 7252
/* function find_angle() */\n\
14044 schaersvoo 7253
 function find_angle(xc,yc,x1,y1){var dx = x1 - xc;var dy = yc - y1;return Math.atan2(dx,dy);};");
11017 schaersvoo 7254
    break;
8448 schaersvoo 7255
    case DRAW_EXTERNAL_IMAGE:
14066 bpr 7256
/*
13969 schaersvoo 7257
the external_canvas is already created: it needs to be FIRST in order to do some drawing onto it
7258
only drag_xy !
7259
snaptogrid | xsnaptogrid | ysnaptogrid works
7260
14/5/2019
7261
on heavy styled wims (unice.fr etc problems with mouse?
7262
now uniform method of retreiving mouse coordinates dragstuff.getMouse()
8448 schaersvoo 7263
*/
13970 obado 7264
fprintf(js_include_file,"\n/* drag external images */\n\
7653 schaersvoo 7265
var external_ctx = external_canvas.getContext(\"2d\");\
7266
var external_canvas_rect = external_canvas.getBoundingClientRect();\
7267
canvas_div.addEventListener(\"mousedown\",setxy,false);\
7268
canvas_div.addEventListener(\"mouseup\",dragstop,false);\
7269
canvas_div.addEventListener(\"mousemove\",dragxy,false);\
7270
var selected_image = null;\
7271
var ext_image_cnt = 0;\
7272
var ext_drag_images = new Array();\
14038 schaersvoo 7273
var ext_centered = 0;\
14044 schaersvoo 7274
function draw_external_image(URL,sx,sy,swidth,sheight,x0,y0,width,height,idx,resizable,draggable,click_cnt,centered,use_snap){\
14038 schaersvoo 7275
 ext_centered = centered;\
7653 schaersvoo 7276
 ext_image_cnt = idx;\
8448 schaersvoo 7277
 if(draggable == 1 ){\
7278
  reply[click_cnt] = 0;\
7279
 };\
7653 schaersvoo 7280
 var image = new Image();\
7281
 image.src = URL;\
7282
 image.onload = function(){\
8448 schaersvoo 7283
  if( sx < 1 ){ sx = 0; };\
7284
  if( sy < 1 ){ sy = 0; };\
7285
  if( swidth < 1 ){swidth = image.width;};\
7286
  if( sheight < 1 ){sheight = image.height;};\
7287
  if( width < 1 ){width = image.width;};\
7288
  if( height < 1 ){height = image.height;};\
7289
  if( resizable == 0 ){\
7290
   if( swidth > image.width ){ swidth = image.width; };\
7291
   if( sheight > image.height){ sheight = image.height;};\
7292
   if( width > image.width ){ width = image.width; };\
7293
   if( height > image.height){ height = image.height;};\
7294
  };\
14044 schaersvoo 7295
  var img = new Array(12);\
7653 schaersvoo 7296
  img[0] = draggable;img[1] = image;img[2] = sx;img[3] = sy;img[4] = swidth;img[5] = sheight;\
14044 schaersvoo 7297
  img[8] = width;img[9] = height;img[10] = click_cnt;img[11] = use_snap;\
14062 schaersvoo 7298
  img[6] = x0;img[7] = y0;\
7653 schaersvoo 7299
  ext_drag_images[idx] = img;\
14062 schaersvoo 7300
  if(centered == 4){\
7301
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],parseInt(img[6] - 0.5*img[8]),parseInt(img[7] - 0.5*img[9]),img[8],img[9]);\
7302
  }else{\
7303
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
7304
  };\
7653 schaersvoo 7305
 };\
7306
};\
7307
function dragstop(evt){\
7308
 selected_image = null;return;\
7309
};\
7310
function dragxy(evt){\
7311
 if( selected_image != null ){\
14044 schaersvoo 7312
  var s_img = ext_drag_images[selected_image];\
13969 schaersvoo 7313
  var mouse = dragstuff.getMouse(evt,external_canvas);\
14044 schaersvoo 7314
  var xy = multisnap_check(mouse.x,mouse.y,s_img[11]);\
14201 schaersvoo 7315
  xy[0] = parseInt(xy[0] - 0.5*s_img[8]);\
7316
  xy[1] = parseInt(xy[1] - 0.5*s_img[9]);\
14062 schaersvoo 7317
  s_img[6] = xy[0];s_img[7] = xy[1];\
7653 schaersvoo 7318
  ext_drag_images[selected_image] = s_img;\
7319
  external_ctx.clearRect(0,0,xsize,ysize);\
7320
  for(var i = 0; i <= ext_image_cnt ; i++){\
7321
   var img = ext_drag_images[i];\
14201 schaersvoo 7322
   external_ctx.drawImage(img[1],img[2],img[3],img[4],img[5],img[6],img[7],img[8],img[9]);\
7653 schaersvoo 7323
  };\
7324
 };\
7325
};\
7326
function setxy(evt){\
7327
 if( ! selected_image && evt.which == 1 ){\
13969 schaersvoo 7328
  var mouse = dragstuff.getMouse(evt,external_canvas);\
7329
  var xm = mouse.x;\
7330
  var ym = mouse.y;\
14062 schaersvoo 7331
  var img;var xmarge;var ymarge;\
7653 schaersvoo 7332
  for(var p = 0 ; p <= ext_image_cnt ; p++){\
8448 schaersvoo 7333
   if( ext_drag_images[p] ){\
7334
    img = ext_drag_images[p];\
7335
    if( img[0] != 0 ){\
14062 schaersvoo 7336
     xmarge = 0.5*img[8];ymarge = 0.5*img[9];\
7337
     if( xm > img[6] - xmarge && xm < img[6] + img[8]){\
7338
      if( ym > img[7] - ymarge && ym < img[7] + img[9]){\
8448 schaersvoo 7339
       if( img[0] == 1){\
7340
        if( reply[img[10]] == 1 ){\
7341
         reply[img[10]] = 0;external_ctx.strokeStyle = '#ffffff';\
7342
        }\
7343
        else\
7344
        {\
7345
         reply[img[10]] = 1;external_ctx.strokeStyle = '#00ff00';\
7346
        };\
13969 schaersvoo 7347
        external_ctx.lineWidth = 4;\
8448 schaersvoo 7348
        external_ctx.beginPath();\
7349
        external_ctx.rect(img[6],img[7],img[8],img[9]);\
7350
        external_ctx.closePath();\
7351
        external_ctx.stroke();\
7352
        return;\
7353
       }\
7354
       else\
7355
       {\
7356
        img[6] = xm;\
7357
        img[7] = ym;\
7358
        ext_drag_images[p] = img;\
7359
        selected_image = p;\
7360
        dragxy(evt);\
7361
       };\
7362
      };\
7653 schaersvoo 7363
     };\
7364
    };\
7365
   };\
7366
  };\
7367
 }\
7368
 else\
7369
 {\
7370
  selected_image = null;\
7371
 };\
8448 schaersvoo 7372
};");
7614 schaersvoo 7373
    break;
8370 schaersvoo 7374
    case DRAW_BEZIER:
13970 obado 7375
fprintf(js_include_file,"\n/* draw bezier curve */\n\
11874 schaersvoo 7376
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8370 schaersvoo 7377
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){\
7378
 var obj;\
7379
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7380
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7381
 }\
7382
 else\
7383
 {\
7384
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7385
 };\
7386
 var ctx = obj.getContext(\"2d\");\
7387
 ctx.save();\
7388
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7389
 ctx.lineWidth = linewidth;\
11088 schaersvoo 7390
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8370 schaersvoo 7391
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7392
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
7393
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7394
 ctx.beginPath();\
7395
 ctx.moveTo(x2px(xy_points[0]),y2px(xy_points[1]));\
7396
 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 7397
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 7398
 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 7399
 ctx.stroke();\
7400
 ctx.restore();\
7401
};\n",canvas_root_id,canvas_root_id,canvas_root_id);
7402
    break;
13829 bpr 7403
 
7614 schaersvoo 7404
    case DRAW_GRIDFILL:/* not used for userdraw */
13970 obado 7405
fprintf(js_include_file,"\n/* draw gridfill */\n\
11827 schaersvoo 7406
var grid_fill_pattern;\
11823 schaersvoo 7407
var draw_gridfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,opacity,xsize,ysize,use_userdraw){\
11820 schaersvoo 7408
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
7409
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
14208 schaersvoo 7410
 var fc = %d+canvas_type;\
11820 schaersvoo 7411
 fill_canvas_no.push(fc);\
14208 schaersvoo 7412
 var obj = create_canvas%d(fc,xsize,ysize);\
7413
 var ctx = obj.getContext('2d');\
7614 schaersvoo 7414
 var x,y;\
14208 schaersvoo 7415
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7416
 ctx.rect(0,0,xsize,ysize);\
7417
 ctx.fill();\
11820 schaersvoo 7418
 ctx.lineWidth = linewidth;\
7419
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7420
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7421
 for( x = 0 ; x < xsize ; x = x + dx ){\
7422
  ctx.beginPath();\
7423
  ctx.moveTo(x,0);\
7424
  ctx.lineTo(x,ysize);\
7425
  ctx.closePath();\
7426
  ctx.stroke();\
7614 schaersvoo 7427
 };\
11820 schaersvoo 7428
 for( y = 0 ; y < ysize; y = y + dy ){\
7429
  ctx.beginPath();\
7430
  ctx.moveTo(0,y);\
7431
  ctx.lineTo(xsize,y);\
7432
  ctx.closePath();\
7433
  ctx.stroke();\
7614 schaersvoo 7434
 };\
11823 schaersvoo 7435
 if( use_userdraw ){\
7436
  grid_fill_pattern = ctx;\
7437
 }\
7438
 else\
7439
 {\
11874 schaersvoo 7440
  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};return;\
7441
};",canvas_root_id,canvas_root_id);
7614 schaersvoo 7442
    break;
8224 bpr 7443
 
7614 schaersvoo 7444
    case DRAW_IMAGEFILL:/* not  used for userdraw */
13970 obado 7445
fprintf(js_include_file,"\n/* draw imagefill */\n\
11874 schaersvoo 7446
var draw_imagefill = function(canvas_type,x0,y0,URL,xsize,ysize,use_userdraw,use_scaling){\
11854 schaersvoo 7447
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7448
 var fc = %d+canvas_type;\
7449
 fill_canvas_no.push(fc);\
7450
 var obj = create_canvas%d(fc,xsize,ysize);\
7451
 var ctx = obj.getContext('2d');\
7452
 var img = new Image();\
7453
 img.src = URL;\
11857 schaersvoo 7454
 obj.style.visibility = 'hidden';\
7455
 img.onload = function(){\
11874 schaersvoo 7456
  if( use_scaling == 1 ){\
7457
   ctx.drawImage(img,x0,y0,xsize,ysize);\
7458
  }else{\
7459
   var w0 = img.width;var h0 = img.height;var w;var h;\
7460
   for( w = x0; w < xsize ; w = w + w0 ){\
7461
    for( h = y0; h < ysize; h = h + h0){\
7462
      ctx.drawImage(img,w,h,w0,h0);\
7463
    };\
7464
   };\
7465
  };\
11857 schaersvoo 7466
  if( use_userdraw ){\
7467
   image_pattern = ctx;\
7468
  }\
7469
  else\
7470
  {\
7471
   setTimeout(function(){ filltoborder( x0,y0,'red','red',canvas_type,true,ctx); },500);\
7472
  };\
7473
 };\
11854 schaersvoo 7474
};",canvas_root_id,canvas_root_id);
7614 schaersvoo 7475
    break;
8224 bpr 7476
 
7614 schaersvoo 7477
    case DRAW_DOTFILL:/* not  used for userdraw */
13970 obado 7478
fprintf(js_include_file,"\n/* draw dotfill */\n\
11827 schaersvoo 7479
var dot_fill_pattern;\
11823 schaersvoo 7480
var draw_dotfill = function(canvas_type,x0,y0,dx,dy,radius,color,opacity,xsize,ysize,use_userdraw){\n\
11820 schaersvoo 7481
if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
11818 schaersvoo 7482
if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
11820 schaersvoo 7483
var fc = %d+canvas_type;\
11818 schaersvoo 7484
fill_canvas_no.push(fc);\
11820 schaersvoo 7485
 var obj = create_canvas%d(fc,xsize,ysize);\
7486
 var ctx = obj.getContext('2d');\
7487
 var x,y;\
7488
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7489
 ctx.rect(0,0,xsize,ysize);\
7490
 ctx.fill();\
7491
 ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
7492
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7493
 for( x = 0 ; x < xsize ; x = x + dx ){\
7494
  for( y = 0 ; y < ysize ; y = y + dy ){\
7495
   ctx.beginPath();\
7496
   ctx.arc(x,y,radius,0,2*Math.PI,false);\
7497
   ctx.closePath();\
7498
   ctx.fill();\
7499
  };\
7500
 };\
11823 schaersvoo 7501
 if( use_userdraw ){\
11824 schaersvoo 7502
  dot_fill_pattern = ctx;\
11823 schaersvoo 7503
 }\
7504
 else\
7505
 {\
11874 schaersvoo 7506
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);\
7507
 };\
7508
return;\
7509
};",canvas_root_id,canvas_root_id);
7614 schaersvoo 7510
    break;
7645 schaersvoo 7511
 
11830 schaersvoo 7512
    case DRAW_TEXTFILL:/* not  used for userdraw */
13970 obado 7513
fprintf(js_include_file,"\n/* draw textfill */\n\
11830 schaersvoo 7514
var text_fill_pattern;\
7515
var draw_textfill = function(canvas_type,x0,y0,color,fontfamily,xsize,ysize,txt,use_userdraw){\n\
7516
if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7517
var fc = %d+canvas_type;\
7518
fill_canvas_no.push(fc);\
7519
 var obj = create_canvas%d(fc,xsize,ysize);\
7520
 var ctx = obj.getContext('2d');\
7521
 ctx.font = fontfamily;\
11832 schaersvoo 7522
 var dx = (ctx.measureText(txt)).width;\
11830 schaersvoo 7523
 var dy = parseInt(fontfamily)+2;\
7524
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7525
 ctx.rect(0,0,xsize,ysize);\
7526
 ctx.fill();\
7527
 ctx.fillStyle=\"rgba(\"+color+\",0.01)\";\
7528
 for(var x = 0 ; x < xsize ; x = x + dx ){\
7529
  for(var y = 0 ; y < ysize ; y = y + dy ){\
7530
   ctx.fillText(txt,x,y);\
7531
  };\
7532
 };\
7533
 if( use_userdraw ){\
7534
  text_fill_pattern = ctx;\
7535
 }\
7536
 else\
7537
 {\
7538
 setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
7539
 return;};",canvas_root_id,canvas_root_id);
7540
    break;
7541
 
7647 schaersvoo 7542
    case DRAW_DIAMONDFILL:/* not used for userdraw */
13970 obado 7543
fprintf(js_include_file,"\n/* draw hatch fill */\n\
11827 schaersvoo 7544
var diamond_fill_pattern;\
11823 schaersvoo 7545
var draw_diamondfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
11820 schaersvoo 7546
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
7547
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7548
 var fc = %d+canvas_type;\
7549
 fill_canvas_no.push(fc);\
7550
 var obj = create_canvas%d(fc,xsize,ysize);\
7551
 var ctx = obj.getContext('2d');\
7614 schaersvoo 7552
 var x;\
7553
 var y;\
7554
 ctx.lineWidth = linewidth;\
11820 schaersvoo 7555
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7556
 ctx.rect(0,0,xsize,ysize);\
7557
 ctx.fill();\
11088 schaersvoo 7558
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
11820 schaersvoo 7559
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7614 schaersvoo 7560
 y = ysize;\
11820 schaersvoo 7561
 ctx.beginPath();\
7562
 for( x = 0 ; x < xsize ; x = x + dx ){\
7563
  ctx.moveTo(x,0);\
7614 schaersvoo 7564
  ctx.lineTo(xsize,y);\
7565
  y = y - dy;\
7566
 };\
11820 schaersvoo 7567
 y=0;\
7614 schaersvoo 7568
 for( x = xsize ; x > 0 ; x = x - dx){\
7569
  ctx.moveTo(x,ysize);\
11820 schaersvoo 7570
  ctx.lineTo(0,y);\
7614 schaersvoo 7571
  y = y + dy;\
7572
 };\
11820 schaersvoo 7573
 y = 0;\
7574
 for( x = 0 ; x < xsize ; x = x + dx ){\
7575
  ctx.moveTo(x,0);\
7576
  ctx.lineTo(0,y);\
7577
  y = y + dy;\
7578
 };\
7579
 y = 0;\
7580
 for( x = 0 ; x < xsize ; x = x + dx ){\
7614 schaersvoo 7581
  ctx.moveTo(xsize,y);\
7582
  ctx.lineTo(x,ysize);\
11820 schaersvoo 7583
  y = y + dy;\
7614 schaersvoo 7584
 };\
11820 schaersvoo 7585
 ctx.closePath();\
7614 schaersvoo 7586
 ctx.stroke();\
11823 schaersvoo 7587
 if( use_userdraw ){\
11827 schaersvoo 7588
  diamond_fill_pattern = ctx;\
11823 schaersvoo 7589
 }\
7590
 else\
7591
 {\
7592
  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
7614 schaersvoo 7593
 return;\
11820 schaersvoo 7594
 }",canvas_root_id,canvas_root_id);
7614 schaersvoo 7595
    break;
8224 bpr 7596
 
7647 schaersvoo 7597
    case DRAW_HATCHFILL:/* not used for userdraw */
13970 obado 7598
fprintf(js_include_file,"\n/* draw hatch fill */\n\
11827 schaersvoo 7599
var hatch_fill_pattern;\
11823 schaersvoo 7600
var draw_hatchfill = function(canvas_type,x0,y0,dx,dy,linewidth,color,stroke_opacity,xsize,ysize,use_userdraw){\
11820 schaersvoo 7601
 if( dx == 0 || dy == 0 ){alert(\"increment is zero !!! \");return;};\
7602
 if( typeof(fill_canvas_no) != 'object' ){ var fill_canvas_no = []; };\
7603
 var fc = %d+canvas_type;\
7604
 fill_canvas_no.push(fc);\
7605
 var obj = create_canvas%d(fc,xsize,ysize);\
7606
 var ctx = obj.getContext('2d');\
7607
 var x,y;\
7608
 ctx.fillStyle='rgba(255,255,255,0.01)';\
7609
 ctx.rect(0,0,xsize,ysize);\
7610
 ctx.fill();\
7611
 ctx.strokeStyle=\"rgba(\"+color+\",0.01)\";\
7647 schaersvoo 7612
 ctx.lineWidth = linewidth;\
11088 schaersvoo 7613
 if(linewidth%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7647 schaersvoo 7614
 y = ysize;\
11820 schaersvoo 7615
 ctx.beginPath();\
7616
 for( x = 0 ; x < xsize ; x = x + dx ){\
7617
  ctx.moveTo(x,0);\
7647 schaersvoo 7618
  ctx.lineTo(xsize,y);\
7619
  y = y - dy;\
7620
 };\
11820 schaersvoo 7621
 y = 0;\
7647 schaersvoo 7622
 for( x = xsize ; x >= dx ; x = x - dx){\
7623
  ctx.moveTo(x,ysize);\
11820 schaersvoo 7624
  ctx.lineTo(0,y);\
7647 schaersvoo 7625
  y = y + dy;\
7626
 };\
11820 schaersvoo 7627
 ctx.closePath();\
7647 schaersvoo 7628
 ctx.stroke();\
11823 schaersvoo 7629
 if( use_userdraw ){\
7630
  hatch_fill_pattern = ctx;\
7631
 }\
7632
 else\
7633
 {\
7634
  setTimeout(function(){ filltoborder( x0,y0,color,color,canvas_type,true,ctx); },500);};\
7647 schaersvoo 7635
 return;\
11820 schaersvoo 7636
 };",canvas_root_id,canvas_root_id);
7647 schaersvoo 7637
    break;
7614 schaersvoo 7638
    case DRAW_CIRCLES:/*  used for userdraw */
13970 obado 7639
fprintf(js_include_file,"\n/* draw circles */\n\
11874 schaersvoo 7640
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7641
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 7642
 ctx.save();\
8071 schaersvoo 7643
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7644
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7645
 ctx.lineWidth = line_width;\
11839 schaersvoo 7646
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
14208 schaersvoo 7647
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
11874 schaersvoo 7648
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 7649
 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 7650
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7651
 for(var p = 0 ; p < x_points.length ; p++ ){\
7652
  ctx.beginPath();\
7653
  ctx.arc(x_points[p],y_points[p],radius[p],0,2*Math.PI,false);\
7654
  ctx.closePath();\
11839 schaersvoo 7655
  if(use_filled != 0 ){ctx.fill();};\
7614 schaersvoo 7656
  ctx.stroke();\
7657
 }\
7658
 ctx.restore();\
7659
 return;\
7653 schaersvoo 7660
};");
7614 schaersvoo 7661
    break;
14066 bpr 7662
    case DRAW_POLYLINE:/* user for userdraw: draw lines through points */
13970 obado 7663
fprintf(js_include_file,"\n/* draw polyline */\n\
11874 schaersvoo 7664
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7665
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 7666
 ctx.save();\
8071 schaersvoo 7667
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7663 schaersvoo 7668
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7669
 ctx.lineWidth = line_width;\
11088 schaersvoo 7670
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7663 schaersvoo 7671
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7672
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7673
 ctx.clearRect(0,0,xsize,ysize);\
7674
 ctx.beginPath();\
7675
 for(var p = 0 ; p < x_points.length-1 ; p++ ){\
7676
  ctx.moveTo(x_points[p],y_points[p]);\
7677
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
7678
 }\
7679
 ctx.closePath();\
7680
 ctx.stroke();\
7681
 for(var p = 0 ; p < x_points.length ; p++ ){\
7682
  ctx.beginPath();\
7683
  ctx.arc(x_points[p],y_points[p],line_width,0,2*Math.PI,false);\
7684
  ctx.closePath();ctx.fill();ctx.stroke();\
7685
 };\
7686
 ctx.restore();\
7687
 return;\
7688
};");
7689
    break;
8224 bpr 7690
 
7614 schaersvoo 7691
    case DRAW_SEGMENTS:/*  used for userdraw */
13970 obado 7692
fprintf(js_include_file,"\n/* draw segments */\n\
8105 schaersvoo 7693
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 7694
 ctx.save();\
8071 schaersvoo 7695
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7696
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7697
 ctx.lineWidth = line_width;\
11088 schaersvoo 7698
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7699
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7700
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7701
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
7702
  ctx.beginPath();\
7703
  ctx.moveTo(x_points[p],y_points[p]);\
7704
  ctx.lineTo(x_points[p+1],y_points[p+1]);\
7705
  ctx.closePath();\
7706
  ctx.stroke();\
7707
  }\
7708
  ctx.restore();\
7709
  return;\
7710
 };");
7711
    break;
8224 bpr 7712
 
7614 schaersvoo 7713
    case DRAW_LINES:/*  used for userdraw */
13970 obado 7714
fprintf(js_include_file,"\n/* draw lines */\n\
7614 schaersvoo 7715
function calc_line(x1,x2,y1,y2){\
7716
 var marge = 2;\
7717
 if(x1 < x2+marge && x1>x2-marge){\
7718
  return [x1,0,x1,ysize];\
7719
 };\
7720
 if(y1 < y2+marge && y1>y2-marge){\
7721
  return [0,y1,xsize,y1];\
7722
 };\
7723
 var Y1 = y1 - (x1)*(y2 - y1)/(x2 - x1);\
7724
 var Y2 = y1 + (xsize - x1)*(y2 - y1)/(x2 - x1);\
7725
 return [0,Y1,xsize,Y2];\
7726
};\
8105 schaersvoo 7727
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 7728
 ctx.save();\
7729
 var line = new Array(4);\
8071 schaersvoo 7730
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7731
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7732
 ctx.lineWidth = line_width;\
11088 schaersvoo 7733
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7734
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7735
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7736
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
7737
  line = calc_line(x_points[p],x_points[p+1],y_points[p],y_points[p+1]);\
7738
  ctx.beginPath();\
7739
  ctx.moveTo(line[0],line[1]);\
7740
  ctx.lineTo(line[2],line[3]);\
7741
  ctx.closePath();\
7742
  ctx.stroke();\
7743
  }\
7744
  ctx.restore();\
7745
  return;\
7746
 };");
7747
    break;
7748
 
8244 schaersvoo 7749
    case DRAW_DEMILINES:/*  used for userdraw */
13970 obado 7750
fprintf(js_include_file,"\n/* draw demilines */\n\
8244 schaersvoo 7751
function find_inf_point(x1,y1,x2,y2){\
7752
 if(x1<x2+2 && x1>x2-2){if(y1<y2){return [x1,y1,x1,ysize];}else{return [x1,0,x1,y1];};};\
7753
 var rc = (y2 - y1)/(x2 - x1);var q = y1 - (x1)*rc;\
7754
 if( x1 < x2 ){ return [x1,y1,xsize,rc*xsize+q];}else{return [x1,y1,0,q];};\
7755
};\
7756
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){\
7757
 ctx.save();\
7758
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7759
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7760
 ctx.lineWidth = line_width;\
11088 schaersvoo 7761
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8244 schaersvoo 7762
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7763
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7764
 var pair = new Array(4);\
7765
 for(var p = 0 ; p < x_points.length ; p = p+2 ){\
7766
  pair = find_inf_point(x_points[p],y_points[p],x_points[p+1],y_points[p+1]);\
7767
  ctx.beginPath();\
7768
  ctx.moveTo(pair[0],pair[1]);\
7769
  ctx.lineTo(pair[2],pair[3]);\
7770
  ctx.closePath();\
7771
  ctx.stroke();\
7772
  }\
7773
  ctx.restore();\
7774
  return;\
7775
 };");
7776
    break;
7777
 
7614 schaersvoo 7778
    case DRAW_CROSSHAIRS:/*  used for userdraw */
13970 obado 7779
fprintf(js_include_file,"\n/* draw crosshairs  */\n\
8105 schaersvoo 7780
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 7781
 ctx.save();\
8071 schaersvoo 7782
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7783
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7784
 ctx.lineWidth = line_width;\
11088 schaersvoo 7785
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7786
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7787
 var x1,x2,y1,y2;\
7788
 for(var p = 0 ; p < x_points.length ; p++ ){\
7789
  x1 = x_points[p] - crosshair_size;\
7790
  x2 = x_points[p] + crosshair_size;\
7791
  y1 = y_points[p] - crosshair_size;\
7792
  y2 = y_points[p] + crosshair_size;\
7793
  ctx.beginPath();\
7794
  ctx.moveTo(x1,y1);\
7795
  ctx.lineTo(x2,y2);\
7796
  ctx.closePath();\
7797
  ctx.stroke();\
7798
  ctx.beginPath();\
7799
  ctx.moveTo(x2,y1);\
7800
  ctx.lineTo(x1,y2);\
7801
  ctx.closePath();\
7802
  ctx.stroke();\
7803
 }\
7804
 ctx.restore();\
7805
  return;\
7653 schaersvoo 7806
};");
7614 schaersvoo 7807
    break;
7808
 
7809
    case DRAW_RECTS:/*  used for userdraw */
13970 obado 7810
fprintf(js_include_file,"\n/* draw rects */\n\
11874 schaersvoo 7811
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7812
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 7813
var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7614 schaersvoo 7814
 ctx.save();\
8071 schaersvoo 7815
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7816
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7817
 ctx.lineWidth = line_width;\
11088 schaersvoo 7818
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
8448 schaersvoo 7819
 ctx.strokeStyle = 'rgba('+stroke_color+','+stroke_opacity+')';\
7614 schaersvoo 7820
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];}};\
11875 schaersvoo 7821
 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 7822
 for(var p = 0 ; p < x_points.length ; p = p + 2){\
7823
  ctx.beginPath();\
7824
  ctx.rect(x_points[p],y_points[p],x_points[p+1]-x_points[p],y_points[p+1]-y_points[p]);\
7825
  ctx.closePath();\
11839 schaersvoo 7826
  if(use_filled != 0 ){ctx.fill();}\
7614 schaersvoo 7827
  ctx.stroke();\
7828
 };\
7829
 ctx.restore();\
7830
 return;\
7653 schaersvoo 7831
};");
7614 schaersvoo 7832
    break;
7833
 
7834
    case DRAW_ROUNDRECTS:/*  used for userdraw */
13970 obado 7835
fprintf(js_include_file,"\n/* draw round rects */\n\
11874 schaersvoo 7836
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7837
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 7838
var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
7614 schaersvoo 7839
 ctx.save();\
8071 schaersvoo 7840
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7841
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7842
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
9462 schaersvoo 7843
 ctx.lineWidth = line_width;\
11088 schaersvoo 7844
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
11875 schaersvoo 7845
 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 7846
 var x,y,w,h,r;\
7847
 for(var p = 0; p < x_points.length; p = p+2){\
7848
  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);\
7849
  ctx.beginPath();ctx.moveTo(x + r, y);\
7850
  ctx.lineTo(x + w - r, y);\
7851
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);\
7852
  ctx.lineTo(x + w, y + h - r);\
7853
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);\
7854
  ctx.lineTo(x + r, y + h);\
7855
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);\
7856
  ctx.lineTo(x, y + r);\
7857
  ctx.quadraticCurveTo(x, y, x + r, y);\
7858
  ctx.closePath();if( use_dashed == 1 ){ctx.setLineDash([dashtype0,dashtype1]);};\
7859
  ctx.strokeStyle =\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11839 schaersvoo 7860
  if( use_filled != 0 ){ctx.fill();};\
7614 schaersvoo 7861
  ctx.stroke();\
7862
 }\
7863
 ctx.restore();\
7653 schaersvoo 7864
};");
8224 bpr 7865
    break;
7614 schaersvoo 7866
 
7867
    case DRAW_ELLIPSES:/* not  used for userdraw */
13970 obado 7868
fprintf(js_include_file,"\n/* draw ellipses */\n\
11874 schaersvoo 7869
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7870
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 7871
 var obj;\
7872
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
7873
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
7874
 }\
7875
 else\
7876
 {\
7877
  obj = create_canvas%d(canvas_type,xsize,ysize);\
7878
 };\
7879
 var ctx = obj.getContext(\"2d\");\
7880
 ctx.save();\
8071 schaersvoo 7881
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7882
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
11875 schaersvoo 7883
 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 7884
 var cx,cy,ry,rx;\
7885
 ctx.lineWidth = line_width;\
11088 schaersvoo 7886
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7887
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7888
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7889
 for(var p=0;p< x_points.length;p = p+2){\
7890
  ctx.beginPath();\
7891
  cx = x_points[p];cy = y_points[p];rx = 0.25*x_points[p+1];ry = 0.25*y_points[p+1];\
7892
  ctx.translate(cx - rx, cy - ry);\
7893
  ctx.scale(rx, ry);\
7894
  ctx.arc(1, 1, 1, 0, 2 * Math.PI, false);\
11839 schaersvoo 7895
  if( use_filled != 0 ){ctx.fill();}\
7614 schaersvoo 7896
  ctx.stroke();\
7897
 };\
7898
 ctx.restore();\
7653 schaersvoo 7899
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 7900
    break;
7901
 
7902
    case DRAW_PATHS: /*  used for userdraw */
13970 obado 7903
fprintf(js_include_file,"\n/* draw paths */\n\
11874 schaersvoo 7904
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 7905
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 7906
 ctx.save();\
8071 schaersvoo 7907
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7908
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7909
 ctx.lineWidth = line_width;\
11088 schaersvoo 7910
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7911
 ctx.lineJoin = \"round\";\
7912
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11874 schaersvoo 7913
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 7914
 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 7915
 ctx.beginPath();\
7916
 ctx.moveTo(x_points[0],y_points[0]);\
7917
 for(var p = 1 ; p < x_points.length ; p++ ){ctx.lineTo(x_points[p],y_points[p]);}\
7918
 if(closed_path == 1){ctx.lineTo(x_points[0],y_points[0]);ctx.closePath();}\
7919
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
11839 schaersvoo 7920
 if(use_filled != 0){ctx.fill();}\
7614 schaersvoo 7921
 ctx.stroke();\
7922
 ctx.restore();\
7923
 return;\
7924
};");
8224 bpr 7925
 
7614 schaersvoo 7926
    break;
7927
    case DRAW_ARROWS:/*  used for userdraw */
13970 obado 7928
fprintf(js_include_file,"\n/* draw arrows */\n\
8105 schaersvoo 7929
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 7930
 ctx.save();\
8071 schaersvoo 7931
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 7932
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
7933
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7934
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
7935
 ctx.lineWidth = line_width;\
11088 schaersvoo 7936
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 7937
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
7938
 ctx.lineCap = \"round\";\
7939
 var x1,y1,x2,y2,dx,dy,len;\
7940
 for(var p = 0 ; p < x_points.length - 1 ; p = p +2){\
7874 schaersvoo 7941
   ctx.save();\
7614 schaersvoo 7942
   x1 = x_points[p];y1 = y_points[p];x2 = x_points[p+1];y2 = y_points[p+1];dx = x2 - x1;dy = y2 - y1;\
7943
   len = Math.sqrt(dx*dx+dy*dy);\
7944
   ctx.translate(x2,y2);\
7945
   ctx.rotate(Math.atan2(dy,dx));\
7946
   ctx.lineCap = \"round\";\
7947
   ctx.beginPath();\
7948
   ctx.moveTo(0,0);\
7949
   ctx.lineTo(-len,0);\
7950
   ctx.closePath();\
7951
   ctx.stroke();\
7952
   ctx.beginPath();\
7953
   ctx.moveTo(0,0);\
7954
   ctx.lineTo(-1*arrow_head,-0.5*arrow_head);\
7955
   ctx.lineTo(-1*arrow_head, 0.5*arrow_head);\
7956
   ctx.closePath();\
7957
   ctx.fill();\
7874 schaersvoo 7958
   ctx.restore();\
7614 schaersvoo 7959
   if( type == 2 ){\
7960
     ctx.save();\
7961
     ctx.translate(x1,y1);\
7962
     ctx.rotate(Math.atan2(-dy,-dx));\
7963
     ctx.beginPath();\
7964
     ctx.moveTo(0,0);\
8347 schaersvoo 7965
     ctx.lineTo(-1*arrow_head,-0.4*arrow_head);\
7966
     ctx.lineTo(-1*arrow_head, 0.4*arrow_head);\
7614 schaersvoo 7967
     ctx.closePath();\
7968
     ctx.stroke();\
7969
     ctx.fill();\
7874 schaersvoo 7970
     ctx.restore();\
8379 schaersvoo 7971
   };\
7972
  };\
7614 schaersvoo 7973
  ctx.restore();\
7974
  return;\
7653 schaersvoo 7975
};");
7614 schaersvoo 7976
    break;
7977
 
7978
    case DRAW_VIDEO:/* not  used for userdraw */
13970 obado 7979
fprintf(js_include_file,"\n/* draw video */\n\
8105 schaersvoo 7980
var draw_video = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 7981
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
7982
 var video_div = document.createElement(\"div\");\
7983
 canvas_div.appendChild(video_div);\
7984
 video_div.style.position = \"absolute\";\
7985
 video_div.style.left = x+\"px\";\
7986
 video_div.style.top = y+\"px\";\
7987
 video_div.style.width = w+\"px\";\
7988
 video_div.style.height = h+\"px\";\
7989
 var video = document.createElement(\"video\");\
7990
 video_div.appendChild(video);\
7991
 video.style.width = w+\"px\";\
7992
 video.style.height = h+\"px\";\
7993
 video.autobuffer = true;\
7994
 video.controls = true;video.autoplay = false;\
7995
 var src = document.createElement(\"source\");\
7996
 src.type = \"video/mp4\";\
7997
 src.src = URL;\
7998
 video.appendChild(src);\
7999
 video.load();\
8000
 return;\
8224 bpr 8001
};");
7614 schaersvoo 8002
    break;
8224 bpr 8003
 
7614 schaersvoo 8004
    case DRAW_AUDIO:/* not used for userdraw */
13970 obado 8005
fprintf(js_include_file,"\n/* draw audio */\n\
8105 schaersvoo 8006
var draw_audio = function(canvas_root_id,x,y,w,h,loop,visible,URL1,URL2){\
7614 schaersvoo 8007
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
8008
 var audio_div = document.createElement(\"div\");\
8009
 canvas_div.appendChild(audio_div);\
8010
 audio_div.style.position = \"absolute\";\
8011
 audio_div.style.left = x+\"px\";\
8012
 audio_div.style.top = y+\"px\";\
8013
 audio_div.style.width = w+\"px\";\
8014
 audio_div.style.height = h+\"px\";\
8015
 var audio = document.createElement(\"audio\");\
8016
 audio_div.appendChild(audio);\
8017
 audio.setAttribute(\"style\",\"width:\"+w+\"px;height:\"+h+\"px\");\
8018
 audio.autobuffer = true;\
8379 schaersvoo 8019
 if(visible == 1 ){ audio.controls = true;audio.autoplay = false;}else{ audio.controls = false;audio.autoplay = true;};\
8020
 if(loop == 1 ){ audio.loop = true;}else{ audio.loop = false;};\
7614 schaersvoo 8021
 var src1 = document.createElement(\"source\");\
8022
 src1.type = \"audio/ogg\";\
8023
 src1.src = URL1;\
8024
 audio.appendChild(src1);\
8025
 var src2 = document.createElement(\"source\");\
8026
 src2.type = \"audio/mpeg\";\
8027
 src2.src = URL2;\
8028
 audio.appendChild(src2);\
8029
 audio.load();\
8030
 return;\
7653 schaersvoo 8031
};");
7614 schaersvoo 8032
    break;
8224 bpr 8033
 
7614 schaersvoo 8034
    case DRAW_HTTP:/* not  used for userdraw */
13970 obado 8035
fprintf(js_include_file,"\n/* draw http */\n\
8105 schaersvoo 8036
var draw_http = function(canvas_root_id,x,y,w,h,URL){\
7614 schaersvoo 8037
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
8038
 var http_div = document.createElement(\"div\");\
8039
 var iframe = document.createElement(\"iframe\");\
8040
 canvas_div.appendChild(http_div);\
8041
 http_div.appendChild(iframe);\
8042
 iframe.src = URL;\
8043
 iframe.setAttribute(\"width\",w);\
8044
 iframe.setAttribute(\"height\",h);\
8045
 return;\
7653 schaersvoo 8046
};");
7614 schaersvoo 8047
    break;
8224 bpr 8048
 
13829 bpr 8049
    case DRAW_XML: /*
14066 bpr 8050
    onclick=1: click
14062 schaersvoo 8051
    onclick=2 drag ==> always centered (use_offset=4)
11238 schaersvoo 8052
    xy:drag_type = 0;
8053
    x:    drag_type = 1;
8054
    y:    drag_type = 2;
8055
    */
8056
 
13970 obado 8057
fprintf(js_include_file,"\n/* draw xml */\n\
14044 schaersvoo 8058
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 8059
 var canvas_div = document.getElementById(\"canvas_div\"+canvas_root_id);\
8060
 var xml_div = document.createElement(\"div\");\
8061
 canvas_div.appendChild(xml_div);\
8062
 xml_div.innerHTML = mathml;\
14038 schaersvoo 8063
 xml_div.style.position = \"absolute\"; xml_div.style.left = x+\"px\";xml_div.style.top = y+\"px\";\
8064
 var factor = 1;\
8065
 if( centered > 0 ){ factor = 0.5;};\
8066
 var xml_div_width = factor*(parseInt(window.getComputedStyle(xml_div).width , 10));\
8067
 var xml_div_height = factor*(parseInt(window.getComputedStyle(xml_div).height ,10));\
8379 schaersvoo 8068
 xml_div.style.color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11745 schaersvoo 8069
 var color_org = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11756 schaersvoo 8070
 var back_color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8071
 var no_color = \"rgba(255,255,255,0)\";\
11745 schaersvoo 8072
 var dragging = false;\
11747 schaersvoo 8073
 if( onclick == 2 ){reply[click_cnt] = px2x(x)+','+px2y(y);};\
8074
 if( onclick == 1 ){reply[click_cnt] = 0;};\
8075
 if( onclick == 2 ){\
8076
  xml_div.onclick = function(){\
11756 schaersvoo 8077
   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 8078
   canvas_div.onmousemove = function(evt){\
8079
    if(!dragging){return;};\
8080
    var x1;var y1;\
8081
    var mouse = dragstuff.getMouse(evt,xml_div);\
14044 schaersvoo 8082
    var xy = multisnap_check(mouse.x,mouse.y,use_snap);\
11747 schaersvoo 8083
    switch(drag_type){\
14044 schaersvoo 8084
     case 0: x1 = xy[0]-xml_div_width;y1=xy[1]-xml_div_height;break;\
8085
     case 1: x1 = xy[0]-xml_div_width;y1 = y;break;\
8086
     case 2: x1 = x;y1 = xy[1]-xml_div_height;break;\
8087
     default:x1 = xy[0];y1 = xy[1]; break;\
11747 schaersvoo 8088
    };\
8089
    xml_div.style.left = x1 + 'px';xml_div.style.top = y1 + 'px';\
14062 schaersvoo 8090
    reply[click_cnt] = px2x(xy[0])+','+px2y(xy[1]);\
11238 schaersvoo 8091
   };\
7614 schaersvoo 8092
  };\
11238 schaersvoo 8093
 };\
8094
 if(onclick == 1){\
11747 schaersvoo 8095
  xml_div.onclick = function(){\
11756 schaersvoo 8096
  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 8097
 };\
8098
 return;\
11745 schaersvoo 8099
};");
7614 schaersvoo 8100
    break;
7654 schaersvoo 8101
    case DRAW_SGRAPH:
8224 bpr 8102
/*
7654 schaersvoo 8103
 xstart = given
8104
 ystart = given
8105
 sgraph(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily)
8106
*/
13970 obado 8107
fprintf(js_include_file,"\n/* draw sgraph */\n\
8105 schaersvoo 8108
var draw_sgraph = function(canvas_type,precision,xmajor,ymajor,xminor,yminor,majorcolor,minorcolor,fontfamily,opacity,font_size){\
7658 schaersvoo 8109
 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);};\
8110
 var ctx = obj.getContext(\"2d\");\
8111
 ctx.font = fontfamily;\
8112
 var minor_opacity = 0.8*opacity;\
8113
 ctx.clearRect(0,0,xsize,ysize);\
7976 schaersvoo 8114
 var zero_x = 0.1*xsize;\
8115
 var zero_y = 0.9*ysize;\
8129 schaersvoo 8116
 var snor_x;var snor_y;\
7654 schaersvoo 8117
 if( xstart != xmin){\
7658 schaersvoo 8118
  snor_x = 0.1*xsize;\
8119
 }\
8120
 else\
8121
 {\
8122
  snor_x = 0;\
8123
  xstart = xmin;\
8124
 };\
8125
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8126
 ctx.lineWidth = 2;\
8127
 ctx.beginPath();\
8128
 ctx.moveTo(xsize,zero_y);\
8129
 ctx.lineTo(zero_x,zero_y);\
8130
 ctx.lineTo(zero_x,0);\
8131
 ctx.stroke();\
8132
 ctx.closePath();\
8133
 ctx.beginPath();\
8134
 ctx.moveTo(zero_x,zero_y);\
8135
 ctx.lineTo(zero_x + 0.25*snor_x,zero_y - 0.1*snor_x);\
8136
 ctx.lineTo(zero_x + 0.5*snor_x,zero_y + 0.1*snor_x);\
8137
 ctx.lineTo(zero_x + 0.75*snor_x,zero_y - 0.1*snor_x);\
8138
 ctx.lineTo(zero_x + snor_x,zero_y);\
8139
 ctx.stroke();\
8140
 ctx.closePath();\
8141
 ctx.beginPath();\
8142
 var num = xstart;\
7660 schaersvoo 8143
 var flipflop = 1;\
7658 schaersvoo 8144
 var step_x = xmajor*(xsize - zero_x - snor_x)/(xmax - xstart);\
7976 schaersvoo 8145
 var txtsize;var txt_marge=step_x - 5;\
7658 schaersvoo 8146
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
7976 schaersvoo 8147
  txtsize = ctx.measureText(num).width;\
8148
  if( txtsize > txt_marge ){if( flipflop == 1 ){flipflop = 0;}else{flipflop = 1;};};\
8149
  if( flipflop == 1){\
8150
   ctx.fillText(num,x - 0.5*txtsize,zero_y+font_size);\
8151
  }\
8152
  else\
8153
  {\
8154
   ctx.fillText(num,x - 0.5*txtsize,zero_y+2*font_size);\
8379 schaersvoo 8155
  };\
7976 schaersvoo 8156
  num = num + xmajor;\
7658 schaersvoo 8157
 };\
8158
 ctx.stroke();\
8159
 ctx.closePath();\
8160
 ctx.lineWidth = 1;\
8161
 ctx.beginPath();\
8162
 for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
8163
   ctx.moveTo(x,zero_y);\
8164
   ctx.lineTo(x,0);\
8165
 };\
8166
 ctx.stroke();\
8167
 ctx.closePath();\
8168
 if( xminor > 1){\
8169
  ctx.lineWidth = 0.5;\
8170
  ctx.beginPath();\
8171
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
8172
  var minor_step_x = step_x / xminor;\
8173
  var nx;\
8174
  for(var x = zero_x+snor_x; x < xsize;x = x + step_x){\
8175
    num = 1;\
8176
    for(var p = 1 ; p < xminor ; p++){\
8177
     nx = x + num*minor_step_x;\
8178
     ctx.moveTo(nx,zero_y);\
8179
     ctx.lineTo(nx,0);\
8180
     num++;\
8181
    };\
8182
  };\
8183
  ctx.stroke();\
8184
  ctx.closePath();\
8185
  ctx.beginPath();\
8186
  ctx.lineWidth = 2;\
8187
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8188
  for(var x = zero_x+snor_x ; x < xsize;x = x + step_x){\
8189
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 12);\
8190
  };\
8191
  for(var x = zero_x+snor_x ; x < xsize;x = x + minor_step_x){\
8192
   ctx.moveTo(x,zero_y);ctx.lineTo(x,zero_y - 6);\
8193
  };\
8194
  ctx.stroke();\
8195
  ctx.closePath();\
8196
  ctx.lineWidth = 0.5;\
8197
 };\
8198
 xmin = xstart - (xmajor*(zero_x+snor_x)/step_x);\
8199
 if( ystart != ymin){\
8200
  snor_y = 0.1*ysize;\
8201
 }\
8202
 else\
8203
 {\
8204
  snor_y = 0;\
8205
  ystart = ymin;\
8206
 };\
8207
 ctx.lineWidth = 2;\
8208
 ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8209
 ctx.beginPath();\
8210
 ctx.moveTo(zero_x,zero_y);\
8211
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.25*snor_y);\
8212
 ctx.lineTo(zero_x + 0.1*snor_y,zero_y - 0.5*snor_y);\
8213
 ctx.lineTo(zero_x - 0.1*snor_y,zero_y - 0.75*snor_y);\
8214
 ctx.lineTo(zero_x,zero_y - snor_y);\
8215
 ctx.stroke();\
8216
 ctx.closePath();\
8217
 ctx.beginPath();\
8218
 ctx.lineWidth = 1;\
8219
 num = ystart;\
8220
 var step_y = ymajor*(zero_y - snor_y)/(ymax - ystart);\
8221
 for(var y = zero_y - snor_y ; y > 0; y = y - step_y){\
8222
  ctx.moveTo(zero_x,y);\
8223
  ctx.lineTo(xsize,y);\
8224
  ctx.fillText(num,zero_x - ctx.measureText(num+\" \").width,parseInt(y+0.2*font_size));\
8225
  num = num + ymajor;\
8226
 };\
8227
 ctx.stroke();\
8228
 ctx.closePath();\
8229
 if( yminor > 1){\
8230
  ctx.lineWidth = 0.5;\
8231
  ctx.beginPath();\
8232
  ctx.strokeStyle = \"rgba(\"+minorcolor+\",\"+minor_opacity+\")\";\
8233
  var minor_step_y = step_y / yminor;\
8234
  var ny;\
8235
  for(var y = 0 ; y < zero_y - snor_y ;y = y + step_y){\
8236
   num = 1;\
8237
   for(var p = 1 ;p < yminor;p++){\
8238
     ny = y + num*minor_step_y;\
8239
     ctx.moveTo(zero_x,ny);\
8240
     ctx.lineTo(xsize,ny);\
8241
     num++;\
8242
    };\
8243
  };\
8244
  ctx.stroke();\
8245
  ctx.closePath();\
8246
  ctx.lineWidth = 2;\
8247
  ctx.beginPath();\
8248
  ctx.strokeStyle = \"rgba(\"+majorcolor+\",\"+opacity+\")\";\
8249
  for(var y = zero_y - snor_y ; y > 0 ;y = y - step_y){\
8250
   ctx.moveTo(zero_x,y);\
8251
   ctx.lineTo(zero_x+12,y);\
8252
  };\
8253
  for(var y = zero_y - snor_y ; y > 0 ;y = y - minor_step_y){\
8254
   ctx.moveTo(zero_x,y);\
8255
   ctx.lineTo(zero_x+6,y);\
8256
  };\
8257
  ctx.stroke();\
8258
  ctx.closePath();\
8259
 };\
8260
 ymin = ystart - (ymajor*(ysize - zero_y + snor_y)/step_y);\
11088 schaersvoo 8261
 if( typeof(legend%d)  !== 'undefined' ){\
7654 schaersvoo 8262
  ctx.globalAlpha = 1.0;\
8263
  var y_offset = 2*font_size;\
8264
  var txt;var txt_size;\
8265
  var x_offset = xsize - 2*font_size;\
8266
  var l_length = legend%d.length;var barcolor = new Array();\
11088 schaersvoo 8267
  if( typeof(legendcolors%d) !== 'undefined' ){\
7654 schaersvoo 8268
   for(var p = 0 ; p < l_length ; p++){\
8269
    barcolor[p] = legendcolors%d[p];\
8270
   };\
8271
  }else{\
8272
   if( barcolor.length == 0 ){\
8273
    for(var p = 0 ; p < l_length ; p++){\
8274
     barcolor[p] = stroke_color;\
8275
    };\
8276
   };\
8277
  };\
8278
  for(var p = 0; p < l_length; p++){\
8279
   ctx.fillStyle = barcolor[p];\
8280
   txt = legend%d[p];\
8281
   txt_size = ctx.measureText(txt).width;\
8282
   ctx.fillText(legend%d[p],x_offset - txt_size, y_offset);\
8283
   y_offset = parseInt(y_offset + 1.5*font_size);\
8284
  };\
8285
 };\
11088 schaersvoo 8286
 if( typeof(xaxislabel) !== 'undefined' ){\
7658 schaersvoo 8287
   ctx.fillStyle = \'#000000\';\
8288
   var txt_size = ctx.measureText(xaxislabel).width + 4 ;\
8289
   ctx.fillText(xaxislabel,xsize - txt_size, zero_y - 7);\
8290
 };\
11088 schaersvoo 8291
 if( typeof(yaxislabel) !== 'undefined'){\
7658 schaersvoo 8292
   ctx.save();\
8293
   ctx.fillStyle = \'#000000\';\
8294
   var txt_size = ctx.measureText(yaxislabel).width;\
8295
   ctx.translate(zero_x+8 + font_size,txt_size+font_size);\
8296
   ctx.rotate(-0.5*Math.PI);\
8297
   ctx.fillText(yaxislabel,0,0);\
7874 schaersvoo 8298
   ctx.restore();\
7658 schaersvoo 8299
 };\
7654 schaersvoo 8300
};\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);
8301
    break;
11890 schaersvoo 8302
    case DRAW_NUMBERLINE:
13970 obado 8303
fprintf(js_include_file,"\n/* draw numberline */\n\
11996 schaersvoo 8304
var draw_numberline = function(canvas_type,use_axis_numbering,x0,x1,xmajor,xminor,y0,y1,linewidth,strokecolor,strokeopacity,fontfamily,fontcolor,precision){\
11890 schaersvoo 8305
 var obj = create_canvas%d(canvas_type,xsize,ysize);\
8306
 var ctx = obj.getContext(\"2d\");\
8307
 ctx.lineWidth = linewidth || 1;\
8308
 ctx.strokeStyle = \"rgba(\"+strokecolor+\",\"+strokeopacity+\")\";\
8309
 ctx.font = fontfamily || 'Ariel 12px';\
8310
 var fontsize = parseInt(ctx.font);\
8311
 ctx.fillStyle =  \"rgba(\"+fontcolor+\",\"+strokeopacity+\")\";\
8312
 x1 = x2px(x1);\
8313
 x0 = x2px(x0);\
8314
 y0 = y2px(y0);\
8315
 y1 = y2px(y1);\
8316
 var sub_devision = -1;\
8317
 if( xminor%%2 == 0 ){ sub_devision = xminor/2; };\
11892 schaersvoo 8318
 var ybase1 = parseInt( y0 + fontsize + 2 );\
8319
 var ybase2 = parseInt( ybase1 + fontsize + 2 );\
11890 schaersvoo 8320
 var yh = Math.abs(parseInt( y0 - 0.3*(y0 -y1)));\
8321
 var ys = Math.abs(parseInt( y0 - 0.6*(y0 -y1)));\
8322
 xmajor = x2px(xmajor) - x2px(0);\
8323
 var i;var len;var p;\
8324
 xminor = xmajor / xminor;\
8325
 ctx.beginPath();\
8326
 for(p = x0 ; p < x1 ; p = p + xmajor){\
8327
  ctx.moveTo(p,y0);ctx.lineTo(p,y1);i = 0;\
8328
  for(var s = p ; s < p + xmajor ; s = s + xminor ){\
8329
   ctx.moveTo(s,y0);\
8330
   if( sub_devision == i){ ctx.lineTo(s,ys); } else { ctx.lineTo(s,yh); };\
8331
   i++;\
8332
  };\
8333
 };\
8334
 ctx.moveTo(p,y0);ctx.lineTo(p,y1);\
8335
 ctx.closePath();\
8336
 ctx.stroke();\
11996 schaersvoo 8337
 if( use_axis_numbering >-1 ){\
11891 schaersvoo 8338
  var str = x_strings[use_axis_numbering];\
8339
  len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
11892 schaersvoo 8340
  var corr;var x_nums;var x_text;var flipflop = 0;var off = ybase1;\
11890 schaersvoo 8341
  ctx.beginPath();\
11891 schaersvoo 8342
  if( x_strings_up[use_axis_numbering] == null){\
11890 schaersvoo 8343
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8344
    var x_nums = x2px(eval(str[p]));\
8345
    var x_text = str[p+1];\
11890 schaersvoo 8346
    corr = ctx.measureText(x_text).width;\
11892 schaersvoo 8347
    if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
11996 schaersvoo 8348
    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),off);\
11890 schaersvoo 8349
   };\
8350
  }\
8351
  else\
8352
  {\
8353
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8354
    x_nums = x2px(eval(str[p]));\
8355
    x_text = str[p+1];\
11892 schaersvoo 8356
    corr = ctx.measureText(x_text).width + ybase1 - fontsize;\
11890 schaersvoo 8357
    ctx.save();\
8358
    ctx.translate(x_nums+0.5*fontsize, corr);\
8359
    ctx.rotate(-1.5708);\
8360
    ctx.fillText(x_text,0,0);\
8361
    ctx.restore();\
8362
   };\
8363
  }\
8364
 }\
8365
 else\
8366
 {\
11892 schaersvoo 8367
  var corr;var num;var flipflop = 0;var off = ybase1;\
8368
  var prec = parseInt(Math.log(precision)/Math.log(10));\
11890 schaersvoo 8369
  for(var p = x0 ; p < x1+xmajor ; p = p+xmajor){\
11892 schaersvoo 8370
   num = (px2x(p)).toFixed(prec);\
11996 schaersvoo 8371
   corr = ctx.measureText(num).width;\
11892 schaersvoo 8372
   if( corr > xmajor){ if(flipflop == 0 ){flipflop = 1; off = ybase2;}else{flipflop = 0; off = ybase1;};};\
11996 schaersvoo 8373
   ctx.fillText(num,parseInt(p - 0.5*corr),off);\
11890 schaersvoo 8374
  };\
8375
 };\
8376
};",canvas_root_id);
8377
    break;
7614 schaersvoo 8378
    case DRAW_GRID:/* not used for userdraw */
13970 obado 8379
fprintf(js_include_file,"\n/* draw grid */\n\
8105 schaersvoo 8380
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 8381
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);};\
8382
var ctx = obj.getContext(\"2d\");ctx.clearRect(0,0,xsize,ysize);\
7614 schaersvoo 8383
if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
8384
ctx.save();\
8071 schaersvoo 8385
if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 8386
if( use_rotate == 1 ){ctx.translate(x2px(0),y2px(0));ctx.rotate(angle*Math.PI/180);ctx.translate(-1*(x2px(0)),-1*(y2px(0)));};\
8387
var stroke_color = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8388
ctx.fillStyle = \"rgba(\"+font_color+\",\"+1.0+\")\";\
8389
var axis_color = \"rgba(\"+axis_color+\",\"+stroke_opacity+\")\";\
8390
ctx.font = font_family;\
7988 schaersvoo 8391
var barcolor = new Array();\
7614 schaersvoo 8392
var xstep = xsize*xmajor/(xmax - xmin);\
8393
var ystep = ysize*ymajor/(ymax - ymin);\
8394
var x2step = xstep / xminor;\
8395
var y2step = ystep / yminor;\
7996 schaersvoo 8396
var zero_x = x2px(0);;var zero_y = y2px(0);var f_x;var f_y;\
8397
if(xmin < 0 ){ f_x = -1;}else{ f_x = 1;}\
8398
if(ymin < 0 ){ f_y = -1;}else{ f_y = 1;}\
11088 schaersvoo 8399
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8400
ctx.beginPath();\
8401
ctx.lineWidth = line_width;\
8402
ctx.strokeStyle = stroke_color;\
8403
for(var p = zero_x ; p < xsize; p = p + xstep){\
8404
 ctx.moveTo(p,0);\
8405
 ctx.lineTo(p,ysize);\
8406
};\
8407
for(var p = zero_x ; p > 0; p = p - xstep){\
8408
 ctx.moveTo(p,0);\
8409
 ctx.lineTo(p,ysize);\
8410
};\
8411
for(var p = zero_y ; p < ysize; p = p + ystep){\
8412
 ctx.moveTo(0,p);\
8413
 ctx.lineTo(xsize,p);\
8414
};\
8415
for(var p = zero_y ; p > 0; p = p - ystep){\
8416
 ctx.moveTo(0,p);\
8417
 ctx.lineTo(xsize,p);\
8418
};\
11088 schaersvoo 8419
if( typeof(xaxislabel) !== 'undefined' ){\
7614 schaersvoo 8420
 ctx.save();\
8421
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
12007 schaersvoo 8422
 var corr =  parseInt(1.1*ctx.measureText(xaxislabel).width);\
8423
 ctx.fillText(xaxislabel,xsize - corr,zero_y - tics_length - 0.4*font_size);\
7614 schaersvoo 8424
 ctx.restore();\
8425
};\
11088 schaersvoo 8426
if( typeof(yaxislabel) !== 'undefined' ){\
7614 schaersvoo 8427
 ctx.save();\
8428
 ctx.font = \"italic \"+font_size+\"px Ariel\";\
12007 schaersvoo 8429
 var corr = parseInt(ctx.measureText(yaxislabel).width + font_size);\
8430
 ctx.translate(zero_x+tics_length + font_size,corr);\
7614 schaersvoo 8431
 ctx.rotate(-0.5*Math.PI);\
8432
 ctx.fillText(yaxislabel,0,0);\
8433
 ctx.restore();\
8434
};\
8435
ctx.stroke();\
8436
ctx.closePath();\
8437
if( use_axis == 1 ){\
7988 schaersvoo 8438
 ctx.save();\
7614 schaersvoo 8439
 ctx.beginPath();\
8440
 ctx.strokeStyle = stroke_color;\
8441
 ctx.lineWidth = 0.6*line_width;\
8442
 for(var p = zero_x ; p < xsize; p = p + x2step){\
8443
  ctx.moveTo(p,0);\
8444
  ctx.lineTo(p,ysize);\
8445
 };\
8446
 for(var p = zero_x ; p > 0; p = p - x2step){\
8447
  ctx.moveTo(p,0);\
8448
  ctx.lineTo(p,ysize);\
8449
 };\
8450
 for(var p = zero_y ; p < ysize; p = p + y2step){\
8451
  ctx.moveTo(0,p);\
8452
  ctx.lineTo(xsize,p);\
8453
 };\
8454
 for(var p = zero_y ; p > 0; p = p - y2step){\
8455
  ctx.moveTo(0,p);\
8456
  ctx.lineTo(xsize,p);\
8457
 };\
8458
 ctx.stroke();\
8459
 ctx.closePath();\
8460
 ctx.beginPath();\
8461
 ctx.lineWidth = 2*line_width;\
8462
 ctx.strokeStyle = axis_color;\
8463
 ctx.moveTo(0,zero_y);\
8464
 ctx.lineTo(xsize,zero_y);\
8465
 ctx.moveTo(zero_x,0);\
8466
 ctx.lineTo(zero_x,ysize);\
8467
 ctx.stroke();\
8468
 ctx.closePath();\
8469
 ctx.lineWidth = line_width+0.5;\
8470
 ctx.beginPath();\
8471
 for(var p = zero_x ; p < xsize; p = p + xstep){\
8472
  ctx.moveTo(p,zero_y-tics_length);\
8473
  ctx.lineTo(p,zero_y+tics_length);\
8474
 };\
8475
 for(var p = zero_x ; p > 0; p = p - xstep){\
8476
  ctx.moveTo(p,zero_y-tics_length);\
8477
  ctx.lineTo(p,zero_y+tics_length);\
8478
 };\
8479
 for(var p = zero_y ; p < ysize; p = p + ystep){\
8480
  ctx.moveTo(zero_x-tics_length,p);\
8481
  ctx.lineTo(zero_x+tics_length,p);\
8482
 };\
8483
 for(var p = zero_y ; p > 0; p = p - ystep){\
8484
  ctx.moveTo(zero_x-tics_length,p);\
8485
  ctx.lineTo(zero_x+tics_length,p);\
8486
 };\
8487
 for(var p = zero_x ; p < xsize; p = p + x2step){\
8488
  ctx.moveTo(p,zero_y-0.5*tics_length);\
8489
  ctx.lineTo(p,zero_y+0.5*tics_length);\
8490
 };\
8491
 for(var p = zero_x ; p > 0; p = p - x2step){\
8492
  ctx.moveTo(p,zero_y-0.5*tics_length);\
8493
  ctx.lineTo(p,zero_y+0.5*tics_length);\
8494
 };\
8495
 for(var p = zero_y ; p < ysize; p = p + y2step){\
8496
  ctx.moveTo(zero_x-0.5*tics_length,p);\
8497
  ctx.lineTo(zero_x+0.5*tics_length,p);\
8498
 };\
8499
 for(var p = zero_y ; p > 0; p = p - y2step){\
8500
  ctx.moveTo(zero_x-0.5*tics_length,p);\
8501
  ctx.lineTo(zero_x+0.5*tics_length,p);\
8502
 };\
8503
 ctx.stroke();\
8504
 ctx.closePath();\
7988 schaersvoo 8505
 ctx.restore();\
8506
};\
11891 schaersvoo 8507
if( use_axis_numbering != -1 ){\
7988 schaersvoo 8508
 ctx.save();\
8509
 ctx.fillColor = axis_color;\
8110 schaersvoo 8510
 ctx.strokeStyle = axis_color;\
8511
 ctx.lineWidth = 2*line_width;\
7988 schaersvoo 8512
 ctx.font = font_family;\
8513
 var shift = zero_y+2*font_size;var flip=0;var skip=0;var corr;var cnt;var disp_cnt;var prec;\
11891 schaersvoo 8514
 if( x_strings[use_axis_numbering] != null ){\
8515
  var str = x_strings[use_axis_numbering];\
8516
  var len = str.length;if((len/2+0.5)%%2 == 0){ alert(\"xaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 8517
  ctx.beginPath();\
11891 schaersvoo 8518
  if( x_strings_up[use_axis_numbering] == null){\
9341 schaersvoo 8519
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8520
    var x_nums = x2px(eval(str[p]));\
8521
    var x_text = str[p+1];\
9341 schaersvoo 8522
    corr = ctx.measureText(x_text).width;\
8523
    skip = 1.2*corr/xstep;\
8524
    if( zero_y+2*font_size > ysize ){shift = ysize - 2*font_size;};\
8525
    if( skip > 1 ){if(flip == 0 ){flip = 1; shift = shift + font_size;}else{flip = 0; shift = shift - font_size;}};\
8526
    ctx.fillText(x_text,parseInt(x_nums-0.5*corr),shift);\
8527
    ctx.moveTo(x_nums,zero_y - tics_length);\
8528
    ctx.lineTo(x_nums,zero_y + tics_length);\
8529
   };\
8530
  }\
8531
  else\
8532
  {\
8533
   for(var p = 0 ; p < len ; p = p+2){\
11891 schaersvoo 8534
    var x_nums = x2px(eval(str[p]));\
8535
    var x_text = str[p+1];\
9341 schaersvoo 8536
    corr = 2 + tics_length + zero_y + ctx.measureText(x_text).width;\
8537
    if( corr > ysize ){corr = ysize;};\
8538
    ctx.save();\
9346 schaersvoo 8539
    ctx.translate(x_nums+0.25*font_size, corr);\
9341 schaersvoo 8540
    ctx.rotate(-1.5708);\
8541
    ctx.fillText(x_text,0,0);\
8542
    ctx.restore();\
8543
    ctx.moveTo(x_nums,zero_y - tics_length);\
8544
    ctx.lineTo(x_nums,zero_y + tics_length);\
8545
   };\
7988 schaersvoo 8546
  };\
8110 schaersvoo 8547
  ctx.closePath();\
7988 schaersvoo 8548
 }\
8549
 else\
8550
 {\
8551
  skip = 1;cnt = px2x(zero_x);\
8552
  prec = Math.log(precision)/(Math.log(10));\
8553
  var y_basis;if(f_y == 1){ y_basis = ysize }else{ y_basis = zero_y + 1.4*font_size;};\
8554
  for( var p = zero_x ; p < xsize ; p = p+xstep){\
8555
   if(skip == 0 ){\
7990 schaersvoo 8556
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8557
    corr = ctx.measureText(disp_cnt).width;\
8558
    skip = parseInt(1.2*corr/xstep);\
8559
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
7614 schaersvoo 8560
   }\
7988 schaersvoo 8561
   else\
8562
   {\
8563
    skip--;\
7614 schaersvoo 8564
   };\
7988 schaersvoo 8565
   cnt = cnt + xmajor;\
7614 schaersvoo 8566
  };\
7988 schaersvoo 8567
  cnt = px2x(zero_x);skip = 1;\
8568
  for( var p = zero_x ; p > 0 ; p = p-xstep){\
8569
   if(skip == 0 ){\
7990 schaersvoo 8570
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8571
    corr = ctx.measureText(disp_cnt).width;\
8572
    skip = parseInt(1.2*corr/xstep);\
8573
    ctx.fillText(disp_cnt,p-0.5*corr,y_basis);\
8574
   }\
8575
   else\
8576
   {\
8577
    skip--;\
7614 schaersvoo 8578
   };\
7988 schaersvoo 8579
   cnt = cnt - xmajor;\
7614 schaersvoo 8580
  };\
8581
 };\
7988 schaersvoo 8582
 if( y_strings != null ){\
8583
  var len = y_strings.length;if((len/2+0.5)%%2 == 0){ alert(\"yaxis number unpaired:  text missing ! \");return;};\
8110 schaersvoo 8584
  ctx.beginPath();\
7988 schaersvoo 8585
  for(var p = 0 ; p < len ; p = p+2){\
8586
   var y_nums = y2px(eval(y_strings[p]));\
8587
   var y_text = y_strings[p+1];\
8588
   corr = 2 + tics_length + ctx.measureText(y_text).width;\
8589
   if( corr > zero_x){corr = parseInt(zero_x+2); }\
8110 schaersvoo 8590
   ctx.fillText(y_text,zero_x - corr,y_nums + 0.5*font_size);\
8591
   ctx.moveTo(zero_x - tics_length,y_nums);\
8592
   ctx.lineTo(zero_x + tics_length,y_nums);\
7614 schaersvoo 8593
  };\
8110 schaersvoo 8594
  ctx.closePath();\
7988 schaersvoo 8595
 }\
8596
 else\
8597
 {\
7991 schaersvoo 8598
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 8599
  cnt = px2y(zero_y);skip = 1;\
8600
  for( var p = zero_y ; p < ysize ; p = p+ystep){\
8601
   if(skip == 0 ){\
8602
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 8603
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8604
    if(f_x == -1 ){ corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
8605
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
8606
   }\
8607
   else\
8608
   {\
8609
    skip--;\
8610
   };\
8611
   cnt = cnt - ymajor;\
7614 schaersvoo 8612
  };\
7988 schaersvoo 8613
  corr = 0;cnt = px2y(zero_y);skip = 1;\
7991 schaersvoo 8614
  if(f_x == 1){ corr = 1.5*tics_length; }\
7988 schaersvoo 8615
  for( var p = zero_y ; p > 0 ; p = p-ystep){\
8616
   if(skip == 0 ){\
8617
    skip = parseInt(1.4*font_size/ystep);\
7990 schaersvoo 8618
    disp_cnt = cnt.toFixed(prec);\
7988 schaersvoo 8619
    if(f_x == -1 ){corr = parseInt(zero_x - (2 + tics_length + ctx.measureText(disp_cnt).width));};\
8620
    ctx.fillText(disp_cnt,parseInt(corr),parseInt(p+(0.4*font_size)));\
8621
   }\
8622
   else\
8623
   {\
8624
    skip--;\
8625
   };\
8626
   cnt = cnt + ymajor;\
7614 schaersvoo 8627
  };\
8628
 };\
7988 schaersvoo 8629
 ctx.stroke();\
7614 schaersvoo 8630
 ctx.restore();\
8631
};\
11088 schaersvoo 8632
if( typeof(legend0)  !== 'undefined' ){\
7988 schaersvoo 8633
 ctx.save();\
7614 schaersvoo 8634
 ctx.globalAlpha = 1.0;\
8635
 ctx.font = \"bold \"+font_size+\"px Ariel\";\
8636
 var y_offset = 2*font_size;\
8637
 var txt;var txt_size;\
8638
 var x_offset = xsize - 2*font_size;\
7956 schaersvoo 8639
 var l_length = legend0.length;\
11088 schaersvoo 8640
 if( typeof(legendcolors0) !== 'undefined' ){\
7614 schaersvoo 8641
  for(var p = 0 ; p < l_length ; p++){\
7956 schaersvoo 8642
    barcolor[p] = legendcolors0[p];\
7614 schaersvoo 8643
  };\
7988 schaersvoo 8644
 }\
8645
 else\
8646
 {\
7614 schaersvoo 8647
  if( barcolor.length == 0 ){\
8648
   for(var p = 0 ; p < l_length ; p++){\
8649
    barcolor[p] = stroke_color;\
8650
   };\
8651
  };\
8652
 };\
8653
 for(var p = 0; p < l_length; p++){\
8654
  ctx.fillStyle = barcolor[p];\
7956 schaersvoo 8655
  txt = legend0[p];\
7614 schaersvoo 8656
  txt_size = ctx.measureText(txt).width;\
7956 schaersvoo 8657
  ctx.fillText(legend0[p],x_offset - txt_size, y_offset);\
7614 schaersvoo 8658
  y_offset = parseInt(y_offset + 1.5*font_size);\
8659
 };\
7988 schaersvoo 8660
 ctx.restore();\
7614 schaersvoo 8661
};\
11088 schaersvoo 8662
if( typeof(barchart_0)  !== 'undefined' ){\
7991 schaersvoo 8663
 ctx.save();\
8664
 var num_barcharts = 0;\
8665
 var bar_name = eval('barchart_0');\
11088 schaersvoo 8666
 while( typeof(bar_name) !== 'undefined' ){\
7991 schaersvoo 8667
    try{ bar_name = eval('barchart_'+num_barcharts);num_barcharts++;}catch(e){break;};\
8668
 };\
9346 schaersvoo 8669
 var bar_width = parseInt(0.8*x2step/(num_barcharts));\
7991 schaersvoo 8670
 for(var i=0 ; i< num_barcharts ; i++){\
8671
  bar_name = eval('barchart_'+i);\
8672
  var bar_x = new Array();\
8673
  var bar_y = new Array();\
8674
  var lb = bar_name.length;\
8675
  var idx = 0;\
8676
  var dx = parseInt(0.5*i*bar_width);\
8677
  for( var p = 0 ; p < lb ; p = p + 3 ){\
8678
   bar_x[idx] = x2px(bar_name[p]);\
8679
   bar_y[idx] = y2px(bar_name[p+1]);\
8680
   barcolor[idx] = bar_name[p+2];\
8681
   idx++;\
8682
  };\
8683
  ctx.globalAlpha = fill_opacity;\
8684
  for( var p = 0; p < idx ; p++ ){\
11739 schaersvoo 8685
   ctx.beginPath();\
7991 schaersvoo 8686
   ctx.strokeStyle = barcolor[p];\
8687
   ctx.fillStyle = barcolor[p];\
9346 schaersvoo 8688
   ctx.rect(bar_x[p]-0.4*x2step+dx,bar_y[p],bar_width,zero_y - bar_y[p]);\
11739 schaersvoo 8689
   ctx.fill();\
8690
   ctx.stroke();\
8691
   ctx.closePath();\
7991 schaersvoo 8692
  };\
8693
 };\
8694
 ctx.restore();\
8695
};\
11088 schaersvoo 8696
if( typeof(linegraph_0) !== 'undefined' ){\
7996 schaersvoo 8697
 ctx.save();\
8698
 ctx.globalAlpha = 1.0;\
8699
 var i = 0;\
8700
 var line_name = eval('linegraph_'+i);\
11088 schaersvoo 8701
 while ( typeof(line_name) !== 'undefined' ){\
7996 schaersvoo 8702
  ctx.strokeStyle = 'rgba('+line_name[0]+','+stroke_opacity+')';\
8703
  ctx.lineWidth = parseInt(line_name[1]);\
8704
  if(line_name[2] == \"1\"){\
8705
   var d1 = parseInt(line_name[3]);\
8706
   var d2 = parseInt(line_name[4]);\
8707
   if(ctx.setLineDash){ ctx.setLineDash([d1,d2]); } else { ctx.mozDash = [d1,d2];};\
8708
  }\
8709
  else\
8710
  {\
8711
  if(ctx.setLineDash){ctx.setLineDash = null;}\
8712
  if(ctx.mozDash){ctx.mozDash = null;}\
8713
  };\
8714
  var data_x = new Array();\
8715
  var data_y = new Array();\
8716
  var lb = line_name.length;\
8717
  var idx = 0;\
8718
  for( var p = 5 ; p < lb ; p = p + 2 ){\
8719
   data_x[idx] = x2px(line_name[p]);\
8720
   data_y[idx] = y2px(line_name[p+1]);\
8721
   idx++;\
8722
  };\
8723
  for( var p = 0; p < idx ; p++){\
8724
   ctx.beginPath();\
8725
   ctx.moveTo(data_x[p],data_y[p]);\
8726
   ctx.lineTo(data_x[p+1],data_y[p+1]);\
8727
   ctx.stroke();\
8728
   ctx.closePath();\
8729
  };\
8730
  i++;\
8731
  try{ line_name = eval('linegraph_'+i); }catch(e){ break; }\
8732
 };\
8733
 ctx.restore();\
8734
};\
7614 schaersvoo 8735
return;\
7989 schaersvoo 8736
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8737
    break;
8224 bpr 8738
 
7614 schaersvoo 8739
    case DRAW_PIECHART:
13970 obado 8740
fprintf(js_include_file,"\n/* draw piecharts */\n\
11875 schaersvoo 8741
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
12538 schaersvoo 8742
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 8743
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8744
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8745
 }\
8746
 else\
8747
 {\
8748
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8749
 };\
12538 schaersvoo 8750
 var center_text = use_offset || 0;\
7614 schaersvoo 8751
 var ld = data_color_list.length;\
8752
 var sum = 0;\
8753
 var idx = 0;\
7956 schaersvoo 8754
 var font_size = parseInt(font_family.replace(/[^0-9\\.]+/g, \"\"));\
7614 schaersvoo 8755
 var colors = new Array();\
8756
 var data = new Array();\
8757
 for(var p = 0;p < ld; p = p + 2){\
8758
  data[idx] = parseFloat(data_color_list[p]);\
8759
  sum = sum + data[idx];\
8760
  colors[idx] = data_color_list[p+1];\
8761
  idx++;\
8762
 };\
11875 schaersvoo 8763
 if( use_filled > 1 ){\
8764
  var i = 2;\
8765
  for(var p = 0 ;  p < idx ; p++){\
8766
   if(i > 5 ){ i = 2; };\
8767
   var pat = create_Pattern(0,0,i,colors[p]); all_fill_patterns[p] = pat;i++;\
8768
  };\
8769
 };\
7614 schaersvoo 8770
 var ctx = obj.getContext(\"2d\");\
8771
 ctx.save();\
8772
 var angle;\
8773
 var angle_end = 0;\
8774
 var offset = Math.PI / 2;\
8775
 ctx.globalAlpha = fill_opacity;\
12538 schaersvoo 8776
 var angles = [];\
7614 schaersvoo 8777
 for(var p=0; p < idx; p++){\
8778
  ctx.beginPath();\
8779
  ctx.moveTo(x_center,y_center);\
8780
  angle = Math.PI * (2 * data[p] / sum);\
8781
  ctx.arc(x_center,y_center, radius, angle_end - offset, angle_end + angle - offset, false);\
8782
  ctx.lineTo(x_center, y_center);\
11875 schaersvoo 8783
  if( use_filled > 1 ){ ctx.fillStyle = all_fill_patterns[p]; }else{ ctx.fillStyle = colors[p];};\
7614 schaersvoo 8784
  ctx.fill();\
8785
  ctx.closePath();\
12538 schaersvoo 8786
  angles.push(angle_end + angle - offset);\
7614 schaersvoo 8787
  angle_end  = angle_end + angle;\
8788
 };\
11088 schaersvoo 8789
 if(typeof(legend0) !== 'undefined'){\
7956 schaersvoo 8790
  var legenda = eval(\"legend\"+legend_cnt);\
7614 schaersvoo 8791
  ctx.globalAlpha = 1.0;\
7956 schaersvoo 8792
  ctx.font = font_family;\
12538 schaersvoo 8793
  var y_offset = font_size;\
7614 schaersvoo 8794
  var x_offset = 0;\
8795
  var txt;var txt_size;\
8796
  for(var p = 0; p < idx; p++){\
8797
   ctx.fillStyle = colors[p];\
7956 schaersvoo 8798
   txt = legenda[p];\
12538 schaersvoo 8799
   txt_size = ctx.measureText(txt).width + 2;\
8800
   if(center_text == 4){\
8801
    ctx.save();\
8802
    ctx.translate(x_center, y_center);\
8803
    ctx.rotate(angles[p]);\
8804
    ctx.fillText(txt,radius-txt_size,0);\
8805
    ctx.restore();\
8806
   }\
8807
   else\
8808
   {\
8809
    if( x_center + radius + txt_size > xsize ){ x_offset =  x_center + radius + txt_size - xsize;} else { x_offset = 0; };\
8810
    ctx.fillText(txt,x_center + radius - x_offset, y_center - radius + y_offset);\
8811
    y_offset = parseInt(y_offset + 1.5*font_size);\
8812
   };\
7614 schaersvoo 8813
  };\
8814
 };\
8815
 ctx.restore();\
7956 schaersvoo 8816
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 8817
    break;
9433 schaersvoo 8818
    case DRAW_JSBOXPLOT:
13970 obado 8819
fprintf(js_include_file,"\n/* draw jsboxplots */\n\
11874 schaersvoo 8820
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
9433 schaersvoo 8821
function statistics(data){\
8822
 var len = data.length;\
8823
 var min = 10000000;\
8824
 var max = -10000000;\
8825
 var sum = 0;var d;\
8826
 for(var i=0;i<len;i++){\
8827
  d = data[i];\
8828
  if(d < min){min = d;}else{if(d > max){max = d;};};\
8829
  sum+= parseFloat(data[i]);\
8830
 };\
8831
 var mean = parseFloat(sum/len);\
8832
 var variance = 0;\
8833
 for(var i=0;i<len;i++){\
8834
  d = data[i];\
8835
  variance += (d - mean)*(d - mean);\
8836
 };\
8837
 variance = parseFloat(variance / len);\
8838
 var std = Math.sqrt(variance);\
8839
 data.sort(function(a,b){return a - b;});\
8840
 var median;var Q1;var Q3;\
8841
 var half = Math.floor(0.5*len);\
8842
 var q1 = Math.floor(0.25*len);\
8843
 var q3 = Math.floor(0.75*len);\
8844
 var half = Math.floor(0.5*len);\
8845
 if(len %%2 == 1){\
8846
  median = data[half];\
8847
  Q1 = data[q1];\
8848
  Q3 = data[q3];\
8849
 }\
8850
 else\
8851
 {\
8852
  median = (data[half - 1] + data[half] )/2;\
8853
  Q1 = (data[q1 - 1] + data[q1] )/2;\
8854
  Q3 = (data[q3 - 1] + data[q3] )/2;\
8855
 };\
8856
 return [min,Q1,median,Q3,max];\
8857
};");
8858
    break;
8859
    case DRAW_BOXPLOT:
13970 obado 8860
fprintf(js_include_file,"\n/* draw boxplots */\n\
11874 schaersvoo 8861
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
9465 schaersvoo 8862
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 8863
 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 8864
 var ctx = obj.getContext(\"2d\");\
8865
 ctx.clearRect(0,0,xsize,ysize);\
8866
 ctx.save();\
8867
 ctx.lineWidth = line_width;\
11088 schaersvoo 8868
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
9433 schaersvoo 8869
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11875 schaersvoo 8870
 var colors = new Array(2);\
8871
 colors[0] = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
8872
 colors[1] = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8873
 if( use_filled > 1 ){\
8874
   var pat = create_Pattern(0,0,3,colors[0]);\
8875
   all_fill_patterns[0] = pat;\
8876
   pat = create_Pattern(0,0,4,colors[1]);\
8877
   all_fill_patterns[1] = pat;\
8878
 };\
9433 schaersvoo 8879
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8880
 var hh = 0.25*hw;\
9465 schaersvoo 8881
 switch(boxplot_source){\
11088 schaersvoo 8882
  case 1: if( typeof(jsboxplot_data) === 'undefined'){return;};data = statistics(jsboxplot_data);break;\
8883
  case 2: if( typeof(student_boxplot_data) === 'undefined'){return;};data = statistics(student_boxplot_data);break;\
8884
  case 3: if( typeof(student_boxplot) === 'undefined'){return;};data = student_boxplot;break;\
9465 schaersvoo 8885
  default: break;\
9433 schaersvoo 8886
 };\
8887
 var min,Q1,median,Q3,max;\
8888
 if(xy == 1 ){\
8889
  min=x2px(data[0]);Q1=x2px(data[1]);median=x2px(data[2]);Q3=x2px(data[3]);max=x2px(data[4]);\
8890
  hh = Math.abs(y2px(hh) - y2px(ystart));\
8891
  hw = Math.abs(y2px(hw) - y2px(ystart));\
8892
  cxy = y2px(cxy);\
9465 schaersvoo 8893
  ctx.beginPath();\
9433 schaersvoo 8894
  ctx.moveTo(min,cxy);\
8895
  ctx.lineTo(Q1,cxy);\
8896
  ctx.moveTo(Q3,cxy);\
8897
  ctx.lineTo(max,cxy);\
8898
  ctx.moveTo(min,cxy+hh);\
8899
  ctx.lineTo(min,cxy-hh);\
8900
  ctx.moveTo(max,cxy+hh);\
8901
  ctx.lineTo(max,cxy-hh);\
9465 schaersvoo 8902
  ctx.closePath();\
8903
  ctx.stroke();\
8904
  ctx.beginPath();\
9433 schaersvoo 8905
  ctx.rect(Q1,cxy-2*hh,median-Q1,hw);\
9465 schaersvoo 8906
  ctx.closePath();\
11839 schaersvoo 8907
  if( use_filled != 0 ){\
12024 schaersvoo 8908
   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
9465 schaersvoo 8909
   ctx.fill();\
8910
  };\
8911
  ctx.stroke();\
8912
  ctx.beginPath();\
9433 schaersvoo 8913
  ctx.rect(median,cxy-2*hh,Q3-median,hw);\
9465 schaersvoo 8914
  ctx.closePath();\
11839 schaersvoo 8915
  if( use_filled != 0 ){\
12075 schaersvoo 8916
   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
9465 schaersvoo 8917
   ctx.fill();\
8918
  };\
8919
  ctx.stroke();\
9433 schaersvoo 8920
 }else{\
8921
  min=y2px(data[0]);Q1=y2px(data[1]);median=y2px(data[2]);Q3=y2px(data[3]);max=y2px(data[4]);\
8922
  hh = Math.abs(x2px(hh) - x2px(xstart));\
8923
  hw = Math.abs(x2px(hw) - x2px(xstart));\
8924
  cxy = x2px(cxy);\
9465 schaersvoo 8925
  ctx.beginPath();\
9433 schaersvoo 8926
  ctx.moveTo(cxy,min);\
8927
  ctx.lineTo(cxy,Q1);\
8928
  ctx.moveTo(cxy,Q3);\
8929
  ctx.lineTo(cxy,max);\
8930
  ctx.moveTo(cxy + hh,min);\
8931
  ctx.lineTo(cxy - hh,min);\
8932
  ctx.moveTo(cxy + hh,max);\
8933
  ctx.lineTo(cxy - hh,max);\
9465 schaersvoo 8934
  ctx.closePath;\
8935
  ctx.stroke();\
8936
  ctx.beginPath();\
9433 schaersvoo 8937
  ctx.rect(cxy - 2*hh,Q1,hw,median - Q1);\
9465 schaersvoo 8938
  ctx.closePath();\
11839 schaersvoo 8939
  if( use_filled != 0 ){\
12075 schaersvoo 8940
   if( use_filled == 1 ) {ctx.fillStyle = colors[0]; }else{ ctx.fillStyle = all_fill_patterns[0] };\
9465 schaersvoo 8941
   ctx.fill();\
8942
  };\
8943
  ctx.stroke();\
8944
  ctx.beginPath();\
9433 schaersvoo 8945
  ctx.rect(cxy - 2*hh,median,hw,Q3 - median);\
9465 schaersvoo 8946
  ctx.closePath();\
11839 schaersvoo 8947
  if( use_filled != 0 ){\
12075 schaersvoo 8948
   if( use_filled == 1 ) {ctx.fillStyle = colors[1]; }else{ ctx.fillStyle = all_fill_patterns[1] };\
9465 schaersvoo 8949
   ctx.fill();\
8950
  };\
8951
  ctx.stroke();\
9433 schaersvoo 8952
 };\
8953
 ctx.restore();};",canvas_root_id,canvas_root_id,canvas_root_id);
8954
    break;
7614 schaersvoo 8955
    case DRAW_ARCS:
13970 obado 8956
fprintf(js_include_file,"\n/* draw arcs */\n\
11874 schaersvoo 8957
if( typeof(all_fill_patterns) != 'object' ){ var all_fill_patterns = []; };\
8105 schaersvoo 8958
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 8959
 ctx.save();\
8960
 if( use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{if(ctx.mozDash){ ctx.mozDash = [dashtype0,dashtype1];};};};\
8071 schaersvoo 8961
 if( use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);};\
7614 schaersvoo 8962
 if( use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);};\
8963
 if(end < start){var tmp = end;end = start;start=tmp;};\
8071 schaersvoo 8964
 start = 360 - start;\
8965
 end = 360 - end;\
7614 schaersvoo 8966
 ctx.lineWidth = line_width;\
11088 schaersvoo 8967
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 8968
 ctx.strokeStyle =  \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
11874 schaersvoo 8969
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 8970
 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 8971
 ctx.beginPath();\
8972
 ctx.moveTo(xc,yc);\
8973
 ctx.arc(xc, yc, r, start*(Math.PI / 180), end*(Math.PI / 180),true);\
8974
 ctx.lineTo(xc,yc);\
8975
 ctx.closePath();\
11875 schaersvoo 8976
 if( use_filled != 0 ){ctx.fill();};\
8071 schaersvoo 8977
 ctx.stroke();\
7614 schaersvoo 8978
 ctx.restore();\
8071 schaersvoo 8979
};");
8224 bpr 8980
 
7614 schaersvoo 8981
    break;
7983 schaersvoo 8982
    case DRAW_CENTERSTRING:
13970 obado 8983
fprintf(js_include_file,"\n/* draw centerstring */\n\
8105 schaersvoo 8984
var draw_centerstring = function(canvas_type,y,font_family,stroke_color,stroke_opacity,text){\
7983 schaersvoo 8985
 var obj;\
8986
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
8987
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
8988
 }\
8989
 else\
8990
 {\
8991
  obj = create_canvas%d(canvas_type,xsize,ysize);\
8992
 };\
8993
 var ctx = obj.getContext(\"2d\");\
8994
 ctx.save();\
9481 schaersvoo 8995
 ctx.clearRect(0,0,xsize,ysize);\
7983 schaersvoo 8996
 ctx.font = font_family;\
8997
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
8998
 var stringwidth = ctx.measureText(text).width;\
8999
 var x = parseInt((xsize - stringwidth)/2);if( x < 0 ){x = 0;};\
9000
 ctx.fillText(text,x,y2px(y));\
9481 schaersvoo 9001
 ctx.restore();\
7983 schaersvoo 9002
return;\
9003
};",canvas_root_id,canvas_root_id,canvas_root_id);
9004
    break;
7614 schaersvoo 9005
    case DRAW_TEXTS:
13970 obado 9006
fprintf(js_include_file,"\n/* draw text */\n\
11811 schaersvoo 9007
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 9008
 var obj;\
9009
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9010
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9011
 }\
9012
 else\
9013
 {\
9014
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9015
 };\
9016
 var ctx = obj.getContext(\"2d\");\
9017
 if( font_family != 'null' ){\
9018
  ctx.font = font_family;\
9019
 }\
9020
 else\
9021
 {\
9022
  ctx.font = font_size+'px Ariel';\
9023
 };\
9024
 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;};};\
9025
 if(angle2 == 0 && angle != 0){\
9026
  ctx.save();\
9027
  if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
9028
  if(use_rotate == 1 ){\
9029
  ctx.rotate(angle*Math.PI/180);};\
9030
  ctx.restore();\
9031
 };\
9032
 ctx.fillStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
9033
 if(angle2 != 0){\
9034
  ctx.save();\
9035
  ctx.translate(x,y);\
9036
  ctx.rotate((360-angle2)*(Math.PI / 180));\
9037
  ctx.fillText(text,0,0);\
9038
  ctx.restore();\
9039
 }\
9040
 else\
9041
 {\
9042
  ctx.fillText(text,x,y);\
9043
 };\
7614 schaersvoo 9044
 return;\
12000 schaersvoo 9045
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 9046
    break;
9047
    case DRAW_CURVE:
13970 obado 9048
fprintf(js_include_file,"\n/* draw curve */\n\
8105 schaersvoo 9049
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 9050
 var obj;\
9051
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9052
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9053
 }\
9054
 else\
9055
 {\
9056
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9057
 };\
9058
 var ctx = obj.getContext(\"2d\");\
9059
 ctx.save();\
8071 schaersvoo 9060
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 9061
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
9062
 ctx.beginPath();ctx.lineWidth = line_width;\
11088 schaersvoo 9063
 if(line_width%%2 == 1 && typeof(zoom_x_increment) === 'undefined'){ctx.translate(0.5,0.5)};\
7614 schaersvoo 9064
 if(use_dashed == 1){if(ctx.setLineDash){ctx.setLineDash([dashtype0,dashtype1]);}else{ctx.mozDash = [dashtype0,dashtype1];};};\
9065
 ctx.strokeStyle = \"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
9066
 ctx.moveTo(x2px(x_points[0]),y2px(y_points[0]));\
9067
 for(var p = 1 ; p < x_points.length ; p++){\
9068
  if( y2px(y_points[p]) > -5 && y2px(y_points[p]) < ysize+5 ){\
9069
  ctx.lineTo(x2px(x_points[p]),y2px(y_points[p]));\
9070
  }\
9071
  else\
9072
  {\
9073
   ctx.stroke();\
9074
   ctx.beginPath();\
9075
   p++;\
9076
   ctx.moveTo(x2px(x_points[p]),y2px(y_points[p]));\
9077
  };\
9078
 };\
9079
 ctx.stroke();\
9080
 ctx.restore();\
7653 schaersvoo 9081
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 9082
    break;
8224 bpr 9083
 
7614 schaersvoo 9084
    case DRAW_INPUTS:
13970 obado 9085
fprintf(js_include_file,"\n/* draw input fields */\n\
11803 schaersvoo 9086
var draw_inputs = function(root_id,input_cnt,x,y,size,readonly,style,value,use_offset){\
7614 schaersvoo 9087
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
9088
var input = document.createElement(\"input\");\
9089
input.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
9090
input.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
9091
input.setAttribute(\"size\",size);\
9092
input.setAttribute(\"value\",value);\
7877 schaersvoo 9093
if( readonly == 0 || wims_status == \"done\" ){ input.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){input.setAttribute(\"value\",\"\");};};\
11803 schaersvoo 9094
canvas_div.appendChild(input);\
9095
if(use_offset != 0 ){ center_input('canvas_input'+input_cnt,x,y,style);};\
9096
};\
9097
function center_input(id,x,y,style){\
9098
 var inp = document.getElementById(id);\
9099
 var pos = inp.getBoundingClientRect();\
9100
 var center_x = parseInt(x - 0.5*(pos.width));\
9101
 var center_y = parseInt(y - 0.5*(pos.height));\
9102
 try{ inp.setAttribute(\"style\",\"position:absolute;left:\"+center_x+\"px;top:\"+center_y+\"px;\"+style );}\
9103
 catch(e){return;};\
9104
};");
7614 schaersvoo 9105
    break;
8224 bpr 9106
 
7614 schaersvoo 9107
    case DRAW_TEXTAREAS:
13970 obado 9108
fprintf(js_include_file,"\n/* draw text area inputfields */\n\
8105 schaersvoo 9109
var draw_textareas = function(root_id,input_cnt,x,y,cols,rows,readonly,style,value){\
7614 schaersvoo 9110
var canvas_div = document.getElementById(\"canvas_div\"+root_id);\
9111
var textarea = document.createElement(\"textarea\");\
9112
textarea.setAttribute(\"id\",\"canvas_input\"+input_cnt);\
9113
textarea.setAttribute(\"style\",\"position:absolute;left:\"+x+\"px;top:\"+y+\"px;\"+style);\
9114
textarea.setAttribute(\"cols\",cols);\
9115
textarea.setAttribute(\"rows\",rows);\
7877 schaersvoo 9116
textarea.value = value;\
9117
if( readonly == 0 || wims_status == \"done\" ){ textarea.setAttribute(\"readonly\",\"readonly\");if( wims_status == \"done\" ){textarea.value=\"\";};};\
7653 schaersvoo 9118
canvas_div.appendChild(textarea);};");
7614 schaersvoo 9119
    break;
8224 bpr 9120
 
7614 schaersvoo 9121
case DRAW_PIXELS:
13970 obado 9122
fprintf(js_include_file,"\n/* draw pixel */\n\
8105 schaersvoo 9123
var draw_setpixel = function(x,y,color,opacity,pixelsize){\
11997 schaersvoo 9124
 var idx = 2000+Math.ceil(1000*(Math.random()));\
9125
 var canvas = create_canvas%d(idx,xsize,ysize);\
7614 schaersvoo 9126
 var d = 0.5*pixelsize;\
9127
 var ctx = canvas.getContext(\"2d\");\
9462 schaersvoo 9128
 if(pixelsize%%2 == 1){ ctx.translate(0.5,0.5);};\
7614 schaersvoo 9129
 ctx.fillStyle = \"rgba(\"+color+\",\"+opacity+\")\";\
9130
 ctx.clearRect(0,0,xsize,ysize);\
9131
 for(var p=0; p<x.length;p++){\
9132
  ctx.fillRect( x2px(x[p]) - d, y2px(y[p]) - d , pixelsize, pixelsize );\
9133
 };\
9134
 ctx.fill();ctx.stroke();\
9135
};",canvas_root_id);
9136
break;
9137
 
9138
case DRAW_CLOCK:
13970 obado 9139
fprintf(js_include_file,"\n/* begin command clock */\n\
7614 schaersvoo 9140
var clock_canvas = create_canvas%d(%d,xsize,ysize);\
9141
var clock_ctx = clock_canvas.getContext(\"2d\");\
9142
var clock = function(xc,yc,radius,H,M,S,type,interaction,h_color,m_color,s_color,bg_color,fg_color){\
8130 schaersvoo 9143
 clock_ctx.clearRect(xc - radius,yc - radius,2*radius,2*radius);\
7614 schaersvoo 9144
 clock_ctx.save();\
7997 schaersvoo 9145
 clock_ctx.globalAlpha = clock_bg_opacity;\
7614 schaersvoo 9146
 this.type = type || 0;\
9147
 this.interaction = interaction || 0;\
7862 schaersvoo 9148
 this.H = H;\
9149
 this.M = M;\
9150
 this.S = S;\
7614 schaersvoo 9151
 this.xc = xc || xsize/2;\
9152
 this.yc = yc || ysize/2;\
9153
 this.radius = radius || xsize/4;\
9154
 var font_size = parseInt(0.2*this.radius);\
11991 schaersvoo 9155
 this.H_color = h_color || \"black\";\
9156
 this.M_color = m_color || \"black\";\
9157
 this.S_color = s_color || \"black\";\
9158
 this.fg_color = fg_color || \"black\";\
7614 schaersvoo 9159
 this.bg_color = bg_color || \"white\";\
9160
 clock_ctx.translate(this.xc,this.yc);\
9161
 clock_ctx.beginPath();\
9162
 clock_ctx.arc(0,0,this.radius,0,2*Math.PI,false);\
9163
 clock_ctx.fillStyle = this.bg_color;\
9164
 clock_ctx.fill();\
9165
 clock_ctx.closePath();\
9166
 clock_ctx.beginPath();\
9167
 clock_ctx.font = font_size+\"px Arial\";\
9168
 clock_ctx.fillStyle = this.fg_color;\
9169
 clock_ctx.textAlign = \"center\";\
9170
 clock_ctx.textBaseline = 'middle';\
9171
 var angle;var x1,y1,x2,y2;\
9172
 var angle_cos;var angle_sin;\
7997 schaersvoo 9173
 clock_ctx.globalAlpha = clock_fg_opacity;\
7614 schaersvoo 9174
 switch(type){\
9175
 case 0:clock_ctx.beginPath();\
9176
 for(var p = 1; p <= 12 ; p++){\
9177
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
9178
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
9179
  x1 = 0.8*angle_cos;y1 = 0.8*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9180
  clock_ctx.moveTo(x1,y1);\
9181
  clock_ctx.lineTo(x2,y2);\
9182
 };\
9183
 for(var p = 1; p <= 60 ; p++){\
9184
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
9185
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
9186
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9187
  clock_ctx.moveTo(x1,y1);\
9188
  clock_ctx.lineTo(x2,y2);\
9189
 };\
9190
 clock_ctx.closePath();\
9191
 clock_ctx.stroke();\
9192
 break;\
9193
 case 1:\
9194
 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 9195
 case 2:\
9196
 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 9197
 clock_ctx.beginPath();\
9198
 for(var p = 1; p <= 12 ; p++){\
9199
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 12));\
9200
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 12));\
9201
  x1 = 0.9*angle_cos;y1 = 0.9*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9202
  clock_ctx.moveTo(x1,y1);\
9203
  clock_ctx.lineTo(x2,y2);\
9204
 };\
9205
 for(var p = 1; p <= 60 ; p++){\
9206
  angle_cos = this.radius*(Math.cos(p * (Math.PI * 2) / 60));\
9207
  angle_sin = this.radius*(Math.sin(p * (Math.PI * 2) / 60));\
9208
  x1 = 0.95*angle_cos;y1 = 0.95*angle_sin;x2 = angle_cos;y2 = angle_sin;\
9209
  clock_ctx.moveTo(x1,y1);\
9210
  clock_ctx.lineTo(x2,y2);\
9211
 };\
9212
 clock_ctx.closePath();\
9213
 clock_ctx.stroke();\
9214
 break;\
9215
 };\
9216
 angle = (this.H - 3 + this.M/60 ) * 2 * Math.PI / 12;\
9217
 clock_ctx.rotate(angle);\
9218
 clock_ctx.beginPath();\
9219
 clock_ctx.moveTo(-3, -2);\
9220
 clock_ctx.lineTo(-3, 2);\
11026 bpr 9221
 clock_ctx.lineTo(this.radius * 0.6, 1);\
9222
 clock_ctx.lineTo(this.radius  * 0.6, -1);\
7614 schaersvoo 9223
 clock_ctx.fillStyle = this.H_color;\
9224
 clock_ctx.fill();\
9225
 clock_ctx.rotate(-angle);\
9226
 angle = (this.M - 15 + this.S/60) * 2 * Math.PI / 60;\
9227
 clock_ctx.rotate(angle);\
9228
 clock_ctx.beginPath();\
9229
 clock_ctx.moveTo(-3, -2);\
9230
 clock_ctx.lineTo(-3, 2);\
9231
 clock_ctx.lineTo(this.radius  * 0.8, 1);\
9232
 clock_ctx.lineTo(this.radius  * 0.8, -1);\
9233
 clock_ctx.fillStyle = this.M_color;\
9234
 clock_ctx.fill();\
9235
 clock_ctx.rotate(-angle);\
9236
 angle = (this.S - 15) * 2 * Math.PI / 60;\
9237
 clock_ctx.rotate(angle);\
9238
 clock_ctx.beginPath();\
9239
 clock_ctx.moveTo(0,0);\
11026 bpr 9240
 clock_ctx.lineTo(this.radius  * 0.9, 1);\
9241
 clock_ctx.lineTo(this.radius  * 0.9, -1);\
7614 schaersvoo 9242
 clock_ctx.strokeStyle = this.S_color;\
9243
 clock_ctx.stroke();\
9244
 clock_ctx.restore();\
7653 schaersvoo 9245
};",canvas_root_id,CLOCK_CANVAS);
7614 schaersvoo 9246
break;
9247
 
9248
case DRAW_LATTICE:
13970 obado 9249
fprintf(js_include_file,"\n/* draw lattice */\n\
11991 schaersvoo 9250
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 9251
 var obj;\
9252
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9253
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9254
 }\
9255
 else\
9256
 {\
9257
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9258
 };\
9259
 var ctx = obj.getContext(\"2d\");\
9260
 ctx.save();\
8071 schaersvoo 9261
 if(use_affine == 1 ){ctx.translate(affine_matrix[4],affine_matrix[5]);}\
7614 schaersvoo 9262
 if(use_rotate == 1 ){ctx.rotate(angle*Math.PI/180);}\
11874 schaersvoo 9263
 var color = \"rgba(\"+fill_color+\",\"+fill_opacity+\")\";\
11875 schaersvoo 9264
 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 9265
 ctx.strokeStyle=\"rgba(\"+stroke_color+\",\"+stroke_opacity+\")\";\
9266
 var radius = line_width;\
9267
 var x = 0;\
9268
 var y = 0;\
9269
 var x_step_px = xsize/(xmax-xmin);\
9270
 var y_step_px = ysize/(ymax-ymin);\
9271
 var xv1 = dx1*x_step_px;\
9272
 var yv1 = dy1*y_step_px;\
9273
 var xv2 = dx2*x_step_px;\
9274
 var yv2 = dy2*y_step_px;\
9275
 for(var p = 0; p < n1 ;p++){\
9276
  x = p*xv1 + x0;\
9277
  y = p*yv1 + y0;\
9278
  for(var c = 0; c < n2 ; c++){\
9279
   ctx.beginPath();\
9280
   ctx.arc(x+c*xv2,y+c*yv2,radius,0,2*Math.PI,false);\
9281
   ctx.fill();\
9282
   ctx.stroke();\
9283
   ctx.closePath();\
9284
  };\
9285
 };\
9286
 ctx.restore();\
9287
 return;\
7653 schaersvoo 9288
};",canvas_root_id,canvas_root_id,canvas_root_id);
7614 schaersvoo 9289
    break;
7735 schaersvoo 9290
case DRAW_XYLOGSCALE:
13970 obado 9291
fprintf(js_include_file,"\n/* draw xylogscale */\n\
8105 schaersvoo 9292
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 9293
 var obj;\
9294
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9295
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9296
 }\
9297
 else\
9298
 {\
9299
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9300
 };\
9301
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 9302
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 9303
 ctx.save();\
7739 schaersvoo 9304
 var xmarge;var ymarge;var x_e;var y_e;var num;var corr;var xtxt;var ytxt;\
7956 schaersvoo 9305
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
9306
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
9307
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
9308
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
11972 schaersvoo 9309
 if(use_axis_numbering != -1){\
7956 schaersvoo 9310
  ctx.font = font_family;\
9311
  xmarge = ctx.measureText(ylogbase+'^'+y_max.toFixed(0)+' ').width;\
9312
  ymarge = parseInt(1.5*font_size);\
9313
  ctx.save();\
9314
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
9315
  ctx.rect(0,0,xmarge,ysize);\
9316
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
9317
  ctx.fill();\
9318
  ctx.restore();\
9319
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 9320
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 9321
  ctx.save();\
9322
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9323
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9324
  corr =  ctx.measureText(xaxislabel).width;\
9325
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
9326
  ctx.restore();\
9327
 };\
11088 schaersvoo 9328
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 9329
  ctx.save();\
9330
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9331
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9332
  corr = ctx.measureText(yaxislabel).width;\
9333
  ctx.translate(xmarge+font_size,corr+font_size);\
9334
  ctx.rotate(-0.5*Math.PI);\
9335
  ctx.fillText(yaxislabel,0,0);\
9336
  ctx.restore();\
9337
 };\
9338
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9339
 ctx.lineWidth = line_width;\
9340
 for(var p = x_min; p <= x_max ; p++){\
9341
  num = Math.pow(xlogbase,p);\
9342
  for(var i = 1 ; i < xlogbase ; i++){\
9343
   x_e = x2px(i*num);\
7735 schaersvoo 9344
   if( i == 1 ){\
7956 schaersvoo 9345
    ctx.lineWidth = line_width;\
9346
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9347
    if( use_axis_numbering != -1 && p > x_min){\
7956 schaersvoo 9348
      xtxt = xlogbase+'^'+p.toFixed(0);\
9349
      corr = 0.5*(ctx.measureText(xtxt).width);\
9350
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
9351
    };\
7735 schaersvoo 9352
   }else{\
7956 schaersvoo 9353
    ctx.lineWidth = 0.2*line_width;\
9354
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9355
   };\
7738 schaersvoo 9356
   if( x_e >= xmarge ){\
7956 schaersvoo 9357
    ctx.beginPath();\
9358
    ctx.moveTo(x_e,0);\
9359
    ctx.lineTo(x_e,ysize - ymarge);\
9360
    ctx.stroke();\
9361
    ctx.closePath();\
7738 schaersvoo 9362
   };\
7956 schaersvoo 9363
  };\
9364
 };\
9365
 for(var p = y_min; p <= y_max ; p++){\
9366
  num = Math.pow(ylogbase,p);\
9367
  for(var i = 1 ; i < ylogbase ; i++){\
9368
   y_e = y2px(i*num);\
9369
   if( i == 1 ){\
9370
    ctx.lineWidth = line_width;\
7735 schaersvoo 9371
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9372
    if( use_axis_numbering != -1 && p > y_min){\
7956 schaersvoo 9373
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
9374
    };\
9375
   }else{\
9376
    ctx.lineWidth = 0.2*line_width;\
9377
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9378
   };\
9379
   ctx.beginPath();\
9380
   ctx.moveTo(xmarge,y_e);\
9381
   ctx.lineTo(xsize,y_e);\
9382
   ctx.stroke();\
9383
   ctx.closePath();\
9384
  };\
9385
 };\
7735 schaersvoo 9386
 ctx.restore();\
9387
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
9388
    break;
7614 schaersvoo 9389
 
7735 schaersvoo 9390
case DRAW_XLOGSCALE:
13970 obado 9391
fprintf(js_include_file,"\n/* draw xlogscale */\n\
8105 schaersvoo 9392
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 9393
 var obj;\
9394
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9395
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9396
 }\
9397
 else\
9398
 {\
9399
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9400
 };\
9401
 var ctx = obj.getContext(\"2d\");\
7735 schaersvoo 9402
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 9403
 ctx.save();\
9404
 ctx.lineWidth = line_width;\
7739 schaersvoo 9405
 var prec = Math.log(precision)/Math.log(10);\
7735 schaersvoo 9406
 var x_min = Math.log(xmin)/Math.log(xlogbase);\
9407
 var x_max = Math.log(xmax)/Math.log(xlogbase);\
9408
 var y_min = 0;var y_max = ysize;var x_e;var corr;\
7739 schaersvoo 9409
 var xtxt;var ytxt;var num;var xmarge;var ymarge;\
11972 schaersvoo 9410
 if(use_axis_numbering != -1){\
7956 schaersvoo 9411
  ctx.font = font_family;\
9412
  xmarge = ctx.measureText(ymax.toFixed(prec)+' ').width;\
9413
  ymarge = parseInt(1.5*font_size);\
9414
  ctx.save();\
9415
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
9416
  ctx.rect(0,0,xmarge,ysize);\
9417
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
9418
  ctx.fill();\
9419
  ctx.restore();\
9420
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 9421
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 9422
  ctx.save();\
9423
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9424
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9425
  corr =  ctx.measureText(xaxislabel).width;\
9426
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
9427
  ctx.restore();\
9428
 };\
11088 schaersvoo 9429
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 9430
  ctx.save();\
9431
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9432
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9433
  corr = ctx.measureText(yaxislabel).width;\
9434
  ctx.translate(xmarge+font_size,corr+font_size);\
9435
  ctx.rotate(-0.5*Math.PI);\
9436
  ctx.fillText(yaxislabel,0,0);\
9437
  ctx.restore();\
9438
 };\
9439
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9440
 ctx.lineWidth = line_width;\
9441
 for(var p = x_min; p <= x_max ; p++){\
9442
  num = Math.pow(xlogbase,p);\
9443
  for(var i = 1 ; i < xlogbase ; i++){\
9444
   x_e = x2px(i*num);\
7735 schaersvoo 9445
   if( i == 1 ){\
7956 schaersvoo 9446
     ctx.lineWidth = line_width;\
7739 schaersvoo 9447
     ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9448
    if( use_axis_numbering != -1 && p > x_min ){\
7735 schaersvoo 9449
      xtxt = xlogbase+'^'+p.toFixed(0);\
9450
      corr = 0.5*(ctx.measureText(xtxt).width);\
9451
      ctx.fillText(xtxt,x_e - corr,ysize - 4);\
9452
    };\
9453
   }else{\
7956 schaersvoo 9454
    ctx.lineWidth = 0.2*line_width;\
7735 schaersvoo 9455
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9456
   };\
7739 schaersvoo 9457
   if( x_e >= xmarge ){\
7956 schaersvoo 9458
    ctx.beginPath();\
9459
    ctx.moveTo(x_e,0);\
9460
    ctx.lineTo(x_e,ysize - ymarge);\
9461
    ctx.stroke();\
9462
    ctx.closePath();\
7739 schaersvoo 9463
   };\
9464
  };\
7956 schaersvoo 9465
 };\
7735 schaersvoo 9466
 var stepy = Math.abs(y2px(ymajor) - y2px(0));\
9467
 var minor_step = stepy / yminor;\
7749 schaersvoo 9468
 for(var y = 0 ; y < ysize - stepy ; y = y + stepy){\
7735 schaersvoo 9469
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 9470
  ctx.lineWidth = line_width;\
9471
  ctx.beginPath();\
9472
  ctx.moveTo(xmarge,y);\
9473
  ctx.lineTo(xsize,y);\
9474
  ctx.stroke();\
9475
  ctx.closePath();\
11972 schaersvoo 9476
  if( use_axis_numbering != -1){\
7735 schaersvoo 9477
   ytxt = (px2y(y)).toFixed(prec);\
9478
   ctx.fillText( ytxt,0 ,y + 0.5*font_size );\
9479
  };\
9480
  for(var dy = 1 ; dy < yminor ; dy++){\
9481
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 9482
   ctx.lineWidth = 0.2*line_width;\
9483
   ctx.beginPath();\
7739 schaersvoo 9484
   ctx.moveTo(xmarge,y+dy*minor_step);\
7956 schaersvoo 9485
   ctx.lineTo(xsize,y+dy*minor_step);\
9486
   ctx.stroke();\
9487
   ctx.closePath();\
7735 schaersvoo 9488
  };\
9489
 };\
7956 schaersvoo 9490
 ctx.restore();\
9491
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7735 schaersvoo 9492
    break;
7729 schaersvoo 9493
case DRAW_YLOGSCALE:
13970 obado 9494
fprintf(js_include_file,"\n/* draw ylogscale */\n\
8105 schaersvoo 9495
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 9496
 var obj;\
9497
 if( document.getElementById(\"wims_canvas%d\"+canvas_type) ){\
9498
  obj = document.getElementById(\"wims_canvas%d\"+canvas_type);\
9499
 }\
9500
 else\
9501
 {\
9502
  obj = create_canvas%d(canvas_type,xsize,ysize);\
9503
 };\
9504
 var ctx = obj.getContext(\"2d\");\
7729 schaersvoo 9505
 ctx.clearRect(0,0,xsize,ysize);\
7956 schaersvoo 9506
 ctx.save();\
9507
 ctx.lineWidth = line_width;\
7735 schaersvoo 9508
 var y_min = Math.log(ymin)/Math.log(ylogbase);\
9509
 var y_max = Math.log(ymax)/Math.log(ylogbase);\
8109 schaersvoo 9510
 var x_min = 0;var x_max = xsize;var y_s;var y_e;var num;var xmarge;var ymarge;\
11972 schaersvoo 9511
 if(use_axis_numbering != -1){\
7956 schaersvoo 9512
  ctx.font = font_family;\
9513
  xmarge = ctx.measureText(ylogbase+\"^\"+y_max.toFixed(0)+' ').width;\
9514
  ymarge = 2*font_size;\
9515
  ctx.save();\
9516
  ctx.fillStyle=\"rgba(255,215,0,0.2)\";\
9517
  ctx.rect(0,0,xmarge,ysize);\
9518
  ctx.rect(0,ysize-ymarge,xsize,ysize);\
9519
  ctx.fill();\
9520
  ctx.restore();\
9521
 }else{xmarge = 0;ymarge = 0;};\
11088 schaersvoo 9522
 if( typeof(xaxislabel) !== 'undefined' ){\
7956 schaersvoo 9523
  ctx.save();\
9524
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9525
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9526
  corr =  ctx.measureText(xaxislabel).width;\
9527
  ctx.fillText(xaxislabel,xsize - 1.5*corr,ysize - 2*font_size);\
9528
  ctx.restore();\
9529
 };\
11088 schaersvoo 9530
 if( typeof(yaxislabel) !== 'undefined' ){\
7956 schaersvoo 9531
  ctx.save();\
9532
  ctx.font = \"italic \"+font_size+\"px Ariel\";\
9533
  ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9534
  corr = ctx.measureText(yaxislabel).width;\
9535
  ctx.translate(xmarge+font_size,corr+font_size);\
9536
  ctx.rotate(-0.5*Math.PI);\
9537
  ctx.fillText(yaxislabel,0,0);\
9538
  ctx.restore();\
9539
 };\
9540
 ctx.fillStyle = \"rgba(\"+font_color+\",\"+major_opacity+\")\";\
9541
 ctx.lineWidth = line_width;\
9542
 for(var p = y_min; p <= y_max ; p++){\
9543
  num = Math.pow(ylogbase,p);\
9544
  for(var i = 1 ; i < ylogbase ; i++){\
9545
   y_e = y2px(i*num);\
7729 schaersvoo 9546
   if( i == 1 ){\
7956 schaersvoo 9547
    ctx.lineWidth = line_width;\
7729 schaersvoo 9548
    ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
11972 schaersvoo 9549
    if( use_axis_numbering != -1 && p > y_min){\
7735 schaersvoo 9550
     ctx.fillText(ylogbase+'^'+p.toFixed(0),0,y_e);\
7729 schaersvoo 9551
    };\
9552
   }else{\
7956 schaersvoo 9553
    ctx.lineWidth = 0.2*line_width;\
7729 schaersvoo 9554
    ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
9555
   };\
7956 schaersvoo 9556
   ctx.beginPath();\
9557
   ctx.moveTo(xmarge,y_e);\
9558
   ctx.lineTo(xsize,y_e);\
9559
   ctx.stroke();\
9560
   ctx.closePath();\
9561
  };\
9562
 };\
7729 schaersvoo 9563
 var stepx = Math.abs(x2px(xmajor) - x2px(0));\
9564
 var minor_step = stepx / xminor;\
9565
 var prec = Math.log(precision)/Math.log(10);\
9566
 var xtxt;var corr;var flip = 0;\
7749 schaersvoo 9567
 for(var x = stepx ; x < xsize ; x = x + stepx){\
7729 schaersvoo 9568
  ctx.strokeStyle=\"rgba(\"+major_color+\",\"+major_opacity+\")\";\
7956 schaersvoo 9569
  ctx.lineWidth = line_width;\
9570
  ctx.beginPath();\
9571
  ctx.moveTo(x,ysize-ymarge);\
9572
  ctx.lineTo(x,0);\
9573
  ctx.stroke();\
9574
  ctx.closePath();\
11972 schaersvoo 9575
  if( use_axis_numbering != -1){\
7729 schaersvoo 9576
   xtxt = (px2x(x)).toFixed(prec);\
9577
   corr = 0.5*(ctx.measureText(xtxt).width);\
9578
   if(flip == 0 ){flip = 1;ctx.fillText( xtxt,x - corr ,ysize - 0.2*font_size );}else{\
9579
   flip = 0;ctx.fillText( xtxt,x - corr ,ysize - 1.2*font_size );};\
9580
  };\
9581
  for(var dx = 1 ; dx < xminor ; dx++){\
9582
   ctx.strokeStyle=\"rgba(\"+minor_color+\",\"+minor_opacity+\")\";\
7956 schaersvoo 9583
   ctx.lineWidth = 0.2*line_width;\
9584
   ctx.beginPath();\
7739 schaersvoo 9585
   ctx.moveTo(x+dx*minor_step,ysize - ymarge);\
7956 schaersvoo 9586
   ctx.lineTo(x+dx*minor_step,0);\
9587
   ctx.stroke();\
9588
   ctx.closePath();\
7735 schaersvoo 9589
  };\
9590
 };\
7956 schaersvoo 9591
 ctx.restore();\
9592
};",canvas_root_id,canvas_root_id,canvas_root_id,canvas_root_id);
7729 schaersvoo 9593
    break;
9213 schaersvoo 9594
 
7614 schaersvoo 9595
    default:break;
9596
   }
9597
  }
9598
 }
9599
  return;
9600
}
9601
 
9602
void check_string_length(int L){
9466 schaersvoo 9603
 if( L > MAX_BUFFER-1){
7614 schaersvoo 9604
  canvas_error("problem with your arguments to command...");
9605
 }
9606
 return;
9607
}
9608
 
9609
 
9610
int get_token(FILE *infile){
9611
        int     c,i=0;
9612
        char    temp[MAX_INT], *input_type;
9613
        char    *line="line",
9614
        *audio="audio",
9615
        *blink="blink",
9616
        *arrowhead="arrowhead",
9617
        *crosshairsize="crosshairsize",
9618
        *crosshair="crosshair",
9619
        *crosshairs="crosshairs",
9620
        *audioobject="audioobject",
9621
        *style="style",
9622
        *mouse="mouse",
7991 schaersvoo 9623
        *mousex="mousex",
9624
        *mousey="mousey",
8071 schaersvoo 9625
        *mouse_display="display",
9626
        *mouse_degree="mouse_degree",
7614 schaersvoo 9627
        *userdraw="userdraw",
9628
        *highlight="highlight",
9629
        *http="http",
9630
        *rays="rays",
9631
        *dashtype="dashtype",
9632
        *dashed="dashed",
9633
        *filled="filled",
9634
        *lattice="lattice",
9635
        *parallel="parallel",
9636
        *segment="segment",
8299 schaersvoo 9637
        *segments="segments",
7614 schaersvoo 9638
        *dsegment="dsegment",
9374 schaersvoo 9639
        *dsegments="dsegments",
7614 schaersvoo 9640
        *seg="seg",
9383 schaersvoo 9641
        *segs="segs",
7614 schaersvoo 9642
        *bgimage="bgimage",
9643
        *bgcolor="bgcolor",
9644
        *strokecolor="strokecolor",
9645
        *backgroundimage="backgroundimage",
9646
        *text="text",
9647
        *textup="textup",
9648
        *mouseprecision="mouseprecision",
9649
        *precision="precision",
9650
        *plotsteps="plotsteps",
9651
        *plotstep="plotstep",
9652
        *tsteps="tsteps",
9653
        *curve="curve",
9654
        *dcurve="dcurve",
14038 schaersvoo 9655
        *curvedarrow="curvedarrow",
9656
        *curvedarrows="curvedarrows",
9657
        *curvedarrow2="curvedarrow2",
9658
        *curvedarrows2="curvedarrows2",
7614 schaersvoo 9659
        *plot="plot",
9660
        *dplot="dplot",
7788 schaersvoo 9661
        *levelcurve="levelcurve",
7614 schaersvoo 9662
        *fontsize="fontsize",
9663
        *fontcolor="fontcolor",
9664
        *axis="axis",
9665
        *axisnumbering="axisnumbering",
9666
        *axisnumbers="axisnumbers",
9667
        *arrow="arrow",
9382 schaersvoo 9668
        *vector="vector",
9669
        *vectors="vectors",
7614 schaersvoo 9670
        *darrow="darrow",
9671
        *arrow2="arrow2",
9672
        *darrow2="darrow2",
8304 schaersvoo 9673
        *arrows="arrows",
8347 schaersvoo 9674
        *arrows2="arrows2",
7614 schaersvoo 9675
        *zoom="zoom",
9676
        *grid="grid",
9677
        *hline="hline",
7786 schaersvoo 9678
        *dhline="dhline",
7614 schaersvoo 9679
        *drag="drag",
9680
        *horizontalline="horizontalline",
9383 schaersvoo 9681
        *horizontallines="horizontallines",
7614 schaersvoo 9682
        *vline="vline",
7786 schaersvoo 9683
        *dvline="dvline",
7614 schaersvoo 9684
        *verticalline="verticalline",
9383 schaersvoo 9685
        *verticallines="verticallines",
7614 schaersvoo 9686
        *triangle="triangle",
9306 schaersvoo 9687
        *triangles="triangles",
7614 schaersvoo 9688
        *ftriangle="ftriangle",
9374 schaersvoo 9689
        *ftriangles="ftriangles",
7614 schaersvoo 9690
        *mathml="mathml",
9691
        *html="html",
9692
        *input="input",
8146 schaersvoo 9693
        *clearbutton="clearbutton",
9386 schaersvoo 9694
        *erase="erase",
9695
        *delete="delete",
7614 schaersvoo 9696
        *inputstyle="inputstyle",
9697
        *textarea="textarea",
9698
        *trange="trange",
9699
        *ranget="ranget",
9700
        *xrange="xrange",
9701
        *yrange="yrange",
9702
        *rangex="rangex",
9703
        *rangey="rangey",
8370 schaersvoo 9704
        *path="path",
7614 schaersvoo 9705
        *polyline="polyline",
8351 schaersvoo 9706
        *brokenline="brokenline",
7614 schaersvoo 9707
        *lines="lines",
9708
        *poly="poly",
9709
        *polygon="polygon",
9710
        *fpolygon="fpolygon",
9711
        *fpoly="fpoly",
9712
        *filledpoly="filledpoly",
9713
        *filledpolygon="filledpolygon",
9714
        *rect="rect",
9715
        *frect="frect",
9716
        *rectangle="rectangle",
9717
        *frectangle="frectangle",
9718
        *square="square",
9719
        *fsquare="fsquare",
9374 schaersvoo 9720
        *fsquares="fsquares",
8363 schaersvoo 9721
        *rects="rects",
9722
        *frects="frects",
7614 schaersvoo 9723
        *dline="dline",
9724
        *arc="arc",
9725
        *filledarc="filledarc",
9374 schaersvoo 9726
        *farc="farc",
7614 schaersvoo 9727
        *size="size",
9728
        *string="string",
9729
        *stringup="stringup",
9730
        *copy="copy",
9731
        *copyresized="copyresized",
9732
        *opacity="opacity",
9733
        *transparent="transparent",
9734
        *fill="fill",
9735
        *point="point",
9736
        *points="points",
9737
        *linewidth="linewidth",
9738
        *circle="circle",
8304 schaersvoo 9739
        *circles="circles",
7614 schaersvoo 9740
        *fcircle="fcircle",
9374 schaersvoo 9741
        *fcircles="fcircles",
7614 schaersvoo 9742
        *disk="disk",
9374 schaersvoo 9743
        *disks="disks",
7614 schaersvoo 9744
        *comment="#",
9745
        *end="end",
9746
        *ellipse="ellipse",
12110 schaersvoo 9747
        *ellipses="ellipses",
7614 schaersvoo 9748
        *fellipse="fellipse",
9749
        *rotate="rotate",
7785 schaersvoo 9750
        *affine="affine",
9907 schaersvoo 9751
        *rotationcenter="rotationcenter",
9752
        *killrotate="killrotate",
7785 schaersvoo 9753
        *killaffine="killaffine",
7614 schaersvoo 9754
        *fontfamily="fontfamily",
9755
        *fillcolor="fillcolor",
9756
        *clicktile="clicktile",
9757
        *clicktile_colors="clicktile_colors",
9758
        *translation="translation",
9759
        *translate="translate",
9760
        *killtranslation="killtranslation",
9761
        *killtranslate="killtranslate",
9762
        *onclick="onclick",
8370 schaersvoo 9763
        *roundrects="roundrects",
7614 schaersvoo 9764
        *roundrect="roundrect",
9765
        *froundrect="froundrect",
9374 schaersvoo 9766
        *froundrects="froundrects",
7614 schaersvoo 9767
        *roundrectangle="roundrectangle",
9768
        *patternfill="patternfill",
9769
        *hatchfill="hatchfill",
9770
        *diafill="diafill",
7647 schaersvoo 9771
        *diamondfill="diamondfill",
7614 schaersvoo 9772
        *dotfill="dotfill",
11830 schaersvoo 9773
        *textfill="textfill",
7614 schaersvoo 9774
        *gridfill="gridfill",
9775
        *imagefill="imagefill",
7735 schaersvoo 9776
        *xlogbase="xlogbase",
9777
        *ylogbase="ylogbase",
7614 schaersvoo 9778
        *xlogscale="xlogscale",
9779
        *ylogscale="ylogscale",
9780
        *xylogscale="xylogscale",
9781
        *intooltip="intooltip",
9329 schaersvoo 9782
        *popup="popup",
7614 schaersvoo 9783
        *replyformat="replyformat",
9784
        *floodfill="floodfill",
11772 schaersvoo 9785
        *fillall="fillall",
7614 schaersvoo 9786
        *filltoborder="filltoborder",
9787
        *setpixel="setpixel",
9788
        *pixels="pixels",
9789
        *pixelsize="pixelsize",
9790
        *xaxis="xaxis",
9341 schaersvoo 9791
        *xaxisup="xaxisup",
7614 schaersvoo 9792
        *yaxis="yaxis",
9793
        *xaxistext="xaxistext",
9341 schaersvoo 9794
        *xaxistextup="xaxistextup",
7614 schaersvoo 9795
        *yaxistext="yaxistext",
9796
        *piechart="piechart",
9433 schaersvoo 9797
        *boxplot="boxplot",
9465 schaersvoo 9798
        *boxplotdata="boxplotdata",
9799
        *userboxplot="userboxplot",
9800
        *userboxplotdata="userboxplotdata",
7614 schaersvoo 9801
        *legend="legend",
9802
        *legendcolors="legendcolors",
9803
        *xlabel="xlabel",
9804
        *ylabel="ylabel",
9805
        *barchart="barchart",
9806
        *linegraph="linegraph",
9807
        *clock="clock",
9808
        *animate="animate",
9809
        *video="video",
9810
        *status="status",
7877 schaersvoo 9811
        *nostatus="nostatus",
7652 schaersvoo 9812
        *snaptogrid="snaptogrid",
7784 schaersvoo 9813
        *xsnaptogrid="xsnaptogrid",
9814
        *ysnaptogrid="ysnaptogrid",
8379 schaersvoo 9815
        *snaptopoints="snaptopoints",
9213 schaersvoo 9816
        *snaptofunction="snaptofunction",
9817
        *snaptofun="snaptofun",
7654 schaersvoo 9818
        *userinput_xy="userinput_xy",
8193 schaersvoo 9819
        *userinput_function="userinput_function",
7663 schaersvoo 9820
        *usertextarea_xy="usertextarea_xy",
8222 schaersvoo 9821
        *userinput="userinput",
7823 schaersvoo 9822
        *jsmath="jsmath",
7858 schaersvoo 9823
        *trace_jscurve="trace_jscurve",
7838 schaersvoo 9824
        *setlimits="setlimits",
7858 schaersvoo 9825
        *jscurve="jscurve",
9826
        *jsplot="jsplot",
7983 schaersvoo 9827
        *sgraph="sgraph",
7984 schaersvoo 9828
        *title="title",
7996 schaersvoo 9829
        *centerstring="centerstring",
9830
        *xunit="xunit",
8071 schaersvoo 9831
        *yunit="yunit",
8101 schaersvoo 9832
        *slider="slider",
8105 schaersvoo 9833
        *killslider="killslider",
8244 schaersvoo 9834
        *angle="angle",
8365 schaersvoo 9835
        *halflines="halflines",
9836
        *demilines="demilines",
8244 schaersvoo 9837
        *halfline="halfline",
8297 schaersvoo 9838
        *demiline="demiline",
8366 schaersvoo 9839
        *hlines="hlines",
9840
        *vlines="vlines",
8370 schaersvoo 9841
        *bezier="bezier",
9213 schaersvoo 9842
        *functionlabel="functionlabel",
9843
        *sliderfunction_x="sliderfunction_x",
9844
        *sliderfunction_y="sliderfunction_y",
9845
        *multidraw="multidraw",
9846
        *multilinewidth="multilinewidth",
9847
        *multistrokecolors="multistrokecolors",
9848
        *multifillcolors="multifillcolors",
9849
        *multistrokeopacity="multistrokeopacity",
9850
        *multifillopacity="multifillopacity",
9851
        *multifill="multifill",
9852
        *multidash="multidash",
9853
        *multilabel="multilabel",
9854
        *multiuserinput="multiuserinput",
14038 schaersvoo 9855
        *multiinput="multiinput",
9289 schaersvoo 9856
        *multisnaptogrid="multisnaptogrid",
14038 schaersvoo 9857
        *multisnap="multisnap",
9289 schaersvoo 9858
        *protractor="protractor",
9386 schaersvoo 9859
        *ruler="ruler",
9860
        *cursor="cursor",
9427 schaersvoo 9861
        *pointer="pointer",
9862
        *yerrorbars="yerrorbars",
11006 schaersvoo 9863
        *xerrorbars="xerrorbars",
11044 schaersvoo 9864
        *noxaxis="noxaxis",
9865
        *noyaxis="noyaxis",
11767 schaersvoo 9866
        *colorpalette="colorpalette",
14038 schaersvoo 9867
        *imagepalette="imagepalette",
12063 schaersvoo 9868
        *yoffset="yoffset",
11802 schaersvoo 9869
        *xoffset="xoffset",
14225 schaersvoo 9870
        *latex="latex",
11802 schaersvoo 9871
        *centered="centered",
9872
        *xyoffset="xyoffset",
9873
        *resetoffset="resetoffset",
11837 schaersvoo 9874
        *fillpattern="fillpattern",
11890 schaersvoo 9875
        *numberline="numberline",
11006 schaersvoo 9876
        *canvastype="canvastype";
7614 schaersvoo 9877
 
10891 schaersvoo 9878
        while(((c = getc(infile)) != EOF)&&(c!='\n')&&(c!=',')&&(c!='=')&&(c!='\r')&&(c!='\t')){
9879
         if( i == 0 && (c == ' ') ){ continue; /* white spaces or tabs allowed before first command identifier */
9880
         }else{
9881
          if( c == ' ' ){
7614 schaersvoo 9882
            break;
10891 schaersvoo 9883
          }else{
9884
           temp[i] = c;
9885
           if(i > MAX_INT - 2){canvas_error("command string too long !");}
9886
           i++;
9887
          }
9888
         }
9889
         if(temp[0] == '#'){ break; }
7614 schaersvoo 9890
        }
10891 schaersvoo 9891
        if (c == '\n' || c == '\r' || c == '\t' ){  line_number++; }
9892
        if (c == EOF) {finished=1;return 0;}
7614 schaersvoo 9893
 
9894
        temp[i]='\0';
9895
        input_type=(char*)my_newmem(strlen(temp));
9896
        snprintf(input_type,sizeof(temp),"%s",temp);
10891 schaersvoo 9897
/* fprintf(stdout,"temp = %s <br/>",input_type); */
7614 schaersvoo 9898
        if( strcmp(input_type, size) == 0 ){
9899
        free(input_type);
9900
        return SIZE;
9901
        }
9902
        if( strcmp(input_type, xrange) == 0 ){
9903
        free(input_type);
9904
        return XRANGE;
9905
        }
9906
        if( strcmp(input_type, rangex) == 0 ){
9907
        free(input_type);
9908
        return XRANGE;
9909
        }
9910
        if( strcmp(input_type, trange) == 0 ){
9911
        free(input_type);
9912
        return TRANGE;
9913
        }
9914
        if( strcmp(input_type, ranget) == 0 ){
9915
        free(input_type);
9916
        return TRANGE;
9917
        }
9918
        if( strcmp(input_type, yrange) == 0 ){
9919
        free(input_type);
9920
        return YRANGE;
9921
        }
9922
        if( strcmp(input_type, rangey) == 0 ){
9923
        free(input_type);
9924
        return YRANGE;
9925
        }
9926
        if( strcmp(input_type, linewidth) == 0 ){
9927
        free(input_type);
9928
        return LINEWIDTH;
9929
        }
9930
        if( strcmp(input_type, dashed) == 0 ){
9931
        free(input_type);
9932
        return DASHED;
9933
        }
9934
        if( strcmp(input_type, dashtype) == 0 ){
9935
        free(input_type);
9936
        return DASHTYPE;
9937
        }
9938
        if( strcmp(input_type, axisnumbering) == 0 ){
9939
        free(input_type);
9940
        return AXIS_NUMBERING;
9941
        }
9942
        if( strcmp(input_type, axisnumbers) == 0 ){
9943
        free(input_type);
9944
        return AXIS_NUMBERING;
9945
        }
9946
        if( strcmp(input_type, axis) == 0 ){
9947
        free(input_type);
9948
        return AXIS;
9949
        }
9950
        if( strcmp(input_type, grid) == 0 ){
9951
        free(input_type);
9952
        return GRID;
9953
        }
9383 schaersvoo 9954
        if( strcmp(input_type, hlines) == 0 || strcmp(input_type, horizontallines) == 0 ){
8366 schaersvoo 9955
        free(input_type);
9956
        return HLINES;
9957
        }
9383 schaersvoo 9958
        if( strcmp(input_type, vlines) == 0 ||  strcmp(input_type, verticallines) == 0 ){
8366 schaersvoo 9959
        free(input_type);
9960
        return VLINES;
9961
        }
9383 schaersvoo 9962
        if( strcmp(input_type, hline) == 0 || strcmp(input_type, horizontalline) == 0 ){
7614 schaersvoo 9963
        free(input_type);
9964
        return HLINE;
9965
        }
9966
        if( strcmp(input_type, vline) == 0 ||  strcmp(input_type, verticalline) == 0 ){
9967
        free(input_type);
9968
        return VLINE;
9969
        }
9970
        if( strcmp(input_type, line) == 0 ){
9971
        free(input_type);
9972
        return LINE;
9973
        }
9383 schaersvoo 9974
        if( strcmp(input_type, segments) == 0 || strcmp(input_type, segs) == 0 ){
8299 schaersvoo 9975
        free(input_type);
9976
        return SEGMENTS;
9977
        }
7614 schaersvoo 9978
        if( strcmp(input_type, seg) == 0 ||  strcmp(input_type, segment) == 0 ){
9979
        free(input_type);
9980
        return SEGMENT;
9981
        }
9374 schaersvoo 9982
        if( strcmp(input_type, dsegments) == 0 ){
9983
        free(input_type);
9984
        use_dashed = TRUE;
9985
        return SEGMENTS;
9986
        }
7614 schaersvoo 9987
        if( strcmp(input_type, dsegment) == 0 ){
9988
        free(input_type);
9989
        use_dashed = TRUE;
9990
        return SEGMENT;
9991
        }
9992
        if( strcmp(input_type, crosshairsize) == 0 ){
9993
        free(input_type);
9994
        return CROSSHAIRSIZE;
9995
        }
9996
        if( strcmp(input_type, arrowhead) == 0 ){
9997
        free(input_type);
9998
        return ARROWHEAD;
9999
        }
10000
        if( strcmp(input_type, crosshairs) == 0 ){
10001
        free(input_type);
10002
        return CROSSHAIRS;
10003
        }
10004
        if( strcmp(input_type, crosshair) == 0 ){
10005
        free(input_type);
10006
        return CROSSHAIR;
10007
        }
10008
        if( strcmp(input_type, onclick) == 0 ){
10009
        free(input_type);
10010
        return ONCLICK;
10011
        }
10012
        if( strcmp(input_type, drag) == 0 ){
10013
        free(input_type);
10014
        return DRAG;
10015
        }
10016
        if( strcmp(input_type, userdraw) == 0 ){
10017
        free(input_type);
10018
        return USERDRAW;
10019
        }
10020
        if( strcmp(input_type, highlight) == 0 || strcmp(input_type, style) == 0 ){
10021
        free(input_type);
10022
        return STYLE;
10023
        }
10024
        if( strcmp(input_type, fillcolor) == 0 ){
10025
        free(input_type);
10026
        return FILLCOLOR;
10027
        }
10028
        if( strcmp(input_type, strokecolor) == 0 ){
10029
        free(input_type);
10030
        return STROKECOLOR;
10031
        }
10032
        if( strcmp(input_type, filled) == 0  ){
10033
        free(input_type);
10034
        return FILLED;
10035
        }
10036
        if( strcmp(input_type, http) == 0 ){
10037
        free(input_type);
10038
        return HTTP;
10039
        }
10040
        if( strcmp(input_type, rays) == 0 ){
10041
        free(input_type);
10042
        return RAYS;
10043
        }
10044
        if( strcmp(input_type, lattice) == 0 ){
10045
        free(input_type);
10046
        return LATTICE;
10047
        }
10048
        if( strcmp(input_type, bgimage) == 0 ){
10049
        free(input_type);
10050
        return BGIMAGE;
10051
        }
10052
        if( strcmp(input_type, bgcolor) == 0 ){
10053
        free(input_type);
10054
        return BGCOLOR;
10055
        }
10056
        if( strcmp(input_type, backgroundimage) == 0 ){
10057
        free(input_type);
10058
        return BGIMAGE;
10059
        }
10060
        if( strcmp(input_type, text) == 0 ){
10061
        free(input_type);
10062
        return FLY_TEXT;
10063
        }
10064
        if( strcmp(input_type, textup) == 0 ){
10065
        free(input_type);
10066
        return FLY_TEXTUP;
10067
        }
10068
        if( strcmp(input_type, mouse) == 0 ){
10069
        free(input_type);
10070
        return MOUSE;
10071
        }
7991 schaersvoo 10072
        if( strcmp(input_type, mousex) == 0 ){
10073
        free(input_type);
10074
        return MOUSEX;
10075
        }
10076
        if( strcmp(input_type, mousey) == 0 ){
10077
        free(input_type);
10078
        return MOUSEY;
10079
        }
8071 schaersvoo 10080
        if( strcmp(input_type, mouse_degree) == 0 ){
10081
        free(input_type);
10082
        return MOUSE_DEGREE;
10083
        }
10084
        if( strcmp(input_type, mouse_display) == 0 ){
10085
        free(input_type);
10086
        return MOUSE_DISPLAY;
10087
        }
7614 schaersvoo 10088
        if( strcmp(input_type, mouseprecision) == 0 ){
10089
        free(input_type);
10090
        return MOUSE_PRECISION;
10091
        }
10092
        if( strcmp(input_type, precision) == 0 ){
10093
        free(input_type);
10094
        return MOUSE_PRECISION;
10095
        }
10096
        if( strcmp(input_type, curve) == 0 ){
10097
        free(input_type);
10098
        return CURVE;
10099
        }
10100
        if( strcmp(input_type, dcurve) == 0 ){
7788 schaersvoo 10101
        use_dashed = TRUE;
7614 schaersvoo 10102
        free(input_type);
10103
        return CURVE;
10104
        }
10105
        if( strcmp(input_type, plot) == 0 ){
10106
        free(input_type);
10107
        return CURVE;
10108
        }
10109
        if( strcmp(input_type, dplot) == 0 ){
7788 schaersvoo 10110
        use_dashed = TRUE;
7614 schaersvoo 10111
        free(input_type);
10112
        return CURVE;
10113
        }
7788 schaersvoo 10114
        if( strcmp(input_type, levelcurve) == 0 ){
10115
        free(input_type);
10116
        return LEVELCURVE;
10117
        }
7614 schaersvoo 10118
        if( strcmp(input_type, plotsteps) == 0 ){
10119
        free(input_type);
10120
        return PLOTSTEPS;
10121
        }
10122
        if( strcmp(input_type, plotstep) == 0 ){
10123
        free(input_type);
10124
        return PLOTSTEPS;
10125
        }
10126
        if( strcmp(input_type, tsteps) == 0 ){
10127
        free(input_type);
10128
        return PLOTSTEPS;
10129
        }
10130
        if( strcmp(input_type, fontsize) == 0 ){
10131
        free(input_type);
10132
        return FONTSIZE;
10133
        }
10134
        if( strcmp(input_type, fontcolor) == 0 ){
10135
        free(input_type);
10136
        return FONTCOLOR;
10137
        }
10138
        if( strcmp(input_type, arrow2) == 0 ){
10139
        free(input_type);
10140
        return ARROW2;
10141
        }
10142
        if( strcmp(input_type, darrow) == 0 ){
10143
        free(input_type);
8071 schaersvoo 10144
        use_dashed = TRUE;
7614 schaersvoo 10145
        return ARROW;
10146
        }
10147
        if( strcmp(input_type, darrow2) == 0 ){
10148
        free(input_type);
10149
        use_dashed = TRUE;
10150
        return ARROW2;
10151
        }
8347 schaersvoo 10152
        if( strcmp(input_type, arrows2) == 0 ){
10153
        free(input_type);
10154
        return ARROWS2;
10155
        }
9382 schaersvoo 10156
        if( strcmp(input_type, arrows) == 0  || strcmp(input_type, vectors) == 0 ){
8304 schaersvoo 10157
        free(input_type);
10158
        return ARROWS;
10159
        }
9382 schaersvoo 10160
        if( strcmp(input_type, arrow) == 0 ||  strcmp(input_type, vector) == 0 ){
8304 schaersvoo 10161
        free(input_type);
10162
        return ARROW;
10163
        }
7614 schaersvoo 10164
        if( strcmp(input_type, zoom) == 0 ){
10165
        free(input_type);
10166
        return ZOOM;
10167
        }
10168
        if( strcmp(input_type, triangle) == 0 ){
10169
        free(input_type);
10170
        return TRIANGLE;
10171
        }
9306 schaersvoo 10172
        if( strcmp(input_type, triangles) == 0 ){
10173
        free(input_type);
10174
        return TRIANGLES;
10175
        }
9374 schaersvoo 10176
        if( strcmp(input_type, ftriangles) == 0 ){
10177
        free(input_type);
10178
        use_filled = TRUE;
10179
        return TRIANGLES;
10180
        }
7614 schaersvoo 10181
        if( strcmp(input_type, ftriangle) == 0 ){
10182
        free(input_type);
10183
        use_filled = TRUE;
10184
        return TRIANGLE;
10185
        }
10186
        if( strcmp(input_type, input) == 0 ){
10187
        free(input_type);
10188
        return INPUT;
10189
        }
10190
        if( strcmp(input_type, inputstyle) == 0 ){
10191
        free(input_type);
10192
        return INPUTSTYLE;
10193
        }
10194
        if( strcmp(input_type, textarea) == 0 ){
10195
        free(input_type);
10196
        return TEXTAREA;
10197
        }
10198
        if( strcmp(input_type, mathml) == 0 ){
10199
        free(input_type);
10200
        return MATHML;
10201
        }
10202
        if( strcmp(input_type, html) == 0 ){
10203
        free(input_type);
10204
        return MATHML;
10205
        }
10206
        if( strcmp(input_type, fontfamily) == 0 ){
10207
        free(input_type);
10208
        return FONTFAMILY;
10209
        }
10975 schaersvoo 10210
        if( strcmp(input_type, polyline) == 0 ||  strcmp(input_type, path) == 0 || strcmp(input_type, brokenline) == 0 ){
7614 schaersvoo 10211
        free(input_type);
10212
        return POLYLINE;
10213
        }
8351 schaersvoo 10214
        if( strcmp(input_type, lines) == 0 ){
10215
        free(input_type);
10216
        return LINES;
10217
        }
9374 schaersvoo 10218
        if( strcmp(input_type, rects) == 0){
8363 schaersvoo 10219
        free(input_type);
10220
        return RECTS;
10221
        }
9383 schaersvoo 10222
        if( strcmp(input_type, frects) == 0 ){
8363 schaersvoo 10223
        free(input_type);
9374 schaersvoo 10224
        use_filled = TRUE;
8363 schaersvoo 10225
        return RECTS;
10226
        }
7614 schaersvoo 10227
        if( strcmp(input_type, rect) == 0  ||  strcmp(input_type, rectangle) == 0 ){
10228
        free(input_type);
10229
        return RECT;
10230
        }
9374 schaersvoo 10231
        if( strcmp(input_type, square) == 0 ){
10232
        free(input_type);
11991 schaersvoo 10233
        return SQUARE;
9374 schaersvoo 10234
        }
10235
        if( strcmp(input_type, fsquare) == 0 ){
10236
        free(input_type);
10237
        use_filled = TRUE;
10238
        return SQUARE;
10239
        }
10240
        if( strcmp(input_type, fsquares) == 0 ){
10241
        free(input_type);
10242
        use_filled = TRUE;
10243
        return RECTS;
10244
        }
8370 schaersvoo 10245
        if( strcmp(input_type, roundrects) == 0 ){
10246
        free(input_type);
10247
        return ROUNDRECTS;
10248
        }
7614 schaersvoo 10249
        if( strcmp(input_type, roundrect) == 0  ||  strcmp(input_type, roundrectangle) == 0 ){
10250
        free(input_type);
10251
        return ROUNDRECT;
10252
        }
9374 schaersvoo 10253
        if( strcmp(input_type, froundrects) == 0 ){
7614 schaersvoo 10254
        free(input_type);
10255
        use_filled = TRUE;
9374 schaersvoo 10256
        return ROUNDRECTS;
7614 schaersvoo 10257
        }
9374 schaersvoo 10258
        if( strcmp(input_type, froundrect) == 0 ){
7614 schaersvoo 10259
        free(input_type);
10260
        use_filled = TRUE;
9374 schaersvoo 10261
        return ROUNDRECT;
7614 schaersvoo 10262
        }
10263
        if( strcmp(input_type, dline) == 0 ){
10264
        use_dashed = TRUE;
10265
        free(input_type);
10266
        return LINE;
10267
        }
7786 schaersvoo 10268
        if( strcmp(input_type, dvline) == 0 ){
10269
        use_dashed = TRUE;
10270
        free(input_type);
10271
        return VLINE;
10272
        }
10273
        if( strcmp(input_type, dhline) == 0 ){
10274
        use_dashed = TRUE;
10275
        free(input_type);
10276
        return HLINE;
10277
        }
9386 schaersvoo 10278
        if( strcmp(input_type, halflines) == 0 || strcmp(input_type, demilines) == 0  ){
10279
        free(input_type);
10280
        return HALFLINES;
10281
        }
10282
        if( strcmp(input_type, halfline) == 0 || strcmp(input_type, demiline) == 0  ){
10283
        free(input_type);
10284
        return HALFLINE;
10285
        }
7614 schaersvoo 10286
        if( strcmp(input_type, frect) == 0 || strcmp(input_type, frectangle) == 0 ){
10287
        use_filled = TRUE;
10288
        free(input_type);
10289
        return RECT;
10290
        }
8304 schaersvoo 10291
        if( strcmp(input_type, circles) == 0 ){
10292
        free(input_type);
10293
        return CIRCLES;
10294
        }
7614 schaersvoo 10295
        if( strcmp(input_type, fcircle) == 0  ||  strcmp(input_type, disk) == 0 ){
10296
        use_filled = TRUE;
10297
        free(input_type);
10298
        return CIRCLE;
10299
        }
9374 schaersvoo 10300
        if( strcmp(input_type, fcircles) == 0  ||  strcmp(input_type, disks) == 0 ){
10301
        use_filled = TRUE;
10302
        free(input_type);
10303
        return CIRCLES;
10304
        }
7614 schaersvoo 10305
        if( strcmp(input_type, circle) == 0 ){
10306
        free(input_type);
10307
        return CIRCLE;
10308
        }
10309
        if( strcmp(input_type, point) == 0 ){
10310
        free(input_type);
10311
        return POINT;
10312
        }
10313
        if( strcmp(input_type, points) == 0 ){
10314
        free(input_type);
10315
        return POINTS;
10316
        }
9374 schaersvoo 10317
        if( strcmp(input_type, filledarc) == 0 || strcmp(input_type, farc) == 0 ){
7614 schaersvoo 10318
        use_filled = TRUE;
10319
        free(input_type);
10320
        return ARC;
10321
        }
10322
        if( strcmp(input_type, arc) == 0 ){
10323
        free(input_type);
10324
        return ARC;
10325
        }
10326
        if( strcmp(input_type, poly) == 0 ||  strcmp(input_type, polygon) == 0 ){
10327
        free(input_type);
10328
        return POLY;
10329
        }
10330
        if( strcmp(input_type, fpoly) == 0 ||  strcmp(input_type, filledpoly) == 0 || strcmp(input_type,filledpolygon) == 0  || strcmp(input_type,fpolygon) == 0  ){
10331
        use_filled = TRUE;
10332
        free(input_type);
10333
        return POLY;
10334
        }
10335
        if( strcmp(input_type, ellipse) == 0){
10336
        free(input_type);
10337
        return ELLIPSE;
10338
        }
12110 schaersvoo 10339
        if( strcmp(input_type, ellipses) == 0){
10340
        free(input_type);
10341
        return ELLIPSES;
10342
        }
7614 schaersvoo 10343
        if( strcmp(input_type, string) == 0 ){
10344
        free(input_type);
10345
        return STRING;
10346
        }
10347
        if( strcmp(input_type, stringup) == 0 ){
10348
        free(input_type);
10349
        return STRINGUP;
10350
        }
9385 schaersvoo 10351
        if( strcmp(input_type, opacity) == 0 || strcmp(input_type, transparent) == 0 ){
7614 schaersvoo 10352
        free(input_type);
10353
        return OPACITY;
10354
        }
10355
        if( strcmp(input_type, comment) == 0){
10356
        free(input_type);
10357
        return COMMENT;
10358
        }
10359
        if( strcmp(input_type, fellipse) == 0){
10360
        free(input_type);
10361
        use_filled = TRUE;
10362
        return ELLIPSE;
8224 bpr 10363
        }
9386 schaersvoo 10364
        if( strcmp(input_type, clearbutton) == 0 || strcmp(input_type, erase) == 0 || strcmp(input_type, delete) == 0){
7614 schaersvoo 10365
        free(input_type);
8146 schaersvoo 10366
        return CLEARBUTTON;
7614 schaersvoo 10367
        }
10368
        if( strcmp(input_type, translation) == 0 ||  strcmp(input_type, translate) == 0  ){
10369
        free(input_type);
10370
        return TRANSLATION;
10371
        }
10372
        if( strcmp(input_type, killtranslation) == 0 ||  strcmp(input_type, killtranslate) == 0){
10373
        free(input_type);
10374
        return KILLTRANSLATION;
10375
        }
10376
        if( strcmp(input_type, rotate) == 0){
10377
        free(input_type);
10378
        return ROTATE;
10379
        }
9907 schaersvoo 10380
        if( strcmp(input_type, killrotate) == 0){
10381
        free(input_type);
10382
        return KILLROTATE;
10383
        }
10384
        if( strcmp(input_type, rotationcenter) == 0){
10385
        free(input_type);
10386
        return ROTATION_CENTER;
10387
        }
7785 schaersvoo 10388
        if( strcmp(input_type, affine) == 0){
10389
        free(input_type);
10390
        return AFFINE;
10391
        }
10392
        if( strcmp(input_type, killaffine) == 0){
10393
        free(input_type);
10394
        return KILLAFFINE;
10395
        }
7614 schaersvoo 10396
        if( strcmp(input_type, slider) == 0 ){
10397
        free(input_type);
10398
        return SLIDER;
10399
        }
8101 schaersvoo 10400
        if( strcmp(input_type, killslider) == 0 ){
10401
        free(input_type);
10402
        return KILLSLIDER;
10403
        }
7614 schaersvoo 10404
        if( strcmp(input_type, copy) == 0 ){
10405
        free(input_type);
10406
        return COPY;
10407
        }
10408
        if( strcmp(input_type, copyresized) == 0 ){
10409
        free(input_type);
10410
        return COPYRESIZED;
10411
        }
10412
        if( strcmp(input_type, xlogscale) == 0 ){
10413
        free(input_type);
10414
        return XLOGSCALE;
10415
        }
10416
        if( strcmp(input_type, ylogscale) == 0 ){
10417
        free(input_type);
10418
        return YLOGSCALE;
10419
        }
10420
        if( strcmp(input_type, xylogscale) == 0 ){
10421
        free(input_type);
10422
        return XYLOGSCALE;
10423
        }
10424
        if( strcmp(input_type, ylogscale) == 0 ){
10425
        free(input_type);
10426
        return YLOGSCALE;
10427
        }
7735 schaersvoo 10428
        if( strcmp(input_type, xlogbase) == 0 ){
7614 schaersvoo 10429
        free(input_type);
7735 schaersvoo 10430
        return XLOGBASE;
7614 schaersvoo 10431
        }
7735 schaersvoo 10432
        if( strcmp(input_type, ylogbase) == 0 ){
10433
        free(input_type);
10434
        return YLOGBASE;
10435
        }
7614 schaersvoo 10436
        if( strcmp(input_type, intooltip) == 0 ){
10437
        free(input_type);
10438
        return INTOOLTIP;
10439
        }
9329 schaersvoo 10440
        if( strcmp(input_type, popup) == 0 ){
10441
        free(input_type);
10442
        return POPUP;
10443
        }
7614 schaersvoo 10444
        if( strcmp(input_type,video) == 0 ){
10445
        free(input_type);
10446
        return VIDEO;
10447
        }
14225 schaersvoo 10448
        if( strcmp(input_type,latex) == 0 ){
10449
        free(input_type);
10450
        return LATEX;
10451
        }
11772 schaersvoo 10452
        if( strcmp(input_type,fillall) == 0 ){
10453
        free(input_type);
10454
        return FILLALL;
10455
        }
7614 schaersvoo 10456
        if( strcmp(input_type,floodfill) == 0 || strcmp(input_type,fill) == 0 ){
10457
        free(input_type);
10458
        return FLOODFILL;
8224 bpr 10459
        }
7614 schaersvoo 10460
        if( strcmp(input_type,filltoborder) == 0 ){
10461
        free(input_type);
10462
        return FILLTOBORDER;
8224 bpr 10463
        }
14038 schaersvoo 10464
        if( strcmp(input_type, curvedarrow2) == 0 ){
10465
        free(input_type);
10466
        return CURVEDARROW2;
10467
        }
10468
        if( strcmp(input_type, curvedarrow) == 0 ){
10469
        free(input_type);
10470
        return CURVEDARROW;
10471
        }
10472
        if( strcmp(input_type, curvedarrows) == 0 ){
10473
        free(input_type);
10474
        return CURVEDARROWS;
10475
        }
10476
        if( strcmp(input_type, curvedarrows2) == 0 ){
10477
        free(input_type);
10478
        return CURVEDARROWS2;
10479
        }
7614 schaersvoo 10480
        if( strcmp(input_type, replyformat) == 0 ){
10481
        free(input_type);
10482
        return REPLYFORMAT;
10483
        }
10484
        if( strcmp(input_type, pixelsize) == 0 ){
10485
        free(input_type);
10486
        return PIXELSIZE;
10487
        }
10488
        if( strcmp(input_type, setpixel) == 0 ){
10489
        free(input_type);
10490
        return SETPIXEL;
10491
        }
10492
        if( strcmp(input_type, pixels) == 0 ){
10493
        free(input_type);
10494
        return PIXELS;
10495
        }
10496
        if( strcmp(input_type, xaxis) == 0 || strcmp(input_type, xaxistext) == 0 ){
10497
        free(input_type);
10498
        return X_AXIS_STRINGS;
10499
        }
9341 schaersvoo 10500
        if( strcmp(input_type, xaxisup) == 0 || strcmp(input_type, xaxistextup) == 0 ){
10501
        free(input_type);
10502
        return X_AXIS_STRINGS_UP;
10503
        }
7614 schaersvoo 10504
        if( strcmp(input_type, yaxis) == 0  ||  strcmp(input_type, yaxistext) == 0 ){
10505
        free(input_type);
10506
        return Y_AXIS_STRINGS;
10507
        }
10508
        if( strcmp(input_type, legend) == 0  ){
10509
        free(input_type);
10510
        return LEGEND;
10511
        }
10512
        if( strcmp(input_type, legendcolors) == 0  ){
10513
        free(input_type);
10514
        return LEGENDCOLORS;
10515
        }
10516
        if( strcmp(input_type, xlabel) == 0  ){
10517
        free(input_type);
10518
        return XLABEL;
10519
        }
10520
        if( strcmp(input_type, ylabel) == 0  ){
10521
        free(input_type);
10522
        return YLABEL;
10523
        }
8370 schaersvoo 10524
        if( strcmp(input_type, bezier) == 0  ){
10525
        free(input_type);
10526
        return BEZIER;
10527
        }
7614 schaersvoo 10528
        if( strcmp(input_type, animate) == 0  ){
10529
        free(input_type);
10530
        return ANIMATE;
10531
        }
9354 schaersvoo 10532
        /* these are bitmap related flydraw commands...must be removed. eventually */
7614 schaersvoo 10533
        if( strcmp(input_type, transparent) == 0 ){
10534
        free(input_type);
10535
        return TRANSPARENT;
10536
        }
7877 schaersvoo 10537
        if( strcmp(input_type, status) == 0 || strcmp(input_type, nostatus) == 0 ){
7614 schaersvoo 10538
        free(input_type);
10539
        return STATUS;
10540
        }
7784 schaersvoo 10541
        if( strcmp(input_type, xsnaptogrid) == 0 ){
10542
        free(input_type);
10543
        return XSNAPTOGRID;
10544
        }
10545
        if( strcmp(input_type, ysnaptogrid) == 0 ){
10546
        free(input_type);
10547
        return YSNAPTOGRID;
10548
        }
8379 schaersvoo 10549
        if( strcmp(input_type, snaptogrid) == 0 ){
10550
        free(input_type);
10551
        return SNAPTOGRID;
10552
        }
10553
        if( strcmp(input_type, snaptopoints) == 0 ){
10554
        free(input_type);
10555
        return SNAPTOPOINTS;
10556
        }
9213 schaersvoo 10557
        if( strcmp(input_type, snaptofunction) == 0  || strcmp(input_type, snaptofun) == 0 ){
10558
        free(input_type);
10559
        return SNAPTOFUNCTION;
10560
        }
7652 schaersvoo 10561
        if( strcmp(input_type, userinput_xy) == 0 ){
7614 schaersvoo 10562
        free(input_type);
7652 schaersvoo 10563
        return USERINPUT_XY;
10564
        }
8193 schaersvoo 10565
        if( strcmp(input_type, userinput_function) == 0 ){
10566
        free(input_type);
10567
        return USERINPUT_FUNCTION;
10568
        }
7663 schaersvoo 10569
        if( strcmp(input_type, usertextarea_xy) == 0 ){
10570
        free(input_type);
10571
        return USERTEXTAREA_XY;
10572
        }
8222 schaersvoo 10573
        if( strcmp(input_type, userinput) == 0 ){
10574
        free(input_type);
10575
        return USERINPUT;
10576
        }
8105 schaersvoo 10577
        if( strcmp(input_type, angle) == 0 ){
7996 schaersvoo 10578
        free(input_type);
8105 schaersvoo 10579
        return ANGLE;
10580
        }
8297 schaersvoo 10581
        if( strcmp(input_type, functionlabel) == 0 ){
8244 schaersvoo 10582
        free(input_type);
8297 schaersvoo 10583
        return FUNCTION_LABEL;
10584
        }
9213 schaersvoo 10585
        if( strcmp(input_type, sliderfunction_x) == 0 ){
8297 schaersvoo 10586
        free(input_type);
9213 schaersvoo 10587
        return SLIDER_X;
10588
        }
10589
        if( strcmp(input_type, sliderfunction_y) == 0 ){
10590
        free(input_type);
10591
        return SLIDER_Y;
10592
        }
10593
        if( strcmp(input_type, multidraw) == 0 ){
10594
        free(input_type);
10595
        return MULTIDRAW;
10596
        }
10597
        if( strcmp(input_type, multistrokeopacity) == 0 ){
10598
        free(input_type);
10599
        return MULTISTROKEOPACITY;
10600
        }
10601
        if( strcmp(input_type, multifillopacity) == 0 ){
10602
        free(input_type);
10603
        return MULTIFILLOPACITY;
10604
        }
10605
        if( strcmp(input_type, multilinewidth) == 0 ){
10606
        free(input_type);
10607
        return MULTILINEWIDTH;
10608
        }
10609
        if( strcmp(input_type, multistrokecolors) == 0 ){
10610
        free(input_type);
10611
        return MULTISTROKECOLORS;
10612
        }
10613
        if( strcmp(input_type, multifill) == 0 ){
10614
        free(input_type);
10615
        return MULTIFILL;
10616
        }
10617
        if( strcmp(input_type, multifillcolors) == 0 ){
10618
        free(input_type);
10619
        return MULTIFILLCOLORS;
10620
        }
10621
        if( strcmp(input_type, multilabel) == 0 ){
10622
        free(input_type);
10623
        return MULTILABEL;
10624
        }
10625
        if( strcmp(input_type, multidash) == 0 ){
10626
        free(input_type);
10627
        return MULTIDASH;
10628
        }
14038 schaersvoo 10629
        if( strcmp(input_type, multisnaptogrid) == 0  ||  strcmp(input_type, multisnap) == 0 ){
9213 schaersvoo 10630
        free(input_type);
10631
        return MULTISNAPTOGRID;
10632
        }
14038 schaersvoo 10633
        if( strcmp(input_type, multiuserinput) == 0 || strcmp(input_type, multiinput) == 0  ){
9213 schaersvoo 10634
        free(input_type);
10635
        return MULTIUSERINPUT;
10636
        }
9386 schaersvoo 10637
        if( strcmp(input_type, parallel) == 0 ){
10638
        free(input_type);
10639
        return PARALLEL;
10640
        }
9289 schaersvoo 10641
        if( strcmp(input_type, protractor) == 0 ){
10642
        free(input_type);
10643
        return PROTRACTOR;
10644
        }
10645
        if( strcmp(input_type, ruler) == 0 ){
10646
        free(input_type);
10647
        return RULER;
10648
        }
9386 schaersvoo 10649
        if( strcmp(input_type, cursor) == 0 ||  strcmp(input_type, pointer) == 0 ){
9213 schaersvoo 10650
        free(input_type);
9386 schaersvoo 10651
        return CURSOR;
10652
        }
10653
        if( strcmp(input_type, sgraph) == 0 ){
10654
        free(input_type);
10655
        return SGRAPH;
10656
        }
10657
        if( strcmp(input_type, jsmath) == 0 ){
10658
        free(input_type);
10659
        return JSMATH;
10660
        }
10661
        if( strcmp(input_type, trace_jscurve) == 0 ){
10662
        free(input_type);
10663
        return TRACE_JSCURVE;
10664
        }
10665
        if( strcmp(input_type, jscurve) == 0  ||  strcmp(input_type, jsplot) == 0 ){
10666
        free(input_type);
10667
        return JSCURVE;
10668
        }
10669
        if( strcmp(input_type, centerstring) == 0 || strcmp(input_type, title) == 0 ){
10670
        free(input_type);
10671
        return CENTERSTRING;
10672
        }
10673
        if( strcmp(input_type, setlimits) == 0 ){
10674
        free(input_type);
10675
        return SETLIMITS;
10676
        }
10677
        if( strcmp(input_type, xunit) == 0 ){
10678
        free(input_type);
10679
        return XUNIT;
10680
        }
10681
        if( strcmp(input_type, yunit) == 0 ){
10682
        free(input_type);
10683
        return YUNIT;
10684
        }
10685
        if( strcmp(input_type, fill) == 0 ){
10686
        free(input_type);
10687
        return FLOODFILL;
10688
        }
10689
        if( strcmp(input_type, end) == 0){
10690
        free(input_type);
10691
        return END;
10692
        }
10693
        if( strcmp(input_type, blink) == 0 ){
10694
        free(input_type);
10695
        return BLINK;
10696
        }
10697
        if( strcmp(input_type, audio) == 0 ){
10698
        free(input_type);
10699
        return AUDIO;
10700
        }
10701
        if( strcmp(input_type, audioobject) == 0 ){
10702
        free(input_type);
10703
        return AUDIOOBJECT;
10704
        }
10705
        if( strcmp(input_type, patternfill) == 0 ){
10706
        free(input_type);
10707
        return PATTERNFILL;
10708
        }
10709
        if( strcmp(input_type, hatchfill) == 0 ){
10710
        free(input_type);
10711
        return HATCHFILL;
10712
        }
10713
        if( strcmp(input_type, diafill) == 0  || strcmp(input_type, diamondfill) == 0  ){
10714
        free(input_type);
10715
        return DIAMONDFILL;
10716
        }
10717
        if( strcmp(input_type, dotfill) == 0 ){
10718
        free(input_type);
10719
        return DOTFILL;
10720
        }
11830 schaersvoo 10721
        if( strcmp(input_type, textfill) == 0 ){
10722
        free(input_type);
10723
        return TEXTFILL;
10724
        }
9386 schaersvoo 10725
        if( strcmp(input_type, gridfill) == 0 ){
10726
        free(input_type);
10727
        return GRIDFILL;
10728
        }
10729
        if( strcmp(input_type, imagefill) == 0 ){
10730
        free(input_type);
10731
        return IMAGEFILL;
10732
        }
10733
        if( strcmp(input_type, clicktile_colors) == 0 ){
10734
        free(input_type);
10735
        return CLICKTILE_COLORS;
10736
        }
10737
        if( strcmp(input_type, clicktile) == 0 ){
10738
        free(input_type);
10739
        return CLICKTILE;
10740
        }
10741
        if( strcmp(input_type, piechart) == 0  ){
10742
        free(input_type);
10743
        return PIECHART;
10744
        }
9433 schaersvoo 10745
        if( strcmp(input_type, boxplot) == 0  ){
10746
        free(input_type);
10747
        return BOXPLOT;
10748
        }
9465 schaersvoo 10749
        if( strcmp(input_type, boxplotdata) == 0  ){
9433 schaersvoo 10750
        free(input_type);
9465 schaersvoo 10751
        return BOXPLOTDATA;
9433 schaersvoo 10752
        }
9465 schaersvoo 10753
        if( strcmp(input_type, userboxplot) == 0  ){
10754
        free(input_type);
10755
        return USERBOXPLOT;
10756
        }
10757
        if( strcmp(input_type, userboxplotdata) == 0  ){
10758
        free(input_type);
10759
        return USERBOXPLOT;
10760
        }
9386 schaersvoo 10761
        if( strcmp(input_type, barchart) == 0  ){
10762
        free(input_type);
10763
        return BARCHART;
10764
        }
10765
        if( strcmp(input_type, linegraph) == 0  ){
10766
        free(input_type);
10767
        return LINEGRAPH;
10768
        }
10769
        if( strcmp(input_type, clock) == 0  ){
10770
        free(input_type);
10771
        return CLOCK;
10772
        }
9427 schaersvoo 10773
        if( strcmp(input_type, yerrorbars) == 0  ){
9386 schaersvoo 10774
        free(input_type);
9427 schaersvoo 10775
        return YERRORBARS;
10776
        }
10777
        if( strcmp(input_type, xerrorbars) == 0  ){
10778
        free(input_type);
10779
        return XERRORBARS;
10780
        }
11006 schaersvoo 10781
        if( strcmp(input_type, canvastype) == 0  ){
9427 schaersvoo 10782
        free(input_type);
11006 schaersvoo 10783
        return CANVASTYPE;
10784
        }
11044 schaersvoo 10785
        if( strcmp(input_type, noyaxis) == 0  ){
11006 schaersvoo 10786
        free(input_type);
11044 schaersvoo 10787
        return NOYAXIS;
10788
        }
10789
        if( strcmp(input_type, noxaxis) == 0  ){
10790
        free(input_type);
10791
        return NOXAXIS;
10792
        }
11767 schaersvoo 10793
        if( strcmp(input_type, colorpalette) == 0  ){
11044 schaersvoo 10794
        free(input_type);
11767 schaersvoo 10795
        return COLORPALETTE;
10796
        }
14038 schaersvoo 10797
        if( strcmp(input_type, imagepalette) == 0  ){
10798
        free(input_type);
10799
        return IMAGEPALETTE;
10800
        }
11802 schaersvoo 10801
        if( strcmp(input_type, resetoffset) == 0  ){
11767 schaersvoo 10802
        free(input_type);
11802 schaersvoo 10803
        return RESETOFFSET;
10804
        }
10805
        if( strcmp(input_type, xyoffset) == 0  ){
10806
        free(input_type);
10807
        return XYOFFSET;
10808
        }
12063 schaersvoo 10809
        if( strcmp(input_type, centered) == 0 ){
11802 schaersvoo 10810
        free(input_type);
12063 schaersvoo 10811
        return CENTERED;
11802 schaersvoo 10812
        }
12063 schaersvoo 10813
        if( strcmp(input_type, yoffset) == 0   ){
11802 schaersvoo 10814
        free(input_type);
11811 schaersvoo 10815
        return YOFFSET;
10816
        }
12063 schaersvoo 10817
        if( strcmp(input_type, xoffset) == 0   ){
10818
        free(input_type);
10819
        return XOFFSET;
10820
        }
11837 schaersvoo 10821
        if( strcmp(input_type, fillpattern) == 0 ){
11811 schaersvoo 10822
        free(input_type);
11837 schaersvoo 10823
        return FILLPATTERN;
10824
        }
11890 schaersvoo 10825
        if( strcmp(input_type, numberline) == 0 ){
11837 schaersvoo 10826
        free(input_type);
11890 schaersvoo 10827
        return NUMBERLINE;
10828
        }
10829
        free(input_type);
7614 schaersvoo 10830
        ungetc(c,infile);
10831
        return 0;
10832
}
14038 schaersvoo 10833
 
10834
 
10835
 
10836
 
10837
 
10838
 
10839
 
10840
 
10841
 
10842
 
10843
 
10844
 
10845
 
14208 schaersvoo 10846